Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/json/json_string_value_serializer.h" | 16 #include "base/json/json_string_value_serializer.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 21 #include "base/run_loop.h" | 21 #include "base/run_loop.h" |
| 22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 23 #include "base/stl_util.h" | 23 #include "base/stl_util.h" |
| 24 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
| 25 #include "base/test/scoped_feature_list.h" | |
| 25 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 26 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 29 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 29 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" | 30 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
| 30 #include "chrome/browser/net/predictor.h" | 31 #include "chrome/browser/net/predictor.h" |
| 32 #include "chrome/browser/net/predictor_tab_helper.h" | |
| 31 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 34 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/test/base/in_process_browser_test.h" | 37 #include "chrome/test/base/in_process_browser_test.h" |
| 36 #include "chrome/test/base/ui_test_utils.h" | 38 #include "chrome/test/base/ui_test_utils.h" |
| 37 #include "components/prefs/pref_service.h" | 39 #include "components/prefs/pref_service.h" |
| 38 #include "content/public/browser/browsing_data_remover.h" | 40 #include "content/public/browser/browsing_data_remover.h" |
| 39 #include "content/public/common/content_switches.h" | 41 #include "content/public/common/content_switches.h" |
| 40 #include "content/public/test/browser_test_utils.h" | 42 #include "content/public/test/browser_test_utils.h" |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 protected: | 515 protected: |
| 514 void SetUpInProcessBrowserTestFixture() override { | 516 void SetUpInProcessBrowserTestFixture() override { |
| 515 scoped_host_resolver_proc_.reset(new net::ScopedDefaultHostResolverProc( | 517 scoped_host_resolver_proc_.reset(new net::ScopedDefaultHostResolverProc( |
| 516 rule_based_resolver_proc_.get())); | 518 rule_based_resolver_proc_.get())); |
| 517 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 519 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 518 } | 520 } |
| 519 | 521 |
| 520 void SetUpCommandLine(base::CommandLine* command_line) override { | 522 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 521 command_line->AppendSwitch( | 523 command_line->AppendSwitch( |
| 522 switches::kEnableExperimentalWebPlatformFeatures); | 524 switches::kEnableExperimentalWebPlatformFeatures); |
| 523 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 525 scoped_feature_list_.InitAndEnableFeature(features::kPreconnectMore); |
|
Ilya Sherman
2017/06/12 21:50:29
Could this be done outside of SetUpCommandLine()?
chaopeng
2017/06/28 19:21:24
Done.
| |
| 524 "PreconnectMore"); | |
| 525 } | 526 } |
| 526 | 527 |
| 527 void SetUpOnMainThread() override { | 528 void SetUpOnMainThread() override { |
| 528 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 529 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 529 task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 530 task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 530 cross_site_test_server()->ServeFilesFromSourceDirectory( | 531 cross_site_test_server()->ServeFilesFromSourceDirectory( |
| 531 "chrome/test/data/"); | 532 "chrome/test/data/"); |
| 532 | 533 |
| 533 connection_listener_.reset(new ConnectionListener()); | 534 connection_listener_.reset(new ConnectionListener()); |
| 534 cross_site_connection_listener_.reset(new ConnectionListener()); | 535 cross_site_connection_listener_.reset(new ConnectionListener()); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 std::unique_ptr<ConnectionListener> connection_listener_; | 792 std::unique_ptr<ConnectionListener> connection_listener_; |
| 792 std::unique_ptr<ConnectionListener> cross_site_connection_listener_; | 793 std::unique_ptr<ConnectionListener> cross_site_connection_listener_; |
| 793 | 794 |
| 794 private: | 795 private: |
| 795 scoped_refptr<net::RuleBasedHostResolverProc> rule_based_resolver_proc_; | 796 scoped_refptr<net::RuleBasedHostResolverProc> rule_based_resolver_proc_; |
| 796 std::unique_ptr<net::ScopedDefaultHostResolverProc> | 797 std::unique_ptr<net::ScopedDefaultHostResolverProc> |
| 797 scoped_host_resolver_proc_; | 798 scoped_host_resolver_proc_; |
| 798 std::unique_ptr<net::EmbeddedTestServer> cross_site_test_server_; | 799 std::unique_ptr<net::EmbeddedTestServer> cross_site_test_server_; |
| 799 std::unique_ptr<CrossSitePredictorObserver> observer_; | 800 std::unique_ptr<CrossSitePredictorObserver> observer_; |
| 800 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 801 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 802 base::test::ScopedFeatureList scoped_feature_list_; | |
| 801 }; | 803 }; |
| 802 | 804 |
| 803 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SingleLookupTest) { | 805 IN_PROC_BROWSER_TEST_F(PredictorBrowserTest, SingleLookupTest) { |
| 804 DiscardAllResultsOnUIThread(); | 806 DiscardAllResultsOnUIThread(); |
| 805 GURL url("http://www.example.test/"); | 807 GURL url("http://www.example.test/"); |
| 806 | 808 |
| 807 // Try to flood the predictor with many concurrent requests. | 809 // Try to flood the predictor with many concurrent requests. |
| 808 std::vector<GURL> names{url}; | 810 std::vector<GURL> names{url}; |
| 809 FloodResolveRequestsOnUIThread(names); | 811 FloodResolveRequestsOnUIThread(names); |
| 810 observer()->WaitUntilHostLookedUp(url); | 812 observer()->WaitUntilHostLookedUp(url); |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1586 // Second navigation to content with an img. | 1588 // Second navigation to content with an img. |
| 1587 std::string img_content = | 1589 std::string img_content = |
| 1588 "<img src=\"" + preconnect_url.spec() + "test.gif\">"; | 1590 "<img src=\"" + preconnect_url.spec() + "test.gif\">"; |
| 1589 NavigateToDataURLWithContent(img_content); | 1591 NavigateToDataURLWithContent(img_content); |
| 1590 connection_listener_->WaitUntilFirstConnectionRead(); | 1592 connection_listener_->WaitUntilFirstConnectionRead(); |
| 1591 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); | 1593 EXPECT_EQ(2u, connection_listener_->GetAcceptedSocketCount()); |
| 1592 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); | 1594 EXPECT_EQ(1u, connection_listener_->GetReadSocketCount()); |
| 1593 } | 1595 } |
| 1594 | 1596 |
| 1595 } // namespace chrome_browser_net | 1597 } // namespace chrome_browser_net |
| OLD | NEW |