Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/run_loop.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/common/prefetch_messages.h" | |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/render_frame_host.h" | |
| 18 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 20 #include "net/url_request/url_request_filter.h" | |
| 21 #include "net/url_request/url_request_job.h" | |
| 22 | |
| 23 using content::BrowserThread; | |
| 16 | 24 |
| 17 namespace { | 25 namespace { |
| 18 | 26 |
| 19 const char kPrefetchPage[] = "files/prerender/simple_prefetch.html"; | 27 const char kPrefetchPage[] = "files/prerender/simple_prefetch.html"; |
| 20 | 28 |
| 21 class PrefetchBrowserTestBase : public InProcessBrowserTest { | 29 class PrefetchBrowserTestBase : public InProcessBrowserTest { |
| 22 public: | 30 public: |
| 23 explicit PrefetchBrowserTestBase(bool do_predictive_networking, | 31 explicit PrefetchBrowserTestBase(bool do_predictive_networking, |
| 24 bool do_prefetch_field_trial) | 32 bool do_prefetch_field_trial) |
| 25 : do_predictive_networking_(do_predictive_networking), | 33 : do_predictive_networking_(do_predictive_networking), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 PrefetchBrowserTestPredictionOffExpOn() | 85 PrefetchBrowserTestPredictionOffExpOn() |
| 78 : PrefetchBrowserTestBase(false, true) {} | 86 : PrefetchBrowserTestBase(false, true) {} |
| 79 }; | 87 }; |
| 80 | 88 |
| 81 class PrefetchBrowserTestPredictionOffExpOff : public PrefetchBrowserTestBase { | 89 class PrefetchBrowserTestPredictionOffExpOff : public PrefetchBrowserTestBase { |
| 82 public: | 90 public: |
| 83 PrefetchBrowserTestPredictionOffExpOff() | 91 PrefetchBrowserTestPredictionOffExpOff() |
| 84 : PrefetchBrowserTestBase(false, false) {} | 92 : PrefetchBrowserTestBase(false, false) {} |
| 85 }; | 93 }; |
| 86 | 94 |
| 95 // URLRequestJob (and associated handler) which hangs. | |
| 96 class HangingURLRequestJob : public net::URLRequestJob { | |
| 97 public: | |
| 98 HangingURLRequestJob(net::URLRequest* request, | |
| 99 net::NetworkDelegate* network_delegate) | |
| 100 : net::URLRequestJob(request, network_delegate) { | |
| 101 } | |
| 102 | |
| 103 virtual void Start() OVERRIDE {} | |
| 104 | |
| 105 private: | |
| 106 virtual ~HangingURLRequestJob() {} | |
| 107 }; | |
| 108 | |
| 109 class HangingRequestInterceptor : public net::URLRequestInterceptor { | |
| 110 public: | |
| 111 explicit HangingRequestInterceptor(base::Closure callback) | |
| 112 : callback_(callback) { | |
| 113 } | |
| 114 | |
| 115 virtual ~HangingRequestInterceptor() {} | |
| 116 | |
| 117 virtual net::URLRequestJob* MaybeInterceptRequest( | |
| 118 net::URLRequest* request, | |
| 119 net::NetworkDelegate* network_delegate) const OVERRIDE { | |
| 120 if (!callback_.is_null()) { | |
| 121 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback_); | |
| 122 } | |
| 123 return new HangingURLRequestJob(request, network_delegate); | |
| 124 } | |
| 125 | |
| 126 private: | |
| 127 base::Closure callback_; | |
| 128 }; | |
| 129 | |
| 130 void CreateHangingRequestInterceptorOnIO(const GURL& url, | |
| 131 base::Closure callback) { | |
| 132 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 133 scoped_ptr<net::URLRequestInterceptor> never_respond_handler( | |
| 134 new HangingRequestInterceptor(callback)); | |
| 135 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | |
| 136 url, never_respond_handler.Pass()); | |
| 137 } | |
| 138 | |
| 87 // Privacy option is on, experiment is on. Prefetch should succeed. | 139 // Privacy option is on, experiment is on. Prefetch should succeed. |
| 88 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOn, PredOnExpOn) { | 140 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOn, PredOnExpOn) { |
| 89 EXPECT_TRUE(RunPrefetchExperiment(true, browser())); | 141 EXPECT_TRUE(RunPrefetchExperiment(true, browser())); |
| 90 } | 142 } |
| 91 | 143 |
| 92 // Privacy option is on, experiment is off. Prefetch should be dropped. | 144 // Privacy option is on, experiment is off. Prefetch should be dropped. |
| 93 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOff, PredOnExpOff) { | 145 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOff, PredOnExpOff) { |
| 94 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 146 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
| 95 } | 147 } |
| 96 | 148 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 111 Browser* incognito_browser = new Browser( | 163 Browser* incognito_browser = new Browser( |
| 112 Browser::CreateParams(incognito_profile, browser()->host_desktop_type())); | 164 Browser::CreateParams(incognito_profile, browser()->host_desktop_type())); |
| 113 | 165 |
| 114 // Navigate just to have a tab in this window, otherwise there is no | 166 // Navigate just to have a tab in this window, otherwise there is no |
| 115 // WebContents for the incognito browser. | 167 // WebContents for the incognito browser. |
| 116 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); | 168 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
| 117 | 169 |
| 118 EXPECT_TRUE(RunPrefetchExperiment(true, incognito_browser)); | 170 EXPECT_TRUE(RunPrefetchExperiment(true, incognito_browser)); |
| 119 } | 171 } |
| 120 | 172 |
| 173 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOn, | |
| 174 PrefetchFromBrowser) { | |
| 175 const GURL kHangingUrl("http://hanging-url.com"); | |
| 176 base::RunLoop loop_; | |
| 177 BrowserThread::PostTask( | |
| 178 BrowserThread::IO, FROM_HERE, | |
| 179 base::Bind(&CreateHangingRequestInterceptorOnIO, | |
| 180 kHangingUrl, | |
| 181 loop_.QuitClosure())); | |
| 182 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | |
| 183 content::RenderFrameHost* rfh = | |
| 184 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | |
| 185 rfh->Send(new PrefetchMsg_Prefetch(rfh->GetRoutingID(), kHangingUrl)); | |
| 186 loop_.Run(); | |
|
jkarlin
2014/06/16 14:48:29
What is this test testing exactly?
tburkard
2014/06/16 15:02:57
Done.
added a comment explaining
| |
| 187 } | |
| 188 | |
| 121 } // namespace | 189 } // namespace |
| 122 | |
| OLD | NEW |