| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 293 |
| 294 NavigateToHTTPS("multiple-connections.html"); | 294 NavigateToHTTPS("multiple-connections.html"); |
| 295 | 295 |
| 296 EXPECT_EQ("PASS", WaitAndGetTitle()); | 296 EXPECT_EQ("PASS", WaitAndGetTitle()); |
| 297 } | 297 } |
| 298 | 298 |
| 299 // Regression test for crbug.com/903553005 | 299 // Regression test for crbug.com/903553005 |
| 300 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, WebSocketAppliesHSTS) { | 300 IN_PROC_BROWSER_TEST_F(WebSocketBrowserTest, WebSocketAppliesHSTS) { |
| 301 net::SpawnedTestServer https_server( | 301 net::SpawnedTestServer https_server( |
| 302 net::SpawnedTestServer::TYPE_HTTPS, | 302 net::SpawnedTestServer::TYPE_HTTPS, |
| 303 net::SpawnedTestServer::SSLOptions( | 303 net::SpawnedTestServer::SSLOptions(), |
| 304 net::SpawnedTestServer::SSLOptions::CERT_OK_FOR_LOCALHOST), | |
| 305 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 304 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 306 net::SpawnedTestServer wss_server( | 305 // This test sets HSTS on 127.0.0.1. To avoid being redirected to https, start |
| 307 net::SpawnedTestServer::TYPE_WSS, | 306 // the http server on "localhost" instead. |
| 308 net::SpawnedTestServer::SSLOptions( | |
| 309 net::SpawnedTestServer::SSLOptions::CERT_OK_FOR_LOCALHOST), | |
| 310 net::GetWebSocketTestDataDirectory()); | |
| 311 // This test sets HSTS on localhost. To avoid being redirected to https, start | |
| 312 // the http server on 127.0.0.1 instead. | |
| 313 net::SpawnedTestServer http_server( | 307 net::SpawnedTestServer http_server( |
| 314 net::SpawnedTestServer::TYPE_HTTP, net::SpawnedTestServer::kLocalhost, | 308 net::SpawnedTestServer::TYPE_HTTP, |
| 309 "localhost", |
| 315 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 310 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 316 ASSERT_TRUE(https_server.StartInBackground()); | 311 ASSERT_TRUE(https_server.StartInBackground()); |
| 317 ASSERT_TRUE(http_server.StartInBackground()); | 312 ASSERT_TRUE(http_server.StartInBackground()); |
| 318 ASSERT_TRUE(wss_server.StartInBackground()); | 313 ASSERT_TRUE(wss_server_.StartInBackground()); |
| 319 ASSERT_TRUE(https_server.BlockUntilStarted()); | 314 ASSERT_TRUE(https_server.BlockUntilStarted()); |
| 320 | 315 |
| 321 // Set HSTS on localhost. | 316 // Set HSTS on 127.0.0.1. |
| 322 content::TitleWatcher title_watcher( | 317 content::TitleWatcher title_watcher( |
| 323 browser()->tab_strip_model()->GetActiveWebContents(), | 318 browser()->tab_strip_model()->GetActiveWebContents(), |
| 324 base::ASCIIToUTF16("SET")); | 319 base::ASCIIToUTF16("SET")); |
| 325 ui_test_utils::NavigateToURL( | 320 ui_test_utils::NavigateToURL( |
| 326 browser(), https_server.GetURL("files/websocket/set-hsts.html")); | 321 browser(), https_server.GetURL("files/websocket/set-hsts.html")); |
| 327 const base::string16 result = title_watcher.WaitAndGetTitle(); | 322 const base::string16 result = title_watcher.WaitAndGetTitle(); |
| 328 EXPECT_TRUE(EqualsASCII(result, "SET")); | 323 EXPECT_TRUE(EqualsASCII(result, "SET")); |
| 329 | 324 |
| 330 // Verify that it applies to WebSockets. | 325 // Verify that it applies to WebSockets. |
| 331 ASSERT_TRUE(wss_server.BlockUntilStarted()); | 326 ASSERT_TRUE(wss_server_.BlockUntilStarted()); |
| 332 GURL wss_url = wss_server.GetURL("echo-with-no-extension"); | 327 GURL wss_url = wss_server_.GetURL("echo-with-no-extension"); |
| 333 std::string scheme("ws"); | 328 std::string scheme("ws"); |
| 334 GURL::Replacements scheme_replacement; | 329 GURL::Replacements scheme_replacement; |
| 335 scheme_replacement.SetSchemeStr(scheme); | 330 scheme_replacement.SetSchemeStr(scheme); |
| 336 GURL ws_url = wss_url.ReplaceComponents(scheme_replacement); | 331 GURL ws_url = wss_url.ReplaceComponents(scheme_replacement); |
| 337 | 332 |
| 338 // An https: URL won't work here here because the mixed content policy | 333 // An https: URL won't work here here because the mixed content policy |
| 339 // disallows connections to unencrypted WebSockets from encrypted pages. | 334 // disallows connections to unencrypted WebSockets from encrypted pages. |
| 340 ASSERT_TRUE(http_server.BlockUntilStarted()); | 335 ASSERT_TRUE(http_server.BlockUntilStarted()); |
| 341 GURL http_url = | 336 GURL http_url = |
| 342 http_server.GetURL("files/websocket/check-hsts.html#" + ws_url.spec()); | 337 http_server.GetURL("files/websocket/check-hsts.html#" + ws_url.spec()); |
| 343 | 338 |
| 344 ui_test_utils::NavigateToURL(browser(), http_url); | 339 ui_test_utils::NavigateToURL(browser(), http_url); |
| 345 | 340 |
| 346 EXPECT_EQ("PASS", WaitAndGetTitle()); | 341 EXPECT_EQ("PASS", WaitAndGetTitle()); |
| 347 } | 342 } |
| 348 | 343 |
| 349 } // namespace | 344 } // namespace |
| OLD | NEW |