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_handshake_stream_create_helper.h" | 5 #include "net/websockets/websocket_handshake_stream_create_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 pool_(1, 1, &histograms_, socket_factory_maker_.factory()) {} | 32 pool_(1, 1, &histograms_, socket_factory_maker_.factory()) {} |
33 | 33 |
34 // The created socket expects |expect_written| to be written to the socket, | 34 // The created socket expects |expect_written| to be written to the socket, |
35 // and will respond with |return_to_read|. The test will fail if the expected | 35 // and will respond with |return_to_read|. The test will fail if the expected |
36 // text is not written, or if all the bytes are not read. | 36 // text is not written, or if all the bytes are not read. |
37 scoped_ptr<ClientSocketHandle> CreateClientSocketHandle( | 37 scoped_ptr<ClientSocketHandle> CreateClientSocketHandle( |
38 const std::string& expect_written, | 38 const std::string& expect_written, |
39 const std::string& return_to_read) { | 39 const std::string& return_to_read) { |
40 socket_factory_maker_.SetExpectations(expect_written, return_to_read); | 40 socket_factory_maker_.SetExpectations(expect_written, return_to_read); |
41 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle); | 41 scoped_ptr<ClientSocketHandle> socket_handle(new ClientSocketHandle); |
42 socket_handle->Init( | 42 socket_handle->Init("a", |
43 "a", | 43 scoped_refptr<MockTransportSocketParams>(), |
44 scoped_refptr<MockTransportSocketParams>(), | 44 MEDIUM, |
45 MEDIUM, | 45 CompletionCallback(), |
46 CompletionCallback(), | 46 &pool_, |
47 &pool_, | 47 BoundNetLog()); |
48 BoundNetLog()); | |
49 return socket_handle.Pass(); | 48 return socket_handle.Pass(); |
50 } | 49 } |
51 | 50 |
52 private: | 51 private: |
53 WebSocketDeterministicMockClientSocketFactoryMaker socket_factory_maker_; | 52 WebSocketDeterministicMockClientSocketFactoryMaker socket_factory_maker_; |
54 ClientSocketPoolHistograms histograms_; | 53 ClientSocketPoolHistograms histograms_; |
55 MockTransportClientSocketPool pool_; | 54 MockTransportClientSocketPool pool_; |
56 | 55 |
57 DISALLOW_COPY_AND_ASSIGN(MockClientSocketHandleFactory); | 56 DISALLOW_COPY_AND_ASSIGN(MockClientSocketHandleFactory); |
58 }; | 57 }; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 return handshake->Upgrade(); | 130 return handshake->Upgrade(); |
132 } | 131 } |
133 | 132 |
134 MockClientSocketHandleFactory socket_handle_factory_; | 133 MockClientSocketHandleFactory socket_handle_factory_; |
135 TestConnectDelegate connect_delegate_; | 134 TestConnectDelegate connect_delegate_; |
136 }; | 135 }; |
137 | 136 |
138 // Confirm that the basic case works as expected. | 137 // Confirm that the basic case works as expected. |
139 TEST_F(WebSocketHandshakeStreamCreateHelperTest, BasicStream) { | 138 TEST_F(WebSocketHandshakeStreamCreateHelperTest, BasicStream) { |
140 scoped_ptr<WebSocketStream> stream = | 139 scoped_ptr<WebSocketStream> stream = |
141 CreateAndInitializeStream("ws://localhost/", "/", | 140 CreateAndInitializeStream("ws://localhost/", |
142 std::vector<std::string>(), "http://localhost/", | 141 "/", |
143 "", ""); | 142 std::vector<std::string>(), |
| 143 "http://localhost/", |
| 144 "", |
| 145 ""); |
144 EXPECT_EQ("", stream->GetExtensions()); | 146 EXPECT_EQ("", stream->GetExtensions()); |
145 EXPECT_EQ("", stream->GetSubProtocol()); | 147 EXPECT_EQ("", stream->GetSubProtocol()); |
146 } | 148 } |
147 | 149 |
148 // Verify that the sub-protocols are passed through. | 150 // Verify that the sub-protocols are passed through. |
149 TEST_F(WebSocketHandshakeStreamCreateHelperTest, SubProtocols) { | 151 TEST_F(WebSocketHandshakeStreamCreateHelperTest, SubProtocols) { |
150 std::vector<std::string> sub_protocols; | 152 std::vector<std::string> sub_protocols; |
151 sub_protocols.push_back("chat"); | 153 sub_protocols.push_back("chat"); |
152 sub_protocols.push_back("superchat"); | 154 sub_protocols.push_back("superchat"); |
153 scoped_ptr<WebSocketStream> stream = | 155 scoped_ptr<WebSocketStream> stream = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 190 |
189 EXPECT_EQ( | 191 EXPECT_EQ( |
190 "permessage-deflate;" | 192 "permessage-deflate;" |
191 " client_max_window_bits=14; server_max_window_bits=14;" | 193 " client_max_window_bits=14; server_max_window_bits=14;" |
192 " server_no_context_takeover; client_no_context_takeover", | 194 " server_no_context_takeover; client_no_context_takeover", |
193 stream->GetExtensions()); | 195 stream->GetExtensions()); |
194 } | 196 } |
195 | 197 |
196 } // namespace | 198 } // namespace |
197 } // namespace net | 199 } // namespace net |
OLD | NEW |