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

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

Issue 2247003003: Revert HTTP/0.9 removal (https://codereview.chromium.org/2144803002/) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add back new error code Created 4 years, 4 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
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 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 NoSubProtocols(), LocalhostOrigin(), 681 NoSubProtocols(), LocalhostOrigin(),
682 LocalhostUrl(), "", "", kRedirectResponse); 682 LocalhostUrl(), "", "", kRedirectResponse);
683 WaitUntilConnectDone(); 683 WaitUntilConnectDone();
684 EXPECT_TRUE(has_failed()); 684 EXPECT_TRUE(has_failed());
685 EXPECT_EQ("Error during WebSocket handshake: Unexpected response code: 302", 685 EXPECT_EQ("Error during WebSocket handshake: Unexpected response code: 302",
686 failure_message()); 686 failure_message());
687 } 687 }
688 688
689 // Malformed responses should be rejected. HttpStreamParser will accept just 689 // Malformed responses should be rejected. HttpStreamParser will accept just
690 // about any garbage in the middle of the headers. To make it give up, the junk 690 // about any garbage in the middle of the headers. To make it give up, the junk
691 // has to be at the start of the response. 691 // has to be at the start of the response. Even then, it just gets treated as an
692 // HTTP/0.9 response.
692 TEST_F(WebSocketStreamCreateTest, MalformedResponse) { 693 TEST_F(WebSocketStreamCreateTest, MalformedResponse) {
693 static const char kMalformedResponse[] = 694 static const char kMalformedResponse[] =
694 "220 mx.google.com ESMTP\r\n" 695 "220 mx.google.com ESMTP\r\n"
695 "HTTP/1.1 101 OK\r\n" 696 "HTTP/1.1 101 OK\r\n"
696 "Upgrade: websocket\r\n" 697 "Upgrade: websocket\r\n"
697 "Connection: Upgrade\r\n" 698 "Connection: Upgrade\r\n"
698 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" 699 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
699 "\r\n"; 700 "\r\n";
700 CreateAndConnectCustomResponse("ws://localhost/", "localhost", "/", 701 CreateAndConnectCustomResponse("ws://localhost/", "localhost", "/",
701 NoSubProtocols(), LocalhostOrigin(), 702 NoSubProtocols(), LocalhostOrigin(),
702 LocalhostUrl(), "", "", kMalformedResponse); 703 LocalhostUrl(), "", "", kMalformedResponse);
703 WaitUntilConnectDone(); 704 WaitUntilConnectDone();
704 EXPECT_TRUE(has_failed()); 705 EXPECT_TRUE(has_failed());
705 EXPECT_EQ("Error during WebSocket handshake: net::ERR_INVALID_HTTP_RESPONSE", 706 EXPECT_EQ("Error during WebSocket handshake: Invalid status line",
706 failure_message()); 707 failure_message());
707 } 708 }
708 709
709 // Upgrade header must be present. 710 // Upgrade header must be present.
710 TEST_F(WebSocketStreamCreateTest, MissingUpgradeHeader) { 711 TEST_F(WebSocketStreamCreateTest, MissingUpgradeHeader) {
711 static const char kMissingUpgradeResponse[] = 712 static const char kMissingUpgradeResponse[] =
712 "HTTP/1.1 101 Switching Protocols\r\n" 713 "HTTP/1.1 101 Switching Protocols\r\n"
713 "Connection: Upgrade\r\n" 714 "Connection: Upgrade\r\n"
714 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" 715 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
715 "\r\n"; 716 "\r\n";
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 LocalhostOrigin(), LocalhostUrl(), "", 1257 LocalhostOrigin(), LocalhostUrl(), "",
1257 std::move(socket_data)); 1258 std::move(socket_data));
1258 WaitUntilConnectDone(); 1259 WaitUntilConnectDone();
1259 EXPECT_TRUE(has_failed()); 1260 EXPECT_TRUE(has_failed());
1260 EXPECT_EQ("Establishing a tunnel via proxy server failed.", 1261 EXPECT_EQ("Establishing a tunnel via proxy server failed.",
1261 failure_message()); 1262 failure_message());
1262 } 1263 }
1263 1264
1264 } // namespace 1265 } // namespace
1265 } // namespace net 1266 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698