OLD | NEW |
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/ref_counted.h" | 8 #include "base/ref_counted.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n" | 256 "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n" |
257 "Sec-WebSocket-Protocol: sample\r\n" | 257 "Sec-WebSocket-Protocol: sample\r\n" |
258 "Upgrade: WebSocket\r\n" | 258 "Upgrade: WebSocket\r\n" |
259 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n" | 259 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n" |
260 "Origin: http://example.com\r\n" | 260 "Origin: http://example.com\r\n" |
261 "\r\n" | 261 "\r\n" |
262 "^n:ds[4U"; | 262 "^n:ds[4U"; |
263 | 263 |
264 bool sent = websocket_->SendData(kHandshakeRequestMessage, | 264 bool sent = websocket_->SendData(kHandshakeRequestMessage, |
265 strlen(kHandshakeRequestMessage)); | 265 strlen(kHandshakeRequestMessage)); |
266 EXPECT_EQ(true, sent); | 266 EXPECT_TRUE(sent); |
267 MessageLoop::current()->RunAllPending(); | 267 MessageLoop::current()->RunAllPending(); |
268 EXPECT_EQ(kHandshakeRequestMessage, socket_->sent_data()); | 268 EXPECT_EQ(kHandshakeRequestMessage, socket_->sent_data()); |
269 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); | 269 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); |
270 websocket_->OnSentData(socket_.get(), strlen(kHandshakeRequestMessage)); | 270 websocket_->OnSentData(socket_.get(), strlen(kHandshakeRequestMessage)); |
271 EXPECT_EQ(strlen(kHandshakeRequestMessage), delegate.amount_sent()); | 271 EXPECT_EQ(strlen(kHandshakeRequestMessage), delegate.amount_sent()); |
272 | 272 |
273 const char kHandshakeResponseMessage[] = | 273 const char kHandshakeResponseMessage[] = |
274 "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" | 274 "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" |
275 "Upgrade: WebSocket\r\n" | 275 "Upgrade: WebSocket\r\n" |
276 "Connection: Upgrade\r\n" | 276 "Connection: Upgrade\r\n" |
(...skipping 24 matching lines...) Expand all Loading... |
301 "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n" | 301 "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n" |
302 "Sec-WebSocket-Protocol: sample\r\n" | 302 "Sec-WebSocket-Protocol: sample\r\n" |
303 "Upgrade: WebSocket\r\n" | 303 "Upgrade: WebSocket\r\n" |
304 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n" | 304 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n" |
305 "Origin: http://example.com\r\n" | 305 "Origin: http://example.com\r\n" |
306 "\r\n" | 306 "\r\n" |
307 "^n:ds[4U"; | 307 "^n:ds[4U"; |
308 | 308 |
309 bool sent = websocket_->SendData(kHandshakeRequestMessage, | 309 bool sent = websocket_->SendData(kHandshakeRequestMessage, |
310 strlen(kHandshakeRequestMessage)); | 310 strlen(kHandshakeRequestMessage)); |
311 EXPECT_EQ(true, sent); | 311 EXPECT_TRUE(sent); |
312 // We assume request is sent in one data chunk (from WebKit) | 312 // We assume request is sent in one data chunk (from WebKit) |
313 // We don't support streaming request. | 313 // We don't support streaming request. |
314 MessageLoop::current()->RunAllPending(); | 314 MessageLoop::current()->RunAllPending(); |
315 EXPECT_EQ(kHandshakeRequestMessage, socket_->sent_data()); | 315 EXPECT_EQ(kHandshakeRequestMessage, socket_->sent_data()); |
316 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); | 316 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); |
317 websocket_->OnSentData(socket_.get(), strlen(kHandshakeRequestMessage)); | 317 websocket_->OnSentData(socket_.get(), strlen(kHandshakeRequestMessage)); |
318 EXPECT_EQ(strlen(kHandshakeRequestMessage), delegate.amount_sent()); | 318 EXPECT_EQ(strlen(kHandshakeRequestMessage), delegate.amount_sent()); |
319 | 319 |
320 const char kHandshakeResponseMessage[] = | 320 const char kHandshakeResponseMessage[] = |
321 "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" | 321 "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 "Sec-WebSocket-Protocol: sample\r\n" | 383 "Sec-WebSocket-Protocol: sample\r\n" |
384 "Upgrade: WebSocket\r\n" | 384 "Upgrade: WebSocket\r\n" |
385 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n" | 385 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n" |
386 "Origin: http://example.com\r\n" | 386 "Origin: http://example.com\r\n" |
387 "Cookie: CR-test=1; CR-test-httponly=1\r\n" | 387 "Cookie: CR-test=1; CR-test-httponly=1\r\n" |
388 "\r\n" | 388 "\r\n" |
389 "^n:ds[4U"; | 389 "^n:ds[4U"; |
390 | 390 |
391 bool sent = websocket_->SendData(kHandshakeRequestMessage, | 391 bool sent = websocket_->SendData(kHandshakeRequestMessage, |
392 strlen(kHandshakeRequestMessage)); | 392 strlen(kHandshakeRequestMessage)); |
393 EXPECT_EQ(true, sent); | 393 EXPECT_TRUE(sent); |
394 MessageLoop::current()->RunAllPending(); | 394 MessageLoop::current()->RunAllPending(); |
395 EXPECT_EQ(kHandshakeRequestExpected, socket_->sent_data()); | 395 EXPECT_EQ(kHandshakeRequestExpected, socket_->sent_data()); |
396 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); | 396 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); |
397 websocket_->OnSentData(socket_, strlen(kHandshakeRequestExpected)); | 397 websocket_->OnSentData(socket_, strlen(kHandshakeRequestExpected)); |
398 EXPECT_EQ(strlen(kHandshakeRequestMessage), delegate.amount_sent()); | 398 EXPECT_EQ(strlen(kHandshakeRequestMessage), delegate.amount_sent()); |
399 | 399 |
400 const char kHandshakeResponseMessage[] = | 400 const char kHandshakeResponseMessage[] = |
401 "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" | 401 "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" |
402 "Upgrade: WebSocket\r\n" | 402 "Upgrade: WebSocket\r\n" |
403 "Connection: Upgrade\r\n" | 403 "Connection: Upgrade\r\n" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n" | 470 "Sec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\n" |
471 "Sec-WebSocket-Protocol: sample\r\n" | 471 "Sec-WebSocket-Protocol: sample\r\n" |
472 "Upgrade: WebSocket\r\n" | 472 "Upgrade: WebSocket\r\n" |
473 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n" | 473 "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n" |
474 "Origin: http://example.com\r\n" | 474 "Origin: http://example.com\r\n" |
475 "\r\n" | 475 "\r\n" |
476 "^n:ds[4U"; | 476 "^n:ds[4U"; |
477 | 477 |
478 bool sent = websocket_->SendData(kHandshakeRequestMessage, | 478 bool sent = websocket_->SendData(kHandshakeRequestMessage, |
479 strlen(kHandshakeRequestMessage)); | 479 strlen(kHandshakeRequestMessage)); |
480 EXPECT_EQ(true, sent); | 480 EXPECT_TRUE(sent); |
481 MessageLoop::current()->RunAllPending(); | 481 MessageLoop::current()->RunAllPending(); |
482 EXPECT_EQ(kHandshakeRequestExpected, socket_->sent_data()); | 482 EXPECT_EQ(kHandshakeRequestExpected, socket_->sent_data()); |
483 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); | 483 EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState()); |
484 websocket_->OnSentData(socket_, strlen(kHandshakeRequestExpected)); | 484 websocket_->OnSentData(socket_, strlen(kHandshakeRequestExpected)); |
485 EXPECT_EQ(strlen(kHandshakeRequestMessage), delegate.amount_sent()); | 485 EXPECT_EQ(strlen(kHandshakeRequestMessage), delegate.amount_sent()); |
486 | 486 |
487 const char kHandshakeResponseMessage[] = | 487 const char kHandshakeResponseMessage[] = |
488 "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" | 488 "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" |
489 "Upgrade: WebSocket\r\n" | 489 "Upgrade: WebSocket\r\n" |
490 "Connection: Upgrade\r\n" | 490 "Connection: Upgrade\r\n" |
(...skipping 24 matching lines...) Expand all Loading... |
515 EXPECT_EQ(2U, cookie_store_->entries().size()); | 515 EXPECT_EQ(2U, cookie_store_->entries().size()); |
516 EXPECT_EQ(cookieUrl, cookie_store_->entries()[0].url); | 516 EXPECT_EQ(cookieUrl, cookie_store_->entries()[0].url); |
517 EXPECT_EQ("CR-test=1", cookie_store_->entries()[0].cookie_line); | 517 EXPECT_EQ("CR-test=1", cookie_store_->entries()[0].cookie_line); |
518 EXPECT_EQ(cookieUrl, cookie_store_->entries()[1].url); | 518 EXPECT_EQ(cookieUrl, cookie_store_->entries()[1].url); |
519 EXPECT_EQ("CR-test-httponly=1", cookie_store_->entries()[1].cookie_line); | 519 EXPECT_EQ("CR-test-httponly=1", cookie_store_->entries()[1].cookie_line); |
520 | 520 |
521 CloseWebSocketJob(); | 521 CloseWebSocketJob(); |
522 } | 522 } |
523 | 523 |
524 } // namespace net | 524 } // namespace net |
OLD | NEW |