| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <deque> | 6 #include <deque> |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 } | 1353 } |
| 1354 | 1354 |
| 1355 void DisableJavascriptCalls() { | 1355 void DisableJavascriptCalls() { |
| 1356 call_javascript_ = false; | 1356 call_javascript_ = false; |
| 1357 } | 1357 } |
| 1358 | 1358 |
| 1359 void DisableLoadEventCheck() { | 1359 void DisableLoadEventCheck() { |
| 1360 check_load_events_ = false; | 1360 check_load_events_ = false; |
| 1361 } | 1361 } |
| 1362 | 1362 |
| 1363 TaskManagerModel* GetModel() const { | |
| 1364 return TaskManager::GetInstance()->model(); | |
| 1365 } | |
| 1366 | |
| 1367 PrerenderManager* GetPrerenderManager() const { | 1363 PrerenderManager* GetPrerenderManager() const { |
| 1368 PrerenderManager* prerender_manager = | 1364 PrerenderManager* prerender_manager = |
| 1369 PrerenderManagerFactory::GetForProfile(current_browser()->profile()); | 1365 PrerenderManagerFactory::GetForProfile(current_browser()->profile()); |
| 1370 return prerender_manager; | 1366 return prerender_manager; |
| 1371 } | 1367 } |
| 1372 | 1368 |
| 1373 const PrerenderLinkManager* GetPrerenderLinkManager() const { | 1369 const PrerenderLinkManager* GetPrerenderLinkManager() const { |
| 1374 PrerenderLinkManager* prerender_link_manager = | 1370 PrerenderLinkManager* prerender_link_manager = |
| 1375 PrerenderLinkManagerFactory::GetForProfile( | 1371 PrerenderLinkManagerFactory::GetForProfile( |
| 1376 current_browser()->profile()); | 1372 current_browser()->profile()); |
| (...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2467 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); | 2463 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); |
| 2468 | 2464 |
| 2469 // Cancel the prerender. | 2465 // Cancel the prerender. |
| 2470 GetPrerenderManager()->CancelAllPrerenders(); | 2466 GetPrerenderManager()->CancelAllPrerenders(); |
| 2471 prerender->WaitForStop(); | 2467 prerender->WaitForStop(); |
| 2472 | 2468 |
| 2473 // All prerenders are now gone. | 2469 // All prerenders are now gone. |
| 2474 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); | 2470 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); |
| 2475 } | 2471 } |
| 2476 | 2472 |
| 2473 #if defined(ENABLE_TASK_MANAGER) |
| 2474 |
| 2477 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerBeforePrerender) { | 2475 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerBeforePrerender) { |
| 2478 // This test is for the old implementation of the task manager. We must | |
| 2479 // explicitly disable the new one. | |
| 2480 task_manager::browsertest_util::EnableOldTaskManager(); | |
| 2481 | |
| 2482 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); | 2476 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); |
| 2483 const base::string16 any_tab = MatchTaskManagerTab("*"); | 2477 const base::string16 any_tab = MatchTaskManagerTab("*"); |
| 2484 const base::string16 original = MatchTaskManagerTab("Preloader"); | 2478 const base::string16 original = MatchTaskManagerTab("Preloader"); |
| 2485 const base::string16 prerender = MatchTaskManagerPrerender("Prerender Page"); | 2479 const base::string16 prerender = MatchTaskManagerPrerender("Prerender Page"); |
| 2486 const base::string16 final = MatchTaskManagerTab("Prerender Page"); | 2480 const base::string16 final = MatchTaskManagerTab("Prerender Page"); |
| 2487 | 2481 |
| 2488 // Show the task manager. This populates the model. | 2482 // Show the task manager. This populates the model. |
| 2489 chrome::OpenTaskManager(current_browser()); | 2483 chrome::OpenTaskManager(current_browser()); |
| 2490 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | 2484 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); |
| 2491 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); | 2485 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2507 // The "Prerender: " TaskManager entry should disappear, being replaced by a | 2501 // The "Prerender: " TaskManager entry should disappear, being replaced by a |
| 2508 // "Tab: Prerender Page" entry, and nothing else. | 2502 // "Tab: Prerender Page" entry, and nothing else. |
| 2509 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, prerender)); | 2503 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, prerender)); |
| 2510 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, original)); | 2504 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, original)); |
| 2511 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final)); | 2505 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final)); |
| 2512 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | 2506 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); |
| 2513 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); | 2507 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); |
| 2514 } | 2508 } |
| 2515 | 2509 |
| 2516 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerAfterPrerender) { | 2510 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerAfterPrerender) { |
| 2517 // This test is for the old implementation of the task manager. We must | |
| 2518 // explicitly disable the new one. | |
| 2519 task_manager::browsertest_util::EnableOldTaskManager(); | |
| 2520 | |
| 2521 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); | 2511 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); |
| 2522 const base::string16 any_tab = MatchTaskManagerTab("*"); | 2512 const base::string16 any_tab = MatchTaskManagerTab("*"); |
| 2523 const base::string16 original = MatchTaskManagerTab("Preloader"); | 2513 const base::string16 original = MatchTaskManagerTab("Preloader"); |
| 2524 const base::string16 prerender = MatchTaskManagerPrerender("Prerender Page"); | 2514 const base::string16 prerender = MatchTaskManagerPrerender("Prerender Page"); |
| 2525 const base::string16 final = MatchTaskManagerTab("Prerender Page"); | 2515 const base::string16 final = MatchTaskManagerTab("Prerender Page"); |
| 2526 | 2516 |
| 2527 // Start with two resources. | 2517 // Start with two resources. |
| 2528 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 2518 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 2529 | 2519 |
| 2530 // Show the task manager. This populates the model. Importantly, we're doing | 2520 // Show the task manager. This populates the model. Importantly, we're doing |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2545 // The "Prerender: Prerender Page" TaskManager row should disappear, being | 2535 // The "Prerender: Prerender Page" TaskManager row should disappear, being |
| 2546 // replaced by "Tab: Prerender Page" | 2536 // replaced by "Tab: Prerender Page" |
| 2547 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, prerender)); | 2537 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, prerender)); |
| 2548 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, original)); | 2538 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, original)); |
| 2549 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final)); | 2539 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final)); |
| 2550 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | 2540 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); |
| 2551 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); | 2541 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); |
| 2552 } | 2542 } |
| 2553 | 2543 |
| 2554 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerAfterSwapIn) { | 2544 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerAfterSwapIn) { |
| 2555 // This test is for the old implementation of the task manager. We must | |
| 2556 // explicitly disable the new one. | |
| 2557 task_manager::browsertest_util::EnableOldTaskManager(); | |
| 2558 | |
| 2559 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); | 2545 const base::string16 any_prerender = MatchTaskManagerPrerender("*"); |
| 2560 const base::string16 any_tab = MatchTaskManagerTab("*"); | 2546 const base::string16 any_tab = MatchTaskManagerTab("*"); |
| 2561 const base::string16 final = MatchTaskManagerTab("Prerender Page"); | 2547 const base::string16 final = MatchTaskManagerTab("Prerender Page"); |
| 2562 | 2548 |
| 2563 // Prerender, and swap it in. | 2549 // Prerender, and swap it in. |
| 2564 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 2550 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 2565 NavigateToDestURL(); | 2551 NavigateToDestURL(); |
| 2566 | 2552 |
| 2567 // Show the task manager. This populates the model. Importantly, we're doing | 2553 // Show the task manager. This populates the model. Importantly, we're doing |
| 2568 // this after the prerender has been swapped in. | 2554 // this after the prerender has been swapped in. |
| 2569 chrome::OpenTaskManager(current_browser()); | 2555 chrome::OpenTaskManager(current_browser()); |
| 2570 | 2556 |
| 2571 // We should not see a prerender resource in the task manager, just a normal | 2557 // We should not see a prerender resource in the task manager, just a normal |
| 2572 // page. | 2558 // page. |
| 2573 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final)); | 2559 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final)); |
| 2574 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); | 2560 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab)); |
| 2575 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); | 2561 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender)); |
| 2576 } | 2562 } |
| 2577 | 2563 |
| 2564 #endif // defined(ENABLE_TASK_MANAGER) |
| 2565 |
| 2578 // Checks that audio loads are deferred on prerendering. | 2566 // Checks that audio loads are deferred on prerendering. |
| 2579 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5Audio) { | 2567 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderHTML5Audio) { |
| 2580 PrerenderTestURL("/prerender/prerender_html5_audio.html", FINAL_STATUS_USED, | 2568 PrerenderTestURL("/prerender/prerender_html5_audio.html", FINAL_STATUS_USED, |
| 2581 1); | 2569 1); |
| 2582 NavigateToDestURL(); | 2570 NavigateToDestURL(); |
| 2583 WaitForASCIITitle(GetActiveWebContents(), kPassTitle); | 2571 WaitForASCIITitle(GetActiveWebContents(), kPassTitle); |
| 2584 } | 2572 } |
| 2585 | 2573 |
| 2586 // Checks that audio loads are deferred on prerendering and played back when | 2574 // Checks that audio loads are deferred on prerendering and played back when |
| 2587 // the prerender is swapped in if autoplay is set. | 2575 // the prerender is swapped in if autoplay is set. |
| (...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3998 WebContents* web_contents = | 3986 WebContents* web_contents = |
| 3999 browser()->tab_strip_model()->GetActiveWebContents(); | 3987 browser()->tab_strip_model()->GetActiveWebContents(); |
| 4000 bool display_test_result = false; | 3988 bool display_test_result = false; |
| 4001 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, | 3989 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(web_contents, |
| 4002 "DidDisplayReallyPass()", | 3990 "DidDisplayReallyPass()", |
| 4003 &display_test_result)); | 3991 &display_test_result)); |
| 4004 ASSERT_TRUE(display_test_result); | 3992 ASSERT_TRUE(display_test_result); |
| 4005 } | 3993 } |
| 4006 #endif // !defined(DISABLE_NACL) | 3994 #endif // !defined(DISABLE_NACL) |
| 4007 | 3995 |
| 4008 #if defined(ENABLE_TASK_MANAGER) | |
| 4009 | |
| 4010 namespace { | |
| 4011 | |
| 4012 base::string16 GetPrerenderTitlePrefix() { | |
| 4013 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, | |
| 4014 base::string16()); | |
| 4015 } | |
| 4016 | |
| 4017 const std::vector<task_management::WebContentsTag*>& GetTrackedTags() { | |
| 4018 return task_management::WebContentsTagsManager::GetInstance()-> | |
| 4019 tracked_tags(); | |
| 4020 } | |
| 4021 | |
| 4022 // Tests the correct recording of tags for the prerender WebContents. | |
| 4023 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, TaskManagementTagsBasic) { | |
| 4024 // Browser tests start with a single tab. | |
| 4025 EXPECT_EQ(1U, GetTrackedTags().size()); | |
| 4026 | |
| 4027 // Start prerendering a page and make sure it's correctly tagged. | |
| 4028 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | |
| 4029 EXPECT_EQ(2U, GetTrackedTags().size()); | |
| 4030 | |
| 4031 // Swap in the prerendered content and make sure its tag is removed. | |
| 4032 NavigateToDestURL(); | |
| 4033 EXPECT_EQ(1U, GetTrackedTags().size()); | |
| 4034 } | |
| 4035 | |
| 4036 // Tests that the task manager will be provided by tasks that correspond to | |
| 4037 // prerendered WebContents. | |
| 4038 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, TaskManagementTasksProvided) { | |
| 4039 task_management::MockWebContentsTaskManager task_manager; | |
| 4040 // Browser tests start with a single tab. | |
| 4041 EXPECT_EQ(1U, GetTrackedTags().size()); | |
| 4042 | |
| 4043 task_manager.StartObserving(); | |
| 4044 | |
| 4045 // The pre-existing tab is provided. | |
| 4046 EXPECT_EQ(1U, task_manager.tasks().size()); | |
| 4047 | |
| 4048 // Start prerendering a page. | |
| 4049 PrerenderTestURL("/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | |
| 4050 | |
| 4051 EXPECT_EQ(2U, GetTrackedTags().size()); | |
| 4052 ASSERT_EQ(2U, task_manager.tasks().size()); | |
| 4053 | |
| 4054 const task_management::Task* task = task_manager.tasks().back(); | |
| 4055 EXPECT_EQ(task_management::Task::RENDERER, task->GetType()); | |
| 4056 const base::string16 title = task->title(); | |
| 4057 const base::string16 expected_prefix = GetPrerenderTitlePrefix(); | |
| 4058 EXPECT_TRUE(base::StartsWith(title, | |
| 4059 expected_prefix, | |
| 4060 base::CompareCase::INSENSITIVE_ASCII)); | |
| 4061 | |
| 4062 NavigateToDestURL(); | |
| 4063 EXPECT_EQ(1U, task_manager.tasks().size()); | |
| 4064 } | |
| 4065 | |
| 4066 } // namespace | |
| 4067 | |
| 4068 #endif // defined(ENABLE_TASK_MANAGER) | |
| 4069 | |
| 4070 } // namespace prerender | 3996 } // namespace prerender |
| OLD | NEW |