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.
5 #include "chrome/browser/task_manager/task_manager.h"
7 #include "base/files/file_path.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/devtools/devtools_window_testing.h"
13 #include "chrome/browser/extensions/extension_browsertest.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/notifications/notification.h"
17 #include "chrome/browser/notifications/notification_test_util.h"
18 #include "chrome/browser/notifications/notification_ui_manager.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/task_manager/resource_provider.h"
21 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_dialogs.h"
25 #include "chrome/browser/ui/browser_navigator.h"
26 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/panels/panel.h"
28 #include "chrome/browser/ui/panels/panel_manager.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/browser/web_applications/web_app.h"
31 #include "chrome/common/chrome_switches.h"
32 #include "chrome/grit/generated_resources.h"
33 #include "chrome/test/base/in_process_browser_test.h"
34 #include "chrome/test/base/ui_test_utils.h"
35 #include "components/infobars/core/confirm_infobar_delegate.h"
36 #include "components/infobars/core/infobar.h"
37 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/page_navigator.h"
39 #include "content/public/browser/render_frame_host.h"
40 #include "content/public/test/browser_test_utils.h"
41 #include "content/public/test/content_browser_test_utils.h"
42 #include "extensions/browser/extension_system.h"
43 #include "extensions/common/extension.h"
44 #include "net/dns/mock_host_resolver.h"
45 #include "net/test/embedded_test_server/embedded_test_server.h"
46 #include "testing/gtest/include/gtest/gtest.h"
47 #include "ui/base/l10n/l10n_util.h"
48 #include "ui/base/page_transition_types.h"
50 using content::WebContents
;
51 using task_manager::browsertest_util::MatchAboutBlankTab
;
52 using task_manager::browsertest_util::MatchAnyApp
;
53 using task_manager::browsertest_util::MatchAnyExtension
;
54 using task_manager::browsertest_util::MatchAnySubframe
;
55 using task_manager::browsertest_util::MatchAnyTab
;
56 using task_manager::browsertest_util::MatchAnyUtility
;
57 using task_manager::browsertest_util::MatchApp
;
58 using task_manager::browsertest_util::MatchExtension
;
59 using task_manager::browsertest_util::MatchSubframe
;
60 using task_manager::browsertest_util::MatchTab
;
61 using task_manager::browsertest_util::MatchUtility
;
62 using task_manager::browsertest_util::WaitForTaskManagerRows
;
63 using task_manager::browsertest_util::WaitForTaskManagerStatToExceed
;
67 const base::FilePath::CharType
* kTitle1File
= FILE_PATH_LITERAL("title1.html");
71 class TaskManagerBrowserTest
: public ExtensionBrowserTest
{
73 TaskManagerBrowserTest() {}
74 ~TaskManagerBrowserTest() override
{}
76 TaskManagerModel
* model() const {
77 return TaskManager::GetInstance()->model();
80 void ShowTaskManager() {
81 EXPECT_EQ(0, model()->ResourceCount());
83 // Show the task manager. This populates the model, and helps with debugging
84 // (you see the task manager).
85 chrome::ShowTaskManager(browser());
88 void HideTaskManager() {
89 // Hide the task manager, and wait for the model to be depopulated.
90 chrome::HideTaskManager();
91 base::RunLoop().RunUntilIdle(); // OnWindowClosed happens asynchronously.
92 EXPECT_EQ(0, model()->ResourceCount());
99 int GetUpdateTimeMs() {
100 return TaskManagerModel::kUpdateTimeMs
;
104 return ui_test_utils::GetTestUrl(
105 base::FilePath(base::FilePath::kCurrentDirectory
),
106 base::FilePath(kTitle1File
));
109 int FindResourceIndex(const base::string16
& title
) {
110 for (int i
= 0; i
< model()->ResourceCount(); ++i
) {
111 if (title
== model()->GetResourceTitle(i
))
118 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
119 ExtensionBrowserTest::SetUpCommandLine(command_line
);
121 // These tests are for the old implementation of the task manager. We must
122 // explicitly disable the new one.
123 task_manager::browsertest_util::EnableOldTaskManager();
125 // Do not launch device discovery process.
126 command_line
->AppendSwitch(switches::kDisableDeviceDiscoveryNotifications
);
130 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest
);
133 class TaskManagerUtilityProcessBrowserTest
: public TaskManagerBrowserTest
{
135 TaskManagerUtilityProcessBrowserTest() {}
138 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
139 TaskManagerBrowserTest::SetUpCommandLine(command_line
);
141 // Enable out-of-process proxy resolver. Use a trivial PAC script to ensure
142 // that some javascript is being executed.
143 command_line
->AppendSwitch(switches::kV8PacMojoOutOfProcess
);
144 command_line
->AppendSwitchASCII(
145 switches::kProxyPacUrl
,
146 "data:,function FindProxyForURL(url, host){return \"DIRECT;\";}");
150 DISALLOW_COPY_AND_ASSIGN(TaskManagerUtilityProcessBrowserTest
);
153 // Parameterized variant of TaskManagerBrowserTest which runs with/without
154 // --site-per-process, which enables out of process iframes (OOPIFs).
155 class TaskManagerOOPIFBrowserTest
: public TaskManagerBrowserTest
,
156 public testing::WithParamInterface
<bool> {
158 TaskManagerOOPIFBrowserTest() {}
161 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
162 TaskManagerBrowserTest::SetUpCommandLine(command_line
);
164 content::IsolateAllSitesForTesting(command_line
);
167 bool ShouldExpectSubframes() {
168 return content::AreAllSitesIsolatedForTesting();
172 DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest
);
175 INSTANTIATE_TEST_CASE_P(, TaskManagerOOPIFBrowserTest
, ::testing::Bool());
177 #if defined(OS_MACOSX) || defined(OS_LINUX)
178 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen
180 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen
183 // Regression test for http://crbug.com/13361
184 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, MAYBE_ShutdownWhileOpen
) {
188 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeTabContentsChanges
) {
190 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
191 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
192 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
194 // Open a new tab and make sure the task manager notices it.
195 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED
);
197 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
198 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
200 // Close the tab and verify that we notice.
201 browser()->tab_strip_model()->CloseWebContentsAt(0,
202 TabStripModel::CLOSE_NONE
);
203 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
204 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
207 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, KillTab
) {
209 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
210 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
211 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
213 // Open a new tab and make sure the task manager notices it.
214 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED
);
216 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
217 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
219 // Killing the tab via task manager should remove the row.
220 int tab
= FindResourceIndex(MatchTab("title1.html"));
222 ASSERT_TRUE(model()->GetResourceWebContents(tab
) != NULL
);
223 ASSERT_TRUE(model()->CanActivate(tab
));
224 TaskManager::GetInstance()->KillProcess(tab
);
225 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
226 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
228 // Tab should reappear in task manager upon reload.
229 chrome::Reload(browser(), CURRENT_TAB
);
230 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
231 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
234 // Test for http://crbug.com/444945, which is not fixed yet.
235 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
,
236 DISABLED_NavigateAwayFromHungRenderer
) {
237 host_resolver()->AddRule("*", "127.0.0.1");
238 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
241 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
242 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
244 GURL
url1(embedded_test_server()->GetURL("/title2.html"));
245 GURL
url3(embedded_test_server()->GetURL("a.com", "/iframe.html"));
247 // Open a new tab and make sure the task manager notices it.
248 AddTabAtIndex(0, url1
, ui::PAGE_TRANSITION_TYPED
);
249 ASSERT_NO_FATAL_FAILURE(
250 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
251 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
252 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
253 WebContents
* tab1
= browser()->tab_strip_model()->GetActiveWebContents();
255 // Initiate a navigation that will create a new WebContents in the same
257 content::WebContentsAddedObserver web_contents_added_observer
;
258 tab1
->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
259 base::ASCIIToUTF16("window.open('title3.html', '_blank');"));
260 // ... then immediately hang the renderer so that title3.html can't load.
261 tab1
->GetMainFrame()->ExecuteJavaScriptForTests(
262 base::ASCIIToUTF16("while(1);"));
264 // Blocks until a new WebContents appears.
265 WebContents
* tab2
= web_contents_added_observer
.GetWebContents();
267 // Make sure the new WebContents is in tab1's hung renderer process.
268 ASSERT_NE(nullptr, tab2
);
269 ASSERT_NE(tab1
, tab2
);
270 ASSERT_EQ(tab1
->GetMainFrame()->GetProcess(),
271 tab2
->GetMainFrame()->GetProcess())
272 << "New WebContents must be in the same process as the old WebContents, "
273 << "so that the new tab doesn't finish loading (what this test is all "
275 ASSERT_EQ(tab1
->GetSiteInstance(), tab2
->GetSiteInstance())
276 << "New WebContents must initially be in the same site instance as the "
277 << "old WebContents";
279 // Now navigate this tab to a different site. This should wind up in a
280 // different renderer process, so it should complete and show up in the task
282 tab2
->OpenURL(content::OpenURLParams(url3
, content::Referrer(), CURRENT_TAB
,
283 ui::PAGE_TRANSITION_TYPED
, false));
285 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
288 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticePanel
) {
289 ASSERT_TRUE(LoadExtension(
290 test_data_dir_
.AppendASCII("good").AppendASCII("Extensions")
291 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
292 .AppendASCII("1.0.0.0")));
294 // Open a new panel to an extension url.
296 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
297 Panel
* panel
= PanelManager::GetInstance()->CreatePanel(
298 web_app::GenerateApplicationNameFromExtensionId(
299 last_loaded_extension_id()),
300 browser()->profile(),
303 PanelManager::CREATE_AS_DOCKED
);
305 // Make sure that a task manager model created after the panel shows the
306 // existence of the panel and the extension.
308 ASSERT_NO_FATAL_FAILURE(
309 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
310 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
313 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
314 "french_sentence.html")));
315 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
316 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
317 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
319 // Close the panel and verify that we notice.
321 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
322 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
325 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
326 "french_sentence.html")));
327 ASSERT_NO_FATAL_FAILURE(
328 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
331 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticePanelChanges
) {
333 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
334 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
336 ASSERT_TRUE(LoadExtension(
337 test_data_dir_
.AppendASCII("good").AppendASCII("Extensions")
338 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
339 .AppendASCII("1.0.0.0")));
341 // Browser, the New Tab Page and Extension background page.
342 ASSERT_NO_FATAL_FAILURE(
343 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
344 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
345 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
347 // Open a new panel to an extension url and make sure we notice that.
349 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
350 Panel
* panel
= PanelManager::GetInstance()->CreatePanel(
351 web_app::GenerateApplicationNameFromExtensionId(
352 last_loaded_extension_id()),
353 browser()->profile(),
356 PanelManager::CREATE_AS_DOCKED
);
357 ASSERT_NO_FATAL_FAILURE(
358 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
359 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
362 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
363 "french_sentence.html")));
364 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
365 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
366 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
368 // Close the panel and verify that we notice.
370 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
371 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
374 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
375 "french_sentence.html")));
376 ASSERT_NO_FATAL_FAILURE(
377 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
380 UnloadExtension(last_loaded_extension_id());
381 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
382 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
385 // Kills a process that has more than one task manager entry.
386 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, KillPanelViaExtensionResource
) {
388 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("good")
389 .AppendASCII("Extensions")
390 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
391 .AppendASCII("1.0.0.0")));
393 // Open a new panel to an extension url.
395 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
396 "french_sentence.html");
397 PanelManager::GetInstance()->CreatePanel(
398 web_app::GenerateApplicationNameFromExtensionId(
399 last_loaded_extension_id()),
400 browser()->profile(),
403 PanelManager::CREATE_AS_DOCKED
);
405 ASSERT_NO_FATAL_FAILURE(
406 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
407 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
410 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
411 "french_sentence.html")));
412 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
413 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
414 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
416 // Kill the process via the BACKGROUND PAGE (not the panel). Verify that both
417 // the background page and the panel go away from the task manager.
418 int background_page
= FindResourceIndex(MatchExtension("My extension 1"));
419 ASSERT_NE(-1, background_page
);
420 ASSERT_TRUE(model()->GetResourceWebContents(background_page
) == NULL
);
421 ASSERT_FALSE(model()->CanActivate(background_page
));
422 TaskManager::GetInstance()->KillProcess(background_page
);
423 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
424 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
427 // Kills a process that has more than one task manager entry. This test is the
428 // same as KillPanelViaExtensionResource except it does the kill via the other
430 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, KillPanelViaPanelResource
) {
431 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("good")
432 .AppendASCII("Extensions")
433 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
434 .AppendASCII("1.0.0.0")));
436 // Open a new panel to an extension url.
438 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
439 "french_sentence.html");
440 PanelManager::GetInstance()->CreatePanel(
441 web_app::GenerateApplicationNameFromExtensionId(
442 last_loaded_extension_id()),
443 browser()->profile(),
446 PanelManager::CREATE_AS_DOCKED
);
449 ASSERT_NO_FATAL_FAILURE(
450 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
451 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
454 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
455 "french_sentence.html")));
456 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
457 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
458 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
460 int background_page
= FindResourceIndex(MatchExtension("My extension 1"));
461 ASSERT_NE(-1, background_page
);
462 ASSERT_TRUE(model()->GetResourceWebContents(background_page
) == NULL
);
463 ASSERT_FALSE(model()->CanActivate(background_page
));
465 // Kill the process via the PANEL RESOURCE (not the background page). Verify
466 // that both the background page and the panel go away from the task manager.
467 int panel
= FindResourceIndex(MatchExtension(
468 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
469 "french_sentence.html"));
470 ASSERT_NE(-1, panel
);
471 ASSERT_TRUE(model()->GetResourceWebContents(panel
) != NULL
);
472 ASSERT_TRUE(model()->CanActivate(panel
));
473 TaskManager::GetInstance()->KillProcess(panel
);
474 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
475 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
478 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeExtensionTabChanges
) {
480 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
481 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
483 ASSERT_TRUE(LoadExtension(
484 test_data_dir_
.AppendASCII("good").AppendASCII("Extensions")
485 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
486 .AppendASCII("1.0.0.0")));
488 // Browser, Extension background page, and the New Tab Page.
489 ASSERT_NO_FATAL_FAILURE(
490 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
491 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
492 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
494 // Open a new tab to an extension URL. Afterwards, the third entry (background
495 // page) should be an extension resource whose title starts with "Extension:".
496 // The fourth entry (page.html) is also of type extension and has both a
497 // WebContents and an extension. The title should start with "Extension:".
498 GURL
url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
499 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
500 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
501 ASSERT_NO_FATAL_FAILURE(
502 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
503 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
504 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
505 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
507 int extension_tab
= FindResourceIndex(MatchExtension("Foobar"));
508 ASSERT_NE(-1, extension_tab
);
509 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab
) != NULL
);
510 ASSERT_TRUE(model()->CanActivate(extension_tab
));
512 int background_page
= FindResourceIndex(MatchExtension("My extension 1"));
513 ASSERT_NE(-1, background_page
);
514 ASSERT_TRUE(model()->GetResourceWebContents(background_page
) == NULL
);
515 ASSERT_FALSE(model()->CanActivate(background_page
));
518 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeExtensionTab
) {
519 // With the task manager closed, open a new tab to an extension URL.
520 // Afterwards, when we open the task manager, the third entry (background
521 // page) should be an extension resource whose title starts with "Extension:".
522 // The fourth entry (page.html) is also of type extension and has both a
523 // WebContents and an extension. The title should start with "Extension:".
524 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("good")
525 .AppendASCII("Extensions")
526 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
527 .AppendASCII("1.0.0.0")));
528 GURL
url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
529 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
532 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
533 ASSERT_NO_FATAL_FAILURE(
534 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
535 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
536 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
537 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
539 int extension_tab
= FindResourceIndex(MatchExtension("Foobar"));
540 ASSERT_NE(-1, extension_tab
);
541 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab
) != NULL
);
542 ASSERT_TRUE(model()->CanActivate(extension_tab
));
544 int background_page
= FindResourceIndex(MatchExtension("My extension 1"));
545 ASSERT_NE(-1, background_page
);
546 ASSERT_TRUE(model()->GetResourceWebContents(background_page
) == NULL
);
547 ASSERT_FALSE(model()->CanActivate(background_page
));
550 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeAppTabChanges
) {
553 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("packaged_app")));
554 ExtensionService
* service
= extensions::ExtensionSystem::Get(
555 browser()->profile())->extension_service();
556 const extensions::Extension
* extension
=
557 service
->GetExtensionById(last_loaded_extension_id(), false);
559 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
560 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
561 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
562 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
564 // Open a new tab to the app's launch URL and make sure we notice that.
565 GURL
url(extension
->GetResourceURL("main.html"));
566 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
568 // There should be 1 "App: " tab and the original new tab page.
569 ASSERT_NO_FATAL_FAILURE(
570 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
571 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
572 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
573 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
574 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
576 // Check that the third entry (main.html) is of type extension and has both
577 // a tab contents and an extension.
578 int app_tab
= FindResourceIndex(MatchApp("Packaged App Test"));
579 ASSERT_NE(-1, app_tab
);
580 ASSERT_TRUE(model()->GetResourceWebContents(app_tab
) != NULL
);
581 ASSERT_TRUE(model()->CanActivate(app_tab
));
582 ASSERT_EQ(task_manager::Resource::EXTENSION
,
583 model()->GetResourceType(app_tab
));
584 ASSERT_EQ(2, browser()->tab_strip_model()->count());
586 // Unload extension to make sure the tab goes away.
587 UnloadExtension(last_loaded_extension_id());
589 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
590 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
591 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
592 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
593 ASSERT_EQ(1, browser()->tab_strip_model()->count());
596 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeAppTab
) {
597 ASSERT_TRUE(LoadExtension(
598 test_data_dir_
.AppendASCII("packaged_app")));
599 ExtensionService
* service
= extensions::ExtensionSystem::Get(
600 browser()->profile())->extension_service();
601 const extensions::Extension
* extension
=
602 service
->GetExtensionById(last_loaded_extension_id(), false);
604 // Open a new tab to the app's launch URL and make sure we notice that.
605 GURL
url(extension
->GetResourceURL("main.html"));
606 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
610 ASSERT_NO_FATAL_FAILURE(
611 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
612 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
613 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
614 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
616 // Check that the third entry (main.html) is of type extension and has both
617 // a tab contents and an extension.
618 int app_tab
= FindResourceIndex(MatchApp("Packaged App Test"));
619 ASSERT_NE(-1, app_tab
);
620 ASSERT_TRUE(model()->GetResourceWebContents(app_tab
) != NULL
);
621 ASSERT_TRUE(model()->CanActivate(app_tab
));
622 ASSERT_EQ(task_manager::Resource::EXTENSION
,
623 model()->GetResourceType(app_tab
));
626 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeHostedAppTabChanges
) {
629 // The app under test acts on URLs whose host is "localhost",
630 // so the URLs we navigate to must have host "localhost".
631 host_resolver()->AddRule("*", "127.0.0.1");
632 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
633 GURL::Replacements replace_host
;
634 replace_host
.SetHostStr("localhost");
635 GURL base_url
= embedded_test_server()->GetURL(
636 "/extensions/api_test/app_process/");
637 base_url
= base_url
.ReplaceComponents(replace_host
);
639 // Open a new tab to an app URL before the app is loaded.
640 GURL
url(base_url
.Resolve("path1/empty.html"));
641 content::WindowedNotificationObserver
observer(
642 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
643 content::NotificationService::AllSources());
644 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
647 // Check that the new entry's title starts with "Tab:".
648 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
650 // Load the hosted app and make sure it still starts with "Tab:",
651 // since it hasn't changed to an app process yet.
652 ASSERT_TRUE(LoadExtension(
653 test_data_dir_
.AppendASCII("api_test").AppendASCII("app_process")));
654 // Force the TaskManager to query the title.
656 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
657 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
658 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
659 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
661 // Now reload and check that the last entry's title now starts with "App:".
662 ui_test_utils::NavigateToURL(browser(), url
);
664 // Force the TaskManager to query the title.
665 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
666 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
667 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
668 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp("Unmodified")));
669 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
671 // Disable extension.
672 DisableExtension(last_loaded_extension_id());
674 // The hosted app should now show up as a normal "Tab: ".
675 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
676 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
677 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
678 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
679 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
682 ui_test_utils::NavigateToURL(browser(), url
);
684 // No change expected.
685 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
686 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
687 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
688 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
689 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
692 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeHostedAppTabAfterReload
) {
693 // The app under test acts on URLs whose host is "localhost",
694 // so the URLs we navigate to must have host "localhost".
695 host_resolver()->AddRule("*", "127.0.0.1");
696 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
697 GURL::Replacements replace_host
;
698 replace_host
.SetHostStr("localhost");
700 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
701 base_url
= base_url
.ReplaceComponents(replace_host
);
703 // Open a new tab to an app URL before the app is loaded.
704 GURL
url(base_url
.Resolve("path1/empty.html"));
705 content::WindowedNotificationObserver
observer(
706 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
707 content::NotificationService::AllSources());
708 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
711 // Load the hosted app and make sure it still starts with "Tab:",
712 // since it hasn't changed to an app process yet.
713 ASSERT_TRUE(LoadExtension(
714 test_data_dir_
.AppendASCII("api_test").AppendASCII("app_process")));
716 // Now reload, which should transition this tab to being an App.
717 ui_test_utils::NavigateToURL(browser(), url
);
721 // The TaskManager should show this as an "App: "
722 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
723 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
724 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
727 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeHostedAppTabBeforeReload
) {
728 // The app under test acts on URLs whose host is "localhost",
729 // so the URLs we navigate to must have host "localhost".
730 host_resolver()->AddRule("*", "127.0.0.1");
731 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
732 GURL::Replacements replace_host
;
733 replace_host
.SetHostStr("localhost");
735 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
736 base_url
= base_url
.ReplaceComponents(replace_host
);
738 // Open a new tab to an app URL before the app is loaded.
739 GURL
url(base_url
.Resolve("path1/empty.html"));
740 content::WindowedNotificationObserver
observer(
741 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
742 content::NotificationService::AllSources());
743 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
746 // Load the hosted app and make sure it still starts with "Tab:",
747 // since it hasn't changed to an app process yet.
748 ASSERT_TRUE(LoadExtension(
749 test_data_dir_
.AppendASCII("api_test").AppendASCII("app_process")));
753 // The TaskManager should show this as a "Tab: " because the page hasn't been
754 // reloaded since the hosted app was installed.
755 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
756 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
757 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
760 // Regression test for http://crbug.com/18693.
761 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, ReloadExtension
) {
763 ASSERT_TRUE(LoadExtension(
764 test_data_dir_
.AppendASCII("common").AppendASCII("background_page")));
766 // Wait until we see the loaded extension in the task manager (the three
767 // resources are: the browser process, New Tab Page, and the extension).
768 ASSERT_NO_FATAL_FAILURE(
769 WaitForTaskManagerRows(1, MatchExtension("background_page")));
771 // Reload the extension a few times and make sure our resource count doesn't
773 std::string extension_id
= last_loaded_extension_id();
774 for (int i
= 1; i
<= 5; i
++) {
775 SCOPED_TRACE(testing::Message() << "Reloading extension for the " << i
777 ReloadExtension(extension_id
);
778 ASSERT_NO_FATAL_FAILURE(
779 WaitForTaskManagerRows(1, MatchExtension("background_page")));
783 // Crashy, http://crbug.com/42301.
784 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
,
785 DISABLED_PopulateWebCacheFields
) {
787 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
789 int resource_count
= TaskManager::GetInstance()->model()->ResourceCount();
791 // Open a new tab and make sure we notice that.
792 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED
);
793 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
795 // Check that we get some value for the cache columns.
796 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count
),
797 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT
));
798 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count
),
799 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT
));
800 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count
),
801 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT
));
804 // Checks that task manager counts a worker thread JS heap size.
805 // http://crbug.com/241066
806 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, WebWorkerJSHeapMemory
) {
808 ui_test_utils::NavigateToURL(browser(), GetTestURL());
809 size_t minimal_heap_size
= 4 * 1024 * 1024 * sizeof(void*);
810 std::string test_js
= base::StringPrintf(
811 "var blob = new Blob([\n"
812 " 'mem = new Array(%lu);',\n"
813 " 'for (var i = 0; i < mem.length; i += 16)',"
815 " 'postMessage(\"okay\");']);\n"
816 "blobURL = window.URL.createObjectURL(blob);\n"
817 "var worker = new Worker(blobURL);\n"
818 "worker.addEventListener('message', function(e) {\n"
819 " window.domAutomationController.send(e.data);\n" // e.data == "okay"
821 "worker.postMessage('go');\n",
822 static_cast<unsigned long>(minimal_heap_size
));
824 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
825 browser()->tab_strip_model()->GetActiveWebContents(), test_js
, &ok
));
826 ASSERT_EQ("okay", ok
);
828 // The worker has allocated objects of at least |minimal_heap_size| bytes.
829 // Wait for the heap stats to reflect this.
830 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
831 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY
,
833 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
834 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY_USED
,
836 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
837 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
840 // Checks that task manager counts renderer JS heap size.
841 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, JSHeapMemory
) {
843 ui_test_utils::NavigateToURL(browser(), GetTestURL());
844 size_t minimal_heap_size
= 4 * 1024 * 1024 * sizeof(void*);
845 std::string test_js
= base::StringPrintf(
846 "mem = new Array(%lu);\n"
847 "for (var i = 0; i < mem.length; i += 16)\n"
849 "window.domAutomationController.send(\"okay\");\n",
850 static_cast<unsigned long>(minimal_heap_size
));
852 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
853 browser()->tab_strip_model()->GetActiveWebContents(), test_js
, &ok
));
854 ASSERT_EQ("okay", ok
);
856 // The page's js has allocated objects of at least |minimal_heap_size| bytes.
857 // Wait for the heap stats to reflect this.
858 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
859 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY
,
861 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
862 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY_USED
,
864 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
865 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
868 // Checks that task manager counts utility process JS heap size.
869 IN_PROC_BROWSER_TEST_F(TaskManagerUtilityProcessBrowserTest
,
870 UtilityJSHeapMemory
) {
872 ui_test_utils::NavigateToURL(browser(), GetTestURL());
873 // The PAC script is trivial, so don't expect a large heap.
874 size_t minimal_heap_size
= 1024;
875 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
877 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME
)),
878 task_manager::browsertest_util::V8_MEMORY
,
880 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
882 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME
)),
883 task_manager::browsertest_util::V8_MEMORY_USED
,
885 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyUtility()));
886 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
887 1, MatchUtility(l10n_util::GetStringUTF16(
888 IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME
))));
891 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, DevToolsNewDockedWindow
) {
892 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
894 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
895 DevToolsWindow
* devtools
=
896 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
897 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
898 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
899 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools
);
902 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, DevToolsNewUndockedWindow
) {
903 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
904 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
905 DevToolsWindow
* devtools
=
906 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
907 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
908 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
909 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools
);
912 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, DevToolsOldDockedWindow
) {
913 DevToolsWindow
* devtools
=
914 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
915 ShowTaskManager(); // Task manager shown AFTER dev tools window.
916 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
917 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
918 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools
);
921 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, DevToolsOldUnockedWindow
) {
922 DevToolsWindow
* devtools
=
923 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
924 ShowTaskManager(); // Task manager shown AFTER dev tools window.
925 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
926 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
927 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools
);
930 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
, KillSubframe
) {
933 host_resolver()->AddRule("*", "127.0.0.1");
934 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
935 content::SetupCrossSiteRedirector(embedded_test_server());
937 GURL
main_url(embedded_test_server()->GetURL(
938 "/cross-site/a.com/iframe_cross_site.html"));
939 browser()->OpenURL(content::OpenURLParams(main_url
, content::Referrer(),
941 ui::PAGE_TRANSITION_TYPED
, false));
943 ASSERT_NO_FATAL_FAILURE(
944 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
945 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
947 if (!ShouldExpectSubframes()) {
948 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
950 ASSERT_NO_FATAL_FAILURE(
951 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
952 ASSERT_NO_FATAL_FAILURE(
953 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
954 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
955 int subframe_b
= FindResourceIndex(MatchSubframe("http://b.com/"));
956 ASSERT_NE(-1, subframe_b
);
957 ASSERT_TRUE(model()->GetResourceWebContents(subframe_b
) != NULL
);
958 ASSERT_TRUE(model()->CanActivate(subframe_b
));
960 TaskManager::GetInstance()->KillProcess(subframe_b
);
962 ASSERT_NO_FATAL_FAILURE(
963 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
964 ASSERT_NO_FATAL_FAILURE(
965 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
966 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
967 ASSERT_NO_FATAL_FAILURE(
968 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
974 if (!ShouldExpectSubframes()) {
975 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
977 ASSERT_NO_FATAL_FAILURE(
978 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
979 ASSERT_NO_FATAL_FAILURE(
980 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
981 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
982 ASSERT_NO_FATAL_FAILURE(
983 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
987 // Tests what happens when a tab navigates to a site (a.com) that it previously
988 // has a cross-process subframe into (b.com).
990 // TODO(nick): http://crbug.com/442532. Disabled because the second navigation
991 // hits an ASSERT(frame()) in WebLocalFrameImpl::loadRequest under --site-per-
993 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
,
994 DISABLED_NavigateToSubframeProcess
) {
997 host_resolver()->AddRule("*", "127.0.0.1");
998 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
999 content::SetupCrossSiteRedirector(embedded_test_server());
1001 // Navigate the tab to a page on a.com with cross-process subframes to
1003 GURL
a_dotcom(embedded_test_server()->GetURL(
1004 "/cross-site/a.com/iframe_cross_site.html"));
1005 browser()->OpenURL(content::OpenURLParams(a_dotcom
, content::Referrer(),
1007 ui::PAGE_TRANSITION_TYPED
, false));
1009 ASSERT_NO_FATAL_FAILURE(
1010 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1011 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1013 if (!ShouldExpectSubframes()) {
1014 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1016 ASSERT_NO_FATAL_FAILURE(
1017 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1018 ASSERT_NO_FATAL_FAILURE(
1019 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1020 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1023 // Now navigate to a page on b.com with a simple (same-site) iframe.
1024 // This should not show any subframe resources in the task manager.
1026 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
1028 browser()->OpenURL(content::OpenURLParams(b_dotcom
, content::Referrer(),
1030 ui::PAGE_TRANSITION_TYPED
, false));
1032 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1033 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1034 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1037 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1038 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1039 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1042 // TODO(nick): Fails flakily under OOPIF due to a ASSERT_NOT_REACHED in
1043 // WebRemoteFrame, at least under debug OSX. http://crbug.com/437956
1044 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
,
1045 DISABLED_NavigateToSiteWithSubframeToOriginalSite
) {
1048 host_resolver()->AddRule("*", "127.0.0.1");
1049 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1050 content::SetupCrossSiteRedirector(embedded_test_server());
1052 // Navigate to a page on b.com with a simple (same-site) iframe.
1053 // This should not show any subframe resources in the task manager.
1055 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
1057 browser()->OpenURL(content::OpenURLParams(b_dotcom
, content::Referrer(),
1059 ui::PAGE_TRANSITION_TYPED
, false));
1061 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1062 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1063 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1065 // Now navigate the tab to a page on a.com with cross-process subframes to
1067 GURL
a_dotcom(embedded_test_server()->GetURL(
1068 "/cross-site/a.com/iframe_cross_site.html"));
1069 browser()->OpenURL(content::OpenURLParams(a_dotcom
, content::Referrer(),
1071 ui::PAGE_TRANSITION_TYPED
, false));
1073 ASSERT_NO_FATAL_FAILURE(
1074 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1075 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1077 if (!ShouldExpectSubframes()) {
1078 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1080 ASSERT_NO_FATAL_FAILURE(
1081 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1082 ASSERT_NO_FATAL_FAILURE(
1083 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1084 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1090 if (!ShouldExpectSubframes()) {
1091 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1093 ASSERT_NO_FATAL_FAILURE(
1094 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1095 ASSERT_NO_FATAL_FAILURE(
1096 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1097 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1101 // Tests what happens when a tab navigates a cross-frame iframe (to b.com)
1102 // back to the site of the parent document (a.com).
1103 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
,
1104 CrossSiteIframeBecomesSameSite
) {
1107 host_resolver()->AddRule("*", "127.0.0.1");
1108 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1109 content::SetupCrossSiteRedirector(embedded_test_server());
1111 // Navigate the tab to a page on a.com with cross-process subframes to
1113 GURL
a_dotcom(embedded_test_server()->GetURL(
1114 "/cross-site/a.com/iframe_cross_site.html"));
1115 browser()->OpenURL(content::OpenURLParams(a_dotcom
, content::Referrer(),
1117 ui::PAGE_TRANSITION_TYPED
, false));
1119 ASSERT_NO_FATAL_FAILURE(
1120 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1121 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1123 if (!ShouldExpectSubframes()) {
1124 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1126 ASSERT_NO_FATAL_FAILURE(
1127 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1128 ASSERT_NO_FATAL_FAILURE(
1129 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1130 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1133 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe
1134 ASSERT_TRUE(content::ExecuteScript(
1135 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
1136 "document.getElementById('frame1').src='/title1.html';"
1137 "document.title='aac';"));
1138 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1139 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1140 if (!ShouldExpectSubframes()) {
1141 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1143 ASSERT_NO_FATAL_FAILURE(
1144 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1145 ASSERT_NO_FATAL_FAILURE(
1146 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1147 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1149 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1150 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1155 if (!ShouldExpectSubframes()) {
1156 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1158 ASSERT_NO_FATAL_FAILURE(
1159 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1160 ASSERT_NO_FATAL_FAILURE(
1161 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1162 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1164 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1165 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1168 // Tests what happens when a tab does a same-site navigation away from a page
1169 // with cross-site iframes.
1170 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
,
1171 LeavePageWithCrossSiteIframes
) {
1174 host_resolver()->AddRule("*", "127.0.0.1");
1175 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1176 content::SetupCrossSiteRedirector(embedded_test_server());
1178 // Navigate the tab to a page on a.com with cross-process subframes.
1179 GURL
a_dotcom_with_iframes(embedded_test_server()->GetURL(
1180 "/cross-site/a.com/iframe_cross_site.html"));
1181 browser()->OpenURL(content::OpenURLParams(a_dotcom_with_iframes
,
1182 content::Referrer(), CURRENT_TAB
,
1183 ui::PAGE_TRANSITION_TYPED
, false));
1185 ASSERT_NO_FATAL_FAILURE(
1186 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1187 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1189 if (!ShouldExpectSubframes()) {
1190 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1192 ASSERT_NO_FATAL_FAILURE(
1193 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1194 ASSERT_NO_FATAL_FAILURE(
1195 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1196 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1199 // Navigate the tab to a page on a.com without cross-process subframes, and
1200 // the subframe processes should disappear.
1201 GURL
a_dotcom_simple(
1202 embedded_test_server()->GetURL("/cross-site/a.com/title2.html"));
1203 browser()->OpenURL(content::OpenURLParams(a_dotcom_simple
,
1204 content::Referrer(), CURRENT_TAB
,
1205 ui::PAGE_TRANSITION_TYPED
, false));
1206 ASSERT_NO_FATAL_FAILURE(
1207 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
1208 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1213 ASSERT_NO_FATAL_FAILURE(
1214 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
1215 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));