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