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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 const GURL& url, | 317 const GURL& url, |
318 const content::Referrer& referrer, | 318 const content::Referrer& referrer, |
319 Origin origin, | 319 Origin origin, |
320 FinalStatus expected_final_status) | 320 FinalStatus expected_final_status) |
321 : PrerenderContents(prerender_manager, profile, url, | 321 : PrerenderContents(prerender_manager, profile, url, |
322 referrer, origin, PrerenderManager::kNoExperiment), | 322 referrer, origin, PrerenderManager::kNoExperiment), |
323 expected_final_status_(expected_final_status), | 323 expected_final_status_(expected_final_status), |
324 new_render_view_host_(NULL), | 324 new_render_view_host_(NULL), |
325 was_hidden_(false), | 325 was_hidden_(false), |
326 was_shown_(false), | 326 was_shown_(false), |
327 should_be_shown_(expected_final_status == FINAL_STATUS_USED), | 327 should_be_shown_(expected_final_status == FINAL_STATUS_USED) { |
328 expected_pending_prerenders_(0) { | |
329 } | 328 } |
330 | 329 |
331 virtual ~TestPrerenderContents() { | 330 virtual ~TestPrerenderContents() { |
332 if (expected_final_status_ == FINAL_STATUS_MAX) { | 331 if (expected_final_status_ == FINAL_STATUS_MAX) { |
333 EXPECT_EQ(match_complete_status(), MATCH_COMPLETE_REPLACEMENT); | 332 EXPECT_EQ(MATCH_COMPLETE_REPLACEMENT, match_complete_status()); |
334 } else { | 333 } else { |
335 EXPECT_EQ(expected_final_status_, final_status()) << | 334 EXPECT_EQ(expected_final_status_, final_status()) << |
336 " when testing URL " << prerender_url().path() << | 335 " when testing URL " << prerender_url().path() << |
337 " (Expected: " << NameFromFinalStatus(expected_final_status_) << | 336 " (Expected: " << NameFromFinalStatus(expected_final_status_) << |
338 ", Actual: " << NameFromFinalStatus(final_status()) << ")"; | 337 ", Actual: " << NameFromFinalStatus(final_status()) << ")"; |
339 } | 338 } |
340 // Prerendering RenderViewHosts should be hidden before the first | 339 // Prerendering RenderViewHosts should be hidden before the first |
341 // navigation, so this should be happen for every PrerenderContents for | 340 // navigation, so this should be happen for every PrerenderContents for |
342 // which a RenderViewHost is created, regardless of whether or not it's | 341 // which a RenderViewHost is created, regardless of whether or not it's |
343 // used. | 342 // used. |
(...skipping 27 matching lines...) Expand all Loading... | |
371 } | 370 } |
372 | 371 |
373 virtual bool CheckURL(const GURL& url) OVERRIDE { | 372 virtual bool CheckURL(const GURL& url) OVERRIDE { |
374 // Prevent FINAL_STATUS_UNSUPPORTED_SCHEME when navigating to about:crash in | 373 // Prevent FINAL_STATUS_UNSUPPORTED_SCHEME when navigating to about:crash in |
375 // the PrerenderRendererCrash test. | 374 // the PrerenderRendererCrash test. |
376 if (url.spec() != content::kChromeUICrashURL) | 375 if (url.spec() != content::kChromeUICrashURL) |
377 return PrerenderContents::CheckURL(url); | 376 return PrerenderContents::CheckURL(url); |
378 return true; | 377 return true; |
379 } | 378 } |
380 | 379 |
381 virtual void AddPendingPrerender( | |
382 scoped_ptr<PendingPrerenderInfo> pending_prerender_info) OVERRIDE { | |
383 PrerenderContents::AddPendingPrerender(pending_prerender_info.Pass()); | |
384 if (expected_pending_prerenders_ > 0 && | |
385 pending_prerender_count() == expected_pending_prerenders_) { | |
386 base::MessageLoop::current()->Quit(); | |
387 } | |
388 } | |
389 | |
390 // Waits until the prerender has |expected_pending_prerenders| pending | |
391 // prerenders. | |
392 void WaitForPendingPrerenders(size_t expected_pending_prerenders) { | |
393 if (pending_prerender_count() < expected_pending_prerenders) { | |
394 expected_pending_prerenders_ = expected_pending_prerenders; | |
395 content::RunMessageLoop(); | |
396 expected_pending_prerenders_ = 0; | |
397 } | |
398 | |
399 EXPECT_EQ(expected_pending_prerenders, pending_prerender_count()); | |
400 } | |
401 | |
402 // For tests that open the prerender in a new background tab, the RenderView | 380 // For tests that open the prerender in a new background tab, the RenderView |
403 // will not have been made visible when the PrerenderContents is destroyed | 381 // will not have been made visible when the PrerenderContents is destroyed |
404 // even though it is used. | 382 // even though it is used. |
405 void set_should_be_shown(bool value) { should_be_shown_ = value; } | 383 void set_should_be_shown(bool value) { should_be_shown_ = value; } |
406 | 384 |
407 FinalStatus expected_final_status() const { return expected_final_status_; } | 385 FinalStatus expected_final_status() const { return expected_final_status_; } |
408 | 386 |
409 private: | 387 private: |
410 virtual void OnRenderViewHostCreated( | 388 virtual void OnRenderViewHostCreated( |
411 RenderViewHost* new_render_view_host) OVERRIDE { | 389 RenderViewHost* new_render_view_host) OVERRIDE { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 // The RenderViewHost created for the prerender, if any. | 426 // The RenderViewHost created for the prerender, if any. |
449 RenderViewHost* new_render_view_host_; | 427 RenderViewHost* new_render_view_host_; |
450 // Set to true when the prerendering RenderWidget is hidden. | 428 // Set to true when the prerendering RenderWidget is hidden. |
451 bool was_hidden_; | 429 bool was_hidden_; |
452 // Set to true when the prerendering RenderWidget is shown, after having been | 430 // Set to true when the prerendering RenderWidget is shown, after having been |
453 // hidden. | 431 // hidden. |
454 bool was_shown_; | 432 bool was_shown_; |
455 // Expected final value of was_shown_. Defaults to true for | 433 // Expected final value of was_shown_. Defaults to true for |
456 // FINAL_STATUS_USED, and false otherwise. | 434 // FINAL_STATUS_USED, and false otherwise. |
457 bool should_be_shown_; | 435 bool should_be_shown_; |
458 | |
459 // Total number of pending prerenders we're currently waiting for. Zero | |
460 // indicates we currently aren't waiting for any. | |
461 size_t expected_pending_prerenders_; | |
462 }; | 436 }; |
463 | 437 |
464 // A handle to a TestPrerenderContents whose lifetime is under the caller's | 438 // A handle to a TestPrerenderContents whose lifetime is under the caller's |
465 // control. A PrerenderContents may be destroyed at any point. This allows | 439 // control. A PrerenderContents may be destroyed at any point. This allows |
466 // tracking the final status, etc. | 440 // tracking the final status, etc. |
467 class TestPrerender : public PrerenderContents::Observer, | 441 class TestPrerender : public PrerenderContents::Observer, |
468 public base::SupportsWeakPtr<TestPrerender> { | 442 public base::SupportsWeakPtr<TestPrerender> { |
469 public: | 443 public: |
470 TestPrerender() | 444 TestPrerender() |
471 : contents_(NULL), | 445 : contents_(NULL), |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1290 // removed from the PrerenderLinkManager when the prerender is canceled from | 1264 // removed from the PrerenderLinkManager when the prerender is canceled from |
1291 // the browser, when the prerenders are cancelled from the renderer process, | 1265 // the browser, when the prerenders are cancelled from the renderer process, |
1292 // or the channel for the renderer process is closed on the IO thread. In the | 1266 // or the channel for the renderer process is closed on the IO thread. In the |
1293 // last case, the code must be careful to wait for the channel to close, as it | 1267 // last case, the code must be careful to wait for the channel to close, as it |
1294 // is done asynchronously after swapping out the old process. See | 1268 // is done asynchronously after swapping out the old process. See |
1295 // ChannelDestructionWatcher. | 1269 // ChannelDestructionWatcher. |
1296 bool IsEmptyPrerenderLinkManager() const { | 1270 bool IsEmptyPrerenderLinkManager() const { |
1297 return GetPrerenderLinkManager()->IsEmpty(); | 1271 return GetPrerenderLinkManager()->IsEmpty(); |
1298 } | 1272 } |
1299 | 1273 |
1274 size_t GetLinkPrerenderCount() const { | |
1275 return GetPrerenderLinkManager()->prerenders_.size(); | |
1276 } | |
1277 | |
1278 size_t GetRunningLinkPrerenderCount() const { | |
1279 return GetPrerenderLinkManager()->CountRunningPrerenders(); | |
1280 } | |
1281 | |
1300 // Returns length of |prerender_manager_|'s history, or -1 on failure. | 1282 // Returns length of |prerender_manager_|'s history, or -1 on failure. |
1301 int GetHistoryLength() const { | 1283 int GetHistoryLength() const { |
1302 scoped_ptr<base::DictionaryValue> prerender_dict( | 1284 scoped_ptr<base::DictionaryValue> prerender_dict( |
1303 static_cast<base::DictionaryValue*>( | 1285 static_cast<base::DictionaryValue*>( |
1304 GetPrerenderManager()->GetAsValue())); | 1286 GetPrerenderManager()->GetAsValue())); |
1305 if (!prerender_dict.get()) | 1287 if (!prerender_dict.get()) |
1306 return -1; | 1288 return -1; |
1307 base::ListValue* history_list; | 1289 base::ListValue* history_list; |
1308 if (!prerender_dict->GetList("history", &history_list)) | 1290 if (!prerender_dict->GetList("history", &history_list)) |
1309 return -1; | 1291 return -1; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1376 bool DidDisplayPass(WebContents* web_contents) const { | 1358 bool DidDisplayPass(WebContents* web_contents) const { |
1377 bool display_test_result = false; | 1359 bool display_test_result = false; |
1378 if (!content::ExecuteScriptAndExtractBool( | 1360 if (!content::ExecuteScriptAndExtractBool( |
1379 web_contents, | 1361 web_contents, |
1380 "window.domAutomationController.send(DidDisplayPass())", | 1362 "window.domAutomationController.send(DidDisplayPass())", |
1381 &display_test_result)) | 1363 &display_test_result)) |
1382 return false; | 1364 return false; |
1383 return display_test_result; | 1365 return display_test_result; |
1384 } | 1366 } |
1385 | 1367 |
1368 scoped_ptr<TestPrerender> ExpectPrerender(FinalStatus expected_final_status) { | |
1369 return prerender_contents_factory_->ExpectPrerenderContents( | |
1370 expected_final_status); | |
1371 } | |
1372 | |
1386 protected: | 1373 protected: |
1387 bool autostart_test_server_; | 1374 bool autostart_test_server_; |
1388 | 1375 |
1389 private: | 1376 private: |
1390 // TODO(davidben): Remove this altogether so the tests don't globally assume | 1377 // TODO(davidben): Remove this altogether so the tests don't globally assume |
1391 // only one prerender. | 1378 // only one prerender. |
1392 TestPrerenderContents* GetPrerenderContents() const { | 1379 TestPrerenderContents* GetPrerenderContents() const { |
1393 return GetPrerenderContentsFor(dest_url_); | 1380 return GetPrerenderContentsFor(dest_url_); |
1394 } | 1381 } |
1395 | 1382 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1538 ChannelDestructionWatcher channel_close_watcher; | 1525 ChannelDestructionWatcher channel_close_watcher; |
1539 channel_close_watcher.WatchChannel( | 1526 channel_close_watcher.WatchChannel( |
1540 GetActiveWebContents()->GetRenderProcessHost()); | 1527 GetActiveWebContents()->GetRenderProcessHost()); |
1541 NavigateToDestURL(); | 1528 NavigateToDestURL(); |
1542 channel_close_watcher.WaitForChannelClose(); | 1529 channel_close_watcher.WaitForChannelClose(); |
1543 | 1530 |
1544 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); | 1531 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); |
1545 } | 1532 } |
1546 | 1533 |
1547 // Checks that pending prerenders launch and receive proper event treatment. | 1534 // Checks that pending prerenders launch and receive proper event treatment. |
1548 // Disabled due to http://crbug.com/167792 | 1535 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPagePending) { |
1549 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DISABLED_PrerenderPagePending) { | 1536 scoped_ptr<TestPrerender> prerender = |
1550 std::vector<FinalStatus> expected_final_status_queue; | 1537 PrerenderTestURL("files/prerender/prerender_page_pending.html", |
1551 expected_final_status_queue.push_back(FINAL_STATUS_USED); | 1538 FINAL_STATUS_USED, 1); |
1552 expected_final_status_queue.push_back(FINAL_STATUS_USED); | |
1553 PrerenderTestURL("files/prerender/prerender_page_pending.html", | |
1554 expected_final_status_queue, 1); | |
1555 | 1539 |
1556 ChannelDestructionWatcher first_channel_close_watcher; | 1540 // Navigate to the prerender. |
1541 scoped_ptr<TestPrerender> prerender2 = ExpectPrerender(FINAL_STATUS_USED); | |
1542 NavigateToDestURL(); | |
1543 // Abort early if the original prerender didn't swap, so as not to hang. | |
1544 ASSERT_FALSE(prerender->contents()); | |
1557 | 1545 |
1558 first_channel_close_watcher.WatchChannel( | 1546 // Wait for the new prerender to be ready. |
1559 GetActiveWebContents()->GetRenderProcessHost()); | 1547 prerender2->WaitForStart(); |
1560 NavigateToDestURL(); | 1548 prerender2->WaitForLoads(1); |
1561 // NavigateToDestURL doesn't run a message loop. Normally that's fine, but in | |
1562 // this case, we need the pending prerenders to start. | |
1563 content::RunMessageLoop(); | |
1564 first_channel_close_watcher.WaitForChannelClose(); | |
1565 | 1549 |
1566 const GURL prerender_page_url = | 1550 const GURL prerender_page_url = |
1567 test_server()->GetURL("files/prerender/prerender_page.html"); | 1551 test_server()->GetURL("files/prerender/prerender_page.html"); |
1568 EXPECT_FALSE(IsEmptyPrerenderLinkManager()); | 1552 EXPECT_FALSE(IsEmptyPrerenderLinkManager()); |
1569 EXPECT_NE(static_cast<TestPrerenderContents*>(NULL), | 1553 EXPECT_NE(static_cast<TestPrerenderContents*>(NULL), |
1570 GetPrerenderContentsFor(prerender_page_url)); | 1554 GetPrerenderContentsFor(prerender_page_url)); |
1571 | 1555 |
1572 // Now navigate to our target page. | 1556 // Now navigate to our target page. |
1573 ChannelDestructionWatcher second_channel_close_watcher; | 1557 NavigationOrSwapObserver swap_observer(current_browser()->tab_strip_model(), |
1574 second_channel_close_watcher.WatchChannel( | 1558 GetActiveWebContents()); |
1575 GetActiveWebContents()->GetRenderProcessHost()); | |
1576 ui_test_utils::NavigateToURLWithDisposition( | 1559 ui_test_utils::NavigateToURLWithDisposition( |
1577 current_browser(), prerender_page_url, CURRENT_TAB, | 1560 current_browser(), prerender_page_url, CURRENT_TAB, |
1578 ui_test_utils::BROWSER_TEST_NONE); | 1561 ui_test_utils::BROWSER_TEST_NONE); |
1579 second_channel_close_watcher.WaitForChannelClose(); | 1562 swap_observer.Wait(); |
1580 | 1563 |
1581 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); | 1564 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); |
1582 } | 1565 } |
1583 | 1566 |
1584 // Checks that pending prerenders which are canceled before they are launched | 1567 // Checks that pending prerenders which are canceled before they are launched |
1585 // never get started. | 1568 // never get started. |
1586 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageRemovesPending) { | 1569 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageRemovesPending) { |
1587 PrerenderTestURL("files/prerender/prerender_page_removes_pending.html", | 1570 PrerenderTestURL("files/prerender/prerender_page_removes_pending.html", |
1588 FINAL_STATUS_USED, 1); | 1571 FINAL_STATUS_USED, 1); |
1589 | 1572 |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2164 | 2147 |
2165 // Checks shutdown code while a prerender is active. | 2148 // Checks shutdown code while a prerender is active. |
2166 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderQuickQuit) { | 2149 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderQuickQuit) { |
2167 DisableJavascriptCalls(); | 2150 DisableJavascriptCalls(); |
2168 DisableLoadEventCheck(); | 2151 DisableLoadEventCheck(); |
2169 PrerenderTestURL("files/prerender/prerender_page.html", | 2152 PrerenderTestURL("files/prerender/prerender_page.html", |
2170 FINAL_STATUS_APP_TERMINATING, | 2153 FINAL_STATUS_APP_TERMINATING, |
2171 0); | 2154 0); |
2172 } | 2155 } |
2173 | 2156 |
2174 // TODO(gavinp,sreeram): Fix http://crbug.com/145248 and deflake this test. | |
2175 // Checks that we don't prerender in an infinite loop. | 2157 // Checks that we don't prerender in an infinite loop. |
2176 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DISABLED_PrerenderInfiniteLoop) { | 2158 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderInfiniteLoop) { |
2177 const char* const kHtmlFileA = "files/prerender/prerender_infinite_a.html"; | 2159 const char* const kHtmlFileA = "files/prerender/prerender_infinite_a.html"; |
2178 const char* const kHtmlFileB = "files/prerender/prerender_infinite_b.html"; | 2160 const char* const kHtmlFileB = "files/prerender/prerender_infinite_b.html"; |
2179 | 2161 |
2180 std::vector<FinalStatus> expected_final_status_queue; | 2162 std::vector<FinalStatus> expected_final_status_queue; |
2181 expected_final_status_queue.push_back(FINAL_STATUS_USED); | 2163 expected_final_status_queue.push_back(FINAL_STATUS_USED); |
2182 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); | 2164 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); |
2183 | 2165 |
2184 ScopedVector<TestPrerender> prerenders = | 2166 ScopedVector<TestPrerender> prerenders = |
2185 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); | 2167 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); |
2186 ASSERT_TRUE(prerenders[0]->contents()); | 2168 ASSERT_TRUE(prerenders[0]->contents()); |
2187 prerenders[0]->contents()->WaitForPendingPrerenders(1u); | 2169 // Assert that the pending prerender is in there already. This relies on the |
2170 // fact that the renderer sends out the AddLinkRelPrerender IPC before sending | |
2171 // the page load one. | |
davidben
2014/01/24 17:50:43
Not entirely thrilled by these "this relies on the
| |
2172 EXPECT_EQ(2U, GetLinkPrerenderCount()); | |
2173 EXPECT_EQ(1U, GetRunningLinkPrerenderCount()); | |
2188 | 2174 |
2189 // Next url should be in pending list but not an active entry. | 2175 // Next url should be in pending list but not an active entry. |
2190 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); | 2176 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); |
2191 | 2177 |
2192 NavigateToDestURL(); | 2178 NavigateToDestURL(); |
2193 | 2179 |
2194 // Make sure the PrerenderContents for the next url is now in the manager | 2180 // Make sure the PrerenderContents for the next url is now in the manager and |
2195 // and not pending. | 2181 // not pending. This relies on pending prerenders being resolved in the same |
2182 // event loop iteration as OnPrerenderStop. | |
2196 EXPECT_TRUE(UrlIsInPrerenderManager(kHtmlFileB)); | 2183 EXPECT_TRUE(UrlIsInPrerenderManager(kHtmlFileB)); |
2184 EXPECT_EQ(1U, GetLinkPrerenderCount()); | |
2185 EXPECT_EQ(1U, GetRunningLinkPrerenderCount()); | |
2197 } | 2186 } |
2198 | 2187 |
2199 // TODO(gavinp,sreeram): Fix http://crbug.com/145248 and deflake this test. | |
2200 // Checks that we don't prerender in an infinite loop and multiple links are | 2188 // Checks that we don't prerender in an infinite loop and multiple links are |
2201 // handled correctly. | 2189 // handled correctly. |
2202 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 2190 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
2203 DISABLED_PrerenderInfiniteLoopMultiple) { | 2191 PrerenderInfiniteLoopMultiple) { |
2204 const char* const kHtmlFileA = | 2192 const char* const kHtmlFileA = |
2205 "files/prerender/prerender_infinite_a_multiple.html"; | 2193 "files/prerender/prerender_infinite_a_multiple.html"; |
2206 const char* const kHtmlFileB = | 2194 const char* const kHtmlFileB = |
2207 "files/prerender/prerender_infinite_b_multiple.html"; | 2195 "files/prerender/prerender_infinite_b_multiple.html"; |
2208 const char* const kHtmlFileC = | 2196 const char* const kHtmlFileC = |
2209 "files/prerender/prerender_infinite_c_multiple.html"; | 2197 "files/prerender/prerender_infinite_c_multiple.html"; |
2210 | 2198 |
2211 // This test is conceptually simplest if concurrency is at two, since we | 2199 // This test is conceptually simplest if concurrency is at two, since we |
2212 // don't have to worry about which of kHtmlFileB or kHtmlFileC gets evicted. | 2200 // don't have to worry about which of kHtmlFileB or kHtmlFileC gets evicted. |
2213 GetPrerenderManager()->mutable_config().max_link_concurrency = 2; | 2201 GetPrerenderManager()->mutable_config().max_link_concurrency = 2; |
2214 GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2; | 2202 GetPrerenderManager()->mutable_config().max_link_concurrency_per_launcher = 2; |
2215 | 2203 |
2216 std::vector<FinalStatus> expected_final_status_queue; | 2204 std::vector<FinalStatus> expected_final_status_queue; |
2217 expected_final_status_queue.push_back(FINAL_STATUS_USED); | 2205 expected_final_status_queue.push_back(FINAL_STATUS_USED); |
2218 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); | 2206 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); |
2219 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); | 2207 expected_final_status_queue.push_back(FINAL_STATUS_APP_TERMINATING); |
2220 | 2208 |
2221 ScopedVector<TestPrerender> prerenders = | 2209 ScopedVector<TestPrerender> prerenders = |
2222 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); | 2210 PrerenderTestURL(kHtmlFileA, expected_final_status_queue, 1); |
2223 ASSERT_TRUE(prerenders[0]->contents()); | 2211 ASSERT_TRUE(prerenders[0]->contents()); |
2224 prerenders[0]->contents()->WaitForPendingPrerenders(2u); | |
2225 | 2212 |
2226 // Next url should be in pending list but not an active entry. | 2213 // Next url should be in pending list but not an active entry. This relies on |
2214 // the fact that the renderer sends out the AddLinkRelPrerender IPC before | |
2215 // sending the page load one. | |
2216 EXPECT_EQ(3U, GetLinkPrerenderCount()); | |
2217 EXPECT_EQ(1U, GetRunningLinkPrerenderCount()); | |
2227 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); | 2218 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); |
2228 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileC)); | 2219 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileC)); |
2229 | 2220 |
2230 NavigateToDestURL(); | 2221 NavigateToDestURL(); |
2231 | 2222 |
2232 // Make sure the PrerenderContents for the next urls are now in the manager | 2223 // Make sure the PrerenderContents for the next urls are now in the manager |
2233 // and not pending. One and only one of the URLs (the last seen) should be the | 2224 // and not pending. One and only one of the URLs (the last seen) should be the |
2234 // active entry. | 2225 // active entry. This relies on pending prerenders being resolved in the same |
2226 // event loop iteration as OnPrerenderStop. | |
2235 bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB); | 2227 bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB); |
2236 bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC); | 2228 bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC); |
2237 EXPECT_TRUE(url_b_is_active_prerender && url_c_is_active_prerender); | 2229 EXPECT_TRUE(url_b_is_active_prerender && url_c_is_active_prerender); |
2230 EXPECT_EQ(2U, GetLinkPrerenderCount()); | |
2231 EXPECT_EQ(2U, GetRunningLinkPrerenderCount()); | |
2232 } | |
2233 | |
2234 // Checks that pending prerenders are aborted (and never launched) when launched | |
2235 // by a prerender that itself gets aborted. | |
2236 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderAbortPendingOnCancel) { | |
2237 const char* const kHtmlFileA = "files/prerender/prerender_infinite_a.html"; | |
2238 const char* const kHtmlFileB = "files/prerender/prerender_infinite_b.html"; | |
2239 | |
2240 scoped_ptr<TestPrerender> prerender = | |
2241 PrerenderTestURL(kHtmlFileA, FINAL_STATUS_CANCELLED, 1); | |
2242 ASSERT_TRUE(prerender->contents()); | |
2243 // Assert that the pending prerender is in there already. This relies on the | |
2244 // fact that the renderer sends out the AddLinkRelPrerender IPC before sending | |
2245 // the page load one. | |
2246 EXPECT_EQ(2U, GetLinkPrerenderCount()); | |
2247 EXPECT_EQ(1U, GetRunningLinkPrerenderCount()); | |
2248 | |
2249 // Next url should be in pending list but not an active entry. | |
2250 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); | |
2251 | |
2252 // Cancel the prerender. | |
2253 GetPrerenderManager()->CancelAllPrerenders(); | |
2254 prerender->WaitForStop(); | |
2255 | |
2256 // All prerenders are now gone. | |
2257 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); | |
2238 } | 2258 } |
2239 | 2259 |
2240 // See crbug.com/131836. | 2260 // See crbug.com/131836. |
2241 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { | 2261 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { |
2242 // Show the task manager. This populates the model. | 2262 // Show the task manager. This populates the model. |
2243 chrome::OpenTaskManager(current_browser()); | 2263 chrome::OpenTaskManager(current_browser()); |
2244 // Wait for the model of task manager to start. | 2264 // Wait for the model of task manager to start. |
2245 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 2265 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
2246 | 2266 |
2247 // Start with two resources. | 2267 // Start with two resources. |
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3716 } | 3736 } |
3717 }; | 3737 }; |
3718 | 3738 |
3719 // Checks that prerendering works in incognito mode. | 3739 // Checks that prerendering works in incognito mode. |
3720 IN_PROC_BROWSER_TEST_F(PrerenderIncognitoBrowserTest, PrerenderIncognito) { | 3740 IN_PROC_BROWSER_TEST_F(PrerenderIncognitoBrowserTest, PrerenderIncognito) { |
3721 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 3741 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
3722 NavigateToDestURL(); | 3742 NavigateToDestURL(); |
3723 } | 3743 } |
3724 | 3744 |
3725 } // namespace prerender | 3745 } // namespace prerender |
OLD | NEW |