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 <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/http/http_request_headers.h" | 14 #include "net/http/http_request_headers.h" |
15 #include "net/http/http_request_info.h" | 15 #include "net/http/http_request_info.h" |
16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
17 #include "net/http/http_response_info.h" | 17 #include "net/http/http_response_info.h" |
18 #include "net/socket/client_socket_handle.h" | 18 #include "net/socket/client_socket_handle.h" |
19 #include "net/socket/socket_test_util.h" | 19 #include "net/socket/socket_test_util.h" |
| 20 #include "net/test/gtest_util.h" |
20 #include "net/websockets/websocket_basic_handshake_stream.h" | 21 #include "net/websockets/websocket_basic_handshake_stream.h" |
21 #include "net/websockets/websocket_stream.h" | 22 #include "net/websockets/websocket_stream.h" |
22 #include "net/websockets/websocket_test_util.h" | 23 #include "net/websockets/websocket_test_util.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "url/gurl.h" | 26 #include "url/gurl.h" |
25 #include "url/origin.h" | 27 #include "url/origin.h" |
26 | 28 |
| 29 using net::test::IsOk; |
| 30 |
27 namespace net { | 31 namespace net { |
28 namespace { | 32 namespace { |
29 | 33 |
30 // This class encapsulates the details of creating a mock ClientSocketHandle. | 34 // This class encapsulates the details of creating a mock ClientSocketHandle. |
31 class MockClientSocketHandleFactory { | 35 class MockClientSocketHandleFactory { |
32 public: | 36 public: |
33 MockClientSocketHandleFactory() | 37 MockClientSocketHandleFactory() |
34 : pool_(1, 1, socket_factory_maker_.factory()) {} | 38 : pool_(1, 1, socket_factory_maker_.factory()) {} |
35 | 39 |
36 // The created socket expects |expect_written| to be written to the socket, | 40 // The created socket expects |expect_written| to be written to the socket, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // will fail and AddressSanitizer should identify the issue. | 101 // will fail and AddressSanitizer should identify the issue. |
98 static_cast<WebSocketBasicHandshakeStream*>(handshake.get()) | 102 static_cast<WebSocketBasicHandshakeStream*>(handshake.get()) |
99 ->SetWebSocketKeyForTesting("dGhlIHNhbXBsZSBub25jZQ=="); | 103 ->SetWebSocketKeyForTesting("dGhlIHNhbXBsZSBub25jZQ=="); |
100 | 104 |
101 HttpRequestInfo request_info; | 105 HttpRequestInfo request_info; |
102 request_info.url = GURL("ws://localhost/"); | 106 request_info.url = GURL("ws://localhost/"); |
103 request_info.method = "GET"; | 107 request_info.method = "GET"; |
104 request_info.load_flags = LOAD_DISABLE_CACHE; | 108 request_info.load_flags = LOAD_DISABLE_CACHE; |
105 int rv = handshake->InitializeStream( | 109 int rv = handshake->InitializeStream( |
106 &request_info, DEFAULT_PRIORITY, BoundNetLog(), CompletionCallback()); | 110 &request_info, DEFAULT_PRIORITY, BoundNetLog(), CompletionCallback()); |
107 EXPECT_EQ(OK, rv); | 111 EXPECT_THAT(rv, IsOk()); |
108 | 112 |
109 HttpRequestHeaders headers; | 113 HttpRequestHeaders headers; |
110 headers.SetHeader("Host", "localhost"); | 114 headers.SetHeader("Host", "localhost"); |
111 headers.SetHeader("Connection", "Upgrade"); | 115 headers.SetHeader("Connection", "Upgrade"); |
112 headers.SetHeader("Pragma", "no-cache"); | 116 headers.SetHeader("Pragma", "no-cache"); |
113 headers.SetHeader("Cache-Control", "no-cache"); | 117 headers.SetHeader("Cache-Control", "no-cache"); |
114 headers.SetHeader("Upgrade", "websocket"); | 118 headers.SetHeader("Upgrade", "websocket"); |
115 headers.SetHeader("Origin", kOrigin); | 119 headers.SetHeader("Origin", kOrigin); |
116 headers.SetHeader("Sec-WebSocket-Version", "13"); | 120 headers.SetHeader("Sec-WebSocket-Version", "13"); |
117 headers.SetHeader("User-Agent", ""); | 121 headers.SetHeader("User-Agent", ""); |
118 headers.SetHeader("Accept-Encoding", "gzip, deflate"); | 122 headers.SetHeader("Accept-Encoding", "gzip, deflate"); |
119 headers.SetHeader("Accept-Language", "en-us,fr"); | 123 headers.SetHeader("Accept-Language", "en-us,fr"); |
120 | 124 |
121 HttpResponseInfo response; | 125 HttpResponseInfo response; |
122 TestCompletionCallback dummy; | 126 TestCompletionCallback dummy; |
123 | 127 |
124 rv = handshake->SendRequest(headers, &response, dummy.callback()); | 128 rv = handshake->SendRequest(headers, &response, dummy.callback()); |
125 | 129 |
126 EXPECT_EQ(OK, rv); | 130 EXPECT_THAT(rv, IsOk()); |
127 | 131 |
128 rv = handshake->ReadResponseHeaders(dummy.callback()); | 132 rv = handshake->ReadResponseHeaders(dummy.callback()); |
129 EXPECT_EQ(OK, rv); | 133 EXPECT_THAT(rv, IsOk()); |
130 EXPECT_EQ(101, response.headers->response_code()); | 134 EXPECT_EQ(101, response.headers->response_code()); |
131 EXPECT_TRUE(response.headers->HasHeaderValue("Connection", "Upgrade")); | 135 EXPECT_TRUE(response.headers->HasHeaderValue("Connection", "Upgrade")); |
132 EXPECT_TRUE(response.headers->HasHeaderValue("Upgrade", "websocket")); | 136 EXPECT_TRUE(response.headers->HasHeaderValue("Upgrade", "websocket")); |
133 return handshake->Upgrade(); | 137 return handshake->Upgrade(); |
134 } | 138 } |
135 | 139 |
136 MockClientSocketHandleFactory socket_handle_factory_; | 140 MockClientSocketHandleFactory socket_handle_factory_; |
137 TestConnectDelegate connect_delegate_; | 141 TestConnectDelegate connect_delegate_; |
138 std::string failure_message_; | 142 std::string failure_message_; |
139 }; | 143 }; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 181 |
178 EXPECT_EQ( | 182 EXPECT_EQ( |
179 "permessage-deflate;" | 183 "permessage-deflate;" |
180 " client_max_window_bits=14; server_max_window_bits=14;" | 184 " client_max_window_bits=14; server_max_window_bits=14;" |
181 " server_no_context_takeover; client_no_context_takeover", | 185 " server_no_context_takeover; client_no_context_takeover", |
182 stream->GetExtensions()); | 186 stream->GetExtensions()); |
183 } | 187 } |
184 | 188 |
185 } // namespace | 189 } // namespace |
186 } // namespace net | 190 } // namespace net |
OLD | NEW |