OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/websockets/websocket_stream.h" | 5 #include "net/websockets/websocket_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // deterministic key to use in the WebSocket handshake. | 92 // deterministic key to use in the WebSocket handshake. |
93 class DeterministicKeyWebSocketHandshakeStreamCreateHelper | 93 class DeterministicKeyWebSocketHandshakeStreamCreateHelper |
94 : public WebSocketHandshakeStreamCreateHelper { | 94 : public WebSocketHandshakeStreamCreateHelper { |
95 public: | 95 public: |
96 DeterministicKeyWebSocketHandshakeStreamCreateHelper( | 96 DeterministicKeyWebSocketHandshakeStreamCreateHelper( |
97 WebSocketStream::ConnectDelegate* connect_delegate, | 97 WebSocketStream::ConnectDelegate* connect_delegate, |
98 const std::vector<std::string>& requested_subprotocols) | 98 const std::vector<std::string>& requested_subprotocols) |
99 : WebSocketHandshakeStreamCreateHelper(connect_delegate, | 99 : WebSocketHandshakeStreamCreateHelper(connect_delegate, |
100 requested_subprotocols) {} | 100 requested_subprotocols) {} |
101 | 101 |
102 virtual void OnStreamCreated(WebSocketBasicHandshakeStream* stream) OVERRIDE { | 102 virtual void OnStreamCreated(WebSocketBasicHandshakeStream* stream) override { |
103 stream->SetWebSocketKeyForTesting("dGhlIHNhbXBsZSBub25jZQ=="); | 103 stream->SetWebSocketKeyForTesting("dGhlIHNhbXBsZSBub25jZQ=="); |
104 } | 104 } |
105 }; | 105 }; |
106 | 106 |
107 class WebSocketStreamCreateTest : public ::testing::Test { | 107 class WebSocketStreamCreateTest : public ::testing::Test { |
108 public: | 108 public: |
109 WebSocketStreamCreateTest() : has_failed_(false), ssl_fatal_(false) {} | 109 WebSocketStreamCreateTest() : has_failed_(false), ssl_fatal_(false) {} |
110 | 110 |
111 void CreateAndConnectCustomResponse( | 111 void CreateAndConnectCustomResponse( |
112 const std::string& socket_url, | 112 const std::string& socket_url, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 194 } |
195 | 195 |
196 const std::string& failure_message() const { return failure_message_; } | 196 const std::string& failure_message() const { return failure_message_; } |
197 bool has_failed() const { return has_failed_; } | 197 bool has_failed() const { return has_failed_; } |
198 | 198 |
199 class TestConnectDelegate : public WebSocketStream::ConnectDelegate { | 199 class TestConnectDelegate : public WebSocketStream::ConnectDelegate { |
200 public: | 200 public: |
201 explicit TestConnectDelegate(WebSocketStreamCreateTest* owner) | 201 explicit TestConnectDelegate(WebSocketStreamCreateTest* owner) |
202 : owner_(owner) {} | 202 : owner_(owner) {} |
203 | 203 |
204 virtual void OnSuccess(scoped_ptr<WebSocketStream> stream) OVERRIDE { | 204 virtual void OnSuccess(scoped_ptr<WebSocketStream> stream) override { |
205 stream.swap(owner_->stream_); | 205 stream.swap(owner_->stream_); |
206 } | 206 } |
207 | 207 |
208 virtual void OnFailure(const std::string& message) OVERRIDE { | 208 virtual void OnFailure(const std::string& message) override { |
209 owner_->has_failed_ = true; | 209 owner_->has_failed_ = true; |
210 owner_->failure_message_ = message; | 210 owner_->failure_message_ = message; |
211 } | 211 } |
212 | 212 |
213 virtual void OnStartOpeningHandshake( | 213 virtual void OnStartOpeningHandshake( |
214 scoped_ptr<WebSocketHandshakeRequestInfo> request) OVERRIDE { | 214 scoped_ptr<WebSocketHandshakeRequestInfo> request) override { |
215 // Can be called multiple times (in the case of HTTP auth). Last call | 215 // Can be called multiple times (in the case of HTTP auth). Last call |
216 // wins. | 216 // wins. |
217 owner_->request_info_ = request.Pass(); | 217 owner_->request_info_ = request.Pass(); |
218 } | 218 } |
219 virtual void OnFinishOpeningHandshake( | 219 virtual void OnFinishOpeningHandshake( |
220 scoped_ptr<WebSocketHandshakeResponseInfo> response) OVERRIDE { | 220 scoped_ptr<WebSocketHandshakeResponseInfo> response) override { |
221 if (owner_->response_info_) | 221 if (owner_->response_info_) |
222 ADD_FAILURE(); | 222 ADD_FAILURE(); |
223 owner_->response_info_ = response.Pass(); | 223 owner_->response_info_ = response.Pass(); |
224 } | 224 } |
225 virtual void OnSSLCertificateError( | 225 virtual void OnSSLCertificateError( |
226 scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> | 226 scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> |
227 ssl_error_callbacks, | 227 ssl_error_callbacks, |
228 const SSLInfo& ssl_info, | 228 const SSLInfo& ssl_info, |
229 bool fatal) OVERRIDE { | 229 bool fatal) override { |
230 owner_->ssl_error_callbacks_ = ssl_error_callbacks.Pass(); | 230 owner_->ssl_error_callbacks_ = ssl_error_callbacks.Pass(); |
231 owner_->ssl_info_ = ssl_info; | 231 owner_->ssl_info_ = ssl_info; |
232 owner_->ssl_fatal_ = fatal; | 232 owner_->ssl_fatal_ = fatal; |
233 } | 233 } |
234 | 234 |
235 private: | 235 private: |
236 WebSocketStreamCreateTest* owner_; | 236 WebSocketStreamCreateTest* owner_; |
237 }; | 237 }; |
238 | 238 |
239 WebSocketTestURLRequestContextHost url_request_context_host_; | 239 WebSocketTestURLRequestContextHost url_request_context_host_; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 public: | 401 public: |
402 // This enum should match with the enum in Delegate in websocket_stream.cc. | 402 // This enum should match with the enum in Delegate in websocket_stream.cc. |
403 enum HandshakeResult { | 403 enum HandshakeResult { |
404 INCOMPLETE, | 404 INCOMPLETE, |
405 CONNECTED, | 405 CONNECTED, |
406 FAILED, | 406 FAILED, |
407 NUM_HANDSHAKE_RESULT_TYPES, | 407 NUM_HANDSHAKE_RESULT_TYPES, |
408 }; | 408 }; |
409 | 409 |
410 class StreamCreation : public WebSocketStreamCreateTest { | 410 class StreamCreation : public WebSocketStreamCreateTest { |
411 virtual void TestBody() OVERRIDE {} | 411 virtual void TestBody() override {} |
412 }; | 412 }; |
413 | 413 |
414 scoped_ptr<base::HistogramSamples> GetSamples(const std::string& name) { | 414 scoped_ptr<base::HistogramSamples> GetSamples(const std::string& name) { |
415 base::HistogramBase* histogram = | 415 base::HistogramBase* histogram = |
416 base::StatisticsRecorder::FindHistogram(name); | 416 base::StatisticsRecorder::FindHistogram(name); |
417 return histogram ? histogram->SnapshotSamples() | 417 return histogram ? histogram->SnapshotSamples() |
418 : scoped_ptr<base::HistogramSamples>(); | 418 : scoped_ptr<base::HistogramSamples>(); |
419 } | 419 } |
420 }; | 420 }; |
421 | 421 |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 if (original) { | 1445 if (original) { |
1446 samples->Subtract(*original); // Cancel the original values. | 1446 samples->Subtract(*original); // Cancel the original values. |
1447 } | 1447 } |
1448 EXPECT_EQ(1, samples->GetCount(INCOMPLETE)); | 1448 EXPECT_EQ(1, samples->GetCount(INCOMPLETE)); |
1449 EXPECT_EQ(0, samples->GetCount(CONNECTED)); | 1449 EXPECT_EQ(0, samples->GetCount(CONNECTED)); |
1450 EXPECT_EQ(0, samples->GetCount(FAILED)); | 1450 EXPECT_EQ(0, samples->GetCount(FAILED)); |
1451 } | 1451 } |
1452 | 1452 |
1453 } // namespace | 1453 } // namespace |
1454 } // namespace net | 1454 } // namespace net |
OLD | NEW |