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> |
11 | 11 |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/http/http_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.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/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
21 #include "net/websockets/websocket_basic_handshake_stream.h" | 21 #include "net/websockets/websocket_basic_handshake_stream.h" |
22 #include "net/websockets/websocket_frame.h" | 22 #include "net/websockets/websocket_frame.h" |
23 #include "net/websockets/websocket_handshake_request_info.h" | 23 #include "net/websockets/websocket_handshake_request_info.h" |
24 #include "net/websockets/websocket_handshake_response_info.h" | 24 #include "net/websockets/websocket_handshake_response_info.h" |
25 #include "net/websockets/websocket_handshake_stream_create_helper.h" | 25 #include "net/websockets/websocket_handshake_stream_create_helper.h" |
26 #include "net/websockets/websocket_test_util.h" | 26 #include "net/websockets/websocket_test_util.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 #include "url/origin.h" |
29 | 30 |
30 namespace net { | 31 namespace net { |
31 namespace { | 32 namespace { |
32 | 33 |
33 typedef std::pair<std::string, std::string> HeaderKeyValuePair; | 34 typedef std::pair<std::string, std::string> HeaderKeyValuePair; |
34 | 35 |
35 std::vector<HeaderKeyValuePair> ToVector(const HttpRequestHeaders& headers) { | 36 std::vector<HeaderKeyValuePair> ToVector(const HttpRequestHeaders& headers) { |
36 HttpRequestHeaders::Iterator it(headers); | 37 HttpRequestHeaders::Iterator it(headers); |
37 std::vector<HeaderKeyValuePair> result; | 38 std::vector<HeaderKeyValuePair> result; |
38 while (it.GetNext()) | 39 while (it.GetNext()) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const std::vector<std::string>& sub_protocols, | 123 const std::vector<std::string>& sub_protocols, |
123 const std::string& origin) { | 124 const std::string& origin) { |
124 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate( | 125 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate( |
125 new TestConnectDelegate(this)); | 126 new TestConnectDelegate(this)); |
126 WebSocketStream::ConnectDelegate* delegate = connect_delegate.get(); | 127 WebSocketStream::ConnectDelegate* delegate = connect_delegate.get(); |
127 stream_request_ = ::net::CreateAndConnectStreamForTesting( | 128 stream_request_ = ::net::CreateAndConnectStreamForTesting( |
128 GURL(socket_url), | 129 GURL(socket_url), |
129 scoped_ptr<WebSocketHandshakeStreamCreateHelper>( | 130 scoped_ptr<WebSocketHandshakeStreamCreateHelper>( |
130 new DeterministicKeyWebSocketHandshakeStreamCreateHelper( | 131 new DeterministicKeyWebSocketHandshakeStreamCreateHelper( |
131 delegate, sub_protocols)), | 132 delegate, sub_protocols)), |
132 GURL(origin), | 133 url::Origin(origin), |
133 url_request_context_host_.GetURLRequestContext(), | 134 url_request_context_host_.GetURLRequestContext(), |
134 BoundNetLog(), | 135 BoundNetLog(), |
135 connect_delegate.Pass()); | 136 connect_delegate.Pass()); |
136 } | 137 } |
137 | 138 |
138 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } | 139 static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); } |
139 | 140 |
140 // A simple function to make the tests more readable. Creates an empty vector. | 141 // A simple function to make the tests more readable. Creates an empty vector. |
141 static std::vector<std::string> NoSubProtocols() { | 142 static std::vector<std::string> NoSubProtocols() { |
142 return std::vector<std::string>(); | 143 return std::vector<std::string>(); |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 socket_data->RunFor(2); | 1002 socket_data->RunFor(2); |
1002 EXPECT_TRUE(has_failed()); | 1003 EXPECT_TRUE(has_failed()); |
1003 EXPECT_FALSE(stream_); | 1004 EXPECT_FALSE(stream_); |
1004 EXPECT_FALSE(response_info_); | 1005 EXPECT_FALSE(response_info_); |
1005 EXPECT_EQ("Connection closed before receiving a handshake response", | 1006 EXPECT_EQ("Connection closed before receiving a handshake response", |
1006 failure_message()); | 1007 failure_message()); |
1007 } | 1008 } |
1008 | 1009 |
1009 } // namespace | 1010 } // namespace |
1010 } // namespace net | 1011 } // namespace net |
OLD | NEW |