| 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_test_util.h" | 5 #include "net/websockets/websocket_test_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_vector.h" |
| 11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "net/socket/socket_test_util.h" | 14 #include "net/socket/socket_test_util.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 const uint64 kA = | 19 const uint64 kA = |
| 19 (static_cast<uint64>(0x5851f42d) << 32) + static_cast<uint64>(0x4c957f2d); | 20 (static_cast<uint64>(0x5851f42d) << 32) + static_cast<uint64>(0x4c957f2d); |
| 20 const uint64 kC = 12345; | 21 const uint64 kC = 12345; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" | 66 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" |
| 66 "%s\r\n", | 67 "%s\r\n", |
| 67 extra_headers.c_str()); | 68 extra_headers.c_str()); |
| 68 } | 69 } |
| 69 | 70 |
| 70 struct WebSocketDeterministicMockClientSocketFactoryMaker::Detail { | 71 struct WebSocketDeterministicMockClientSocketFactoryMaker::Detail { |
| 71 std::string expect_written; | 72 std::string expect_written; |
| 72 std::string return_to_read; | 73 std::string return_to_read; |
| 73 std::vector<MockRead> reads; | 74 std::vector<MockRead> reads; |
| 74 MockWrite write; | 75 MockWrite write; |
| 75 scoped_ptr<DeterministicSocketData> data; | 76 ScopedVector<DeterministicSocketData> socket_data_vector; |
| 77 ScopedVector<SSLSocketDataProvider> ssl_socket_data_vector; |
| 76 DeterministicMockClientSocketFactory factory; | 78 DeterministicMockClientSocketFactory factory; |
| 77 }; | 79 }; |
| 78 | 80 |
| 79 WebSocketDeterministicMockClientSocketFactoryMaker:: | 81 WebSocketDeterministicMockClientSocketFactoryMaker:: |
| 80 WebSocketDeterministicMockClientSocketFactoryMaker() | 82 WebSocketDeterministicMockClientSocketFactoryMaker() |
| 81 : detail_(new Detail) {} | 83 : detail_(new Detail) {} |
| 82 | 84 |
| 83 WebSocketDeterministicMockClientSocketFactoryMaker:: | 85 WebSocketDeterministicMockClientSocketFactoryMaker:: |
| 84 ~WebSocketDeterministicMockClientSocketFactoryMaker() {} | 86 ~WebSocketDeterministicMockClientSocketFactoryMaker() {} |
| 85 | 87 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 110 kHttpStreamParserBufferSize), | 112 kHttpStreamParserBufferSize), |
| 111 sequence++)); | 113 sequence++)); |
| 112 } | 114 } |
| 113 scoped_ptr<DeterministicSocketData> socket_data( | 115 scoped_ptr<DeterministicSocketData> socket_data( |
| 114 new DeterministicSocketData(vector_as_array(&detail_->reads), | 116 new DeterministicSocketData(vector_as_array(&detail_->reads), |
| 115 detail_->reads.size(), | 117 detail_->reads.size(), |
| 116 &detail_->write, | 118 &detail_->write, |
| 117 1)); | 119 1)); |
| 118 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 120 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 119 socket_data->SetStop(sequence); | 121 socket_data->SetStop(sequence); |
| 120 SetRawExpectations(socket_data.Pass()); | 122 AddRawExpectations(socket_data.Pass()); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void WebSocketDeterministicMockClientSocketFactoryMaker::SetRawExpectations( | 125 void WebSocketDeterministicMockClientSocketFactoryMaker::AddRawExpectations( |
| 124 scoped_ptr<DeterministicSocketData> socket_data) { | 126 scoped_ptr<DeterministicSocketData> socket_data) { |
| 125 detail_->data = socket_data.Pass(); | 127 detail_->factory.AddSocketDataProvider(socket_data.get()); |
| 126 detail_->factory.AddSocketDataProvider(detail_->data.get()); | 128 detail_->socket_data_vector.push_back(socket_data.release()); |
| 129 } |
| 130 |
| 131 void |
| 132 WebSocketDeterministicMockClientSocketFactoryMaker::AddSSLSocketDataProvider( |
| 133 scoped_ptr<SSLSocketDataProvider> ssl_socket_data) { |
| 134 detail_->factory.AddSSLSocketDataProvider(ssl_socket_data.get()); |
| 135 detail_->ssl_socket_data_vector.push_back(ssl_socket_data.release()); |
| 127 } | 136 } |
| 128 | 137 |
| 129 WebSocketTestURLRequestContextHost::WebSocketTestURLRequestContextHost() | 138 WebSocketTestURLRequestContextHost::WebSocketTestURLRequestContextHost() |
| 130 : url_request_context_(true) { | 139 : url_request_context_(true) { |
| 131 url_request_context_.set_client_socket_factory(maker_.factory()); | 140 url_request_context_.set_client_socket_factory(maker_.factory()); |
| 132 } | 141 } |
| 133 | 142 |
| 134 WebSocketTestURLRequestContextHost::~WebSocketTestURLRequestContextHost() {} | 143 WebSocketTestURLRequestContextHost::~WebSocketTestURLRequestContextHost() {} |
| 135 | 144 |
| 136 void WebSocketTestURLRequestContextHost::SetRawExpectations( | 145 void WebSocketTestURLRequestContextHost::AddRawExpectations( |
| 137 scoped_ptr<DeterministicSocketData> socket_data) { | 146 scoped_ptr<DeterministicSocketData> socket_data) { |
| 138 maker_.SetRawExpectations(socket_data.Pass()); | 147 maker_.AddRawExpectations(socket_data.Pass()); |
| 148 } |
| 149 |
| 150 void WebSocketTestURLRequestContextHost::AddSSLSocketDataProvider( |
| 151 scoped_ptr<SSLSocketDataProvider> ssl_socket_data) { |
| 152 maker_.AddSSLSocketDataProvider(ssl_socket_data.Pass()); |
| 139 } | 153 } |
| 140 | 154 |
| 141 TestURLRequestContext* | 155 TestURLRequestContext* |
| 142 WebSocketTestURLRequestContextHost::GetURLRequestContext() { | 156 WebSocketTestURLRequestContextHost::GetURLRequestContext() { |
| 143 url_request_context_.Init(); | 157 url_request_context_.Init(); |
| 144 // A Network Delegate is required to make the URLRequest::Delegate work. | 158 // A Network Delegate is required to make the URLRequest::Delegate work. |
| 145 url_request_context_.set_network_delegate(&network_delegate_); | 159 url_request_context_.set_network_delegate(&network_delegate_); |
| 146 return &url_request_context_; | 160 return &url_request_context_; |
| 147 } | 161 } |
| 148 | 162 |
| 149 } // namespace net | 163 } // namespace net |
| OLD | NEW |