| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_create_test_base.h" | 5 #include "net/websockets/websocket_stream_create_test_base.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/callback.h" | 9 #include "base/callback.h" |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "net/http/http_request_headers.h" | 11 #include "net/http/http_request_headers.h" |
| 10 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
| 11 #include "net/websockets/websocket_basic_handshake_stream.h" | 13 #include "net/websockets/websocket_basic_handshake_stream.h" |
| 12 #include "net/websockets/websocket_handshake_request_info.h" | 14 #include "net/websockets/websocket_handshake_request_info.h" |
| 13 #include "net/websockets/websocket_handshake_response_info.h" | 15 #include "net/websockets/websocket_handshake_response_info.h" |
| 14 #include "net/websockets/websocket_handshake_stream_create_helper.h" | 16 #include "net/websockets/websocket_handshake_stream_create_helper.h" |
| 15 #include "net/websockets/websocket_stream.h" | 17 #include "net/websockets/websocket_stream.h" |
| 16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 void OnFailure(const std::string& message) override { | 57 void OnFailure(const std::string& message) override { |
| 56 owner_->has_failed_ = true; | 58 owner_->has_failed_ = true; |
| 57 owner_->failure_message_ = message; | 59 owner_->failure_message_ = message; |
| 58 done_callback_.Run(); | 60 done_callback_.Run(); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void OnStartOpeningHandshake( | 63 void OnStartOpeningHandshake( |
| 62 scoped_ptr<WebSocketHandshakeRequestInfo> request) override { | 64 scoped_ptr<WebSocketHandshakeRequestInfo> request) override { |
| 63 // Can be called multiple times (in the case of HTTP auth). Last call | 65 // Can be called multiple times (in the case of HTTP auth). Last call |
| 64 // wins. | 66 // wins. |
| 65 owner_->request_info_ = request.Pass(); | 67 owner_->request_info_ = std::move(request); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void OnFinishOpeningHandshake( | 70 void OnFinishOpeningHandshake( |
| 69 scoped_ptr<WebSocketHandshakeResponseInfo> response) override { | 71 scoped_ptr<WebSocketHandshakeResponseInfo> response) override { |
| 70 if (owner_->response_info_) | 72 if (owner_->response_info_) |
| 71 ADD_FAILURE(); | 73 ADD_FAILURE(); |
| 72 owner_->response_info_ = response.Pass(); | 74 owner_->response_info_ = std::move(response); |
| 73 } | 75 } |
| 74 | 76 |
| 75 void OnSSLCertificateError( | 77 void OnSSLCertificateError( |
| 76 scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> | 78 scoped_ptr<WebSocketEventInterface::SSLErrorCallbacks> |
| 77 ssl_error_callbacks, | 79 ssl_error_callbacks, |
| 78 const SSLInfo& ssl_info, | 80 const SSLInfo& ssl_info, |
| 79 bool fatal) override { | 81 bool fatal) override { |
| 80 owner_->ssl_error_callbacks_ = ssl_error_callbacks.Pass(); | 82 owner_->ssl_error_callbacks_ = std::move(ssl_error_callbacks); |
| 81 owner_->ssl_info_ = ssl_info; | 83 owner_->ssl_info_ = ssl_info; |
| 82 owner_->ssl_fatal_ = fatal; | 84 owner_->ssl_fatal_ = fatal; |
| 83 } | 85 } |
| 84 | 86 |
| 85 private: | 87 private: |
| 86 WebSocketStreamCreateTestBase* owner_; | 88 WebSocketStreamCreateTestBase* owner_; |
| 87 base::Closure done_callback_; | 89 base::Closure done_callback_; |
| 88 DISALLOW_COPY_AND_ASSIGN(TestConnectDelegate); | 90 DISALLOW_COPY_AND_ASSIGN(TestConnectDelegate); |
| 89 }; | 91 }; |
| 90 | 92 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 url_request_context_host_.AddSSLSocketDataProvider(std::move(ssl_data_[i])); | 106 url_request_context_host_.AddSSLSocketDataProvider(std::move(ssl_data_[i])); |
| 105 } | 107 } |
| 106 ssl_data_.clear(); | 108 ssl_data_.clear(); |
| 107 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate( | 109 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate( |
| 108 new TestConnectDelegate(this, connect_run_loop_.QuitClosure())); | 110 new TestConnectDelegate(this, connect_run_loop_.QuitClosure())); |
| 109 WebSocketStream::ConnectDelegate* delegate = connect_delegate.get(); | 111 WebSocketStream::ConnectDelegate* delegate = connect_delegate.get(); |
| 110 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( | 112 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( |
| 111 new DeterministicKeyWebSocketHandshakeStreamCreateHelper(delegate, | 113 new DeterministicKeyWebSocketHandshakeStreamCreateHelper(delegate, |
| 112 sub_protocols)); | 114 sub_protocols)); |
| 113 stream_request_ = CreateAndConnectStreamForTesting( | 115 stream_request_ = CreateAndConnectStreamForTesting( |
| 114 GURL(socket_url), create_helper.Pass(), origin, | 116 GURL(socket_url), std::move(create_helper), origin, |
| 115 url_request_context_host_.GetURLRequestContext(), BoundNetLog(), | 117 url_request_context_host_.GetURLRequestContext(), BoundNetLog(), |
| 116 connect_delegate.Pass(), | 118 std::move(connect_delegate), |
| 117 timer ? timer.Pass() | 119 timer ? std::move(timer) |
| 118 : scoped_ptr<base::Timer>(new base::Timer(false, false))); | 120 : scoped_ptr<base::Timer>(new base::Timer(false, false))); |
| 119 } | 121 } |
| 120 | 122 |
| 121 std::vector<HeaderKeyValuePair> | 123 std::vector<HeaderKeyValuePair> |
| 122 WebSocketStreamCreateTestBase::RequestHeadersToVector( | 124 WebSocketStreamCreateTestBase::RequestHeadersToVector( |
| 123 const HttpRequestHeaders& headers) { | 125 const HttpRequestHeaders& headers) { |
| 124 HttpRequestHeaders::Iterator it(headers); | 126 HttpRequestHeaders::Iterator it(headers); |
| 125 std::vector<HeaderKeyValuePair> result; | 127 std::vector<HeaderKeyValuePair> result; |
| 126 while (it.GetNext()) | 128 while (it.GetNext()) |
| 127 result.push_back(HeaderKeyValuePair(it.name(), it.value())); | 129 result.push_back(HeaderKeyValuePair(it.name(), it.value())); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 141 | 143 |
| 142 void WebSocketStreamCreateTestBase::WaitUntilConnectDone() { | 144 void WebSocketStreamCreateTestBase::WaitUntilConnectDone() { |
| 143 connect_run_loop_.Run(); | 145 connect_run_loop_.Run(); |
| 144 } | 146 } |
| 145 | 147 |
| 146 std::vector<std::string> WebSocketStreamCreateTestBase::NoSubProtocols() { | 148 std::vector<std::string> WebSocketStreamCreateTestBase::NoSubProtocols() { |
| 147 return std::vector<std::string>(); | 149 return std::vector<std::string>(); |
| 148 } | 150 } |
| 149 | 151 |
| 150 } // namespace net | 152 } // namespace net |
| OLD | NEW |