| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 void SetUpCommandLine(base::CommandLine* command_line) override { | 223 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 224 command_line->AppendSwitch( | 224 command_line->AppendSwitch( |
| 225 switches::kEnableExperimentalWebPlatformFeatures); | 225 switches::kEnableExperimentalWebPlatformFeatures); |
| 226 command_line->AppendSwitchASCII( | 226 command_line->AppendSwitchASCII( |
| 227 switches::kEnableBlinkFeatures, kBlinkPreconnectFeature); | 227 switches::kEnableBlinkFeatures, kBlinkPreconnectFeature); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void SetUpOnMainThread() override { | 230 void SetUpOnMainThread() override { |
| 231 connection_listener_.reset(new ConnectionListener()); | 231 connection_listener_.reset(new ConnectionListener()); |
| 232 embedded_test_server()->SetConnectionListener(connection_listener_.get()); | 232 embedded_test_server()->SetConnectionListener(connection_listener_.get()); |
| 233 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 233 ASSERT_TRUE(embedded_test_server()->Start()); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void TearDownOnMainThread() override { | 236 void TearDownOnMainThread() override { |
| 237 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | 237 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Navigates to a data URL containing the given content, with a MIME type of | 240 // Navigates to a data URL containing the given content, with a MIME type of |
| 241 // text/html. | 241 // text/html. |
| 242 void NavigateToDataURLWithContent(const std::string& content) { | 242 void NavigateToDataURLWithContent(const std::string& content) { |
| 243 std::string encoded_content; | 243 std::string encoded_content; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 WaitUntilHostHasBeenRequested(target_url_.host()); | 336 WaitUntilHostHasBeenRequested(target_url_.host()); |
| 337 } | 337 } |
| 338 | 338 |
| 339 // Flaky on Windows: http://crbug.com/469120 | 339 // Flaky on Windows: http://crbug.com/469120 |
| 340 #if defined(OS_WIN) | 340 #if defined(OS_WIN) |
| 341 #define MAYBE_DnsPrefetch DISABLED_DnsPrefetch | 341 #define MAYBE_DnsPrefetch DISABLED_DnsPrefetch |
| 342 #else | 342 #else |
| 343 #define MAYBE_DnsPrefetch DnsPrefetch | 343 #define MAYBE_DnsPrefetch DnsPrefetch |
| 344 #endif | 344 #endif |
| 345 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, MAYBE_DnsPrefetch) { | 345 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, MAYBE_DnsPrefetch) { |
| 346 ASSERT_TRUE(test_server()->Start()); | |
| 347 int hostnames_requested_before_load = RequestedHostnameCount(); | 346 int hostnames_requested_before_load = RequestedHostnameCount(); |
| 348 ui_test_utils::NavigateToURL( | 347 ui_test_utils::NavigateToURL( |
| 349 browser(), | 348 browser(), |
| 350 GURL(test_server()->GetURL("files/predictor/dns_prefetch.html"))); | 349 GURL(embedded_test_server()->GetURL("/predictor/dns_prefetch.html"))); |
| 351 WaitUntilHostHasBeenRequested(kChromiumHostname); | 350 WaitUntilHostHasBeenRequested(kChromiumHostname); |
| 352 ASSERT_FALSE(HasHostBeenRequested(kInvalidLongHostname)); | 351 ASSERT_FALSE(HasHostBeenRequested(kInvalidLongHostname)); |
| 353 ASSERT_EQ(hostnames_requested_before_load + 1, RequestedHostnameCount()); | 352 ASSERT_EQ(hostnames_requested_before_load + 1, RequestedHostnameCount()); |
| 354 } | 353 } |
| 355 | 354 |
| 356 // Tests that preconnect warms up a socket connection to a test server. | 355 // Tests that preconnect warms up a socket connection to a test server. |
| 357 // Note: This test uses a data URI to serve the preconnect hint, to make sure | 356 // Note: This test uses a data URI to serve the preconnect hint, to make sure |
| 358 // that the network stack doesn't just re-use its connection to the test server. | 357 // that the network stack doesn't just re-use its connection to the test server. |
| 359 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectNonCORS) { | 358 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, PreconnectNonCORS) { |
| 360 GURL preconnect_url = embedded_test_server()->base_url(); | 359 GURL preconnect_url = embedded_test_server()->base_url(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 // Second navigation to content with an img. | 453 // Second navigation to content with an img. |
| 455 std::string img_content = | 454 std::string img_content = |
| 456 "<img src=\"" + preconnect_url.spec() + "test.gif\">"; | 455 "<img src=\"" + preconnect_url.spec() + "test.gif\">"; |
| 457 NavigateToDataURLWithContent(img_content); | 456 NavigateToDataURLWithContent(img_content); |
| 458 connection_listener_->WaitUntilFirstConnectionRead(); | 457 connection_listener_->WaitUntilFirstConnectionRead(); |
| 459 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); | 458 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); |
| 460 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); | 459 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); |
| 461 } | 460 } |
| 462 | 461 |
| 463 } // namespace chrome_browser_net | 462 } // namespace chrome_browser_net |
| OLD | NEW |