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/run_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 class PrefetchBrowserTestBase : public InProcessBrowserTest { | 29 class PrefetchBrowserTestBase : public InProcessBrowserTest { |
30 public: | 30 public: |
31 explicit PrefetchBrowserTestBase(bool do_predictive_networking, | 31 explicit PrefetchBrowserTestBase(bool do_predictive_networking, |
32 bool do_prefetch_field_trial) | 32 bool do_prefetch_field_trial) |
33 : do_predictive_networking_(do_predictive_networking), | 33 : do_predictive_networking_(do_predictive_networking), |
34 do_prefetch_field_trial_(do_prefetch_field_trial) {} | 34 do_prefetch_field_trial_(do_prefetch_field_trial) {} |
35 | 35 |
36 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 36 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
37 if (do_prefetch_field_trial_) { | 37 if (do_prefetch_field_trial_) { |
38 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 38 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
39 "Prefetch/ExperimentYes/"); | 39 "Prefetch/ExperimentDisabled/"); |
40 } else { | 40 } else { |
41 command_line->AppendSwitchASCII(switches::kForceFieldTrials, | 41 command_line->AppendSwitchASCII(switches::kForceFieldTrials, |
42 "Prefetch/ExperimentNo/"); | 42 "Prefetch/ExperimentEnabled/"); |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 virtual void SetUpOnMainThread() OVERRIDE { | 46 virtual void SetUpOnMainThread() OVERRIDE { |
47 browser()->profile()->GetPrefs()->SetBoolean( | 47 browser()->profile()->GetPrefs()->SetBoolean( |
48 prefs::kNetworkPredictionEnabled, do_predictive_networking_); | 48 prefs::kNetworkPredictionEnabled, do_predictive_networking_); |
49 } | 49 } |
50 | 50 |
51 bool RunPrefetchExperiment(bool expect_success, Browser* browser) { | 51 bool RunPrefetchExperiment(bool expect_success, Browser* browser) { |
52 CHECK(test_server()->Start()); | 52 CHECK(test_server()->Start()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 base::Closure callback) { | 129 base::Closure callback) { |
130 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 130 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
131 scoped_ptr<net::URLRequestInterceptor> never_respond_handler( | 131 scoped_ptr<net::URLRequestInterceptor> never_respond_handler( |
132 new HangingRequestInterceptor(callback)); | 132 new HangingRequestInterceptor(callback)); |
133 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( | 133 net::URLRequestFilter::GetInstance()->AddUrlInterceptor( |
134 url, never_respond_handler.Pass()); | 134 url, never_respond_handler.Pass()); |
135 } | 135 } |
136 | 136 |
137 // Privacy option is on, experiment is on. Prefetch should succeed. | 137 // Privacy option is on, experiment is on. Prefetch should succeed. |
138 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOn, PredOnExpOn) { | 138 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOn, PredOnExpOn) { |
139 EXPECT_TRUE(RunPrefetchExperiment(true, browser())); | 139 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
140 } | 140 } |
141 | 141 |
142 // Privacy option is on, experiment is off. Prefetch should be dropped. | 142 // Privacy option is on, experiment is off. Prefetch should be dropped. |
143 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOff, PredOnExpOff) { | 143 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOff, PredOnExpOff) { |
144 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 144 EXPECT_TRUE(RunPrefetchExperiment(true, browser())); |
145 } | 145 } |
146 | 146 |
147 // Privacy option is off, experiment is on. Prefetch should be dropped. | 147 // Privacy option is off, experiment is on. Prefetch should be dropped. |
148 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOffExpOn, PredOffExpOn) { | 148 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOffExpOn, PredOffExpOn) { |
149 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 149 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
150 } | 150 } |
151 | 151 |
152 // Privacy option is off, experiment is off. Prefetch should be dropped. | 152 // Privacy option is off, experiment is off. Prefetch should be dropped. |
153 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOffExpOff, PredOffExpOff) { | 153 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOffExpOff, PredOffExpOff) { |
154 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); | 154 EXPECT_TRUE(RunPrefetchExperiment(false, browser())); |
155 } | 155 } |
156 | 156 |
157 // Bug 339909: When in incognito mode the browser crashed due to an | 157 // Bug 339909: When in incognito mode the browser crashed due to an |
158 // uninitialized preference member. Verify that it no longer does. | 158 // uninitialized preference member. Verify that it no longer does. |
159 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOn, IncognitoTest) { | 159 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOff, IncognitoTest) { |
160 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); | 160 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); |
161 Browser* incognito_browser = new Browser( | 161 Browser* incognito_browser = new Browser( |
162 Browser::CreateParams(incognito_profile, browser()->host_desktop_type())); | 162 Browser::CreateParams(incognito_profile, browser()->host_desktop_type())); |
163 | 163 |
164 // Navigate just to have a tab in this window, otherwise there is no | 164 // Navigate just to have a tab in this window, otherwise there is no |
165 // WebContents for the incognito browser. | 165 // WebContents for the incognito browser. |
166 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); | 166 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
167 | 167 |
168 EXPECT_TRUE(RunPrefetchExperiment(true, incognito_browser)); | 168 EXPECT_TRUE(RunPrefetchExperiment(true, incognito_browser)); |
169 } | 169 } |
170 | 170 |
171 // This test will verify the following: | 171 // This test will verify the following: |
172 // - that prefetches from the browser are actually launched | 172 // - that prefetches from the browser are actually launched |
173 // - if a prefetch is in progress, but the originating renderer is destroyed, | 173 // - if a prefetch is in progress, but the originating renderer is destroyed, |
174 // that the pending prefetch request is cleaned up cleanly and does not | 174 // that the pending prefetch request is cleaned up cleanly and does not |
175 // result in a crash. | 175 // result in a crash. |
176 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOn, | 176 IN_PROC_BROWSER_TEST_F(PrefetchBrowserTestPredictionOnExpOff, |
177 PrefetchFromBrowser) { | 177 PrefetchFromBrowser) { |
178 const GURL kHangingUrl("http://hanging-url.com"); | 178 const GURL kHangingUrl("http://hanging-url.com"); |
179 base::RunLoop loop_; | 179 base::RunLoop loop_; |
180 BrowserThread::PostTask(BrowserThread::IO, | 180 BrowserThread::PostTask(BrowserThread::IO, |
181 FROM_HERE, | 181 FROM_HERE, |
182 base::Bind(&CreateHangingRequestInterceptorOnIO, | 182 base::Bind(&CreateHangingRequestInterceptorOnIO, |
183 kHangingUrl, | 183 kHangingUrl, |
184 loop_.QuitClosure())); | 184 loop_.QuitClosure())); |
185 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 185 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
186 content::RenderFrameHost* rfh = | 186 content::RenderFrameHost* rfh = |
187 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(); | 187 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(); |
188 rfh->Send(new PrefetchMsg_Prefetch(rfh->GetRoutingID(), kHangingUrl)); | 188 rfh->Send(new PrefetchMsg_Prefetch(rfh->GetRoutingID(), kHangingUrl)); |
189 loop_.Run(); | 189 loop_.Run(); |
190 } | 190 } |
191 | 191 |
192 } // namespace | 192 } // namespace |
OLD | NEW |