| 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 GetWebSocketTestDataDirectory()); | 378 GetWebSocketTestDataDirectory()); |
| 379 ASSERT_TRUE(ws_server.Start()); | 379 ASSERT_TRUE(ws_server.Start()); |
| 380 InitialiseContext(); | 380 InitialiseContext(); |
| 381 | 381 |
| 382 GURL ws_url = ws_server.GetURL("truncated-headers"); | 382 GURL ws_url = ws_server.GetURL("truncated-headers"); |
| 383 EXPECT_FALSE(ConnectAndWait(ws_url)); | 383 EXPECT_FALSE(ConnectAndWait(ws_url)); |
| 384 } | 384 } |
| 385 | 385 |
| 386 // Regression test for crbug.com/455215 "HSTS not applied to WebSocket" | 386 // Regression test for crbug.com/455215 "HSTS not applied to WebSocket" |
| 387 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsHttpsToWebSocket)) { | 387 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsHttpsToWebSocket)) { |
| 388 SpawnedTestServer::SSLOptions ssl_options( | 388 SpawnedTestServer::SSLOptions ssl_options; |
| 389 SpawnedTestServer::SSLOptions::CERT_OK_FOR_LOCALHOST); | |
| 390 SpawnedTestServer https_server( | 389 SpawnedTestServer https_server( |
| 391 SpawnedTestServer::TYPE_HTTPS, ssl_options, | 390 SpawnedTestServer::TYPE_HTTPS, ssl_options, |
| 392 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 391 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 393 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, | 392 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 394 GetWebSocketTestDataDirectory()); | 393 GetWebSocketTestDataDirectory()); |
| 395 | |
| 396 ASSERT_TRUE(https_server.StartInBackground()); | 394 ASSERT_TRUE(https_server.StartInBackground()); |
| 397 ASSERT_TRUE(wss_server.StartInBackground()); | 395 ASSERT_TRUE(wss_server.StartInBackground()); |
| 398 ASSERT_TRUE(https_server.BlockUntilStarted()); | 396 ASSERT_TRUE(https_server.BlockUntilStarted()); |
| 399 ASSERT_TRUE(wss_server.BlockUntilStarted()); | 397 ASSERT_TRUE(wss_server.BlockUntilStarted()); |
| 400 InitialiseContext(); | 398 InitialiseContext(); |
| 401 // Set HSTS via https: | 399 // Set HSTS via https: |
| 402 TestDelegate delegate; | 400 TestDelegate delegate; |
| 403 GURL https_page = https_server.GetURL("files/hsts-headers.html"); | 401 GURL https_page = https_server.GetURL("files/hsts-headers.html"); |
| 404 scoped_ptr<URLRequest> request( | 402 scoped_ptr<URLRequest> request( |
| 405 context_.CreateRequest(https_page, DEFAULT_PRIORITY, &delegate)); | 403 context_.CreateRequest(https_page, DEFAULT_PRIORITY, &delegate)); |
| 406 request->Start(); | 404 request->Start(); |
| 407 // TestDelegate exits the message loop when the request completes. | 405 // TestDelegate exits the message loop when the request completes. |
| 408 base::RunLoop().Run(); | 406 base::RunLoop().Run(); |
| 409 EXPECT_TRUE(request->status().is_success()); | 407 EXPECT_TRUE(request->status().is_success()); |
| 410 | 408 |
| 411 // Check HSTS with ws: | 409 // Check HSTS with ws: |
| 412 // Change the scheme from wss: to ws: to verify that it is switched back. | 410 // Change the scheme from wss: to ws: to verify that it is switched back. |
| 413 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); | 411 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); |
| 414 EXPECT_TRUE(ConnectAndWait(ws_url)); | 412 EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 415 } | 413 } |
| 416 | 414 |
| 417 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToHttps)) { | 415 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToHttps)) { |
| 418 SpawnedTestServer::SSLOptions ssl_options( | 416 SpawnedTestServer::SSLOptions ssl_options; |
| 419 SpawnedTestServer::SSLOptions::CERT_OK_FOR_LOCALHOST); | |
| 420 SpawnedTestServer https_server( | 417 SpawnedTestServer https_server( |
| 421 SpawnedTestServer::TYPE_HTTPS, ssl_options, | 418 SpawnedTestServer::TYPE_HTTPS, ssl_options, |
| 422 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 419 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); |
| 423 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, | 420 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 424 GetWebSocketTestDataDirectory()); | 421 GetWebSocketTestDataDirectory()); |
| 425 ASSERT_TRUE(https_server.StartInBackground()); | 422 ASSERT_TRUE(https_server.StartInBackground()); |
| 426 ASSERT_TRUE(wss_server.StartInBackground()); | 423 ASSERT_TRUE(wss_server.StartInBackground()); |
| 427 ASSERT_TRUE(https_server.BlockUntilStarted()); | 424 ASSERT_TRUE(https_server.BlockUntilStarted()); |
| 428 ASSERT_TRUE(wss_server.BlockUntilStarted()); | 425 ASSERT_TRUE(wss_server.BlockUntilStarted()); |
| 429 InitialiseContext(); | 426 InitialiseContext(); |
| 430 // Set HSTS via wss: | 427 // Set HSTS via wss: |
| 431 GURL wss_url = wss_server.GetURL("set-hsts"); | 428 GURL wss_url = wss_server.GetURL("set-hsts"); |
| 432 EXPECT_TRUE(ConnectAndWait(wss_url)); | 429 EXPECT_TRUE(ConnectAndWait(wss_url)); |
| 433 | 430 |
| 434 // Verify via http: | 431 // Verify via http: |
| 435 TestDelegate delegate; | 432 TestDelegate delegate; |
| 436 GURL http_page = | 433 GURL http_page = |
| 437 ReplaceUrlScheme(https_server.GetURL("files/simple.html"), "http"); | 434 ReplaceUrlScheme(https_server.GetURL("files/simple.html"), "http"); |
| 438 scoped_ptr<URLRequest> request( | 435 scoped_ptr<URLRequest> request( |
| 439 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate)); | 436 context_.CreateRequest(http_page, DEFAULT_PRIORITY, &delegate)); |
| 440 request->Start(); | 437 request->Start(); |
| 441 // TestDelegate exits the message loop when the request completes. | 438 // TestDelegate exits the message loop when the request completes. |
| 442 base::RunLoop().Run(); | 439 base::RunLoop().Run(); |
| 443 EXPECT_TRUE(request->status().is_success()); | 440 EXPECT_TRUE(request->status().is_success()); |
| 444 EXPECT_TRUE(request->url().SchemeIs("https")); | 441 EXPECT_TRUE(request->url().SchemeIs("https")); |
| 445 } | 442 } |
| 446 | 443 |
| 447 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToWebSocket)) { | 444 TEST_F(WebSocketEndToEndTest, DISABLED_ON_ANDROID(HstsWebSocketToWebSocket)) { |
| 448 SpawnedTestServer::SSLOptions ssl_options( | 445 SpawnedTestServer::SSLOptions ssl_options; |
| 449 SpawnedTestServer::SSLOptions::CERT_OK_FOR_LOCALHOST); | |
| 450 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, | 446 SpawnedTestServer wss_server(SpawnedTestServer::TYPE_WSS, ssl_options, |
| 451 GetWebSocketTestDataDirectory()); | 447 GetWebSocketTestDataDirectory()); |
| 452 ASSERT_TRUE(wss_server.Start()); | 448 ASSERT_TRUE(wss_server.Start()); |
| 453 InitialiseContext(); | 449 InitialiseContext(); |
| 454 // Set HSTS via wss: | 450 // Set HSTS via wss: |
| 455 GURL wss_url = wss_server.GetURL("set-hsts"); | 451 GURL wss_url = wss_server.GetURL("set-hsts"); |
| 456 EXPECT_TRUE(ConnectAndWait(wss_url)); | 452 EXPECT_TRUE(ConnectAndWait(wss_url)); |
| 457 | 453 |
| 458 // Verify via wss: | 454 // Verify via wss: |
| 459 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); | 455 GURL ws_url = ReplaceUrlScheme(wss_server.GetURL(kEchoServer), "ws"); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 488 GURL ws_url = ws_server.GetURL("header-continuation"); | 484 GURL ws_url = ws_server.GetURL("header-continuation"); |
| 489 | 485 |
| 490 EXPECT_TRUE(ConnectAndWait(ws_url)); | 486 EXPECT_TRUE(ConnectAndWait(ws_url)); |
| 491 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", | 487 EXPECT_EQ("permessage-deflate; server_max_window_bits=10", |
| 492 event_interface_->extensions()); | 488 event_interface_->extensions()); |
| 493 } | 489 } |
| 494 | 490 |
| 495 } // namespace | 491 } // namespace |
| 496 | 492 |
| 497 } // namespace net | 493 } // namespace net |
| OLD | NEW |