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/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/metrics/histogram_samples.h" | 15 #include "base/metrics/histogram_samples.h" |
16 #include "base/metrics/statistics_recorder.h" | 16 #include "base/metrics/statistics_recorder.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/timer/mock_timer.h" | 19 #include "base/timer/mock_timer.h" |
20 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/test_data_directory.h" | 22 #include "net/base/test_data_directory.h" |
23 #include "net/http/http_request_headers.h" | 23 #include "net/http/http_request_headers.h" |
24 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
25 #include "net/proxy/proxy_service.h" | |
25 #include "net/socket/client_socket_handle.h" | 26 #include "net/socket/client_socket_handle.h" |
26 #include "net/socket/socket_test_util.h" | 27 #include "net/socket/socket_test_util.h" |
27 #include "net/test/cert_test_util.h" | 28 #include "net/test/cert_test_util.h" |
28 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
29 #include "net/websockets/websocket_basic_handshake_stream.h" | 30 #include "net/websockets/websocket_basic_handshake_stream.h" |
30 #include "net/websockets/websocket_frame.h" | 31 #include "net/websockets/websocket_frame.h" |
31 #include "net/websockets/websocket_handshake_request_info.h" | 32 #include "net/websockets/websocket_handshake_request_info.h" |
32 #include "net/websockets/websocket_handshake_response_info.h" | 33 #include "net/websockets/websocket_handshake_response_info.h" |
33 #include "net/websockets/websocket_handshake_stream_create_helper.h" | 34 #include "net/websockets/websocket_handshake_stream_create_helper.h" |
34 #include "net/websockets/websocket_test_util.h" | 35 #include "net/websockets/websocket_test_util.h" |
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1405 MockWrite writes[] = {MockWrite(SYNCHRONOUS, 0, request.c_str())}; | 1406 MockWrite writes[] = {MockWrite(SYNCHRONOUS, 0, request.c_str())}; |
1406 scoped_ptr<DeterministicSocketData> socket_data( | 1407 scoped_ptr<DeterministicSocketData> socket_data( |
1407 BuildSocketData(reads, writes)); | 1408 BuildSocketData(reads, writes)); |
1408 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 1409 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
1409 CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(), | 1410 CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(), |
1410 "http://localhost", socket_data.Pass()); | 1411 "http://localhost", socket_data.Pass()); |
1411 RunUntilIdle(); | 1412 RunUntilIdle(); |
1412 EXPECT_TRUE(has_failed()); | 1413 EXPECT_TRUE(has_failed()); |
1413 } | 1414 } |
1414 | 1415 |
1416 TEST_F(WebSocketStreamCreateTest, HandleErrTunnelConnectionFailed) { | |
1417 static const char kConnectRequest[] = | |
1418 "CONNECT localhost:80 HTTP/1.1\r\n" | |
1419 "Host: localhost\r\n" | |
1420 "Proxy-Connection: keep-alive\r\n" | |
1421 "\r\n"; | |
1422 | |
1423 static const char kTruncatedResponse[] = | |
yhirano
2015/02/06 04:27:01
Is this truncated?
Adam Rice
2015/02/06 08:05:57
No. Sorry. Too much copy and paste! Fixed.
| |
1424 "HTTP/1.1 403 Forbidden\r\n" | |
1425 "Content-Type: text/html\r\n" | |
1426 "Content-Length: 9\r\n" | |
1427 "Connection: keep-alive\r\n" | |
1428 "\r\n" | |
1429 "Forbidden"; | |
1430 | |
1431 MockRead reads[] = {MockRead(SYNCHRONOUS, 1, kTruncatedResponse)}; | |
1432 MockWrite writes[] = {MockWrite(SYNCHRONOUS, 0, kConnectRequest)}; | |
1433 scoped_ptr<DeterministicSocketData> socket_data( | |
1434 BuildSocketData(reads, writes)); | |
1435 std::string proxy_config = "https=proxy:8000"; | |
1436 scoped_ptr<ProxyService> proxy_service( | |
1437 ProxyService::CreateFixed(proxy_config)); | |
1438 url_request_context_host_.SetProxyService(proxy_service.Pass()); | |
1439 CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(), | |
1440 "http://localhost", socket_data.Pass()); | |
1441 RunUntilIdle(); | |
1442 EXPECT_TRUE(has_failed()); | |
1443 EXPECT_EQ("Establishing a tunnel via proxy server failed.", | |
1444 failure_message()); | |
1445 } | |
1446 | |
1415 } // namespace | 1447 } // namespace |
1416 } // namespace net | 1448 } // namespace net |
OLD | NEW |