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> |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 EXPECT_EQ("Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT", | 1114 EXPECT_EQ("Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT", |
1115 failure_message()); | 1115 failure_message()); |
1116 } | 1116 } |
1117 | 1117 |
1118 // The server doesn't respond to the opening handshake. | 1118 // The server doesn't respond to the opening handshake. |
1119 TEST_F(WebSocketStreamCreateTest, HandshakeTimeout) { | 1119 TEST_F(WebSocketStreamCreateTest, HandshakeTimeout) { |
1120 scoped_ptr<DeterministicSocketData> socket_data(BuildNullSocketData()); | 1120 scoped_ptr<DeterministicSocketData> socket_data(BuildNullSocketData()); |
1121 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); | 1121 socket_data->set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
1122 scoped_ptr<MockWeakTimer> timer(new MockWeakTimer(false, false)); | 1122 scoped_ptr<MockWeakTimer> timer(new MockWeakTimer(false, false)); |
1123 base::WeakPtr<MockWeakTimer> weak_timer = timer->AsWeakPtr(); | 1123 base::WeakPtr<MockWeakTimer> weak_timer = timer->AsWeakPtr(); |
1124 CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(), | 1124 CreateAndConnectRawExpectations("ws://localhost/", |
1125 "http://localhost", socket_data.Pass(), | 1125 NoSubProtocols(), |
1126 timer.PassAs<base::Timer>()); | 1126 "http://localhost", |
| 1127 socket_data.Pass(), |
| 1128 timer.Pass()); |
1127 EXPECT_FALSE(has_failed()); | 1129 EXPECT_FALSE(has_failed()); |
1128 ASSERT_TRUE(weak_timer.get()); | 1130 ASSERT_TRUE(weak_timer.get()); |
1129 EXPECT_TRUE(weak_timer->IsRunning()); | 1131 EXPECT_TRUE(weak_timer->IsRunning()); |
1130 | 1132 |
1131 weak_timer->Fire(); | 1133 weak_timer->Fire(); |
1132 RunUntilIdle(); | 1134 RunUntilIdle(); |
1133 | 1135 |
1134 EXPECT_TRUE(has_failed()); | 1136 EXPECT_TRUE(has_failed()); |
1135 EXPECT_EQ("WebSocket opening handshake timed out", failure_message()); | 1137 EXPECT_EQ("WebSocket opening handshake timed out", failure_message()); |
1136 ASSERT_TRUE(weak_timer.get()); | 1138 ASSERT_TRUE(weak_timer.get()); |
1137 EXPECT_FALSE(weak_timer->IsRunning()); | 1139 EXPECT_FALSE(weak_timer->IsRunning()); |
1138 } | 1140 } |
1139 | 1141 |
1140 // When the connection establishes the timer should be stopped. | 1142 // When the connection establishes the timer should be stopped. |
1141 TEST_F(WebSocketStreamCreateTest, HandshakeTimerOnSuccess) { | 1143 TEST_F(WebSocketStreamCreateTest, HandshakeTimerOnSuccess) { |
1142 scoped_ptr<MockWeakTimer> timer(new MockWeakTimer(false, false)); | 1144 scoped_ptr<MockWeakTimer> timer(new MockWeakTimer(false, false)); |
1143 base::WeakPtr<MockWeakTimer> weak_timer = timer->AsWeakPtr(); | 1145 base::WeakPtr<MockWeakTimer> weak_timer = timer->AsWeakPtr(); |
1144 | 1146 |
1145 CreateAndConnectStandard( | 1147 CreateAndConnectStandard("ws://localhost/", |
1146 "ws://localhost/", "/", NoSubProtocols(), "http://localhost", "", "", | 1148 "/", |
1147 timer.PassAs<base::Timer>()); | 1149 NoSubProtocols(), |
| 1150 "http://localhost", |
| 1151 "", |
| 1152 "", |
| 1153 timer.Pass()); |
1148 ASSERT_TRUE(weak_timer); | 1154 ASSERT_TRUE(weak_timer); |
1149 EXPECT_TRUE(weak_timer->IsRunning()); | 1155 EXPECT_TRUE(weak_timer->IsRunning()); |
1150 | 1156 |
1151 RunUntilIdle(); | 1157 RunUntilIdle(); |
1152 EXPECT_FALSE(has_failed()); | 1158 EXPECT_FALSE(has_failed()); |
1153 EXPECT_TRUE(stream_); | 1159 EXPECT_TRUE(stream_); |
1154 ASSERT_TRUE(weak_timer); | 1160 ASSERT_TRUE(weak_timer); |
1155 EXPECT_FALSE(weak_timer->IsRunning()); | 1161 EXPECT_FALSE(weak_timer->IsRunning()); |
1156 } | 1162 } |
1157 | 1163 |
1158 // When the connection fails the timer should be stopped. | 1164 // When the connection fails the timer should be stopped. |
1159 TEST_F(WebSocketStreamCreateTest, HandshakeTimerOnFailure) { | 1165 TEST_F(WebSocketStreamCreateTest, HandshakeTimerOnFailure) { |
1160 scoped_ptr<DeterministicSocketData> socket_data(BuildNullSocketData()); | 1166 scoped_ptr<DeterministicSocketData> socket_data(BuildNullSocketData()); |
1161 socket_data->set_connect_data( | 1167 socket_data->set_connect_data( |
1162 MockConnect(SYNCHRONOUS, ERR_CONNECTION_REFUSED)); | 1168 MockConnect(SYNCHRONOUS, ERR_CONNECTION_REFUSED)); |
1163 scoped_ptr<MockWeakTimer> timer(new MockWeakTimer(false, false)); | 1169 scoped_ptr<MockWeakTimer> timer(new MockWeakTimer(false, false)); |
1164 base::WeakPtr<MockWeakTimer> weak_timer = timer->AsWeakPtr(); | 1170 base::WeakPtr<MockWeakTimer> weak_timer = timer->AsWeakPtr(); |
1165 CreateAndConnectRawExpectations("ws://localhost/", NoSubProtocols(), | 1171 CreateAndConnectRawExpectations("ws://localhost/", |
1166 "http://localhost", socket_data.Pass(), | 1172 NoSubProtocols(), |
1167 timer.PassAs<base::Timer>()); | 1173 "http://localhost", |
| 1174 socket_data.Pass(), |
| 1175 timer.Pass()); |
1168 ASSERT_TRUE(weak_timer.get()); | 1176 ASSERT_TRUE(weak_timer.get()); |
1169 EXPECT_TRUE(weak_timer->IsRunning()); | 1177 EXPECT_TRUE(weak_timer->IsRunning()); |
1170 | 1178 |
1171 RunUntilIdle(); | 1179 RunUntilIdle(); |
1172 EXPECT_TRUE(has_failed()); | 1180 EXPECT_TRUE(has_failed()); |
1173 EXPECT_EQ("Error in connection establishment: net::ERR_CONNECTION_REFUSED", | 1181 EXPECT_EQ("Error in connection establishment: net::ERR_CONNECTION_REFUSED", |
1174 failure_message()); | 1182 failure_message()); |
1175 ASSERT_TRUE(weak_timer.get()); | 1183 ASSERT_TRUE(weak_timer.get()); |
1176 EXPECT_FALSE(weak_timer->IsRunning()); | 1184 EXPECT_FALSE(weak_timer->IsRunning()); |
1177 } | 1185 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 if (original) { | 1453 if (original) { |
1446 samples->Subtract(*original); // Cancel the original values. | 1454 samples->Subtract(*original); // Cancel the original values. |
1447 } | 1455 } |
1448 EXPECT_EQ(1, samples->GetCount(INCOMPLETE)); | 1456 EXPECT_EQ(1, samples->GetCount(INCOMPLETE)); |
1449 EXPECT_EQ(0, samples->GetCount(CONNECTED)); | 1457 EXPECT_EQ(0, samples->GetCount(CONNECTED)); |
1450 EXPECT_EQ(0, samples->GetCount(FAILED)); | 1458 EXPECT_EQ(0, samples->GetCount(FAILED)); |
1451 } | 1459 } |
1452 | 1460 |
1453 } // namespace | 1461 } // namespace |
1454 } // namespace net | 1462 } // namespace net |
OLD | NEW |