| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <deque> | 5 #include <deque> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 const content::Referrer& referrer, | 335 const content::Referrer& referrer, |
| 336 Origin origin, | 336 Origin origin, |
| 337 FinalStatus expected_final_status) | 337 FinalStatus expected_final_status) |
| 338 : PrerenderContents(prerender_manager, profile, url, | 338 : PrerenderContents(prerender_manager, profile, url, |
| 339 referrer, origin, PrerenderManager::kNoExperiment), | 339 referrer, origin, PrerenderManager::kNoExperiment), |
| 340 expected_final_status_(expected_final_status), | 340 expected_final_status_(expected_final_status), |
| 341 new_render_view_host_(NULL), | 341 new_render_view_host_(NULL), |
| 342 was_hidden_(false), | 342 was_hidden_(false), |
| 343 was_shown_(false), | 343 was_shown_(false), |
| 344 should_be_shown_(expected_final_status == FINAL_STATUS_USED), | 344 should_be_shown_(expected_final_status == FINAL_STATUS_USED), |
| 345 skip_final_checks_(false), | 345 skip_final_checks_(false) { |
| 346 expected_pending_prerenders_(0) { | |
| 347 } | 346 } |
| 348 | 347 |
| 349 virtual ~TestPrerenderContents() { | 348 virtual ~TestPrerenderContents() { |
| 350 if (skip_final_checks_) | 349 if (skip_final_checks_) |
| 351 return; | 350 return; |
| 352 | 351 |
| 353 if (expected_final_status_ == FINAL_STATUS_MAX) { | 352 if (expected_final_status_ == FINAL_STATUS_MAX) { |
| 354 EXPECT_EQ(match_complete_status(), MATCH_COMPLETE_REPLACEMENT); | 353 EXPECT_EQ(MATCH_COMPLETE_REPLACEMENT, match_complete_status()); |
| 355 } else { | 354 } else { |
| 356 EXPECT_EQ(expected_final_status_, final_status()) << | 355 EXPECT_EQ(expected_final_status_, final_status()) << |
| 357 " when testing URL " << prerender_url().path() << | 356 " when testing URL " << prerender_url().path() << |
| 358 " (Expected: " << NameFromFinalStatus(expected_final_status_) << | 357 " (Expected: " << NameFromFinalStatus(expected_final_status_) << |
| 359 ", Actual: " << NameFromFinalStatus(final_status()) << ")"; | 358 ", Actual: " << NameFromFinalStatus(final_status()) << ")"; |
| 360 } | 359 } |
| 361 // Prerendering RenderViewHosts should be hidden before the first | 360 // Prerendering RenderViewHosts should be hidden before the first |
| 362 // navigation, so this should be happen for every PrerenderContents for | 361 // navigation, so this should be happen for every PrerenderContents for |
| 363 // which a RenderViewHost is created, regardless of whether or not it's | 362 // which a RenderViewHost is created, regardless of whether or not it's |
| 364 // used. | 363 // used. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 392 } | 391 } |
| 393 | 392 |
| 394 virtual bool CheckURL(const GURL& url) OVERRIDE { | 393 virtual bool CheckURL(const GURL& url) OVERRIDE { |
| 395 // Prevent FINAL_STATUS_UNSUPPORTED_SCHEME when navigating to about:crash in | 394 // Prevent FINAL_STATUS_UNSUPPORTED_SCHEME when navigating to about:crash in |
| 396 // the PrerenderRendererCrash test. | 395 // the PrerenderRendererCrash test. |
| 397 if (url.spec() != content::kChromeUICrashURL) | 396 if (url.spec() != content::kChromeUICrashURL) |
| 398 return PrerenderContents::CheckURL(url); | 397 return PrerenderContents::CheckURL(url); |
| 399 return true; | 398 return true; |
| 400 } | 399 } |
| 401 | 400 |
| 402 virtual void AddPendingPrerender( | |
| 403 scoped_ptr<PendingPrerenderInfo> pending_prerender_info) OVERRIDE { | |
| 404 PrerenderContents::AddPendingPrerender(pending_prerender_info.Pass()); | |
| 405 if (expected_pending_prerenders_ > 0 && | |
| 406 pending_prerender_count() == expected_pending_prerenders_) { | |
| 407 base::MessageLoop::current()->Quit(); | |
| 408 } | |
| 409 } | |
| 410 | |
| 411 // Waits until the prerender has |expected_pending_prerenders| pending | |
| 412 // prerenders. | |
| 413 void WaitForPendingPrerenders(size_t expected_pending_prerenders) { | |
| 414 if (pending_prerender_count() < expected_pending_prerenders) { | |
| 415 expected_pending_prerenders_ = expected_pending_prerenders; | |
| 416 content::RunMessageLoop(); | |
| 417 expected_pending_prerenders_ = 0; | |
| 418 } | |
| 419 | |
| 420 EXPECT_EQ(expected_pending_prerenders, pending_prerender_count()); | |
| 421 } | |
| 422 | |
| 423 // For tests that open the prerender in a new background tab, the RenderView | 401 // For tests that open the prerender in a new background tab, the RenderView |
| 424 // will not have been made visible when the PrerenderContents is destroyed | 402 // will not have been made visible when the PrerenderContents is destroyed |
| 425 // even though it is used. | 403 // even though it is used. |
| 426 void set_should_be_shown(bool value) { should_be_shown_ = value; } | 404 void set_should_be_shown(bool value) { should_be_shown_ = value; } |
| 427 | 405 |
| 428 // For tests which do not know whether the prerender will be used. | 406 // For tests which do not know whether the prerender will be used. |
| 429 void set_skip_final_checks(bool value) { skip_final_checks_ = value; } | 407 void set_skip_final_checks(bool value) { skip_final_checks_ = value; } |
| 430 | 408 |
| 431 FinalStatus expected_final_status() const { return expected_final_status_; } | 409 FinalStatus expected_final_status() const { return expected_final_status_; } |
| 432 | 410 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // Set to true when the prerendering RenderWidget is hidden. | 452 // Set to true when the prerendering RenderWidget is hidden. |
| 475 bool was_hidden_; | 453 bool was_hidden_; |
| 476 // Set to true when the prerendering RenderWidget is shown, after having been | 454 // Set to true when the prerendering RenderWidget is shown, after having been |
| 477 // hidden. | 455 // hidden. |
| 478 bool was_shown_; | 456 bool was_shown_; |
| 479 // Expected final value of was_shown_. Defaults to true for | 457 // Expected final value of was_shown_. Defaults to true for |
| 480 // FINAL_STATUS_USED, and false otherwise. | 458 // FINAL_STATUS_USED, and false otherwise. |
| 481 bool should_be_shown_; | 459 bool should_be_shown_; |
| 482 // If true, |expected_final_status_| and other shutdown checks are skipped. | 460 // If true, |expected_final_status_| and other shutdown checks are skipped. |
| 483 bool skip_final_checks_; | 461 bool skip_final_checks_; |
| 484 | |
| 485 // Total number of pending prerenders we're currently waiting for. Zero | |
| 486 // indicates we currently aren't waiting for any. | |
| 487 size_t expected_pending_prerenders_; | |
| 488 }; | 462 }; |
| 489 | 463 |
| 490 // A handle to a TestPrerenderContents whose lifetime is under the caller's | 464 // A handle to a TestPrerenderContents whose lifetime is under the caller's |
| 491 // control. A PrerenderContents may be destroyed at any point. This allows | 465 // control. A PrerenderContents may be destroyed at any point. This allows |
| 492 // tracking the final status, etc. | 466 // tracking the final status, etc. |
| 493 class TestPrerender : public PrerenderContents::Observer, | 467 class TestPrerender : public PrerenderContents::Observer, |
| 494 public base::SupportsWeakPtr<TestPrerender> { | 468 public base::SupportsWeakPtr<TestPrerender> { |
| 495 public: | 469 public: |
| 496 TestPrerender() | 470 TestPrerender() |
| 497 : contents_(NULL), | 471 : contents_(NULL), |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 // removed from the PrerenderLinkManager when the prerender is canceled from | 1290 // removed from the PrerenderLinkManager when the prerender is canceled from |
| 1317 // the browser, when the prerenders are cancelled from the renderer process, | 1291 // the browser, when the prerenders are cancelled from the renderer process, |
| 1318 // or the channel for the renderer process is closed on the IO thread. In the | 1292 // or the channel for the renderer process is closed on the IO thread. In the |
| 1319 // last case, the code must be careful to wait for the channel to close, as it | 1293 // last case, the code must be careful to wait for the channel to close, as it |
| 1320 // is done asynchronously after swapping out the old process. See | 1294 // is done asynchronously after swapping out the old process. See |
| 1321 // ChannelDestructionWatcher. | 1295 // ChannelDestructionWatcher. |
| 1322 bool IsEmptyPrerenderLinkManager() const { | 1296 bool IsEmptyPrerenderLinkManager() const { |
| 1323 return GetPrerenderLinkManager()->IsEmpty(); | 1297 return GetPrerenderLinkManager()->IsEmpty(); |
| 1324 } | 1298 } |
| 1325 | 1299 |
| 1300 size_t GetLinkPrerenderCount() const { |
| 1301 return GetPrerenderLinkManager()->prerenders_.size(); |
| 1302 } |
| 1303 |
| 1304 size_t GetRunningLinkPrerenderCount() const { |
| 1305 return GetPrerenderLinkManager()->CountRunningPrerenders(); |
| 1306 } |
| 1307 |
| 1326 // Returns length of |prerender_manager_|'s history, or -1 on failure. | 1308 // Returns length of |prerender_manager_|'s history, or -1 on failure. |
| 1327 int GetHistoryLength() const { | 1309 int GetHistoryLength() const { |
| 1328 scoped_ptr<base::DictionaryValue> prerender_dict( | 1310 scoped_ptr<base::DictionaryValue> prerender_dict( |
| 1329 static_cast<base::DictionaryValue*>( | 1311 static_cast<base::DictionaryValue*>( |
| 1330 GetPrerenderManager()->GetAsValue())); | 1312 GetPrerenderManager()->GetAsValue())); |
| 1331 if (!prerender_dict.get()) | 1313 if (!prerender_dict.get()) |
| 1332 return -1; | 1314 return -1; |
| 1333 base::ListValue* history_list; | 1315 base::ListValue* history_list; |
| 1334 if (!prerender_dict->GetList("history", &history_list)) | 1316 if (!prerender_dict->GetList("history", &history_list)) |
| 1335 return -1; | 1317 return -1; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 ChannelDestructionWatcher channel_close_watcher; | 1560 ChannelDestructionWatcher channel_close_watcher; |
| 1579 channel_close_watcher.WatchChannel( | 1561 channel_close_watcher.WatchChannel( |
| 1580 GetActiveWebContents()->GetRenderProcessHost()); | 1562 GetActiveWebContents()->GetRenderProcessHost()); |
| 1581 NavigateToDestURL(); | 1563 NavigateToDestURL(); |
| 1582 channel_close_watcher.WaitForChannelClose(); | 1564 channel_close_watcher.WaitForChannelClose(); |
| 1583 | 1565 |
| 1584 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); | 1566 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); |
| 1585 } | 1567 } |
| 1586 | 1568 |
| 1587 // Checks that pending prerenders launch and receive proper event treatment. | 1569 // Checks that pending prerenders launch and receive proper event treatment. |
| 1588 // Disabled due to http://crbug.com/167792 | 1570 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPagePending) { |
| 1589 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DISABLED_PrerenderPagePending) { | 1571 scoped_ptr<TestPrerender> prerender = |
| 1590 std::vector<FinalStatus> expected_final_status_queue; | 1572 PrerenderTestURL("files/prerender/prerender_page_pending.html", |
| 1591 expected_final_status_queue.push_back(FINAL_STATUS_USED); | 1573 FINAL_STATUS_USED, 1); |
| 1592 expected_final_status_queue.push_back(FINAL_STATUS_USED); | |
| 1593 PrerenderTestURL("files/prerender/prerender_page_pending.html", | |
| 1594 expected_final_status_queue, 1); | |
| 1595 | 1574 |
| 1596 ChannelDestructionWatcher first_channel_close_watcher; | 1575 // Navigate to the prerender. |
| 1576 scoped_ptr<TestPrerender> prerender2 = ExpectPrerender(FINAL_STATUS_USED); |
| 1577 NavigateToDestURL(); |
| 1578 // Abort early if the original prerender didn't swap, so as not to hang. |
| 1579 ASSERT_FALSE(prerender->contents()); |
| 1597 | 1580 |
| 1598 first_channel_close_watcher.WatchChannel( | 1581 // Wait for the new prerender to be ready. |
| 1599 GetActiveWebContents()->GetRenderProcessHost()); | 1582 prerender2->WaitForStart(); |
| 1600 NavigateToDestURL(); | 1583 prerender2->WaitForLoads(1); |
| 1601 // NavigateToDestURL doesn't run a message loop. Normally that's fine, but in | |
| 1602 // this case, we need the pending prerenders to start. | |
| 1603 content::RunMessageLoop(); | |
| 1604 first_channel_close_watcher.WaitForChannelClose(); | |
| 1605 | 1584 |
| 1606 const GURL prerender_page_url = | 1585 const GURL prerender_page_url = |
| 1607 test_server()->GetURL("files/prerender/prerender_page.html"); | 1586 test_server()->GetURL("files/prerender/prerender_page.html"); |
| 1608 EXPECT_FALSE(IsEmptyPrerenderLinkManager()); | 1587 EXPECT_FALSE(IsEmptyPrerenderLinkManager()); |
| 1609 EXPECT_NE(static_cast<TestPrerenderContents*>(NULL), | 1588 EXPECT_NE(static_cast<TestPrerenderContents*>(NULL), |
| 1610 GetPrerenderContentsFor(prerender_page_url)); | 1589 GetPrerenderContentsFor(prerender_page_url)); |
| 1611 | 1590 |
| 1612 // Now navigate to our target page. | 1591 // Now navigate to our target page. |
| 1613 ChannelDestructionWatcher second_channel_close_watcher; | 1592 NavigationOrSwapObserver swap_observer(current_browser()->tab_strip_model(), |
| 1614 second_channel_close_watcher.WatchChannel( | 1593 GetActiveWebContents()); |
| 1615 GetActiveWebContents()->GetRenderProcessHost()); | |
| 1616 ui_test_utils::NavigateToURLWithDisposition( | 1594 ui_test_utils::NavigateToURLWithDisposition( |
| 1617 current_browser(), prerender_page_url, CURRENT_TAB, | 1595 current_browser(), prerender_page_url, CURRENT_TAB, |
| 1618 ui_test_utils::BROWSER_TEST_NONE); | 1596 ui_test_utils::BROWSER_TEST_NONE); |
| 1619 second_channel_close_watcher.WaitForChannelClose(); | 1597 swap_observer.Wait(); |
| 1620 | 1598 |
| 1621 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); | 1599 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); |
| 1622 } | 1600 } |
| 1623 | 1601 |
| 1624 // Checks that pending prerenders which are canceled before they are launched | 1602 // Checks that pending prerenders which are canceled before they are launched |
| 1625 // never get started. | 1603 // never get started. |
| 1626 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageRemovesPending) { | 1604 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageRemovesPending) { |
| 1627 PrerenderTestURL("files/prerender/prerender_page_removes_pending.html", | 1605 PrerenderTestURL("files/prerender/prerender_page_removes_pending.html", |
| 1628 FINAL_STATUS_USED, 1); | 1606 FINAL_STATUS_USED, 1); |
| 1629 | 1607 |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2203 | 2181 |
| 2204 // Checks shutdown code while a prerender is active. | 2182 // Checks shutdown code while a prerender is active. |
| 2205 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderQuickQuit) { | 2183 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderQuickQuit) { |
| 2206 DisableJavascriptCalls(); | 2184 DisableJavascriptCalls(); |
| 2207 DisableLoadEventCheck(); | 2185 DisableLoadEventCheck(); |
| 2208 PrerenderTestURL("files/prerender/prerender_page.html", | 2186 PrerenderTestURL("files/prerender/prerender_page.html", |
| 2209 FINAL_STATUS_APP_TERMINATING, | 2187 FINAL_STATUS_APP_TERMINATING, |
| 2210 0); | 2188 0); |
| 2211 } | 2189 } |
| 2212 | 2190 |
| 2213 // TODO(gavinp,sreeram): Fix http://crbug.com/145248 and deflake this test. | |
| 2214 // Checks that we don't prerender in an infinite loop. | 2191 // Checks that we don't prerender in an infinite loop. |
| 2215 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DISABLED_PrerenderInfiniteLoop) { | 2192 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderInfiniteLoop) { |
| 2216 const char* const kHtmlFileA = "files/prerender/prerender_infinite_a.html"; | 2193 const char* const kHtmlFileA = "files/prerender/prerender_infinite_a.html"; |
| 2217 const char* const kHtmlFileB = "files/prerender/prerender_infinite_b.html"; | 2194 const char* const kHtmlFileB = "files/prerender/prerender_infinite_b.html"; |
| 2218 | 2195 |
| 2219 std::vector<FinalStatus> expected_final_status_queue; | 2196 std::vector<FinalStatus> expected_final_status_queue; |
| 2220 expected_final_status_queue.push_back(FINAL_STATUS_USED); | 2197 expected_final_status_queue.push_back(FINAL_STATUS_USED); |
| 2221 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); | 2198 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); |
| 2222 | 2199 |
| 2223 ScopedVector<TestPrerender> prerenders = | 2200 ScopedVector<TestPrerender> prerenders = |
| 2224 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); | 2201 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); |
| 2225 ASSERT_TRUE(prerenders[0]->contents()); | 2202 ASSERT_TRUE(prerenders[0]->contents()); |
| 2226 prerenders[0]->contents()->WaitForPendingPrerenders(1u); | 2203 // Assert that the pending prerender is in there already. This relies on the |
| 2204 // fact that the renderer sends out the AddLinkRelPrerender IPC before sending |
| 2205 // the page load one. |
| 2206 EXPECT_EQ(2U, GetLinkPrerenderCount()); |
| 2207 EXPECT_EQ(1U, GetRunningLinkPrerenderCount()); |
| 2227 | 2208 |
| 2228 // Next url should be in pending list but not an active entry. | 2209 // Next url should be in pending list but not an active entry. |
| 2229 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); | 2210 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); |
| 2230 | 2211 |
| 2231 NavigateToDestURL(); | 2212 NavigateToDestURL(); |
| 2232 | 2213 |
| 2233 // Make sure the PrerenderContents for the next url is now in the manager | 2214 // Make sure the PrerenderContents for the next url is now in the manager and |
| 2234 // and not pending. | 2215 // not pending. This relies on pending prerenders being resolved in the same |
| 2216 // event loop iteration as OnPrerenderStop. |
| 2235 EXPECT_TRUE(UrlIsInPrerenderManager(kHtmlFileB)); | 2217 EXPECT_TRUE(UrlIsInPrerenderManager(kHtmlFileB)); |
| 2218 EXPECT_EQ(1U, GetLinkPrerenderCount()); |
| 2219 EXPECT_EQ(1U, GetRunningLinkPrerenderCount()); |
| 2236 } | 2220 } |
| 2237 | 2221 |
| 2238 // TODO(gavinp,sreeram): Fix http://crbug.com/145248 and deflake this test. | |
| 2239 // Checks that we don't prerender in an infinite loop and multiple links are | 2222 // Checks that we don't prerender in an infinite loop and multiple links are |
| 2240 // handled correctly. | 2223 // handled correctly. |
| 2241 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 2224 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
| 2242 DISABLED_PrerenderInfiniteLoopMultiple) { | 2225 PrerenderInfiniteLoopMultiple) { |
| 2243 const char* const kHtmlFileA = | 2226 const char* const kHtmlFileA = |
| 2244 "files/prerender/prerender_infinite_a_multiple.html"; | 2227 "files/prerender/prerender_infinite_a_multiple.html"; |
| 2245 const char* const kHtmlFileB = | 2228 const char* const kHtmlFileB = |
| 2246 "files/prerender/prerender_infinite_b_multiple.html"; | 2229 "files/prerender/prerender_infinite_b_multiple.html"; |
| 2247 const char* const kHtmlFileC = | 2230 const char* const kHtmlFileC = |
| 2248 "files/prerender/prerender_infinite_c_multiple.html"; | 2231 "files/prerender/prerender_infinite_c_multiple.html"; |
| 2249 | 2232 |
| 2250 // This test is conceptually simplest if concurrency is at two, since we | 2233 // This test is conceptually simplest if concurrency is at two, since we |
| 2251 // don't have to worry about which of kHtmlFileB or kHtmlFileC gets evicted. | 2234 // don't have to worry about which of kHtmlFileB or kHtmlFileC gets evicted. |
| 2252 GetPrerenderManager()->mutable_config().max_link_concurrency = 2; | 2235 GetPrerenderManager()->mutable_config().max_link_concurrency = 2; |
| 2253 GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2; | 2236 GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2; |
| 2254 | 2237 |
| 2255 std::vector<FinalStatus> expected_final_status_queue; | 2238 std::vector<FinalStatus> expected_final_status_queue; |
| 2256 expected_final_status_queue.push_back(FINAL_STATUS_USED); | 2239 expected_final_status_queue.push_back(FINAL_STATUS_USED); |
| 2257 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); | 2240 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); |
| 2258 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); | 2241 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); |
| 2259 | 2242 |
| 2260 ScopedVector<TestPrerender> prerenders = | 2243 ScopedVector<TestPrerender> prerenders = |
| 2261 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); | 2244 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); |
| 2262 ASSERT_TRUE(prerenders[0]->contents()); | 2245 ASSERT_TRUE(prerenders[0]->contents()); |
| 2263 prerenders[0]->contents()->WaitForPendingPrerenders(2u); | |
| 2264 | 2246 |
| 2265 // Next url should be in pending list but not an active entry. | 2247 // Next url should be in pending list but not an active entry. This relies on |
| 2248 // the fact that the renderer sends out the AddLinkRelPrerender IPC before |
| 2249 // sending the page load one. |
| 2250 EXPECT_EQ(3U, GetLinkPrerenderCount()); |
| 2251 EXPECT_EQ(1U, GetRunningLinkPrerenderCount()); |
| 2266 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); | 2252 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); |
| 2267 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileC)); | 2253 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileC)); |
| 2268 | 2254 |
| 2269 NavigateToDestURL(); | 2255 NavigateToDestURL(); |
| 2270 | 2256 |
| 2271 // Make sure the PrerenderContents for the next urls are now in the manager | 2257 // Make sure the PrerenderContents for the next urls are now in the manager |
| 2272 // and not pending. One and only one of the URLs (the last seen) should be the | 2258 // and not pending. One and only one of the URLs (the last seen) should be the |
| 2273 // active entry. | 2259 // active entry. This relies on pending prerenders being resolved in the same |
| 2260 // event loop iteration as OnPrerenderStop. |
| 2274 bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB); | 2261 bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB); |
| 2275 bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC); | 2262 bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC); |
| 2276 EXPECT_TRUE(url_b_is_active_prerender && url_c_is_active_prerender); | 2263 EXPECT_TRUE(url_b_is_active_prerender && url_c_is_active_prerender); |
| 2264 EXPECT_EQ(2U, GetLinkPrerenderCount()); |
| 2265 EXPECT_EQ(2U, GetRunningLinkPrerenderCount()); |
| 2266 } |
| 2267 |
| 2268 // Checks that pending prerenders are aborted (and never launched) when launched |
| 2269 // by a prerender that itself gets aborted. |
| 2270 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAbortPendingOnCancel) { |
| 2271 const char* const kHtmlFileA = "files/prerender/prerender_infinite_a.html"; |
| 2272 const char* const kHtmlFileB = "files/prerender/prerender_infinite_b.html"; |
| 2273 |
| 2274 scoped_ptr<TestPrerender> prerender = |
| 2275 PrerenderTestURL(kHtmlFileA, FINAL_STATUS_CANCELLED, 1); |
| 2276 ASSERT_TRUE(prerender->contents()); |
| 2277 // Assert that the pending prerender is in there already. This relies on the |
| 2278 // fact that the renderer sends out the AddLinkRelPrerender IPC before sending |
| 2279 // the page load one. |
| 2280 EXPECT_EQ(2U, GetLinkPrerenderCount()); |
| 2281 EXPECT_EQ(1U, GetRunningLinkPrerenderCount()); |
| 2282 |
| 2283 // Next url should be in pending list but not an active entry. |
| 2284 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); |
| 2285 |
| 2286 // Cancel the prerender. |
| 2287 GetPrerenderManager()->CancelAllPrerenders(); |
| 2288 prerender->WaitForStop(); |
| 2289 |
| 2290 // All prerenders are now gone. |
| 2291 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); |
| 2277 } | 2292 } |
| 2278 | 2293 |
| 2279 // See crbug.com/131836. | 2294 // See crbug.com/131836. |
| 2280 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { | 2295 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { |
| 2281 // Show the task manager. This populates the model. | 2296 // Show the task manager. This populates the model. |
| 2282 chrome::OpenTaskManager(current_browser()); | 2297 chrome::OpenTaskManager(current_browser()); |
| 2283 // Wait for the model of task manager to start. | 2298 // Wait for the model of task manager to start. |
| 2284 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 2299 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 2285 | 2300 |
| 2286 // Start with two resources. | 2301 // Start with two resources. |
| (...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3856 } | 3871 } |
| 3857 }; | 3872 }; |
| 3858 | 3873 |
| 3859 // Checks that prerendering works in incognito mode. | 3874 // Checks that prerendering works in incognito mode. |
| 3860 IN_PROC_BROWSER_TEST_F(PrerenderIncognitoBrowserTest, PrerenderIncognito) { | 3875 IN_PROC_BROWSER_TEST_F(PrerenderIncognitoBrowserTest, PrerenderIncognito) { |
| 3861 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 3876 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 3862 NavigateToDestURL(); | 3877 NavigateToDestURL(); |
| 3863 } | 3878 } |
| 3864 | 3879 |
| 3865 } // namespace prerender | 3880 } // namespace prerender |
| OLD | NEW |