Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 185873003: Task Manager: overhaul & re-enable task manager browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-upload after 500's Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 using content::DevToolsClientHost; 93 using content::DevToolsClientHost;
94 using content::DevToolsManager; 94 using content::DevToolsManager;
95 using content::NavigationController; 95 using content::NavigationController;
96 using content::OpenURLParams; 96 using content::OpenURLParams;
97 using content::Referrer; 97 using content::Referrer;
98 using content::RenderViewHost; 98 using content::RenderViewHost;
99 using content::RenderWidgetHost; 99 using content::RenderWidgetHost;
100 using content::TestNavigationObserver; 100 using content::TestNavigationObserver;
101 using content::WebContents; 101 using content::WebContents;
102 using content::WebContentsObserver; 102 using content::WebContentsObserver;
103 using task_manager::browsertest_util::WaitForTaskManagerRows;
103 104
104 // Prerender tests work as follows: 105 // Prerender tests work as follows:
105 // 106 //
106 // A page with a prefetch link to the test page is loaded. Once prerendered, 107 // A page with a prefetch link to the test page is loaded. Once prerendered,
107 // its Javascript function DidPrerenderPass() is called, which returns true if 108 // its Javascript function DidPrerenderPass() is called, which returns true if
108 // the page behaves as expected when prerendered. 109 // the page behaves as expected when prerendered.
109 // 110 //
110 // The prerendered page is then displayed on a tab. The Javascript function 111 // The prerendered page is then displayed on a tab. The Javascript function
111 // DidDisplayPass() is called, and returns true if the page behaved as it 112 // DidDisplayPass() is called, and returns true if the page behaved as it
112 // should while being displayed. 113 // should while being displayed.
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 1452
1452 void AddPrerender(const GURL& url, int index) { 1453 void AddPrerender(const GURL& url, int index) {
1453 std::string javascript = base::StringPrintf( 1454 std::string javascript = base::StringPrintf(
1454 "AddPrerender('%s', %d)", url.spec().c_str(), index); 1455 "AddPrerender('%s', %d)", url.spec().c_str(), index);
1455 RenderViewHost* render_view_host = 1456 RenderViewHost* render_view_host =
1456 GetActiveWebContents()->GetRenderViewHost(); 1457 GetActiveWebContents()->GetRenderViewHost();
1457 render_view_host->ExecuteJavascriptInWebFrame( 1458 render_view_host->ExecuteJavascriptInWebFrame(
1458 base::string16(), base::ASCIIToUTF16(javascript)); 1459 base::string16(), base::ASCIIToUTF16(javascript));
1459 } 1460 }
1460 1461
1462 // Returns a string for pattern-matching TaskManager tab entries.
1463 base::string16 MatchTaskManagerTab(const char* page_title) {
1464 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX,
1465 base::ASCIIToUTF16(page_title));
1466 }
1467
1468 // Returns a string for pattern-matching TaskManager prerender entries.
1469 base::string16 MatchTaskManagerPrerender(const char* page_title) {
1470 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX,
1471 base::ASCIIToUTF16(page_title));
1472 }
1473
1461 protected: 1474 protected:
1462 bool autostart_test_server_; 1475 bool autostart_test_server_;
1463 1476
1464 private: 1477 private:
1465 // TODO(davidben): Remove this altogether so the tests don't globally assume 1478 // TODO(davidben): Remove this altogether so the tests don't globally assume
1466 // only one prerender. 1479 // only one prerender.
1467 TestPrerenderContents* GetPrerenderContents() const { 1480 TestPrerenderContents* GetPrerenderContents() const {
1468 return GetPrerenderContentsFor(dest_url_); 1481 return GetPrerenderContentsFor(dest_url_);
1469 } 1482 }
1470 1483
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB)); 2406 EXPECT_FALSE(UrlIsInPrerenderManager(kHtmlFileB));
2394 2407
2395 // Cancel the prerender. 2408 // Cancel the prerender.
2396 GetPrerenderManager()->CancelAllPrerenders(); 2409 GetPrerenderManager()->CancelAllPrerenders();
2397 prerender->WaitForStop(); 2410 prerender->WaitForStop();
2398 2411
2399 // All prerenders are now gone. 2412 // All prerenders are now gone.
2400 EXPECT_TRUE(IsEmptyPrerenderLinkManager()); 2413 EXPECT_TRUE(IsEmptyPrerenderLinkManager());
2401 } 2414 }
2402 2415
2403 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { 2416 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerBeforePrerender) {
2417 const base::string16 any_prerender = MatchTaskManagerPrerender("*");
2418 const base::string16 any_tab = MatchTaskManagerTab("*");
2419 const base::string16 original = MatchTaskManagerTab("Preloader");
2420 const base::string16 prerender = MatchTaskManagerPrerender("Prerender Page");
2421 const base::string16 final = MatchTaskManagerTab("Prerender Page");
2422
2404 // Show the task manager. This populates the model. 2423 // Show the task manager. This populates the model.
2405 chrome::OpenTaskManager(current_browser()); 2424 chrome::OpenTaskManager(current_browser());
2406 // Wait for the model of task manager to start. 2425 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab));
2407 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 2426 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender));
2427
2428 // Prerender a page in addition to the original tab.
2429 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
2430
2431 // A TaskManager entry should appear like "Prerender: Prerender Page"
2432 // alongside the original tab entry. There should be just these two entries.
2433 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, prerender));
2434 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, original));
2435 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, final));
2436 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_prerender));
2437 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab));
2438
2439 // Swap in the prerendered content.
2440 NavigateToDestURL();
2441
2442 // The "Prerender: " TaskManager entry should disappear, being replaced by a
2443 // "Tab: Prerender Page" entry, and nothing else.
2444 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, prerender));
2445 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, original));
2446 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final));
2447 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab));
2448 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender));
2449 }
2450
2451 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerAfterPrerender) {
2452 const base::string16 any_prerender = MatchTaskManagerPrerender("*");
2453 const base::string16 any_tab = MatchTaskManagerTab("*");
2454 const base::string16 original = MatchTaskManagerTab("Preloader");
2455 const base::string16 prerender = MatchTaskManagerPrerender("Prerender Page");
2456 const base::string16 final = MatchTaskManagerTab("Prerender Page");
2408 2457
2409 // Start with two resources. 2458 // Start with two resources.
2410 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 2459 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
2411 2460
2412 // One of the resources that has a WebContents associated with it should have 2461 // Show the task manager. This populates the model. Importantly, we're doing
2413 // the Prerender prefix. 2462 // this after the prerender WebContents already exists - the task manager
2414 const base::string16 prefix = 2463 // needs to find it, it can't just listen for creation.
2415 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, 2464 chrome::OpenTaskManager(current_browser());
2416 base::string16());
2417 base::string16 prerender_title;
2418 int num_prerender_tabs = 0;
2419 2465
2420 TaskManagerModel* model = GetModel(); 2466 // A TaskManager entry should appear like "Prerender: Prerender Page"
2421 // The task manager caches values. Force the titles to be fresh. 2467 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, prerender));
2422 model->Refresh(); 2468 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, original));
2423 for (int i = 0; i < model->ResourceCount(); ++i) { 2469 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, final));
2424 if (model->GetResourceWebContents(i)) { 2470 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_prerender));
2425 prerender_title = model->GetResourceTitle(i); 2471 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab));
2426 if (StartsWith(prerender_title, prefix, true))
2427 ++num_prerender_tabs;
2428 }
2429 }
2430 EXPECT_EQ(1, num_prerender_tabs);
2431 const base::string16 prerender_page_title =
2432 prerender_title.substr(prefix.length());
2433 2472
2473 // Swap in the tab.
2434 NavigateToDestURL(); 2474 NavigateToDestURL();
2435 2475
2436 // There should be no tabs with the Prerender prefix. 2476 // The "Prerender: Prerender Page" TaskManager row should disappear, being
2437 const base::string16 tab_prefix = 2477 // replaced by "Tab: Prerender Page"
2438 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_TAB_PREFIX, base::string16()); 2478 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, prerender));
2439 num_prerender_tabs = 0; 2479 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, original));
2440 int num_tabs_with_prerender_page_title = 0; 2480 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final));
2441 model->Refresh(); 2481 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab));
2442 for (int i = 0; i < model->ResourceCount(); ++i) { 2482 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender));
2443 if (model->GetResourceWebContents(i)) { 2483 }
2444 base::string16 tab_title = model->GetResourceTitle(i);
2445 if (StartsWith(tab_title, prefix, true)) {
2446 ++num_prerender_tabs;
2447 } else {
2448 EXPECT_TRUE(StartsWith(tab_title, tab_prefix, true));
2449 2484
2450 // The prerender tab should now be a normal tab but the title should be 2485 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, OpenTaskManagerAfterSwapIn) {
2451 // the same. Depending on timing, there may be more than one of these. 2486 const base::string16 any_prerender = MatchTaskManagerPrerender("*");
2452 const base::string16 tab_page_title = 2487 const base::string16 any_tab = MatchTaskManagerTab("*");
2453 tab_title.substr(tab_prefix.length()); 2488 const base::string16 final = MatchTaskManagerTab("Prerender Page");
2454 if (prerender_page_title.compare(tab_page_title) == 0)
2455 ++num_tabs_with_prerender_page_title;
2456 }
2457 }
2458 }
2459 EXPECT_EQ(0, num_prerender_tabs);
2460 2489
2461 // We may have deleted the prerender tab, but the swapped in tab should be 2490 // Prerender, and swap it in.
2462 // active. 2491 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
2463 EXPECT_GE(num_tabs_with_prerender_page_title, 1); 2492 NavigateToDestURL();
2464 EXPECT_LE(num_tabs_with_prerender_page_title, 2); 2493
2494 // Show the task manager. This populates the model. Importantly, we're doing
2495 // this after the prerender has been swapped in.
2496 chrome::OpenTaskManager(current_browser());
2497
2498 // We should not see a prerender resource in the task manager, just a normal
2499 // page.
2500 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, final));
2501 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, any_tab));
2502 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, any_prerender));
2465 } 2503 }
2466 2504
2467 // Checks that audio loads are deferred on prerendering. 2505 // Checks that audio loads are deferred on prerendering.
2468 // Times out under AddressSanitizer, see http://crbug.com/108402 2506 // Times out under AddressSanitizer, see http://crbug.com/108402
2469 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DISABLED_PrerenderHTML5Audio) { 2507 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, DISABLED_PrerenderHTML5Audio) {
2470 PrerenderTestURL("files/prerender/prerender_html5_audio.html", 2508 PrerenderTestURL("files/prerender/prerender_html5_audio.html",
2471 FINAL_STATUS_USED, 2509 FINAL_STATUS_USED,
2472 1); 2510 1);
2473 NavigateToDestURL(); 2511 NavigateToDestURL();
2474 WaitForASCIITitle(GetActiveWebContents(), kPassTitle); 2512 WaitForASCIITitle(GetActiveWebContents(), kPassTitle);
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after
4113 } 4151 }
4114 }; 4152 };
4115 4153
4116 // Checks that prerendering works in incognito mode. 4154 // Checks that prerendering works in incognito mode.
4117 IN_PROC_BROWSER_TEST_F(PrerenderIncognitoBrowserTest, PrerenderIncognito) { 4155 IN_PROC_BROWSER_TEST_F(PrerenderIncognitoBrowserTest, PrerenderIncognito) {
4118 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 4156 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
4119 NavigateToDestURL(); 4157 NavigateToDestURL();
4120 } 4158 }
4121 4159
4122 } // namespace prerender 4160 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698