OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // End-to-end tests for WebSocket. | 5 // End-to-end tests for WebSocket. |
6 // | 6 // |
7 // A python server is (re)started for each test, which is moderately | 7 // A python server is (re)started for each test, which is moderately |
8 // inefficient. However, it makes these tests a good fit for scenarios which | 8 // inefficient. However, it makes these tests a good fit for scenarios which |
9 // require special server configurations. | 9 // require special server configurations. |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
24 #include "base/strings/string_piece.h" | 24 #include "base/strings/string_piece.h" |
25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
26 #include "net/base/auth.h" | 26 #include "net/base/auth.h" |
27 #include "net/base/proxy_delegate.h" | 27 #include "net/base/proxy_delegate.h" |
28 #include "net/proxy/proxy_service.h" | 28 #include "net/proxy/proxy_service.h" |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 #include "net/test/spawned_test_server/spawned_test_server.h" | 30 #include "net/test/spawned_test_server/spawned_test_server.h" |
31 #include "net/test/test_data_directory.h" | 31 #include "net/test/test_data_directory.h" |
| 32 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
32 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
33 #include "net/websockets/websocket_channel.h" | 34 #include "net/websockets/websocket_channel.h" |
34 #include "net/websockets/websocket_event_interface.h" | 35 #include "net/websockets/websocket_event_interface.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "url/origin.h" | 37 #include "url/origin.h" |
37 | 38 |
38 namespace net { | 39 namespace net { |
39 | 40 |
40 class URLRequest; | 41 class URLRequest; |
41 | 42 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 // The test server doesn't have an unauthenticated proxy mode. WebSockets | 385 // The test server doesn't have an unauthenticated proxy mode. WebSockets |
385 // cannot provide auth information that isn't already cached, so it's | 386 // cannot provide auth information that isn't already cached, so it's |
386 // necessary to preflight an HTTP request to authenticate against the proxy. | 387 // necessary to preflight an HTTP request to authenticate against the proxy. |
387 // It doesn't matter what the URL is, as long as it is an HTTP navigation. | 388 // It doesn't matter what the URL is, as long as it is an HTTP navigation. |
388 GURL http_page = | 389 GURL http_page = |
389 ReplaceUrlScheme(ws_server.GetURL("connect_check.html"), "http"); | 390 ReplaceUrlScheme(ws_server.GetURL("connect_check.html"), "http"); |
390 TestDelegate delegate; | 391 TestDelegate delegate; |
391 delegate.set_credentials( | 392 delegate.set_credentials( |
392 AuthCredentials(base::ASCIIToUTF16("foo"), base::ASCIIToUTF16("bar"))); | 393 AuthCredentials(base::ASCIIToUTF16("foo"), base::ASCIIToUTF16("bar"))); |
393 { | 394 { |
394 std::unique_ptr<URLRequest> request( | 395 std::unique_ptr<URLRequest> request(context_.CreateRequest( |
395 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate)); | 396 http_page, DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
396 request->Start(); | 397 request->Start(); |
397 // TestDelegate exits the message loop when the request completes by | 398 // TestDelegate exits the message loop when the request completes by |
398 // default. | 399 // default. |
399 base::RunLoop().Run(); | 400 base::RunLoop().Run(); |
400 EXPECT_TRUE(delegate.auth_required_called()); | 401 EXPECT_TRUE(delegate.auth_required_called()); |
401 } | 402 } |
402 | 403 |
403 GURL ws_url = ws_server.GetURL(kEchoServer); | 404 GURL ws_url = ws_server.GetURL(kEchoServer); |
404 EXPECT_TRUE(ConnectAndWait(ws_url)); | 405 EXPECT_TRUE(ConnectAndWait(ws_url)); |
405 const TestProxyDelegateWithProxyInfo::ResolvedProxyInfo& info = | 406 const TestProxyDelegateWithProxyInfo::ResolvedProxyInfo& info = |
(...skipping 26 matching lines...) Expand all Loading... |
432 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 433 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
433 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, | 434 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
434 GetWebSocketTestDataDirectory()); | 435 GetWebSocketTestDataDirectory()); |
435 | 436 |
436 ASSERT_TRUE(https_server.Start()); | 437 ASSERT_TRUE(https_server.Start()); |
437 ASSERT_TRUE(wss_server.Start()); | 438 ASSERT_TRUE(wss_server.Start()); |
438 InitialiseContext(); | 439 InitialiseContext(); |
439 // Set HSTS via https: | 440 // Set HSTS via https: |
440 TestDelegate delegate; | 441 TestDelegate delegate; |
441 GURL https_page = https_server.GetURL("/hsts-headers.html"); | 442 GURL https_page = https_server.GetURL("/hsts-headers.html"); |
442 std::unique_ptr<URLRequest> request( | 443 std::unique_ptr<URLRequest> request(context_.CreateRequest( |
443 context_.CreateRequest(https_page, DEFAULT_PRIORITY, &delegate)); | 444 https_page, DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
444 request->Start(); | 445 request->Start(); |
445 // TestDelegate exits the message loop when the request completes. | 446 // TestDelegate exits the message loop when the request completes. |
446 base::RunLoop().Run(); | 447 base::RunLoop().Run(); |
447 EXPECT_EQ(OK, delegate.request_status()); | 448 EXPECT_EQ(OK, delegate.request_status()); |
448 | 449 |
449 // Check HSTS with ws: | 450 // Check HSTS with ws: |
450 // Change the scheme from wss: to ws: to verify that it is switched back. | 451 // Change the scheme from wss: to ws: to verify that it is switched back. |
451 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); | 452 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); |
452 EXPECT_TRUE(ConnectAndWait(ws_url)); | 453 EXPECT_TRUE(ConnectAndWait(ws_url)); |
453 } | 454 } |
(...skipping 12 matching lines...) Expand all Loading... |
466 ASSERT_TRUE(wss_server.Start()); | 467 ASSERT_TRUE(wss_server.Start()); |
467 InitialiseContext(); | 468 InitialiseContext(); |
468 // Set HSTS via wss: | 469 // Set HSTS via wss: |
469 GURL wss_url = wss_server.GetURL("set-hsts"); | 470 GURL wss_url = wss_server.GetURL("set-hsts"); |
470 EXPECT_TRUE(ConnectAndWait(wss_url)); | 471 EXPECT_TRUE(ConnectAndWait(wss_url)); |
471 | 472 |
472 // Verify via http: | 473 // Verify via http: |
473 TestDelegate delegate; | 474 TestDelegate delegate; |
474 GURL http_page = | 475 GURL http_page = |
475 ReplaceUrlScheme(https_server.GetURL("/simple.html"), "http"); | 476 ReplaceUrlScheme(https_server.GetURL("/simple.html"), "http"); |
476 std::unique_ptr<URLRequest> request( | 477 std::unique_ptr<URLRequest> request(context_.CreateRequest( |
477 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate)); | 478 http_page, DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
478 request->Start(); | 479 request->Start(); |
479 // TestDelegate exits the message loop when the request completes. | 480 // TestDelegate exits the message loop when the request completes. |
480 base::RunLoop().Run(); | 481 base::RunLoop().Run(); |
481 EXPECT_EQ(OK, delegate.request_status()); | 482 EXPECT_EQ(OK, delegate.request_status()); |
482 EXPECT_TRUE(request->url().SchemeIs("https")); | 483 EXPECT_TRUE(request->url().SchemeIs("https")); |
483 } | 484 } |
484 | 485 |
485 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToWebSocket)) { | 486 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToWebSocket)) { |
486 SpawnedTestServer::SSLOptions ssl_options( | 487 SpawnedTestServer::SSLOptions ssl_options( |
487 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 488 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 GURL ws_url = ws_server.GetURL("header-continuation"); | 527 GURL ws_url = ws_server.GetURL("header-continuation"); |
527 | 528 |
528 EXPECT_TRUE(ConnectAndWait(ws_url)); | 529 EXPECT_TRUE(ConnectAndWait(ws_url)); |
529 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", | 530 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", |
530 event_interface_->extensions()); | 531 event_interface_->extensions()); |
531 } | 532 } |
532 | 533 |
533 } // namespace | 534 } // namespace |
534 | 535 |
535 } // namespace net | 536 } // namespace net |
OLD | NEW |