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 namespace prerender { | |
|
pasko
2016/09/30 18:29:21
nit: extra empty line above namespace
mattcary
2016/10/03 10:58:35
Done.
| |
| 34 | |
| 35 // The various uses of URLs in these tests (the test server, request capture, | |
| 36 // etc) are fussy about relative versus absolute paths. With the exception of | |
|
pasko
2016/09/30 18:29:21
fussy? that's very concrete and easy to understand
mattcary
2016/10/03 10:58:35
Acknowledged.
| |
| 37 // kPrefetchLoaderPath, which is only used in PrerenderTestURLImpl, all other | |
| 38 // paths should be relative. | |
| 39 const char kPrefetchImagePage[] = "prerender/prefetch_image.html"; | |
| 40 const char kPrefetchLoopPage[] = "prerender/prefetch_loop.html"; | |
| 41 const char kPrefetchJpeg[] = "prerender/image.jpeg"; | |
| 42 const char kPrefetchLoaderPath[] = "/prerender/prefetch_loader.html"; | |
| 43 const char kPrefetchPage[] = "prerender/prefetch_page.html"; | |
| 44 const char kPrefetchPage2[] = "prerender/prefetch_page2.html"; | |
| 45 const char kPrefetchPng[] = "prerender/image.png"; | |
| 46 const char kPrefetchScript[] = "prerender/prefetch.js"; | |
| 47 const char kPrefetchScript2[] = "prerender/prefetch2.js"; | |
| 48 const char kPrefetchSubresourceRedirectPage[] = | |
| 49 "prerender/prefetch_subresource_redirect.html"; | |
| 50 | |
| 51 const char kPageBool[] = "pageBool"; | |
| 52 const char kScriptBool[] = "scriptBool"; | |
| 53 | |
| 54 class NoStatePrefetchBrowserTest | |
| 55 : public test_utils::PrerenderInProcessBrowserTest { | |
| 56 public: | |
| 57 NoStatePrefetchBrowserTest() {} | |
| 58 | |
| 59 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 60 PrerenderInProcessBrowserTest::SetUpCommandLine(command_line); | |
| 61 command_line->AppendSwitchASCII( | |
| 62 switches::kPrerenderMode, switches::kPrerenderModeSwitchValuePrefetch); | |
| 63 } | |
| 64 | |
| 65 // Set up a request counter for the path. | |
| 66 void CountRequestFor(const std::string& path, RequestCounter* counter) { | |
| 67 GURL::Replacements replacement; | |
| 68 replacement.SetPathStr(path); | |
| 69 const GURL url = src_server()->base_url().ReplaceComponents(replacement); | |
| 70 base::FilePath url_file = | |
| 71 ui_test_utils::GetTestFilePath(base::FilePath(), base::FilePath(path)); | |
| 72 content::BrowserThread::PostTask( | |
| 73 content::BrowserThread::IO, FROM_HERE, | |
| 74 base::Bind(&CreateCountingInterceptorOnIO, url, url_file, | |
| 75 counter->AsWeakPtr())); | |
| 76 } | |
| 77 | |
| 78 // Fetches a boolean value from javascript. Returns whether the fetch | |
| 79 // succeeded; the value of the variable is returned in value. If | |
| 80 // javascript_variable does not exist, this returns false and value is | |
| 81 // unchanged. The function checks that script execution works. | |
| 82 bool GetJavascriptBoolean(const std::string& javascript_variable, | |
|
pasko
2016/09/30 18:29:20
static? why does this need to be in the NoStatePre
mattcary
2016/10/03 10:58:35
Done.
| |
| 83 content::WebContents* web_contents, | |
| 84 bool* value) { | |
| 85 // In order to detect unknown variables we need a three-valued return. | |
|
pasko
2016/09/30 18:29:20
nit: ... a three-valued return is needed.
mattcary
2016/10/03 10:58:34
Done.
| |
| 86 int result; | |
| 87 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | |
|
pasko
2016/09/30 18:29:21
should this rather be a fatal failure? It does not
mattcary
2016/10/03 10:58:35
Yes, but it won't compile! ASSERT_TRUE can only be
droger
2016/10/03 11:07:13
The relevant gtest doc is here:
https://github.com
pasko
2016/10/03 18:54:16
Thanks for investigation, folks. Agreed that ASSER
mattcary
2016/10/04 08:25:12
Acknowledged.
| |
| 88 web_contents, | |
| 89 "try { if (" + javascript_variable + ") { " + | |
| 90 "window.domAutomationController.send(1) } else { " + | |
| 91 "window.domAutomationController.send(0); } } catch(err) {" + | |
| 92 "window.domAutomationController.send(2) }", | |
| 93 &result)); | |
| 94 if (result == 2) { | |
| 95 // This means an exception was caught, usually because of a missing | |
| 96 // variable. | |
| 97 return false; | |
| 98 } | |
| 99 *value = (result == 1); | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 // As above, but just checks for a missing variable. | |
| 104 bool JavascriptVariableMissing(const std::string& javascript_variable, | |
| 105 content::WebContents* web_contents) { | |
| 106 bool unused; | |
| 107 return !GetJavascriptBoolean(javascript_variable, web_contents, &unused); | |
| 108 } | |
| 109 | |
| 110 private: | |
| 111 ScopedVector<TestPrerender> PrerenderTestURLImpl( | |
| 112 const GURL& prerender_url, | |
| 113 const std::vector<FinalStatus>& expected_final_status_queue, | |
| 114 int expected_number_of_loads) override { | |
| 115 base::StringPairs replacement_text; | |
| 116 replacement_text.push_back( | |
| 117 make_pair("REPLACE_WITH_PREFETCH_URL", prerender_url.spec())); | |
| 118 std::string replacement_path; | |
| 119 net::test_server::GetFilePathWithReplacements( | |
| 120 kPrefetchLoaderPath, replacement_text, &replacement_path); | |
| 121 GURL loader_url = src_server()->GetURL(replacement_path); | |
| 122 | |
| 123 ScopedVector<TestPrerender> prerenders = NavigateWithPrerenders( | |
| 124 loader_url, expected_final_status_queue, expected_number_of_loads); | |
| 125 | |
| 126 TestPrerenderContents* prerender_contents = prerenders[0]->contents(); | |
| 127 CHECK(prerender_contents); | |
| 128 // Check that the prerender contents final status is unchanged from its | |
| 129 // default value, meaning that the contents has not been destroyed. | |
| 130 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); | |
| 131 | |
| 132 EXPECT_EQ(expected_number_of_loads, prerenders[0]->number_of_loads()); | |
| 133 | |
| 134 return prerenders; | |
| 135 } | |
| 136 }; | |
| 137 | |
| 138 // Checks that when the prefetch page is loaded in full, javascript values are | |
|
pasko
2016/09/30 18:29:20
s/prefetch/prefetcher/ or 'the initial page reques
mattcary
2016/10/03 10:58:34
Done.
| |
| 139 // set as expected. This checks that our test system is working as expected. | |
| 140 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, CheckJavascript) { | |
| 141 ui_test_utils::NavigateToURL( | |
| 142 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
| 143 content::WebContents* web_contents = | |
| 144 current_browser()->tab_strip_model()->GetActiveWebContents(); | |
| 145 | |
| 146 // Confirm we can get true and false values. | |
| 147 bool value = false; | |
| 148 EXPECT_TRUE(GetJavascriptBoolean(kPageBool, web_contents, &value)); | |
| 149 EXPECT_TRUE(value); | |
| 150 value = true; | |
| 151 EXPECT_TRUE(GetJavascriptBoolean("pageAntiBool", web_contents, &value)); | |
| 152 EXPECT_FALSE(value); | |
| 153 | |
| 154 // Confirm a value from the script is plumbed through. | |
| 155 value = false; | |
| 156 EXPECT_TRUE(GetJavascriptBoolean(kScriptBool, web_contents, &value)); | |
| 157 EXPECT_TRUE(value); | |
| 158 | |
| 159 // Confirm that the expected happens when a value doesn't exist. | |
| 160 EXPECT_TRUE(JavascriptVariableMissing("iDontExist", web_contents)); | |
| 161 } | |
| 162 | |
| 163 // Checks that a page is correctly prefetched in the case of a | |
| 164 // <link rel=prerender> tag and then loaded into a tab in response to a | |
| 165 // navigation, when NoState Prefetch is enabled, but that the page is not loaded | |
| 166 // (which confirmed by checking that javascript is not executed). | |
| 167 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchSimple) { | |
| 168 RequestCounter script_counter; | |
| 169 CountRequestFor(kPrefetchScript, &script_counter); | |
| 170 RequestCounter main_counter; | |
| 171 CountRequestFor(kPrefetchPage, &main_counter); | |
| 172 | |
| 173 std::unique_ptr<TestPrerender> test_prerender = | |
| 174 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 175 main_counter.WaitForCount(1); | |
| 176 script_counter.WaitForCount(1); | |
| 177 | |
| 178 content::WebContents* contents = | |
| 179 test_prerender->contents()->prerender_contents(); | |
| 180 content::WebContents* active_contents = | |
| 181 current_browser()->tab_strip_model()->GetActiveWebContents(); | |
| 182 EXPECT_TRUE(JavascriptVariableMissing(kPageBool, contents)); | |
| 183 EXPECT_TRUE(JavascriptVariableMissing(kScriptBool, contents)); | |
| 184 EXPECT_TRUE(JavascriptVariableMissing(kPageBool, active_contents)); | |
| 185 EXPECT_TRUE(JavascriptVariableMissing(kScriptBool, active_contents)); | |
| 186 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
| 187 histogram_tester().ExpectBucketCount( | |
| 188 "Prerender.websame_NoStatePrefetchResponseTypes", | |
| 189 4 /* cacheable, main resource */, 1); | |
| 190 histogram_tester().ExpectBucketCount( | |
| 191 "Prerender.websame_NoStatePrefetchResponseTypes", | |
| 192 0 /* cacheable, non-main resource */, 1); | |
| 193 histogram_tester().ExpectTotalCount("Prerender.none_MainResourceRedirects", | |
| 194 0); | |
| 195 histogram_tester().ExpectTotalCount("Prerender.none_SubResourceRedirects", 0); | |
| 196 } | |
| 197 | |
| 198 // Check the histograms on reuse of a prefetch. | |
|
pasko
2016/09/30 18:29:20
More concrete: Checks that the TTFCP histograms ar
mattcary
2016/10/03 10:58:35
Done.
| |
| 199 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
| 200 PrefetchReusedWarmHistograms) { | |
| 201 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 202 GetTestPrerenderManager()->AdvanceTime(base::TimeDelta::FromSeconds(10)); | |
| 203 ui_test_utils::NavigateToURL( | |
| 204 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
| 205 histogram_tester().ExpectTotalCount( | |
| 206 "Prerender.websame_NoStatePrefetchTTFCP.Warm.Cacheable", 1); | |
| 207 histogram_tester().ExpectTotalCount( | |
| 208 "Prerender.websame_NoStatePrefetchTTFCP.Cold.Cacheable", 0); | |
| 209 } | |
| 210 | |
| 211 // Check the histograms on reuse of a prefetch. | |
|
pasko
2016/09/30 18:29:20
Checks
mattcary
2016/10/03 10:58:35
Done.
| |
| 212 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
| 213 PrefetchReusedColdHistograms) { | |
| 214 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_TIMED_OUT, 1); | |
| 215 GetTestPrerenderManager()->AdvanceTime(base::TimeDelta::FromSeconds(600)); | |
| 216 ui_test_utils::NavigateToURL( | |
| 217 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
| 218 | |
| 219 histogram_tester().ExpectTotalCount( | |
| 220 "Prerender.websame_NoStatePrefetchTTFCP.Warm.Cacheable", 0); | |
| 221 histogram_tester().ExpectTotalCount( | |
| 222 "Prerender.websame_NoStatePrefetchTTFCP.Cold.Cacheable", 1); | |
| 223 } | |
| 224 | |
| 225 // Test that we prefetch an img tag in body using our particular | |
|
pasko
2016/09/30 18:29:21
Tests
avoid we, our
why using polluting words lik
mattcary
2016/10/03 10:58:35
Done.
| |
| 226 // prerender_prefetch_image.html setup. | |
| 227 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchImage) { | |
| 228 RequestCounter image_counter; | |
| 229 CountRequestFor(kPrefetchJpeg, &image_counter); | |
| 230 base::StringPairs replacement_text; | |
| 231 replacement_text.push_back( | |
| 232 std::make_pair("REPLACE_WITH_IMAGE_URL", MakeAbsolute(kPrefetchJpeg))); | |
| 233 std::string main_page_path; | |
| 234 net::test_server::GetFilePathWithReplacements( | |
| 235 kPrefetchImagePage, replacement_text, &main_page_path); | |
| 236 // Note that we can't CountRequestFor the main page as we use the test server | |
| 237 // for handling the image url replacement. | |
| 238 PrerenderTestURL(main_page_path, FINAL_STATUS_APP_TERMINATING, 1); | |
| 239 image_counter.WaitForCount(1); | |
| 240 } | |
| 241 | |
| 242 // Check cross-domain prefetching by looking at histograms. | |
|
pasko
2016/09/30 18:29:20
Checks that .. cross-domain prefetching does X whe
mattcary
2016/10/03 10:58:35
Done.
| |
| 243 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchCrossDomain) { | |
| 244 static const std::string secondary_domain = "www.foo.com"; | |
| 245 host_resolver()->AddRule(secondary_domain, "127.0.0.1"); | |
| 246 GURL cross_domain_url(base::StringPrintf( | |
| 247 "http://%s:%d/%s", secondary_domain.c_str(), | |
| 248 embedded_test_server()->host_port_pair().port(), kPrefetchPage)); | |
| 249 PrerenderTestURL(cross_domain_url, FINAL_STATUS_APP_TERMINATING, 1); | |
| 250 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
| 251 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1); | |
| 252 histogram_tester().ExpectTotalCount( | |
| 253 "Prerender.webcross_PrerenderNotSwappedInPLT", 1); | |
| 254 } | |
| 255 | |
| 256 // Check that we support simultaneous prefetch. | |
| 257 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchSimultaneous) { | |
| 258 RequestCounter first_main_counter; | |
| 259 CountRequestFor(kPrefetchPage, &first_main_counter); | |
| 260 RequestCounter second_main_counter; | |
| 261 CountRequestFor(kPrefetchPage2, &second_main_counter); | |
| 262 RequestCounter first_script_counter; | |
| 263 CountRequestFor(kPrefetchScript, &first_script_counter); | |
| 264 RequestCounter second_script_counter; | |
| 265 CountRequestFor(kPrefetchScript2, &second_script_counter); | |
| 266 | |
| 267 // The first prerender is marked as canceled as when the second starts, it | |
| 268 // sees that the first has been abandoned (presumably because we detach | |
| 269 // immediately and so it dies quickly). | |
| 270 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_CANCELLED, 1); | |
| 271 PrerenderTestURL(kPrefetchPage2, FINAL_STATUS_APP_TERMINATING, 1); | |
| 272 first_main_counter.WaitForCount(1); | |
| 273 second_main_counter.WaitForCount(1); | |
| 274 first_script_counter.WaitForCount(1); | |
| 275 second_script_counter.WaitForCount(1); | |
| 276 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 2); | |
| 277 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 2); | |
| 278 } | |
| 279 | |
| 280 // Check that we correctly handle a prefetch to a nonexisting page. | |
| 281 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchNonexisting) { | |
| 282 PrerenderTestURL("nonexisting-page.html", FINAL_STATUS_APP_TERMINATING, 0); | |
| 283 // TODO(mattcary): we fire up a prerenderer before we discover that the main | |
| 284 // page doesn't exist, we still count this as a prerender. Also we don't fail | |
| 285 // the renderer (presumably because we've detached the resource, etc). Is this | |
| 286 // what we want? | |
| 287 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLT", 1); | |
| 288 } | |
| 289 | |
| 290 // Check that we follow a 301 redirect. | |
| 291 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Redirect) { | |
| 292 RequestCounter script_counter; | |
| 293 CountRequestFor(kPrefetchScript, &script_counter); | |
| 294 PrerenderTestURL( | |
| 295 "/server-redirect/?" + | |
| 296 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false), | |
| 297 FINAL_STATUS_APP_TERMINATING, 1); | |
| 298 script_counter.WaitForCount(1); | |
| 299 histogram_tester().ExpectTotalCount( | |
| 300 "Prerender.websame_NoStatePrefetchMainResourceRedirects", 1); | |
| 301 } | |
| 302 | |
| 303 // Check that we follow a subresource 301 redirect. | |
| 304 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Subresource) { | |
| 305 RequestCounter script_counter; | |
| 306 CountRequestFor(kPrefetchScript, &script_counter); | |
| 307 PrerenderTestURL(kPrefetchSubresourceRedirectPage, | |
| 308 FINAL_STATUS_APP_TERMINATING, 1); | |
| 309 script_counter.WaitForCount(1); | |
| 310 histogram_tester().ExpectTotalCount( | |
| 311 "Prerender.websame_NoStatePrefetchMainResourceRedirects", 1); | |
| 312 } | |
| 313 | |
| 314 // Check that we don't follow a client redirect. | |
| 315 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchClientRedirect) { | |
| 316 RequestCounter script_counter; | |
| 317 CountRequestFor(kPrefetchScript, &script_counter); | |
| 318 // We use a sentinel via a complete load kPrefetchPage2. Otherwise we end | |
| 319 // before script_counter would reliable see the load of kPrefetchScript, were | |
| 320 // it to happen. | |
| 321 RequestCounter sentinel_counter; | |
| 322 CountRequestFor(kPrefetchScript2, &sentinel_counter); | |
| 323 PrerenderTestURL( | |
| 324 "/client-redirect/?" + | |
| 325 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false), | |
| 326 FINAL_STATUS_APP_TERMINATING, 1); | |
| 327 ui_test_utils::NavigateToURL( | |
| 328 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage2))); | |
| 329 sentinel_counter.WaitForCount(1); | |
| 330 script_counter.WaitForCount(0); | |
| 331 } | |
| 332 | |
| 333 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchHttps) { | |
| 334 UseHttpsSrcServer(); | |
| 335 RequestCounter main_counter; | |
| 336 CountRequestFor(kPrefetchPage, &main_counter); | |
| 337 RequestCounter script_counter; | |
| 338 CountRequestFor(kPrefetchScript, &script_counter); | |
| 339 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 340 main_counter.WaitForCount(1); | |
| 341 script_counter.WaitForCount(1); | |
| 342 } | |
| 343 | |
| 344 // Check that if an SSL error happens we don't fetch. | |
| 345 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, SSLError) { | |
| 346 // We only send the loaded page, not the loader, through SSL. | |
| 347 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
| 348 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | |
| 349 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); | |
| 350 ASSERT_TRUE(https_server.Start()); | |
| 351 std::unique_ptr<TestPrerender> prerender = | |
| 352 PrerenderTestURL(https_server.GetURL(MakeAbsolute(kPrefetchPage)), | |
| 353 FINAL_STATUS_SSL_ERROR, 0); | |
| 354 DestructionWaiter waiter(prerender->contents(), FINAL_STATUS_SSL_ERROR); | |
| 355 EXPECT_TRUE(waiter.WaitForDestroy()); | |
| 356 } | |
| 357 | |
| 358 // We should not have a problem if a subresource fails SSL. | |
| 359 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, SSLSubresourceError) { | |
| 360 // First confirm that the image loads as expected. | |
| 361 | |
| 362 // Note that we start a separate HTTPS server for the subresource; | |
| 363 // src_server() is non-HTTPS. | |
| 364 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | |
| 365 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | |
| 366 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); | |
| 367 ASSERT_TRUE(https_server.Start()); | |
| 368 GURL https_url = https_server.GetURL("/prerender/image.jpeg"); | |
| 369 base::StringPairs replacement_text; | |
| 370 replacement_text.push_back( | |
| 371 std::make_pair("REPLACE_WITH_IMAGE_URL", https_url.spec())); | |
| 372 std::string main_page_path; | |
| 373 net::test_server::GetFilePathWithReplacements( | |
| 374 kPrefetchImagePage, replacement_text, &main_page_path); | |
| 375 RequestCounter script_counter; | |
| 376 CountRequestFor(kPrefetchScript, &script_counter); | |
| 377 | |
| 378 std::unique_ptr<TestPrerender> prerender = | |
| 379 PrerenderTestURL(main_page_path, FINAL_STATUS_APP_TERMINATING, 1); | |
| 380 // Check that the presumed failure of the image load didn't affect the script | |
| 381 // fetch. This assumes waiting for the script load is enough to see any error | |
| 382 // from the image load. | |
| 383 script_counter.WaitForCount(1); | |
| 384 } | |
| 385 | |
| 386 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Loop) { | |
| 387 RequestCounter script_counter; | |
| 388 CountRequestFor(kPrefetchScript, &script_counter); | |
| 389 RequestCounter main_counter; | |
| 390 CountRequestFor(kPrefetchLoopPage, &main_counter); | |
| 391 | |
| 392 std::unique_ptr<TestPrerender> test_prerender = | |
| 393 PrerenderTestURL(kPrefetchLoopPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 394 main_counter.WaitForCount(1); | |
| 395 script_counter.WaitForCount(1); | |
| 396 } | |
| 397 | |
| 398 #if defined(ENABLE_TASK_MANAGER) | |
| 399 | |
| 400 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
| 401 OpenTaskManagerBeforePrefetch) { | |
| 402 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); | |
| 403 const base::string16 any_tab = MatchTaskManagerTab("*"); | |
| 404 const base::string16 original = MatchTaskManagerTab("Prefetch Loader"); | |
| 405 // Presumably we don't see the title in the task manager as the page has not | |
| 406 // been fully parsed. | |
| 407 const base::string16 prerender = | |
| 408 MatchTaskManagerPrerender("*prefetch_page.html*"); | |
| 409 | |
| 410 // Show the task manager. This populates the model. | |
| 411 chrome::OpenTaskManager(current_browser()); | |
| 412 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | |
| 413 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); | |
| 414 | |
| 415 // Prerender a page in addition to the original tab. | |
| 416 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 1); | |
| 417 | |
| 418 // A TaskManager entry should appear like "Prerender: Prerender Page" | |
| 419 // alongside the original tab entry. There should be just these two entries. | |
| 420 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, prerender)); | |
| 421 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, original)); | |
| 422 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_prerender)); | |
| 423 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | |
| 424 } | |
| 425 | |
| 426 #endif // defined(ENABLE_TASK_MANAGER) | |
| 427 | |
| 428 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, RendererCrash) { | |
| 429 std::unique_ptr<TestPrerender> prerender = | |
| 430 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_RENDERER_CRASHED, 1); | |
| 431 prerender->contents()->prerender_contents()->GetController().LoadURL( | |
| 432 GURL(content::kChromeUICrashURL), content::Referrer(), | |
| 433 ui::PAGE_TRANSITION_TYPED, std::string()); | |
| 434 prerender->WaitForStop(); | |
| 435 } | |
| 436 | |
| 437 // For the next two tests, there is nothing for the prefetch scanner to do. But | |
| 438 // we make sure we behave as expect. | |
| 439 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Png) { | |
| 440 RequestCounter counter; | |
| 441 CountRequestFor(kPrefetchPng, &counter); | |
| 442 PrerenderTestURL(kPrefetchPng, FINAL_STATUS_APP_TERMINATING, 1); | |
| 443 counter.WaitForCount(1); | |
| 444 } | |
| 445 | |
| 446 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Jpeg) { | |
| 447 RequestCounter counter; | |
| 448 CountRequestFor(kPrefetchJpeg, &counter); | |
| 449 PrerenderTestURL(kPrefetchJpeg, FINAL_STATUS_APP_TERMINATING, 1); | |
| 450 counter.WaitForCount(1); | |
| 451 } | |
| 452 | |
| 453 // We should not prefetch from malware sites. | |
| 454 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, | |
| 455 PrerenderSafeBrowsingTopLevel) { | |
| 456 GURL url = src_server()->GetURL(MakeAbsolute(kPrefetchPage)); | |
| 457 GetFakeSafeBrowsingDatabaseManager()->SetThreatTypeForUrl( | |
| 458 url, safe_browsing::SB_THREAT_TYPE_URL_MALWARE); | |
| 459 // Prefetch resource are blocked, but the prerender is not killed in any | |
| 460 // special way. | |
| 461 // TODO(mattcary): do we care about detecting if the main resource is fetched | |
| 462 // and preload scanning has started? | |
| 463 std::unique_ptr<TestPrerender> prerender = | |
| 464 PrerenderTestURL(kPrefetchPage, FINAL_STATUS_APP_TERMINATING, 0); | |
| 465 } | |
| 466 | |
| 467 } // namespace prerender | |
| OLD | NEW |