Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/command_line.h" | |
| 6 #include "base/strings/string_split.h" | |
| 7 #include "chrome/browser/prerender/prerender_manager.h" | |
| 8 #include "chrome/browser/prerender/prerender_manager_factory.h" | |
| 9 #include "chrome/browser/prerender/prerender_test_utils.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "chrome/browser/ui/browser_commands.h" | |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 15 #include "chrome/common/chrome_switches.h" | |
| 16 #include "chrome/grit/generated_resources.h" | |
| 17 #include "chrome/test/base/ui_test_utils.h" | |
| 18 #include "content/public/common/content_switches.h" | |
| 19 #include "content/public/common/url_constants.h" | |
| 20 #include "content/public/test/browser_test_utils.h" | |
| 21 #include "net/base/escape.h" | |
| 22 #include "net/dns/mock_host_resolver.h" | |
| 23 #include "net/test/embedded_test_server/request_handler_util.h" | |
| 24 #include "testing/gtest/include/gtest/gtest.h" | |
| 25 #include "ui/base/l10n/l10n_util.h" | |
| 26 | |
| 27 using prerender::test_utils::CreateCountingInterceptorOnIO; | |
| 28 using prerender::test_utils::DestructionWaiter; | |
| 29 using prerender::test_utils::RequestCounter; | |
| 30 using prerender::test_utils::TestPrerender; | |
| 31 using prerender::test_utils::TestPrerenderContents; | |
| 32 using task_manager::browsertest_util::WaitForTaskManagerRows; | |
| 33 | |
| 34 namespace { | |
| 35 // Fetches a boolean value from javascript. Returns whether the fetch | |
| 36 // succeeded; the value of the variable is returned in value. If | |
| 37 // javascript_variable does not exist, this returns false and value is | |
| 38 // unchanged. The function checks that script execution works. | |
| 39 bool GetJavascriptBoolean(const std::string& javascript_variable, | |
| 40 content::WebContents* web_contents, | |
| 41 bool* value) { | |
| 42 // In order to detect unknown variables a three-valued return is needed. | |
| 43 int result; | |
| 44 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 45 web_contents, | |
| 46 "try { if (" + javascript_variable + ") { " + | |
| 47 "window.domAutomationController.send(1) } else { " + | |
| 48 "window.domAutomationController.send(0); } } catch(err) {" + | |
| 49 "window.domAutomationController.send(2) }", | |
| 50 &result)); | |
| 51 if (result == 2) { | |
| 52 // This means an exception was caught, usually because of a missing | |
| 53 // variable. | |
| 54 return false; | |
| 55 } | |
| 56 *value = (result == 1); | |
| 57 return true; | |
| 58 } | |
| 59 | |
| 60 // As above, but just checks for a missing variable. | |
| 61 bool JavascriptVariableMissing(const std::string& javascript_variable, | |
| 62 content::WebContents* web_contents) { | |
| 63 bool unused; | |
| 64 return !GetJavascriptBoolean(javascript_variable, web_contents, &unused); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 namespace prerender { | |
| 70 | |
| 71 // These URLs used for test resources must be relative with the exception of | |
| 72 // |PrefetchLoaderPath|, which is only used in |PrerenderTestURLImpl()|. | |
| 73 const char kPrefetchImagePage[] = "prerender/prefetch_image.html"; | |
| 74 const char kPrefetchLoopPage[] = "prerender/prefetch_loop.html"; | |
| 75 const char kPrefetchJpeg[] = "prerender/image.jpeg"; | |
| 76 const char kPrefetchLoaderPath[] = "/prerender/prefetch_loader.html"; | |
| 77 const char kPrefetchPage[] = "prerender/prefetch_page.html"; | |
| 78 const char kPrefetchPage2[] = "prerender/prefetch_page2.html"; | |
| 79 const char kPrefetchPng[] = "prerender/image.png"; | |
| 80 const char kPrefetchScript[] = "prerender/prefetch.js"; | |
| 81 const char kPrefetchScript2[] = "prerender/prefetch2.js"; | |
| 82 const char kPrefetchSubresourceRedirectPage[] = | |
| 83 "prerender/prefetch_subresource_redirect.html"; | |
| 84 | |
| 85 const char kPageBool[] = "pageBool"; | |
| 86 const char kScriptBool[] = "scriptBool"; | |
| 87 | |
| 88 class NoStatePrefetchBrowserTest | |
| 89 : public test_utils::PrerenderInProcessBrowserTest { | |
| 90 public: | |
| 91 class BrowserTestTime : public PrerenderManager::TimeOverride { | |
| 92 public: | |
| 93 BrowserTestTime() {} | |
| 94 | |
| 95 base::Time GetCurrentTime() const override { | |
| 96 if (delta_.is_zero()) { | |
| 97 return base::Time::Now(); | |
| 98 } | |
| 99 return time_ + delta_; | |
| 100 } | |
| 101 | |
| 102 base::TimeTicks GetCurrentTimeTicks() const override { | |
| 103 if (delta_.is_zero()) { | |
| 104 return base::TimeTicks::Now(); | |
| 105 } | |
| 106 return time_ticks_ + delta_; | |
| 107 } | |
| 108 | |
| 109 void AdvanceTime(base::TimeDelta delta) { | |
| 110 if (delta_.is_zero()) { | |
|
pasko
2016/10/05 12:35:25
could this avoid storing delta_? In the c-tor it c
mattcary
2016/10/10 11:54:43
This seemed the easier way to manipulate both time
pasko
2016/10/10 12:40:20
I don't think TimeTicks and Time will ever need to
mattcary
2016/10/10 13:56:07
Also discussed offline w/rt SimpleTestClock change
| |
| 111 time_ = base::Time::Now(); | |
| 112 time_ticks_ = base::TimeTicks::Now(); | |
| 113 delta_ = delta; | |
| 114 } else { | |
| 115 delta_ += delta; | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 private: | |
| 120 base::Time time_; | |
| 121 base::TimeTicks time_ticks_; | |
| 122 base::TimeDelta delta_; | |
| 123 }; | |
| 124 | |
| 125 NoStatePrefetchBrowserTest() {} | |
| 126 | |
| 127 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 128 PrerenderInProcessBrowserTest::SetUpCommandLine(command_line); | |
| 129 command_line->AppendSwitchASCII( | |
| 130 switches::kPrerenderMode, switches::kPrerenderModeSwitchValuePrefetch); | |
| 131 } | |
| 132 | |
| 133 void SetUpOnMainThread() override { | |
|
pasko
2016/10/05 12:35:24
I think we would need to call the parent's SetUpOn
mattcary
2016/10/10 11:54:43
? PrerenderInProcessBrowserTest is the parent of t
pasko
2016/10/10 12:40:20
Yes.
mattcary
2016/10/10 13:56:07
Acknowledged.
pasko
2016/10/11 13:56:23
Pardon, I don't know how, but I missed the fact th
mattcary
2016/10/11 15:08:58
Right, it can't be done in the constructor as the
| |
| 134 PrerenderInProcessBrowserTest::SetUpOnMainThread(); | |
| 135 std::unique_ptr<BrowserTestTime> test_time = | |
| 136 base::MakeUnique<BrowserTestTime>(); | |
| 137 browser_test_time_ = test_time.get(); | |
| 138 GetPrerenderManager()->SetTimeOverride(std::move(test_time)); | |
| 139 } | |
| 140 | |
| 141 // Set up a request counter for the path. | |
| 142 void CountRequestFor(const std::string& path, RequestCounter* counter) { | |
| 143 GURL::Replacements replacement; | |
| 144 replacement.SetPathStr(path); | |
| 145 const GURL url = src_server()->base_url().ReplaceComponents(replacement); | |
| 146 base::FilePath url_file = | |
| 147 ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath(path)); | |
| 148 content::BrowserThread::PostTask( | |
| 149 content::BrowserThread::IO, FROM_HERE, | |
| 150 base::Bind(&CreateCountingInterceptorOnIO, url, url_file, | |
| 151 counter->AsWeakPtr())); | |
| 152 } | |
| 153 | |
| 154 BrowserTestTime* GetTimeOverride() const { return browser_test_time_; } | |
|
pasko
2016/10/05 12:35:25
please make it private or explain why this method
mattcary
2016/10/10 11:54:43
It's used by the test subclasses, like all the oth
pasko
2016/10/10 12:40:20
I see. I was thinking about my proposal where time
mattcary
2016/10/10 13:56:07
Looking through overrides of InProcessBrowserTest,
pasko
2016/10/11 13:56:23
I am not sure we are talking about the same thing.
mattcary
2016/10/11 15:08:58
ErrorPageBrowserTest, UnloadTest, SdchBrowserTest.
pasko
2016/10/11 15:40:19
SdchBrowserTest::SetUpCommandLine(...) is non-triv
mattcary
2016/10/12 09:02:52
Acknowledged.
| |
| 155 | |
| 156 private: | |
| 157 ScopedVector<TestPrerender> PrerenderTestURLImpl( | |
| 158 const GURL& prerender_url, | |
| 159 const std::vector<FinalStatus>& expected_final_status_queue, | |
| 160 int expected_number_of_loads) override { | |
| 161 base::StringPairs replacement_text; | |
| 162 replacement_text.push_back( | |
| 163 make_pair("REPLACE_WITH_PREFETCH_URL", prerender_url.spec())); | |
| 164 std::string replacement_path; | |
| 165 net::test_server::GetFilePathWithReplacements( | |
| 166 kPrefetchLoaderPath, replacement_text, &replacement_path); | |
| 167 GURL loader_url = src_server()->GetURL(replacement_path); | |
| 168 | |
| 169 ScopedVector<TestPrerender> prerenders = NavigateWithPrerenders( | |
| 170 loader_url, expected_final_status_queue, expected_number_of_loads); | |
| 171 | |
| 172 TestPrerenderContents* prerender_contents = prerenders[0]->contents(); | |
| 173 CHECK(prerender_contents); | |
| 174 // Checks that the prerender contents final status is unchanged from its | |
| 175 // default value, meaning that the contents has not been destroyed. | |
| 176 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); | |
| 177 | |
| 178 EXPECT_EQ(expected_number_of_loads, prerenders[0]->number_of_loads()); | |
| 179 | |
| 180 return prerenders; | |
| 181 } | |
| 182 | |
| 183 BrowserTestTime* browser_test_time_; | |
| 184 }; | |
| 185 | |
| 186 // Performs a full load of the target page and check that javascript values are | |
| 187 // set as expected. This confirms that our test system is working correctly, so | |
| 188 // that when the target page is prefetched it can be confirmed that javascript | |
| 189 // is not executed. | |
| 190 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, CheckJavascript) { | |
| 191 ui_test_utils::NavigateToURL( | |
| 192 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
| 193 content::WebContents* web_contents = | |
| 194 current_browser()->tab_strip_model()->GetActiveWebContents(); | |
| 195 | |
| 196 // Confirms that true and false values can appear. | |
| 197 bool value = false; | |
| 198 EXPECT_TRUE(GetJavascriptBoolean(kPageBool, web_contents, &value)); | |
| 199 EXPECT_TRUE(value); | |
| 200 value = true; | |
| 201 EXPECT_TRUE(GetJavascriptBoolean("pageAntiBool", web_contents, &value)); | |
| 202 EXPECT_FALSE(value); | |
| 203 | |
| 204 // Confirm a value from the script is plumbed through. | |
| 205 value = false; | |
| 206 EXPECT_TRUE(GetJavascriptBoolean(kScriptBool, web_contents, &value)); | |
| 207 EXPECT_TRUE(value); | |
| 208 | |
| 209 // Confirm that the expected happens when a value doesn't exist. | |
| 210 EXPECT_TRUE(JavascriptVariableMissing("iDontExist", web_contents)); | |
| 211 } | |
| 212 | |
| 213 // Checks that a page is correctly prefetched in the case of a | |
| 214 // <link rel=prerender> tag and then loaded into a tab in response to a | |
| 215 // navigation, when NoState Prefetch is enabled, but that the page is not loaded | |
| 216 // (which confirmed by checking that javascript is not executed). | |
| 217 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchSimple) { | |
| 218 RequestCounter script_counter; | |
| 219 CountRequestFor(kPrefetchScript, &script_counter); | |
| 220 RequestCounter main_counter; | |
| 221 CountRequestFor(kPrefetchPage, &main_counter); | |
| 222 | |
| 223 std::unique_ptr<TestPrerender> test_prerender = | |
| 224 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 225 main_counter.WaitForCount(1); | |
| 226 script_counter.WaitForCount(1); | |
| 227 | |
| 228 content::WebContents* contents = | |
| 229 test_prerender->contents()->prerender_contents(); | |
| 230 content::WebContents* active_contents = | |
| 231 current_browser()->tab_strip_model()->GetActiveWebContents(); | |
| 232 EXPECT_TRUE(JavascriptVariableMissing(kPageBool, contents)); | |
| 233 EXPECT_TRUE(JavascriptVariableMissing(kScriptBool, contents)); | |
| 234 EXPECT_TRUE(JavascriptVariableMissing(kPageBool, active_contents)); | |
| 235 EXPECT_TRUE(JavascriptVariableMissing(kScriptBool, active_contents)); | |
| 236 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
| 237 histogram_tester().ExpectBucketCount( | |
| 238 "Prerender.websame_NoStatePrefetchResponseTypes", | |
| 239 4 /* cacheable, main resource */, 1); | |
| 240 histogram_tester().ExpectBucketCount( | |
| 241 "Prerender.websame_NoStatePrefetchResponseTypes", | |
| 242 0 /* cacheable, non-main resource */, 1); | |
| 243 histogram_tester().ExpectTotalCount("Prerender.none_MainResourceRedirects", | |
| 244 0); | |
| 245 histogram_tester().ExpectTotalCount("Prerender.none_SubResourceRedirects", 0); | |
| 246 } | |
| 247 | |
| 248 // Checks the TTFCP histograms on fast reuse of a prefetch. | |
| 249 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchReusedWarm) { | |
| 250 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 251 GetTimeOverride()->AdvanceTime(base::TimeDelta::FromSeconds(10)); | |
| 252 ui_test_utils::NavigateToURL( | |
| 253 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
| 254 histogram_tester().ExpectTotalCount( | |
| 255 "Prerender.websame_NoStatePrefetchTTFCP.Warm.Cacheable", 1); | |
| 256 histogram_tester().ExpectTotalCount( | |
| 257 "Prerender.websame_NoStatePrefetchTTFCP.Cold.Cacheable", 0); | |
| 258 } | |
| 259 | |
| 260 // Checks the histograms on slow reuse of a prefetch. | |
| 261 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchReusedCold) { | |
| 262 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_TIMED_OUT, 1); | |
| 263 GetTimeOverride()->AdvanceTime(base::TimeDelta::FromSeconds(600)); | |
| 264 ui_test_utils::NavigateToURL( | |
| 265 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
| 266 | |
| 267 histogram_tester().ExpectTotalCount( | |
| 268 "Prerender.websame_NoStatePrefetchTTFCP.Warm.Cacheable", 0); | |
| 269 histogram_tester().ExpectTotalCount( | |
| 270 "Prerender.websame_NoStatePrefetchTTFCP.Cold.Cacheable", 1); | |
| 271 } | |
| 272 | |
| 273 // Checks the prefetch of an img tag. | |
| 274 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchImage) { | |
| 275 RequestCounter image_counter; | |
| 276 CountRequestFor(kPrefetchJpeg, &image_counter); | |
| 277 base::StringPairs replacement_text; | |
| 278 replacement_text.push_back( | |
| 279 std::make_pair("REPLACE_WITH_IMAGE_URL", MakeAbsolute(kPrefetchJpeg))); | |
| 280 std::string main_page_path; | |
| 281 net::test_server::GetFilePathWithReplacements( | |
| 282 kPrefetchImagePage, replacement_text, &main_page_path); | |
| 283 // Note CountRequestFor cannot be used on the main page as the test server | |
| 284 // must handling the image url replacement. | |
| 285 PrerenderTestURL(main_page_path, FINAL_STATUS_APP_TERMINATING, 1); | |
| 286 image_counter.WaitForCount(1); | |
| 287 } | |
| 288 | |
| 289 // Checks that a cross-domain prefetching works correctly by looking at | |
| 290 // histograms. | |
| 291 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchCrossDomain) { | |
| 292 static const std::string secondary_domain = "www.foo.com"; | |
| 293 host_resolver()->AddRule(secondary_domain, "127.0.0.1"); | |
| 294 GURL cross_domain_url(base::StringPrintf( | |
| 295 "http://%s:%d/%s", secondary_domain.c_str(), | |
| 296 embedded_test_server()->host_port_pair().port(), kPrefetchPage)); | |
| 297 PrerenderTestURL(cross_domain_url, FINAL_STATUS_APP_TERMINATING, 1); | |
| 298 // TODO(mattcary): remove PLT histograms (here and elsewhere). | |
| 299 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
| 300 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1); | |
| 301 histogram_tester().ExpectTotalCount( | |
| 302 "Prerender.webcross_PrerenderNotSwappedInPLT", 1); | |
| 303 } | |
| 304 | |
| 305 // Checks simultaneous prefetch. | |
| 306 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchSimultaneous) { | |
| 307 RequestCounter first_main_counter; | |
| 308 CountRequestFor(kPrefetchPage, &first_main_counter); | |
| 309 RequestCounter second_main_counter; | |
| 310 CountRequestFor(kPrefetchPage2, &second_main_counter); | |
| 311 RequestCounter first_script_counter; | |
| 312 CountRequestFor(kPrefetchScript, &first_script_counter); | |
| 313 RequestCounter second_script_counter; | |
| 314 CountRequestFor(kPrefetchScript2, &second_script_counter); | |
| 315 | |
| 316 // The first prerender is marked as canceled as when the second starts, it | |
| 317 // sees that the first has been abandoned (presumably because it is detached | |
| 318 // immediately and so dies quickly). | |
| 319 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_CANCELLED, 1); | |
| 320 PrerenderTestURL(kPrefetchPage2, FINAL_STATUS_APP_TERMINATING, 1); | |
| 321 first_main_counter.WaitForCount(1); | |
| 322 second_main_counter.WaitForCount(1); | |
| 323 first_script_counter.WaitForCount(1); | |
| 324 second_script_counter.WaitForCount(1); | |
| 325 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 2); | |
| 326 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 2); | |
| 327 } | |
| 328 | |
| 329 // Checks a prefetch to a nonexisting page. | |
| 330 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchNonexisting) { | |
| 331 PrerenderTestURL("nonexisting-page.html", FINAL_STATUS_APP_TERMINATING, 0); | |
| 332 // TODO(mattcary): we fire up a prerenderer before we discover that the main | |
| 333 // page doesn't exist, we still count this as a prerender. Also we don't fail | |
| 334 // the renderer (presumably because we've detached the resource, etc). Is this | |
| 335 // what we want? | |
| 336 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
| 337 } | |
| 338 | |
| 339 // Checks that a 301 redirect is followed. | |
| 340 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Redirect) { | |
| 341 RequestCounter script_counter; | |
| 342 CountRequestFor(kPrefetchScript, &script_counter); | |
| 343 PrerenderTestURL( | |
| 344 "/server-redirect/?" + | |
| 345 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false), | |
| 346 FINAL_STATUS_APP_TERMINATING, 1); | |
| 347 script_counter.WaitForCount(1); | |
| 348 histogram_tester().ExpectTotalCount( | |
| 349 "Prerender.websame_NoStatePrefetchMainResourceRedirects", 1); | |
| 350 } | |
| 351 | |
| 352 // Checks that a subresource 301 redirect is followed. | |
| 353 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Subresource) { | |
| 354 RequestCounter script_counter; | |
| 355 CountRequestFor(kPrefetchScript, &script_counter); | |
| 356 PrerenderTestURL(kPrefetchSubresourceRedirectPage, | |
| 357 FINAL_STATUS_APP_TERMINATING, 1); | |
| 358 script_counter.WaitForCount(1); | |
| 359 histogram_tester().ExpectTotalCount( | |
| 360 "Prerender.websame_NoStatePrefetchMainResourceRedirects", 1); | |
| 361 } | |
| 362 | |
| 363 // Checks a client redirect is not followed. | |
| 364 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchClientRedirect) { | |
| 365 RequestCounter script_counter; | |
| 366 CountRequestFor(kPrefetchScript, &script_counter); | |
| 367 // A complete load of kPrefetchPage2 is used as a sentinal. Otherwise the test | |
| 368 // ends before script_counter would reliably see the load of kPrefetchScript, | |
| 369 // were it to happen. | |
| 370 RequestCounter sentinel_counter; | |
| 371 CountRequestFor(kPrefetchScript2, &sentinel_counter); | |
| 372 PrerenderTestURL( | |
| 373 "/client-redirect/?" + | |
| 374 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false), | |
| 375 FINAL_STATUS_APP_TERMINATING, 1); | |
| 376 ui_test_utils::NavigateToURL( | |
| 377 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage2))); | |
| 378 sentinel_counter.WaitForCount(1); | |
| 379 script_counter.WaitForCount(0); | |
| 380 } | |
| 381 | |
| 382 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchHttps) { | |
| 383 UseHttpsSrcServer(); | |
| 384 RequestCounter main_counter; | |
| 385 CountRequestFor(kPrefetchPage, &main_counter); | |
| 386 RequestCounter script_counter; | |
| 387 CountRequestFor(kPrefetchScript, &script_counter); | |
| 388 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 389 main_counter.WaitForCount(1); | |
| 390 script_counter.WaitForCount(1); | |
| 391 } | |
| 392 | |
| 393 // Checks that an SSL error prevents prefetch. | |
| 394 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, SSLError) { | |
| 395 // Only send the loaded page, not the loader, through SSL. | |
| 396 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
| 397 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | |
| 398 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); | |
| 399 ASSERT_TRUE(https_server.Start()); | |
| 400 std::unique_ptr<TestPrerender> prerender = | |
| 401 PrerenderTestURL(https_server.GetURL(MakeAbsolute(kPrefetchPage)), | |
| 402 FINAL_STATUS_SSL_ERROR, 0); | |
| 403 DestructionWaiter waiter(prerender->contents(), FINAL_STATUS_SSL_ERROR); | |
| 404 EXPECT_TRUE(waiter.WaitForDestroy()); | |
| 405 } | |
| 406 | |
| 407 // Checks that a subresource failing SSL does not prevent prefetch on the rest | |
| 408 // of the page. | |
| 409 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, SSLSubresourceError) { | |
| 410 // First confirm that the image loads as expected. | |
| 411 | |
| 412 // A separate HTTPS server is started for the subresource; src_server() is | |
| 413 // non-HTTPS. | |
| 414 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
| 415 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | |
| 416 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); | |
| 417 ASSERT_TRUE(https_server.Start()); | |
| 418 GURL https_url = https_server.GetURL("/prerender/image.jpeg"); | |
| 419 base::StringPairs replacement_text; | |
| 420 replacement_text.push_back( | |
| 421 std::make_pair("REPLACE_WITH_IMAGE_URL", https_url.spec())); | |
| 422 std::string main_page_path; | |
| 423 net::test_server::GetFilePathWithReplacements( | |
| 424 kPrefetchImagePage, replacement_text, &main_page_path); | |
| 425 RequestCounter script_counter; | |
| 426 CountRequestFor(kPrefetchScript, &script_counter); | |
| 427 | |
| 428 std::unique_ptr<TestPrerender> prerender = | |
| 429 PrerenderTestURL(main_page_path, FINAL_STATUS_APP_TERMINATING, 1); | |
| 430 // Checks that the presumed failure of the image load didn't affect the script | |
| 431 // fetch. This assumes waiting for the script load is enough to see any error | |
| 432 // from the image load. | |
| 433 script_counter.WaitForCount(1); | |
| 434 } | |
| 435 | |
| 436 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Loop) { | |
| 437 RequestCounter script_counter; | |
| 438 CountRequestFor(kPrefetchScript, &script_counter); | |
| 439 RequestCounter main_counter; | |
| 440 CountRequestFor(kPrefetchLoopPage, &main_counter); | |
| 441 | |
| 442 std::unique_ptr<TestPrerender> test_prerender = | |
| 443 PrerenderTestURL(kPrefetchLoopPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 444 main_counter.WaitForCount(1); | |
| 445 script_counter.WaitForCount(1); | |
| 446 } | |
| 447 | |
| 448 #if defined(ENABLE_TASK_MANAGER) | |
| 449 | |
| 450 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
| 451 OpenTaskManagerBeforePrefetch) { | |
| 452 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); | |
| 453 const base::string16 any_tab = MatchTaskManagerTab("*"); | |
| 454 const base::string16 original = MatchTaskManagerTab("Prefetch Loader"); | |
| 455 // The page title is not visible in the task manager, presumably because the | |
| 456 // page has not been fully parsed. | |
| 457 const base::string16 prerender = | |
| 458 MatchTaskManagerPrerender("*prefetch_page.html*"); | |
| 459 | |
| 460 // Show the task manager. This populates the model. | |
| 461 chrome::OpenTaskManager(current_browser()); | |
| 462 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | |
| 463 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); | |
| 464 | |
| 465 // Prerender a page in addition to the original tab. | |
| 466 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 467 | |
| 468 // A TaskManager entry should appear like "Prerender: Prerender Page" | |
| 469 // alongside the original tab entry. There should be just these two entries. | |
| 470 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, prerender)); | |
| 471 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, original)); | |
| 472 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_prerender)); | |
| 473 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | |
| 474 } | |
| 475 | |
| 476 #endif // defined(ENABLE_TASK_MANAGER) | |
| 477 | |
| 478 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, RendererCrash) { | |
| 479 std::unique_ptr<TestPrerender> prerender = | |
| 480 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_RENDERER_CRASHED, 1); | |
| 481 prerender->contents()->prerender_contents()->GetController().LoadURL( | |
| 482 GURL(content::kChromeUICrashURL), content::Referrer(), | |
| 483 ui::PAGE_TRANSITION_TYPED, std::string()); | |
| 484 prerender->WaitForStop(); | |
| 485 } | |
| 486 | |
| 487 // Checks that the prefetch of png correctly loads the png. | |
| 488 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Png) { | |
| 489 RequestCounter counter; | |
| 490 CountRequestFor(kPrefetchPng, &counter); | |
| 491 PrerenderTestURL(kPrefetchPng, FINAL_STATUS_APP_TERMINATING, 1); | |
| 492 counter.WaitForCount(1); | |
| 493 } | |
| 494 | |
| 495 // Checks that the prefetch of png correctly loads the jpeg. | |
| 496 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Jpeg) { | |
| 497 RequestCounter counter; | |
| 498 CountRequestFor(kPrefetchJpeg, &counter); | |
| 499 PrerenderTestURL(kPrefetchJpeg, FINAL_STATUS_APP_TERMINATING, 1); | |
| 500 counter.WaitForCount(1); | |
| 501 } | |
| 502 | |
| 503 // Checks that nothing is prefetched from malware sites. | |
| 504 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
| 505 PrerenderSafeBrowsingTopLevel) { | |
| 506 GURL url = src_server()->GetURL(MakeAbsolute(kPrefetchPage)); | |
| 507 GetFakeSafeBrowsingDatabaseManager()->SetThreatTypeForUrl( | |
| 508 url, safe_browsing::SB_THREAT_TYPE_URL_MALWARE); | |
| 509 // Prefetch resources are blocked, but the prerender is not killed in any | |
| 510 // special way. | |
| 511 // TODO(mattcary): since the prerender will count itself as loaded even if the | |
| 512 // fetch of the main resource fails, the test doesn't actually confirm what we | |
| 513 // want it to confirm. This may be fixed by planned changes to the prerender | |
| 514 // lifecycle. | |
| 515 std::unique_ptr<TestPrerender> prerender = | |
| 516 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 517 } | |
| 518 | |
| 519 } // namespace prerender | |
| OLD | NEW |