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

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

Issue 1108002: Implement new websocket handshake based on draft-hixie-thewebsocketprotocol-76 (Closed)
Patch Set: fix for review comments Created 10 years, 9 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/string_util.h"
9 #include "net/websockets/websocket_handshake.h" 10 #include "net/websockets/websocket_handshake.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
13 14
14 namespace net { 15 namespace net {
15 16
16 TEST(WebSocketHandshakeTest, Connect) { 17 class WebSocketHandshakeTest : public testing::Test {
18 public:
19 static void SetUpParameter(WebSocketHandshake* handshake,
20 uint32 number_1, uint32 number_2,
21 const std::string& key_1, const std::string& key_2,
22 const std::string& key_3) {
23 WebSocketHandshake::Parameter* parameter =
24 new WebSocketHandshake::Parameter;
25 parameter->number_1_ = number_1;
26 parameter->number_2_ = number_2;
27 parameter->key_1_ = key_1;
28 parameter->key_2_ = key_2;
29 parameter->key_3_ = key_3;
30 handshake->parameter_.reset(parameter);
31 }
32
33 static void ExpectHeaderEquals(const std::string& expected,
34 const std::string& actual) {
35 std::vector<std::string> expected_lines;
36 Tokenize(expected, "\r\n", &expected_lines);
37 std::vector<std::string> actual_lines;
38 Tokenize(actual, "\r\n", &actual_lines);
39 // Request lines.
40 EXPECT_EQ(expected_lines[0], actual_lines[0]);
41
42 std::vector<std::string> expected_headers;
43 for (size_t i = 1; i < expected_lines.size(); i++) {
44 // Finish at first CRLF CRLF. Note that /key_3/ might include CRLF.
45 if (expected_lines[i] == "")
46 break;
47 expected_headers.push_back(expected_lines[i]);
48 }
49 sort(expected_headers.begin(), expected_headers.end());
50
51 std::vector<std::string> actual_headers;
52 for (size_t i = 1; i < actual_lines.size(); i++) {
53 // Finish at first CRLF CRLF. Note that /key_3/ might include CRLF.
54 if (actual_lines[i] == "")
55 break;
56 actual_headers.push_back(actual_lines[i]);
57 }
58 sort(actual_headers.begin(), actual_headers.end());
59
60 EXPECT_EQ(expected_headers.size(), actual_headers.size())
61 << "expected:" << expected
62 << "\nactual:" << actual;
63 for (size_t i = 0; i < expected_headers.size(); i++) {
64 EXPECT_EQ(expected_headers[i], actual_headers[i]);
65 }
66 }
67
68 static void ExpectHandshakeMessageEquals(const std::string& expected,
69 const std::string& actual) {
70 // Headers.
71 ExpectHeaderEquals(expected, actual);
72 // Compare tailing \r\n\r\n<key3> (4 + 8 bytes).
73 ASSERT_GT(expected.size(), 12U);
74 const char* expected_key3 = expected.data() + expected.size() - 12;
75 EXPECT_GT(actual.size(), 12U);
76 if (actual.size() <= 12U)
77 return;
78 const char* actual_key3 = actual.data() + actual.size() - 12;
79 EXPECT_TRUE(memcmp(expected_key3, actual_key3, 12) == 0)
80 << "expected_key3:" << DumpKey(expected_key3, 12)
81 << ", actual_key3:" << DumpKey(actual_key3, 12);
82 }
83
84 static std::string DumpKey(const char* buf, int len) {
85 std::string s;
86 for (int i = 0; i < len; i++) {
87 if (isprint(buf[i]))
88 s += StringPrintf("%c", buf[i]);
89 else
90 s += StringPrintf("\\x%02x", buf[i]);
91 }
92 return s;
93 }
94
95 static std::string GetResourceName(WebSocketHandshake* handshake) {
96 return handshake->GetResourceName();
97 }
98 static std::string GetHostFieldValue(WebSocketHandshake* handshake) {
99 return handshake->GetHostFieldValue();
100 }
101 static std::string GetOriginFieldValue(WebSocketHandshake* handshake) {
102 return handshake->GetOriginFieldValue();
103 }
104 };
105
106
107 TEST_F(WebSocketHandshakeTest, Connect) {
17 const std::string kExpectedClientHandshakeMessage = 108 const std::string kExpectedClientHandshakeMessage =
18 "GET /demo HTTP/1.1\r\n" 109 "GET /demo HTTP/1.1\r\n"
19 "Upgrade: WebSocket\r\n" 110 "Upgrade: WebSocket\r\n"
20 "Connection: Upgrade\r\n" 111 "Connection: Upgrade\r\n"
21 "Host: example.com\r\n" 112 "Host: example.com\r\n"
22 "Origin: http://example.com\r\n" 113 "Origin: http://example.com\r\n"
23 "WebSocket-Protocol: sample\r\n" 114 "Sec-WebSocket-Protocol: sample\r\n"
24 "\r\n"; 115 "Sec-WebSocket-Key1: 388P O503D&ul7 {K%gX( %7 15\r\n"
116 "Sec-WebSocket-Key2: 1 N ?|k UT0or 3o 4 I97N 5-S3O 31\r\n"
117 "\r\n"
118 "\x47\x30\x22\x2D\x5A\x3F\x47\x58";
25 119
26 scoped_ptr<WebSocketHandshake> handshake( 120 scoped_ptr<WebSocketHandshake> handshake(
27 new WebSocketHandshake(GURL("ws://example.com/demo"), 121 new WebSocketHandshake(GURL("ws://example.com/demo"),
28 "http://example.com", 122 "http://example.com",
29 "ws://example.com/demo", 123 "ws://example.com/demo",
30 "sample")); 124 "sample"));
31 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode()); 125 SetUpParameter(handshake.get(), 777007543U, 114997259U,
32 EXPECT_EQ(kExpectedClientHandshakeMessage, 126 "388P O503D&ul7 {K%gX( %7 15",
33 handshake->CreateClientHandshakeMessage()); 127 "1 N ?|k UT0or 3o 4 I97N 5-S3O 31",
34 128 std::string("\x47\x30\x22\x2D\x5A\x3F\x47\x58", 8));
35 const char kResponse[] = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" 129 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
36 "Upgrade: WebSocket\r\n" 130 ExpectHandshakeMessageEquals(
37 "Connection: Upgrade\r\n" 131 kExpectedClientHandshakeMessage,
38 "WebSocket-Origin: http://example.com\r\n" 132 handshake->CreateClientHandshakeMessage());
39 "WebSocket-Location: ws://example.com/demo\r\n" 133
40 "WebSocket-Protocol: sample\r\n" 134 const char kResponse[] = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
41 "\r\n"; 135 "Upgrade: WebSocket\r\n"
136 "Connection: Upgrade\r\n"
137 "Sec-WebSocket-Origin: http://example.com\r\n"
138 "Sec-WebSocket-Location: ws://example.com/demo\r\n"
139 "Sec-WebSocket-Protocol: sample\r\n"
140 "\r\n"
141 "\x30\x73\x74\x33\x52\x6C\x26\x71\x2D\x32\x5A\x55\x5E\x77\x65\x75";
142 std::vector<std::string> response_lines;
143 SplitStringDontTrim(kResponse, '\n', &response_lines);
42 144
43 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode()); 145 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
44 // too short 146 // too short
45 EXPECT_EQ(-1, handshake->ReadServerHandshake(kResponse, 16)); 147 EXPECT_EQ(-1, handshake->ReadServerHandshake(kResponse, 16));
46 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode()); 148 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
149
47 // only status line 150 // only status line
48 EXPECT_EQ(-1, handshake->ReadServerHandshake( 151 std::string response = response_lines[0];
49 kResponse, 152 EXPECT_EQ(-1, handshake->ReadServerHandshake(
50 WebSocketHandshake::kServerHandshakeHeaderLength)); 153 response.data(), response.size()));
51 EXPECT_EQ(WebSocketHandshake::MODE_NORMAL, handshake->mode()); 154 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
52 // by upgrade header 155 // by upgrade header
53 EXPECT_EQ(-1, handshake->ReadServerHandshake( 156 response += response_lines[1];
54 kResponse, 157 EXPECT_EQ(-1, handshake->ReadServerHandshake(
55 WebSocketHandshake::kServerHandshakeHeaderLength + 158 response.data(), response.size()));
56 WebSocketHandshake::kUpgradeHeaderLength)); 159 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
57 EXPECT_EQ(WebSocketHandshake::MODE_NORMAL, handshake->mode());
58 // by connection header 160 // by connection header
59 EXPECT_EQ(-1, handshake->ReadServerHandshake( 161 response += response_lines[2];
60 kResponse, 162 EXPECT_EQ(-1, handshake->ReadServerHandshake(
61 WebSocketHandshake::kServerHandshakeHeaderLength + 163 response.data(), response.size()));
62 WebSocketHandshake::kUpgradeHeaderLength + 164 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
63 WebSocketHandshake::kConnectionHeaderLength)); 165
64 EXPECT_EQ(WebSocketHandshake::MODE_NORMAL, handshake->mode()); 166 response += response_lines[3]; // Sec-WebSocket-Origin
65 167 response += response_lines[4]; // Sec-WebSocket-Location
66 EXPECT_EQ(-1, handshake->ReadServerHandshake( 168 response += response_lines[5]; // Sec-WebSocket-Protocol
67 kResponse, sizeof(kResponse) - 2)); 169 EXPECT_EQ(-1, handshake->ReadServerHandshake(
68 EXPECT_EQ(WebSocketHandshake::MODE_NORMAL, handshake->mode()); 170 response.data(), response.size()));
69 171 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
70 int handshake_length = strlen(kResponse); 172
173 response += response_lines[6]; // \r\n
174 EXPECT_EQ(-1, handshake->ReadServerHandshake(
175 response.data(), response.size()));
176 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
177
178 int handshake_length = sizeof(kResponse) - 1; // -1 for terminating \0
71 EXPECT_EQ(handshake_length, handshake->ReadServerHandshake( 179 EXPECT_EQ(handshake_length, handshake->ReadServerHandshake(
72 kResponse, sizeof(kResponse) - 1)); // -1 for terminating \0 180 kResponse, handshake_length)); // -1 for terminating \0
73 EXPECT_EQ(WebSocketHandshake::MODE_CONNECTED, handshake->mode()); 181 EXPECT_EQ(WebSocketHandshake::MODE_CONNECTED, handshake->mode());
74 } 182 }
75 183
76 TEST(WebSocketHandshakeTest, ServerSentData) { 184 TEST_F(WebSocketHandshakeTest, ServerSentData) {
77 const std::string kExpectedClientHandshakeMessage = 185 const std::string kExpectedClientHandshakeMessage =
78 "GET /demo HTTP/1.1\r\n" 186 "GET /demo HTTP/1.1\r\n"
79 "Upgrade: WebSocket\r\n" 187 "Upgrade: WebSocket\r\n"
80 "Connection: Upgrade\r\n" 188 "Connection: Upgrade\r\n"
81 "Host: example.com\r\n" 189 "Host: example.com\r\n"
82 "Origin: http://example.com\r\n" 190 "Origin: http://example.com\r\n"
83 "WebSocket-Protocol: sample\r\n" 191 "Sec-WebSocket-Protocol: sample\r\n"
84 "\r\n"; 192 "Sec-WebSocket-Key1: 388P O503D&ul7 {K%gX( %7 15\r\n"
193 "Sec-WebSocket-Key2: 1 N ?|k UT0or 3o 4 I97N 5-S3O 31\r\n"
194 "\r\n"
195 "\x47\x30\x22\x2D\x5A\x3F\x47\x58";
85 scoped_ptr<WebSocketHandshake> handshake( 196 scoped_ptr<WebSocketHandshake> handshake(
86 new WebSocketHandshake(GURL("ws://example.com/demo"), 197 new WebSocketHandshake(GURL("ws://example.com/demo"),
87 "http://example.com", 198 "http://example.com",
88 "ws://example.com/demo", 199 "ws://example.com/demo",
89 "sample")); 200 "sample"));
90 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode()); 201 SetUpParameter(handshake.get(), 777007543U, 114997259U,
91 EXPECT_EQ(kExpectedClientHandshakeMessage, 202 "388P O503D&ul7 {K%gX( %7 15",
92 handshake->CreateClientHandshakeMessage()); 203 "1 N ?|k UT0or 3o 4 I97N 5-S3O 31",
93 204 std::string("\x47\x30\x22\x2D\x5A\x3F\x47\x58", 8));
94 const char kResponse[] ="HTTP/1.1 101 Web Socket Protocol Handshake\r\n" 205 EXPECT_EQ(WebSocketHandshake::MODE_INCOMPLETE, handshake->mode());
95 "Upgrade: WebSocket\r\n" 206 ExpectHandshakeMessageEquals(
96 "Connection: Upgrade\r\n" 207 kExpectedClientHandshakeMessage,
97 "WebSocket-Origin: http://example.com\r\n" 208 handshake->CreateClientHandshakeMessage());
98 "WebSocket-Location: ws://example.com/demo\r\n" 209
99 "WebSocket-Protocol: sample\r\n" 210 const char kResponse[] = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n"
100 "\r\n" 211 "Upgrade: WebSocket\r\n"
212 "Connection: Upgrade\r\n"
213 "Sec-WebSocket-Origin: http://example.com\r\n"
214 "Sec-WebSocket-Location: ws://example.com/demo\r\n"
215 "Sec-WebSocket-Protocol: sample\r\n"
216 "\r\n"
217 "\x30\x73\x74\x33\x52\x6C\x26\x71\x2D\x32\x5A\x55\x5E\x77\x65\x75"
101 "\0Hello\xff"; 218 "\0Hello\xff";
102 219
103 int handshake_length = strlen(kResponse); 220 int handshake_length = strlen(kResponse); // key3 doesn't contain \0.
104 EXPECT_EQ(handshake_length, handshake->ReadServerHandshake( 221 EXPECT_EQ(handshake_length, handshake->ReadServerHandshake(
105 kResponse, sizeof(kResponse) - 1)); // -1 for terminating \0 222 kResponse, sizeof(kResponse) - 1)); // -1 for terminating \0
106 EXPECT_EQ(WebSocketHandshake::MODE_CONNECTED, handshake->mode()); 223 EXPECT_EQ(WebSocketHandshake::MODE_CONNECTED, handshake->mode());
107 } 224 }
108 225
109 TEST(WebSocketHandshakeTest, is_secure_false) { 226 TEST_F(WebSocketHandshakeTest, is_secure_false) {
110 scoped_ptr<WebSocketHandshake> handshake( 227 scoped_ptr<WebSocketHandshake> handshake(
111 new WebSocketHandshake(GURL("ws://example.com/demo"), 228 new WebSocketHandshake(GURL("ws://example.com/demo"),
112 "http://example.com", 229 "http://example.com",
113 "ws://example.com/demo", 230 "ws://example.com/demo",
114 "sample")); 231 "sample"));
115 EXPECT_FALSE(handshake->is_secure()); 232 EXPECT_FALSE(handshake->is_secure());
116 } 233 }
117 234
118 TEST(WebSocketHandshakeTest, is_secure_true) { 235 TEST_F(WebSocketHandshakeTest, is_secure_true) {
119 // wss:// is secure. 236 // wss:// is secure.
120 scoped_ptr<WebSocketHandshake> handshake( 237 scoped_ptr<WebSocketHandshake> handshake(
121 new WebSocketHandshake(GURL("wss://example.com/demo"), 238 new WebSocketHandshake(GURL("wss://example.com/demo"),
122 "http://example.com", 239 "http://example.com",
123 "wss://example.com/demo", 240 "wss://example.com/demo",
124 "sample")); 241 "sample"));
125 EXPECT_TRUE(handshake->is_secure()); 242 EXPECT_TRUE(handshake->is_secure());
126 } 243 }
127 244
128 TEST(WebSocketHandshakeTest, CreateClientHandshakeMessage_Simple) { 245 TEST_F(WebSocketHandshakeTest, CreateClientHandshakeMessage_ResourceName) {
129 scoped_ptr<WebSocketHandshake> handshake(
130 new WebSocketHandshake(GURL("ws://example.com/demo"),
131 "http://example.com",
132 "ws://example.com/demo",
133 "sample"));
134 EXPECT_EQ("GET /demo HTTP/1.1\r\n"
135 "Upgrade: WebSocket\r\n"
136 "Connection: Upgrade\r\n"
137 "Host: example.com\r\n"
138 "Origin: http://example.com\r\n"
139 "WebSocket-Protocol: sample\r\n"
140 "\r\n",
141 handshake->CreateClientHandshakeMessage());
142 }
143
144 TEST(WebSocketHandshakeTest, CreateClientHandshakeMessage_PathAndQuery) {
145 scoped_ptr<WebSocketHandshake> handshake( 246 scoped_ptr<WebSocketHandshake> handshake(
146 new WebSocketHandshake(GURL("ws://example.com/Test?q=xxx&p=%20"), 247 new WebSocketHandshake(GURL("ws://example.com/Test?q=xxx&p=%20"),
147 "http://example.com", 248 "http://example.com",
148 "ws://example.com/demo", 249 "ws://example.com/demo",
149 "sample")); 250 "sample"));
150 // Path and query should be preserved as-is. 251 // Path and query should be preserved as-is.
151 EXPECT_THAT(handshake->CreateClientHandshakeMessage(), 252 EXPECT_EQ("/Test?q=xxx&p=%20", GetResourceName(handshake.get()));
152 testing::HasSubstr("GET /Test?q=xxx&p=%20 HTTP/1.1\r\n"));
153 } 253 }
154 254
155 TEST(WebSocketHandshakeTest, CreateClientHandshakeMessage_Host) { 255 TEST_F(WebSocketHandshakeTest, CreateClientHandshakeMessage_Host) {
156 scoped_ptr<WebSocketHandshake> handshake( 256 scoped_ptr<WebSocketHandshake> handshake(
157 new WebSocketHandshake(GURL("ws://Example.Com/demo"), 257 new WebSocketHandshake(GURL("ws://Example.Com/demo"),
158 "http://Example.Com", 258 "http://Example.Com",
159 "ws://Example.Com/demo", 259 "ws://Example.Com/demo",
160 "sample")); 260 "sample"));
161 // Host should be lowercased 261 // Host should be lowercased
162 EXPECT_THAT(handshake->CreateClientHandshakeMessage(), 262 EXPECT_EQ("example.com", GetHostFieldValue(handshake.get()));
163 testing::HasSubstr("Host: example.com\r\n")); 263 EXPECT_EQ("http://example.com", GetOriginFieldValue(handshake.get()));
164 EXPECT_THAT(handshake->CreateClientHandshakeMessage(),
165 testing::HasSubstr("Origin: http://example.com\r\n"));
166 } 264 }
167 265
168 TEST(WebSocketHandshakeTest, CreateClientHandshakeMessage_TrimPort80) { 266 TEST_F(WebSocketHandshakeTest, CreateClientHandshakeMessage_TrimPort80) {
169 scoped_ptr<WebSocketHandshake> handshake( 267 scoped_ptr<WebSocketHandshake> handshake(
170 new WebSocketHandshake(GURL("ws://example.com:80/demo"), 268 new WebSocketHandshake(GURL("ws://example.com:80/demo"),
171 "http://example.com", 269 "http://example.com",
172 "ws://example.com/demo", 270 "ws://example.com/demo",
173 "sample")); 271 "sample"));
174 // :80 should be trimmed as it's the default port for ws://. 272 // :80 should be trimmed as it's the default port for ws://.
175 EXPECT_THAT(handshake->CreateClientHandshakeMessage(), 273 EXPECT_EQ("example.com", GetHostFieldValue(handshake.get()));
176 testing::HasSubstr("Host: example.com\r\n"));
177 } 274 }
178 275
179 TEST(WebSocketHandshakeTest, CreateClientHandshakeMessage_TrimPort443) { 276 TEST_F(WebSocketHandshakeTest, CreateClientHandshakeMessage_TrimPort443) {
180 scoped_ptr<WebSocketHandshake> handshake( 277 scoped_ptr<WebSocketHandshake> handshake(
181 new WebSocketHandshake(GURL("wss://example.com:443/demo"), 278 new WebSocketHandshake(GURL("wss://example.com:443/demo"),
182 "http://example.com", 279 "http://example.com",
183 "wss://example.com/demo", 280 "wss://example.com/demo",
184 "sample")); 281 "sample"));
185 // :443 should be trimmed as it's the default port for wss://. 282 // :443 should be trimmed as it's the default port for wss://.
186 EXPECT_THAT(handshake->CreateClientHandshakeMessage(), 283 EXPECT_EQ("example.com", GetHostFieldValue(handshake.get()));
187 testing::HasSubstr("Host: example.com\r\n"));
188 } 284 }
189 285
190 TEST(WebSocketHandshakeTest, CreateClientHandshakeMessage_NonDefaultPortForWs) { 286 TEST_F(WebSocketHandshakeTest,
287 CreateClientHandshakeMessage_NonDefaultPortForWs) {
191 scoped_ptr<WebSocketHandshake> handshake( 288 scoped_ptr<WebSocketHandshake> handshake(
192 new WebSocketHandshake(GURL("ws://example.com:8080/demo"), 289 new WebSocketHandshake(GURL("ws://example.com:8080/demo"),
193 "http://example.com", 290 "http://example.com",
194 "wss://example.com/demo", 291 "wss://example.com/demo",
195 "sample")); 292 "sample"));
196 // :8080 should be preserved as it's not the default port for ws://. 293 // :8080 should be preserved as it's not the default port for ws://.
197 EXPECT_THAT(handshake->CreateClientHandshakeMessage(), 294 EXPECT_EQ("example.com:8080", GetHostFieldValue(handshake.get()));
198 testing::HasSubstr("Host: example.com:8080\r\n"));
199 } 295 }
200 296
201 TEST(WebSocketHandshakeTest, 297 TEST_F(WebSocketHandshakeTest,
202 CreateClientHandshakeMessage_NonDefaultPortForWss) { 298 CreateClientHandshakeMessage_NonDefaultPortForWss) {
203 scoped_ptr<WebSocketHandshake> handshake( 299 scoped_ptr<WebSocketHandshake> handshake(
204 new WebSocketHandshake(GURL("wss://example.com:4443/demo"), 300 new WebSocketHandshake(GURL("wss://example.com:4443/demo"),
205 "http://example.com", 301 "http://example.com",
206 "wss://example.com/demo", 302 "wss://example.com/demo",
207 "sample")); 303 "sample"));
208 // :4443 should be preserved as it's not the default port for wss://. 304 // :4443 should be preserved as it's not the default port for wss://.
209 EXPECT_THAT(handshake->CreateClientHandshakeMessage(), 305 EXPECT_EQ("example.com:4443", GetHostFieldValue(handshake.get()));
210 testing::HasSubstr("Host: example.com:4443\r\n"));
211 } 306 }
212 307
213 TEST(WebSocketHandshakeTest, CreateClientHandshakeMessage_WsBut443) { 308 TEST_F(WebSocketHandshakeTest, CreateClientHandshakeMessage_WsBut443) {
214 scoped_ptr<WebSocketHandshake> handshake( 309 scoped_ptr<WebSocketHandshake> handshake(
215 new WebSocketHandshake(GURL("ws://example.com:443/demo"), 310 new WebSocketHandshake(GURL("ws://example.com:443/demo"),
216 "http://example.com", 311 "http://example.com",
217 "ws://example.com/demo", 312 "ws://example.com/demo",
218 "sample")); 313 "sample"));
219 // :443 should be preserved as it's not the default port for ws://. 314 // :443 should be preserved as it's not the default port for ws://.
220 EXPECT_THAT(handshake->CreateClientHandshakeMessage(), 315 EXPECT_EQ("example.com:443", GetHostFieldValue(handshake.get()));
221 testing::HasSubstr("Host: example.com:443\r\n"));
222 } 316 }
223 317
224 TEST(WebSocketHandshakeTest, CreateClientHandshakeMessage_WssBut80) { 318 TEST_F(WebSocketHandshakeTest, CreateClientHandshakeMessage_WssBut80) {
225 scoped_ptr<WebSocketHandshake> handshake( 319 scoped_ptr<WebSocketHandshake> handshake(
226 new WebSocketHandshake(GURL("wss://example.com:80/demo"), 320 new WebSocketHandshake(GURL("wss://example.com:80/demo"),
227 "http://example.com", 321 "http://example.com",
228 "wss://example.com/demo", 322 "wss://example.com/demo",
229 "sample")); 323 "sample"));
230 // :80 should be preserved as it's not the default port for wss://. 324 // :80 should be preserved as it's not the default port for wss://.
231 EXPECT_THAT(handshake->CreateClientHandshakeMessage(), 325 EXPECT_EQ("example.com:80", GetHostFieldValue(handshake.get()));
232 testing::HasSubstr("Host: example.com:80\r\n"));
233 } 326 }
234 327
235 } // namespace net 328 } // namespace net
OLDNEW
« no previous file with comments | « net/websockets/websocket_handshake_draft75_unittest.cc ('k') | net/websockets/websocket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698