| 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 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
| 22 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
| 23 #include "net/base/auth.h" | 23 #include "net/base/auth.h" |
| 24 #include "net/base/network_delegate.h" | 24 #include "net/base/network_delegate.h" |
| 25 #include "net/base/test_data_directory.h" | 25 #include "net/base/test_data_directory.h" |
| 26 #include "net/proxy/proxy_service.h" | 26 #include "net/proxy/proxy_service.h" |
| 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 27 #include "net/test/spawned_test_server/spawned_test_server.h" | 28 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 28 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
| 29 #include "net/websockets/websocket_channel.h" | 30 #include "net/websockets/websocket_channel.h" |
| 30 #include "net/websockets/websocket_event_interface.h" | 31 #include "net/websockets/websocket_event_interface.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "url/origin.h" | 33 #include "url/origin.h" |
| 33 | 34 |
| 34 namespace net { | 35 namespace net { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 GetWebSocketTestDataDirectory()); | 382 GetWebSocketTestDataDirectory()); |
| 382 ASSERT_TRUE(ws_server.Start()); | 383 ASSERT_TRUE(ws_server.Start()); |
| 383 InitialiseContext(); | 384 InitialiseContext(); |
| 384 | 385 |
| 385 GURL ws_url = ws_server.GetURL("truncated-headers"); | 386 GURL ws_url = ws_server.GetURL("truncated-headers"); |
| 386 EXPECT_FALSE(ConnectAndWait(ws_url)); | 387 EXPECT_FALSE(ConnectAndWait(ws_url)); |
| 387 } | 388 } |
| 388 | 389 |
| 389 // Regression test for crbug.com/455215 "HSTS not applied to WebSocket" | 390 // Regression test for crbug.com/455215 "HSTS not applied to WebSocket" |
| 390 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsHttpsToWebSocket)) { | 391 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsHttpsToWebSocket)) { |
| 392 EmbeddedTestServer https_server(net::EmbeddedTestServer::Type::TYPE_HTTPS); |
| 393 https_server.SetSSLConfig( |
| 394 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 395 https_server.ServeFilesFromSourceDirectory("net/data/url_request_unittest"); |
| 396 |
| 391 SpawnedTestServer::SSLOptions ssl_options( | 397 SpawnedTestServer::SSLOptions ssl_options( |
| 392 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 398 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
| 393 SpawnedTestServer https_server( | |
| 394 SpawnedTestServer::TYPE_HTTPS, ssl_options, | |
| 395 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
| 396 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, | 399 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 397 GetWebSocketTestDataDirectory()); | 400 GetWebSocketTestDataDirectory()); |
| 398 | 401 |
| 399 ASSERT_TRUE(https_server.StartInBackground()); | 402 ASSERT_TRUE(https_server.Start()); |
| 400 ASSERT_TRUE(wss_server.StartInBackground()); | 403 ASSERT_TRUE(wss_server.Start()); |
| 401 ASSERT_TRUE(https_server.BlockUntilStarted()); | |
| 402 ASSERT_TRUE(wss_server.BlockUntilStarted()); | |
| 403 InitialiseContext(); | 404 InitialiseContext(); |
| 404 // Set HSTS via https: | 405 // Set HSTS via https: |
| 405 TestDelegate delegate; | 406 TestDelegate delegate; |
| 406 GURL https_page = https_server.GetURL("files/hsts-headers.html"); | 407 GURL https_page = https_server.GetURL("/hsts-headers.html"); |
| 407 scoped_ptr<URLRequest> request( | 408 scoped_ptr<URLRequest> request( |
| 408 context_.CreateRequest(https_page, DEFAULT_PRIORITY, &delegate)); | 409 context_.CreateRequest(https_page, DEFAULT_PRIORITY, &delegate)); |
| 409 request->Start(); | 410 request->Start(); |
| 410 // TestDelegate exits the message loop when the request completes. | 411 // TestDelegate exits the message loop when the request completes. |
| 411 base::RunLoop().Run(); | 412 base::RunLoop().Run(); |
| 412 EXPECT_TRUE(request->status().is_success()); | 413 EXPECT_TRUE(request->status().is_success()); |
| 413 | 414 |
| 414 // Check HSTS with ws: | 415 // Check HSTS with ws: |
| 415 // Change the scheme from wss: to ws: to verify that it is switched back. | 416 // Change the scheme from wss: to ws: to verify that it is switched back. |
| 416 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); | 417 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); |
| 417 EXPECT_TRUE(ConnectAndWait(ws_url)); | 418 EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 418 } | 419 } |
| 419 | 420 |
| 420 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToHttps)) { | 421 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToHttps)) { |
| 422 EmbeddedTestServer https_server(net::EmbeddedTestServer::Type::TYPE_HTTPS); |
| 423 https_server.SetSSLConfig( |
| 424 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 425 https_server.ServeFilesFromSourceDirectory("net/data/url_request_unittest"); |
| 426 |
| 421 SpawnedTestServer::SSLOptions ssl_options( | 427 SpawnedTestServer::SSLOptions ssl_options( |
| 422 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 428 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
| 423 SpawnedTestServer https_server( | |
| 424 SpawnedTestServer::TYPE_HTTPS, ssl_options, | |
| 425 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
| 426 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, | 429 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 427 GetWebSocketTestDataDirectory()); | 430 GetWebSocketTestDataDirectory()); |
| 428 ASSERT_TRUE(https_server.StartInBackground()); | 431 ASSERT_TRUE(https_server.Start()); |
| 429 ASSERT_TRUE(wss_server.StartInBackground()); | 432 ASSERT_TRUE(wss_server.Start()); |
| 430 ASSERT_TRUE(https_server.BlockUntilStarted()); | |
| 431 ASSERT_TRUE(wss_server.BlockUntilStarted()); | |
| 432 InitialiseContext(); | 433 InitialiseContext(); |
| 433 // Set HSTS via wss: | 434 // Set HSTS via wss: |
| 434 GURL wss_url = wss_server.GetURL("set-hsts"); | 435 GURL wss_url = wss_server.GetURL("set-hsts"); |
| 435 EXPECT_TRUE(ConnectAndWait(wss_url)); | 436 EXPECT_TRUE(ConnectAndWait(wss_url)); |
| 436 | 437 |
| 437 // Verify via http: | 438 // Verify via http: |
| 438 TestDelegate delegate; | 439 TestDelegate delegate; |
| 439 GURL http_page = | 440 GURL http_page = |
| 440 ReplaceUrlScheme(https_server.GetURL("files/simple.html"), "http"); | 441 ReplaceUrlScheme(https_server.GetURL("/simple.html"), "http"); |
| 441 scoped_ptr<URLRequest> request( | 442 scoped_ptr<URLRequest> request( |
| 442 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate)); | 443 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate)); |
| 443 request->Start(); | 444 request->Start(); |
| 444 // TestDelegate exits the message loop when the request completes. | 445 // TestDelegate exits the message loop when the request completes. |
| 445 base::RunLoop().Run(); | 446 base::RunLoop().Run(); |
| 446 EXPECT_TRUE(request->status().is_success()); | 447 EXPECT_TRUE(request->status().is_success()); |
| 447 EXPECT_TRUE(request->url().SchemeIs("https")); | 448 EXPECT_TRUE(request->url().SchemeIs("https")); |
| 448 } | 449 } |
| 449 | 450 |
| 450 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToWebSocket)) { | 451 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToWebSocket)) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 GURL ws_url = ws_server.GetURL("header-continuation"); | 492 GURL ws_url = ws_server.GetURL("header-continuation"); |
| 492 | 493 |
| 493 EXPECT_TRUE(ConnectAndWait(ws_url)); | 494 EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 494 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", | 495 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", |
| 495 event_interface_->extensions()); | 496 event_interface_->extensions()); |
| 496 } | 497 } |
| 497 | 498 |
| 498 } // namespace | 499 } // namespace |
| 499 | 500 |
| 500 } // namespace net | 501 } // namespace net |
| OLD | NEW |