Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: net/websockets/websocket_stream_test.cc

Issue 2628333003: Cancel URLRequest with an appropriate code when WebSocket handshake succeeds (Closed)
Patch Set: fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/websockets/websocket_stream.cc ('k') | net/websockets/websocket_test_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 NoSubProtocols(), LocalhostOrigin(), LocalhostUrl(), 330 NoSubProtocols(), LocalhostOrigin(), LocalhostUrl(),
331 "", "", ""); 331 "", "", "");
332 EXPECT_FALSE(request_info_); 332 EXPECT_FALSE(request_info_);
333 EXPECT_FALSE(response_info_); 333 EXPECT_FALSE(response_info_);
334 EXPECT_TRUE(url_request_); 334 EXPECT_TRUE(url_request_);
335 WaitUntilConnectDone(); 335 WaitUntilConnectDone();
336 EXPECT_FALSE(has_failed()); 336 EXPECT_FALSE(has_failed());
337 EXPECT_TRUE(stream_); 337 EXPECT_TRUE(stream_);
338 EXPECT_TRUE(request_info_); 338 EXPECT_TRUE(request_info_);
339 EXPECT_TRUE(response_info_); 339 EXPECT_TRUE(response_info_);
340 EXPECT_EQ(ERR_WEBSOCKET_HANDSHAKE_SUCCESS,
341 url_request_context_host_.network_delegate().last_error());
340 } 342 }
341 343
342 TEST_F(WebSocketStreamCreateTest, HandshakeInfo) { 344 TEST_F(WebSocketStreamCreateTest, HandshakeInfo) {
343 static const char kResponse[] = 345 static const char kResponse[] =
344 "HTTP/1.1 101 Switching Protocols\r\n" 346 "HTTP/1.1 101 Switching Protocols\r\n"
345 "Upgrade: websocket\r\n" 347 "Upgrade: websocket\r\n"
346 "Connection: Upgrade\r\n" 348 "Connection: Upgrade\r\n"
347 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" 349 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
348 "foo: bar, baz\r\n" 350 "foo: bar, baz\r\n"
349 "hoge: fuga\r\n" 351 "hoge: fuga\r\n"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 "/testing_path", NoSubProtocols(), GoogleOrigin(), 478 "/testing_path", NoSubProtocols(), GoogleOrigin(),
477 GoogleUrl(), "", "", 479 GoogleUrl(), "", "",
478 "Sec-WebSocket-Protocol: chatv20.chromium.org\r\n"); 480 "Sec-WebSocket-Protocol: chatv20.chromium.org\r\n");
479 WaitUntilConnectDone(); 481 WaitUntilConnectDone();
480 EXPECT_FALSE(stream_); 482 EXPECT_FALSE(stream_);
481 EXPECT_TRUE(has_failed()); 483 EXPECT_TRUE(has_failed());
482 EXPECT_EQ("Error during WebSocket handshake: " 484 EXPECT_EQ("Error during WebSocket handshake: "
483 "Response must not include 'Sec-WebSocket-Protocol' header " 485 "Response must not include 'Sec-WebSocket-Protocol' header "
484 "if not present in request: chatv20.chromium.org", 486 "if not present in request: chatv20.chromium.org",
485 failure_message()); 487 failure_message());
488 EXPECT_EQ(ERR_INVALID_RESPONSE,
489 url_request_context_host_.network_delegate().last_error());
486 } 490 }
487 491
488 // Missing sub-protocol response is rejected. 492 // Missing sub-protocol response is rejected.
489 TEST_F(WebSocketStreamCreateTest, UnacceptedSubProtocol) { 493 TEST_F(WebSocketStreamCreateTest, UnacceptedSubProtocol) {
490 std::vector<std::string> sub_protocols; 494 std::vector<std::string> sub_protocols;
491 sub_protocols.push_back("chat.example.com"); 495 sub_protocols.push_back("chat.example.com");
492 CreateAndConnectStandard("ws://localhost/testing_path", "localhost", 496 CreateAndConnectStandard("ws://localhost/testing_path", "localhost",
493 "/testing_path", sub_protocols, LocalhostOrigin(), 497 "/testing_path", sub_protocols, LocalhostOrigin(),
494 LocalhostUrl(), "", 498 LocalhostUrl(), "",
495 "Sec-WebSocket-Protocol: chat.example.com\r\n", ""); 499 "Sec-WebSocket-Protocol: chat.example.com\r\n", "");
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 LocalhostOrigin(), LocalhostUrl(), "", 1263 LocalhostOrigin(), LocalhostUrl(), "",
1260 std::move(socket_data)); 1264 std::move(socket_data));
1261 WaitUntilConnectDone(); 1265 WaitUntilConnectDone();
1262 EXPECT_TRUE(has_failed()); 1266 EXPECT_TRUE(has_failed());
1263 EXPECT_EQ("Establishing a tunnel via proxy server failed.", 1267 EXPECT_EQ("Establishing a tunnel via proxy server failed.",
1264 failure_message()); 1268 failure_message());
1265 } 1269 }
1266 1270
1267 } // namespace 1271 } // namespace
1268 } // namespace net 1272 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_stream.cc ('k') | net/websockets/websocket_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698