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/desktop_notification_service.h"
17 #include "chrome/browser/notifications/notification.h"
18 #include "chrome/browser/notifications/notification_test_util.h"
19 #include "chrome/browser/notifications/notification_ui_manager.h"
20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/task_manager/resource_provider.h"
22 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_commands.h"
25 #include "chrome/browser/ui/browser_dialogs.h"
26 #include "chrome/browser/ui/browser_navigator.h"
27 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/panels/panel.h"
29 #include "chrome/browser/ui/panels/panel_manager.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/browser/web_applications/web_app.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/grit/generated_resources.h"
34 #include "chrome/test/base/in_process_browser_test.h"
35 #include "chrome/test/base/ui_test_utils.h"
36 #include "components/infobars/core/confirm_infobar_delegate.h"
37 #include "components/infobars/core/infobar.h"
38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/page_navigator.h"
40 #include "content/public/browser/render_frame_host.h"
41 #include "content/public/common/content_switches.h"
42 #include "content/public/test/browser_test_utils.h"
43 #include "content/public/test/content_browser_test_utils.h"
44 #include "extensions/browser/extension_system.h"
45 #include "extensions/common/extension.h"
46 #include "net/dns/mock_host_resolver.h"
47 #include "net/test/embedded_test_server/embedded_test_server.h"
48 #include "testing/gtest/include/gtest/gtest.h"
49 #include "ui/base/l10n/l10n_util.h"
50 #include "ui/base/page_transition_types.h"
52 using content::WebContents
;
53 using task_manager::browsertest_util::MatchAboutBlankTab
;
54 using task_manager::browsertest_util::MatchAnyApp
;
55 using task_manager::browsertest_util::MatchAnyExtension
;
56 using task_manager::browsertest_util::MatchAnySubframe
;
57 using task_manager::browsertest_util::MatchAnyTab
;
58 using task_manager::browsertest_util::MatchAnyUtility
;
59 using task_manager::browsertest_util::MatchApp
;
60 using task_manager::browsertest_util::MatchExtension
;
61 using task_manager::browsertest_util::MatchSubframe
;
62 using task_manager::browsertest_util::MatchTab
;
63 using task_manager::browsertest_util::MatchUtility
;
64 using task_manager::browsertest_util::WaitForTaskManagerRows
;
65 using task_manager::browsertest_util::WaitForTaskManagerStatToExceed
;
69 const base::FilePath::CharType
* kTitle1File
= FILE_PATH_LITERAL("title1.html");
73 class TaskManagerBrowserTest
: public ExtensionBrowserTest
{
75 TaskManagerBrowserTest() {}
76 ~TaskManagerBrowserTest() override
{}
78 TaskManagerModel
* model() const {
79 return TaskManager::GetInstance()->model();
82 void ShowTaskManager() {
83 EXPECT_EQ(0, model()->ResourceCount());
85 // Show the task manager. This populates the model, and helps with debugging
86 // (you see the task manager).
87 chrome::ShowTaskManager(browser());
90 void HideTaskManager() {
91 // Hide the task manager, and wait for the model to be depopulated.
92 chrome::HideTaskManager();
93 base::RunLoop().RunUntilIdle(); // OnWindowClosed happens asynchronously.
94 EXPECT_EQ(0, model()->ResourceCount());
101 int GetUpdateTimeMs() {
102 return TaskManagerModel::kUpdateTimeMs
;
106 return ui_test_utils::GetTestUrl(
107 base::FilePath(base::FilePath::kCurrentDirectory
),
108 base::FilePath(kTitle1File
));
111 int FindResourceIndex(const base::string16
& title
) {
112 for (int i
= 0; i
< model()->ResourceCount(); ++i
) {
113 if (title
== model()->GetResourceTitle(i
))
120 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
121 ExtensionBrowserTest::SetUpCommandLine(command_line
);
123 // Do not launch device discovery process.
124 command_line
->AppendSwitch(switches::kDisableDeviceDiscoveryNotifications
);
128 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest
);
131 class TaskManagerUtilityProcessBrowserTest
: public TaskManagerBrowserTest
{
133 TaskManagerUtilityProcessBrowserTest() {}
136 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
137 TaskManagerBrowserTest::SetUpCommandLine(command_line
);
139 // Enable out-of-process proxy resolver. Use a trivial PAC script to ensure
140 // that some javascript is being executed.
141 command_line
->AppendSwitch(switches::kV8PacMojoOutOfProcess
);
142 command_line
->AppendSwitchASCII(
143 switches::kProxyPacUrl
,
144 "data:,function FindProxyForURL(url, host){return \"DIRECT;\";}");
148 DISALLOW_COPY_AND_ASSIGN(TaskManagerUtilityProcessBrowserTest
);
151 // Parameterized variant of TaskManagerBrowserTest which runs with/without
152 // --site-per-process, which enables out of process iframes (OOPIFs).
153 class TaskManagerOOPIFBrowserTest
: public TaskManagerBrowserTest
,
154 public testing::WithParamInterface
<bool> {
156 TaskManagerOOPIFBrowserTest() {}
159 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
160 TaskManagerBrowserTest::SetUpCommandLine(command_line
);
162 command_line
->AppendSwitch(switches::kSitePerProcess
);
165 bool ShouldExpectSubframes() {
166 return base::CommandLine::ForCurrentProcess()->HasSwitch(
167 switches::kSitePerProcess
);
171 DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest
);
174 INSTANTIATE_TEST_CASE_P(, TaskManagerOOPIFBrowserTest
, ::testing::Bool());
176 #if defined(OS_MACOSX) || defined(OS_LINUX)
177 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen
179 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen
182 // Regression test for http://crbug.com/13361
183 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, MAYBE_ShutdownWhileOpen
) {
187 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeTabContentsChanges
) {
189 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
190 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
191 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
193 // Open a new tab and make sure the task manager notices it.
194 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED
);
196 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
197 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
199 // Close the tab and verify that we notice.
200 browser()->tab_strip_model()->CloseWebContentsAt(0,
201 TabStripModel::CLOSE_NONE
);
202 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
203 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
206 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, KillTab
) {
208 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
209 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
210 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
212 // Open a new tab and make sure the task manager notices it.
213 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED
);
215 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
216 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
218 // Killing the tab via task manager should remove the row.
219 int tab
= FindResourceIndex(MatchTab("title1.html"));
221 ASSERT_TRUE(model()->GetResourceWebContents(tab
) != NULL
);
222 ASSERT_TRUE(model()->CanActivate(tab
));
223 TaskManager::GetInstance()->KillProcess(tab
);
224 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
225 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
227 // Tab should reappear in task manager upon reload.
228 chrome::Reload(browser(), CURRENT_TAB
);
229 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
230 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
233 // Test for http://crbug.com/444945, which is not fixed yet.
234 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
,
235 DISABLED_NavigateAwayFromHungRenderer
) {
236 host_resolver()->AddRule("*", "127.0.0.1");
237 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
240 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
241 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
243 GURL
url1(embedded_test_server()->GetURL("/title2.html"));
244 GURL
url3(embedded_test_server()->GetURL("a.com", "/iframe.html"));
246 // Open a new tab and make sure the task manager notices it.
247 AddTabAtIndex(0, url1
, ui::PAGE_TRANSITION_TYPED
);
248 ASSERT_NO_FATAL_FAILURE(
249 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
250 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
251 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
252 WebContents
* tab1
= browser()->tab_strip_model()->GetActiveWebContents();
254 // Initiate a navigation that will create a new WebContents in the same
256 content::WebContentsAddedObserver web_contents_added_observer
;
257 tab1
->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
258 base::ASCIIToUTF16("window.open('title3.html', '_blank');"));
259 // ... then immediately hang the renderer so that title3.html can't load.
260 tab1
->GetMainFrame()->ExecuteJavaScriptForTests(
261 base::ASCIIToUTF16("while(1);"));
263 // Blocks until a new WebContents appears.
264 WebContents
* tab2
= web_contents_added_observer
.GetWebContents();
266 // Make sure the new WebContents is in tab1's hung renderer process.
267 ASSERT_NE(nullptr, tab2
);
268 ASSERT_NE(tab1
, tab2
);
269 ASSERT_EQ(tab1
->GetMainFrame()->GetProcess(),
270 tab2
->GetMainFrame()->GetProcess())
271 << "New WebContents must be in the same process as the old WebContents, "
272 << "so that the new tab doesn't finish loading (what this test is all "
274 ASSERT_EQ(tab1
->GetSiteInstance(), tab2
->GetSiteInstance())
275 << "New WebContents must initially be in the same site instance as the "
276 << "old WebContents";
278 // Now navigate this tab to a different site. This should wind up in a
279 // different renderer process, so it should complete and show up in the task
281 tab2
->OpenURL(content::OpenURLParams(url3
, content::Referrer(), CURRENT_TAB
,
282 ui::PAGE_TRANSITION_TYPED
, false));
284 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
287 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticePanel
) {
288 ASSERT_TRUE(LoadExtension(
289 test_data_dir_
.AppendASCII("good").AppendASCII("Extensions")
290 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
291 .AppendASCII("1.0.0.0")));
293 // Open a new panel to an extension url.
295 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
296 Panel
* panel
= PanelManager::GetInstance()->CreatePanel(
297 web_app::GenerateApplicationNameFromExtensionId(
298 last_loaded_extension_id()),
299 browser()->profile(),
302 PanelManager::CREATE_AS_DOCKED
);
304 // Make sure that a task manager model created after the panel shows the
305 // existence of the panel and the extension.
307 ASSERT_NO_FATAL_FAILURE(
308 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
309 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
312 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
313 "french_sentence.html")));
314 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
315 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
316 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
318 // Close the panel and verify that we notice.
320 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
321 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
324 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
325 "french_sentence.html")));
326 ASSERT_NO_FATAL_FAILURE(
327 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
330 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticePanelChanges
) {
332 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
333 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
335 ASSERT_TRUE(LoadExtension(
336 test_data_dir_
.AppendASCII("good").AppendASCII("Extensions")
337 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
338 .AppendASCII("1.0.0.0")));
340 // Browser, the New Tab Page and Extension background page.
341 ASSERT_NO_FATAL_FAILURE(
342 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
343 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
344 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
346 // Open a new panel to an extension url and make sure we notice that.
348 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
349 Panel
* panel
= PanelManager::GetInstance()->CreatePanel(
350 web_app::GenerateApplicationNameFromExtensionId(
351 last_loaded_extension_id()),
352 browser()->profile(),
355 PanelManager::CREATE_AS_DOCKED
);
356 ASSERT_NO_FATAL_FAILURE(
357 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
358 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
361 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
362 "french_sentence.html")));
363 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
364 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
365 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
367 // Close the panel and verify that we notice.
369 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
370 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
373 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
374 "french_sentence.html")));
375 ASSERT_NO_FATAL_FAILURE(
376 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
379 UnloadExtension(last_loaded_extension_id());
380 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
381 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
384 // Kills a process that has more than one task manager entry.
385 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, KillPanelViaExtensionResource
) {
387 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("good")
388 .AppendASCII("Extensions")
389 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
390 .AppendASCII("1.0.0.0")));
392 // Open a new panel to an extension url.
394 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
395 "french_sentence.html");
396 PanelManager::GetInstance()->CreatePanel(
397 web_app::GenerateApplicationNameFromExtensionId(
398 last_loaded_extension_id()),
399 browser()->profile(),
402 PanelManager::CREATE_AS_DOCKED
);
404 ASSERT_NO_FATAL_FAILURE(
405 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
406 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
409 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
410 "french_sentence.html")));
411 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
412 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
413 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
415 // Kill the process via the BACKGROUND PAGE (not the panel). Verify that both
416 // the background page and the panel go away from the task manager.
417 int background_page
= FindResourceIndex(MatchExtension("My extension 1"));
418 ASSERT_NE(-1, background_page
);
419 ASSERT_TRUE(model()->GetResourceWebContents(background_page
) == NULL
);
420 ASSERT_FALSE(model()->CanActivate(background_page
));
421 TaskManager::GetInstance()->KillProcess(background_page
);
422 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
423 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
426 // Kills a process that has more than one task manager entry. This test is the
427 // same as KillPanelViaExtensionResource except it does the kill via the other
429 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, KillPanelViaPanelResource
) {
430 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("good")
431 .AppendASCII("Extensions")
432 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
433 .AppendASCII("1.0.0.0")));
435 // Open a new panel to an extension url.
437 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
438 "french_sentence.html");
439 PanelManager::GetInstance()->CreatePanel(
440 web_app::GenerateApplicationNameFromExtensionId(
441 last_loaded_extension_id()),
442 browser()->profile(),
445 PanelManager::CREATE_AS_DOCKED
);
448 ASSERT_NO_FATAL_FAILURE(
449 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
450 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
453 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
454 "french_sentence.html")));
455 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
456 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
457 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
459 int background_page
= FindResourceIndex(MatchExtension("My extension 1"));
460 ASSERT_NE(-1, background_page
);
461 ASSERT_TRUE(model()->GetResourceWebContents(background_page
) == NULL
);
462 ASSERT_FALSE(model()->CanActivate(background_page
));
464 // Kill the process via the PANEL RESOURCE (not the background page). Verify
465 // that both the background page and the panel go away from the task manager.
466 int panel
= FindResourceIndex(MatchExtension(
467 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
468 "french_sentence.html"));
469 ASSERT_NE(-1, panel
);
470 ASSERT_TRUE(model()->GetResourceWebContents(panel
) != NULL
);
471 ASSERT_TRUE(model()->CanActivate(panel
));
472 TaskManager::GetInstance()->KillProcess(panel
);
473 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
474 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
477 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeExtensionTabChanges
) {
479 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
480 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
482 ASSERT_TRUE(LoadExtension(
483 test_data_dir_
.AppendASCII("good").AppendASCII("Extensions")
484 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
485 .AppendASCII("1.0.0.0")));
487 // Browser, Extension background page, and the New Tab Page.
488 ASSERT_NO_FATAL_FAILURE(
489 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
490 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
491 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
493 // Open a new tab to an extension URL. Afterwards, the third entry (background
494 // page) should be an extension resource whose title starts with "Extension:".
495 // The fourth entry (page.html) is also of type extension and has both a
496 // WebContents and an extension. The title should start with "Extension:".
497 GURL
url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
498 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
499 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
500 ASSERT_NO_FATAL_FAILURE(
501 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
502 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
503 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
504 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
506 int extension_tab
= FindResourceIndex(MatchExtension("Foobar"));
507 ASSERT_NE(-1, extension_tab
);
508 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab
) != NULL
);
509 ASSERT_TRUE(model()->CanActivate(extension_tab
));
511 int background_page
= FindResourceIndex(MatchExtension("My extension 1"));
512 ASSERT_NE(-1, background_page
);
513 ASSERT_TRUE(model()->GetResourceWebContents(background_page
) == NULL
);
514 ASSERT_FALSE(model()->CanActivate(background_page
));
517 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeExtensionTab
) {
518 // With the task manager closed, open a new tab to an extension URL.
519 // Afterwards, when we open the task manager, the third entry (background
520 // page) should be an extension resource whose title starts with "Extension:".
521 // The fourth entry (page.html) is also of type extension and has both a
522 // WebContents and an extension. The title should start with "Extension:".
523 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("good")
524 .AppendASCII("Extensions")
525 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
526 .AppendASCII("1.0.0.0")));
527 GURL
url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
528 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
531 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
532 ASSERT_NO_FATAL_FAILURE(
533 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
534 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
535 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
536 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
538 int extension_tab
= FindResourceIndex(MatchExtension("Foobar"));
539 ASSERT_NE(-1, extension_tab
);
540 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab
) != NULL
);
541 ASSERT_TRUE(model()->CanActivate(extension_tab
));
543 int background_page
= FindResourceIndex(MatchExtension("My extension 1"));
544 ASSERT_NE(-1, background_page
);
545 ASSERT_TRUE(model()->GetResourceWebContents(background_page
) == NULL
);
546 ASSERT_FALSE(model()->CanActivate(background_page
));
549 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeAppTabChanges
) {
552 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("packaged_app")));
553 ExtensionService
* service
= extensions::ExtensionSystem::Get(
554 browser()->profile())->extension_service();
555 const extensions::Extension
* extension
=
556 service
->GetExtensionById(last_loaded_extension_id(), false);
558 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
559 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
560 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
561 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
563 // Open a new tab to the app's launch URL and make sure we notice that.
564 GURL
url(extension
->GetResourceURL("main.html"));
565 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
567 // There should be 1 "App: " tab and the original new tab page.
568 ASSERT_NO_FATAL_FAILURE(
569 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
570 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
571 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
572 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
573 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
575 // Check that the third entry (main.html) is of type extension and has both
576 // a tab contents and an extension.
577 int app_tab
= FindResourceIndex(MatchApp("Packaged App Test"));
578 ASSERT_NE(-1, app_tab
);
579 ASSERT_TRUE(model()->GetResourceWebContents(app_tab
) != NULL
);
580 ASSERT_TRUE(model()->CanActivate(app_tab
));
581 ASSERT_EQ(task_manager::Resource::EXTENSION
,
582 model()->GetResourceType(app_tab
));
583 ASSERT_EQ(2, browser()->tab_strip_model()->count());
585 // Unload extension to make sure the tab goes away.
586 UnloadExtension(last_loaded_extension_id());
588 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
589 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
590 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
591 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
592 ASSERT_EQ(1, browser()->tab_strip_model()->count());
595 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeAppTab
) {
596 ASSERT_TRUE(LoadExtension(
597 test_data_dir_
.AppendASCII("packaged_app")));
598 ExtensionService
* service
= extensions::ExtensionSystem::Get(
599 browser()->profile())->extension_service();
600 const extensions::Extension
* extension
=
601 service
->GetExtensionById(last_loaded_extension_id(), false);
603 // Open a new tab to the app's launch URL and make sure we notice that.
604 GURL
url(extension
->GetResourceURL("main.html"));
605 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
609 ASSERT_NO_FATAL_FAILURE(
610 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
611 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
612 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
613 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
615 // Check that the third entry (main.html) is of type extension and has both
616 // a tab contents and an extension.
617 int app_tab
= FindResourceIndex(MatchApp("Packaged App Test"));
618 ASSERT_NE(-1, app_tab
);
619 ASSERT_TRUE(model()->GetResourceWebContents(app_tab
) != NULL
);
620 ASSERT_TRUE(model()->CanActivate(app_tab
));
621 ASSERT_EQ(task_manager::Resource::EXTENSION
,
622 model()->GetResourceType(app_tab
));
625 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeHostedAppTabChanges
) {
628 // The app under test acts on URLs whose host is "localhost",
629 // so the URLs we navigate to must have host "localhost".
630 host_resolver()->AddRule("*", "127.0.0.1");
631 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
632 GURL::Replacements replace_host
;
633 replace_host
.SetHostStr("localhost");
634 GURL base_url
= embedded_test_server()->GetURL(
635 "/extensions/api_test/app_process/");
636 base_url
= base_url
.ReplaceComponents(replace_host
);
638 // Open a new tab to an app URL before the app is loaded.
639 GURL
url(base_url
.Resolve("path1/empty.html"));
640 content::WindowedNotificationObserver
observer(
641 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
642 content::NotificationService::AllSources());
643 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
646 // Check that the new entry's title starts with "Tab:".
647 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
649 // Load the hosted app and make sure it still starts with "Tab:",
650 // since it hasn't changed to an app process yet.
651 ASSERT_TRUE(LoadExtension(
652 test_data_dir_
.AppendASCII("api_test").AppendASCII("app_process")));
653 // Force the TaskManager to query the title.
655 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
656 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
657 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
658 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
660 // Now reload and check that the last entry's title now starts with "App:".
661 ui_test_utils::NavigateToURL(browser(), url
);
663 // Force the TaskManager to query the title.
664 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
665 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
666 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
667 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp("Unmodified")));
668 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
670 // Disable extension.
671 DisableExtension(last_loaded_extension_id());
673 // The hosted app should now show up as a normal "Tab: ".
674 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
675 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
676 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
677 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
678 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
681 ui_test_utils::NavigateToURL(browser(), url
);
683 // No change expected.
684 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
685 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
686 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
687 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
688 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
691 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeHostedAppTabAfterReload
) {
692 // The app under test acts on URLs whose host is "localhost",
693 // so the URLs we navigate to must have host "localhost".
694 host_resolver()->AddRule("*", "127.0.0.1");
695 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
696 GURL::Replacements replace_host
;
697 replace_host
.SetHostStr("localhost");
699 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
700 base_url
= base_url
.ReplaceComponents(replace_host
);
702 // Open a new tab to an app URL before the app is loaded.
703 GURL
url(base_url
.Resolve("path1/empty.html"));
704 content::WindowedNotificationObserver
observer(
705 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
706 content::NotificationService::AllSources());
707 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
710 // Load the hosted app and make sure it still starts with "Tab:",
711 // since it hasn't changed to an app process yet.
712 ASSERT_TRUE(LoadExtension(
713 test_data_dir_
.AppendASCII("api_test").AppendASCII("app_process")));
715 // Now reload, which should transition this tab to being an App.
716 ui_test_utils::NavigateToURL(browser(), url
);
720 // The TaskManager should show this as an "App: "
721 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
722 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
723 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
726 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, NoticeHostedAppTabBeforeReload
) {
727 // The app under test acts on URLs whose host is "localhost",
728 // so the URLs we navigate to must have host "localhost".
729 host_resolver()->AddRule("*", "127.0.0.1");
730 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
731 GURL::Replacements replace_host
;
732 replace_host
.SetHostStr("localhost");
734 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
735 base_url
= base_url
.ReplaceComponents(replace_host
);
737 // Open a new tab to an app URL before the app is loaded.
738 GURL
url(base_url
.Resolve("path1/empty.html"));
739 content::WindowedNotificationObserver
observer(
740 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
741 content::NotificationService::AllSources());
742 AddTabAtIndex(0, url
, ui::PAGE_TRANSITION_TYPED
);
745 // Load the hosted app and make sure it still starts with "Tab:",
746 // since it hasn't changed to an app process yet.
747 ASSERT_TRUE(LoadExtension(
748 test_data_dir_
.AppendASCII("api_test").AppendASCII("app_process")));
752 // The TaskManager should show this as a "Tab: " because the page hasn't been
753 // reloaded since the hosted app was installed.
754 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
755 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
756 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
759 // Regression test for http://crbug.com/18693.
760 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, ReloadExtension
) {
762 ASSERT_TRUE(LoadExtension(
763 test_data_dir_
.AppendASCII("common").AppendASCII("background_page")));
765 // Wait until we see the loaded extension in the task manager (the three
766 // resources are: the browser process, New Tab Page, and the extension).
767 ASSERT_NO_FATAL_FAILURE(
768 WaitForTaskManagerRows(1, MatchExtension("background_page")));
770 // Reload the extension a few times and make sure our resource count doesn't
772 std::string extension_id
= last_loaded_extension_id();
773 for (int i
= 1; i
<= 5; i
++) {
774 SCOPED_TRACE(testing::Message() << "Reloading extension for the " << i
776 ReloadExtension(extension_id
);
777 ASSERT_NO_FATAL_FAILURE(
778 WaitForTaskManagerRows(1, MatchExtension("background_page")));
782 // Crashy, http://crbug.com/42301.
783 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
,
784 DISABLED_PopulateWebCacheFields
) {
786 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
788 int resource_count
= TaskManager::GetInstance()->model()->ResourceCount();
790 // Open a new tab and make sure we notice that.
791 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED
);
792 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
794 // Check that we get some value for the cache columns.
795 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count
),
796 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT
));
797 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count
),
798 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT
));
799 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count
),
800 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT
));
803 // Checks that task manager counts a worker thread JS heap size.
804 // http://crbug.com/241066
805 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, WebWorkerJSHeapMemory
) {
807 ui_test_utils::NavigateToURL(browser(), GetTestURL());
808 size_t minimal_heap_size
= 4 * 1024 * 1024 * sizeof(void*);
809 std::string test_js
= base::StringPrintf(
810 "var blob = new Blob([\n"
811 " 'mem = new Array(%lu);',\n"
812 " 'for (var i = 0; i < mem.length; i += 16)',"
814 " 'postMessage(\"okay\");']);\n"
815 "blobURL = window.URL.createObjectURL(blob);\n"
816 "var worker = new Worker(blobURL);\n"
817 "worker.addEventListener('message', function(e) {\n"
818 " window.domAutomationController.send(e.data);\n" // e.data == "okay"
820 "worker.postMessage('go');\n",
821 static_cast<unsigned long>(minimal_heap_size
));
823 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
824 browser()->tab_strip_model()->GetActiveWebContents(), test_js
, &ok
));
825 ASSERT_EQ("okay", ok
);
827 // The worker has allocated objects of at least |minimal_heap_size| bytes.
828 // Wait for the heap stats to reflect this.
829 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
830 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY
,
832 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
833 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY_USED
,
835 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
836 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
839 // Checks that task manager counts renderer JS heap size.
840 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, JSHeapMemory
) {
842 ui_test_utils::NavigateToURL(browser(), GetTestURL());
843 size_t minimal_heap_size
= 4 * 1024 * 1024 * sizeof(void*);
844 std::string test_js
= base::StringPrintf(
845 "mem = new Array(%lu);\n"
846 "for (var i = 0; i < mem.length; i += 16)\n"
848 "window.domAutomationController.send(\"okay\");\n",
849 static_cast<unsigned long>(minimal_heap_size
));
851 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
852 browser()->tab_strip_model()->GetActiveWebContents(), test_js
, &ok
));
853 ASSERT_EQ("okay", ok
);
855 // The page's js has allocated objects of at least |minimal_heap_size| bytes.
856 // Wait for the heap stats to reflect this.
857 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
858 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY
,
860 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
861 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY_USED
,
863 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
864 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
867 // Checks that task manager counts utility process JS heap size.
868 IN_PROC_BROWSER_TEST_F(TaskManagerUtilityProcessBrowserTest
,
869 UtilityJSHeapMemory
) {
871 ui_test_utils::NavigateToURL(browser(), GetTestURL());
872 // The PAC script is trivial, so don't expect a large heap.
873 size_t minimal_heap_size
= 1024;
874 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
876 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME
)),
877 task_manager::browsertest_util::V8_MEMORY
,
879 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
881 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME
)),
882 task_manager::browsertest_util::V8_MEMORY_USED
,
884 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyUtility()));
885 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
886 1, MatchUtility(l10n_util::GetStringUTF16(
887 IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME
))));
890 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, DevToolsNewDockedWindow
) {
891 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
893 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
894 DevToolsWindow
* devtools
=
895 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
896 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
897 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
898 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools
);
901 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, DevToolsNewUndockedWindow
) {
902 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
903 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
904 DevToolsWindow
* devtools
=
905 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
906 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
907 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
908 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools
);
911 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, DevToolsOldDockedWindow
) {
912 DevToolsWindow
* devtools
=
913 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
914 ShowTaskManager(); // Task manager shown AFTER dev tools window.
915 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
916 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
917 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools
);
920 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest
, DevToolsOldUnockedWindow
) {
921 DevToolsWindow
* devtools
=
922 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
923 ShowTaskManager(); // Task manager shown AFTER dev tools window.
924 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
925 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
926 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools
);
929 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
, KillSubframe
) {
932 host_resolver()->AddRule("*", "127.0.0.1");
933 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
934 content::SetupCrossSiteRedirector(embedded_test_server());
936 GURL
main_url(embedded_test_server()->GetURL(
937 "/cross-site/a.com/iframe_cross_site.html"));
938 browser()->OpenURL(content::OpenURLParams(main_url
, content::Referrer(),
940 ui::PAGE_TRANSITION_TYPED
, false));
942 ASSERT_NO_FATAL_FAILURE(
943 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
944 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
946 if (!ShouldExpectSubframes()) {
947 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
949 ASSERT_NO_FATAL_FAILURE(
950 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
951 ASSERT_NO_FATAL_FAILURE(
952 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
953 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
954 int subframe_b
= FindResourceIndex(MatchSubframe("http://b.com/"));
955 ASSERT_NE(-1, subframe_b
);
956 ASSERT_TRUE(model()->GetResourceWebContents(subframe_b
) != NULL
);
957 ASSERT_TRUE(model()->CanActivate(subframe_b
));
959 TaskManager::GetInstance()->KillProcess(subframe_b
);
961 ASSERT_NO_FATAL_FAILURE(
962 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
963 ASSERT_NO_FATAL_FAILURE(
964 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
965 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
966 ASSERT_NO_FATAL_FAILURE(
967 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
973 if (!ShouldExpectSubframes()) {
974 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
976 ASSERT_NO_FATAL_FAILURE(
977 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
978 ASSERT_NO_FATAL_FAILURE(
979 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
980 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
981 ASSERT_NO_FATAL_FAILURE(
982 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
986 // Tests what happens when a tab navigates to a site (a.com) that it previously
987 // has a cross-process subframe into (b.com).
989 // TODO(nick): http://crbug.com/442532. Disabled because the second navigation
990 // hits an ASSERT(frame()) in WebLocalFrameImpl::loadRequest under --site-per-
992 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
,
993 DISABLED_NavigateToSubframeProcess
) {
996 host_resolver()->AddRule("*", "127.0.0.1");
997 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
998 content::SetupCrossSiteRedirector(embedded_test_server());
1000 // Navigate the tab to a page on a.com with cross-process subframes to
1002 GURL
a_dotcom(embedded_test_server()->GetURL(
1003 "/cross-site/a.com/iframe_cross_site.html"));
1004 browser()->OpenURL(content::OpenURLParams(a_dotcom
, content::Referrer(),
1006 ui::PAGE_TRANSITION_TYPED
, false));
1008 ASSERT_NO_FATAL_FAILURE(
1009 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1010 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1012 if (!ShouldExpectSubframes()) {
1013 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1015 ASSERT_NO_FATAL_FAILURE(
1016 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1017 ASSERT_NO_FATAL_FAILURE(
1018 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1019 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1022 // Now navigate to a page on b.com with a simple (same-site) iframe.
1023 // This should not show any subframe resources in the task manager.
1025 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
1027 browser()->OpenURL(content::OpenURLParams(b_dotcom
, content::Referrer(),
1029 ui::PAGE_TRANSITION_TYPED
, false));
1031 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1032 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1033 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1036 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1037 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1038 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1041 // TODO(nick): Fails flakily under OOPIF due to a ASSERT_NOT_REACHED in
1042 // WebRemoteFrame, at least under debug OSX. http://crbug.com/437956
1043 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
,
1044 DISABLED_NavigateToSiteWithSubframeToOriginalSite
) {
1047 host_resolver()->AddRule("*", "127.0.0.1");
1048 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1049 content::SetupCrossSiteRedirector(embedded_test_server());
1051 // Navigate to a page on b.com with a simple (same-site) iframe.
1052 // This should not show any subframe resources in the task manager.
1054 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
1056 browser()->OpenURL(content::OpenURLParams(b_dotcom
, content::Referrer(),
1058 ui::PAGE_TRANSITION_TYPED
, false));
1060 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1061 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1062 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1064 // Now navigate the tab to a page on a.com with cross-process subframes to
1066 GURL
a_dotcom(embedded_test_server()->GetURL(
1067 "/cross-site/a.com/iframe_cross_site.html"));
1068 browser()->OpenURL(content::OpenURLParams(a_dotcom
, content::Referrer(),
1070 ui::PAGE_TRANSITION_TYPED
, false));
1072 ASSERT_NO_FATAL_FAILURE(
1073 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1074 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1076 if (!ShouldExpectSubframes()) {
1077 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1079 ASSERT_NO_FATAL_FAILURE(
1080 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1081 ASSERT_NO_FATAL_FAILURE(
1082 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1083 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1089 if (!ShouldExpectSubframes()) {
1090 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1092 ASSERT_NO_FATAL_FAILURE(
1093 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1094 ASSERT_NO_FATAL_FAILURE(
1095 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1096 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1100 // Tests what happens when a tab navigates a cross-frame iframe (to b.com)
1101 // back to the site of the parent document (a.com).
1102 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
,
1103 CrossSiteIframeBecomesSameSite
) {
1106 host_resolver()->AddRule("*", "127.0.0.1");
1107 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1108 content::SetupCrossSiteRedirector(embedded_test_server());
1110 // Navigate the tab to a page on a.com with cross-process subframes to
1112 GURL
a_dotcom(embedded_test_server()->GetURL(
1113 "/cross-site/a.com/iframe_cross_site.html"));
1114 browser()->OpenURL(content::OpenURLParams(a_dotcom
, content::Referrer(),
1116 ui::PAGE_TRANSITION_TYPED
, false));
1118 ASSERT_NO_FATAL_FAILURE(
1119 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1120 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1122 if (!ShouldExpectSubframes()) {
1123 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1125 ASSERT_NO_FATAL_FAILURE(
1126 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1127 ASSERT_NO_FATAL_FAILURE(
1128 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1129 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1132 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe
1133 ASSERT_TRUE(content::ExecuteScript(
1134 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
1135 "document.getElementById('frame1').src='/title1.html';"
1136 "document.title='aac';"));
1137 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1138 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1139 if (!ShouldExpectSubframes()) {
1140 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1142 ASSERT_NO_FATAL_FAILURE(
1143 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1144 ASSERT_NO_FATAL_FAILURE(
1145 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1146 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1148 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1149 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1154 if (!ShouldExpectSubframes()) {
1155 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1157 ASSERT_NO_FATAL_FAILURE(
1158 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1159 ASSERT_NO_FATAL_FAILURE(
1160 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1161 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1163 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1164 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1167 // Tests what happens when a tab does a same-site navigation away from a page
1168 // with cross-site iframes.
1169 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest
,
1170 LeavePageWithCrossSiteIframes
) {
1173 host_resolver()->AddRule("*", "127.0.0.1");
1174 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1175 content::SetupCrossSiteRedirector(embedded_test_server());
1177 // Navigate the tab to a page on a.com with cross-process subframes.
1178 GURL
a_dotcom_with_iframes(embedded_test_server()->GetURL(
1179 "/cross-site/a.com/iframe_cross_site.html"));
1180 browser()->OpenURL(content::OpenURLParams(a_dotcom_with_iframes
,
1181 content::Referrer(), CURRENT_TAB
,
1182 ui::PAGE_TRANSITION_TYPED
, false));
1184 ASSERT_NO_FATAL_FAILURE(
1185 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1186 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1188 if (!ShouldExpectSubframes()) {
1189 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1191 ASSERT_NO_FATAL_FAILURE(
1192 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1193 ASSERT_NO_FATAL_FAILURE(
1194 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1195 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1198 // Navigate the tab to a page on a.com without cross-process subframes, and
1199 // the subframe processes should disappear.
1200 GURL
a_dotcom_simple(
1201 embedded_test_server()->GetURL("/cross-site/a.com/title2.html"));
1202 browser()->OpenURL(content::OpenURLParams(a_dotcom_simple
,
1203 content::Referrer(), CURRENT_TAB
,
1204 ui::PAGE_TRANSITION_TYPED
, false));
1205 ASSERT_NO_FATAL_FAILURE(
1206 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
1207 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1212 ASSERT_NO_FATAL_FAILURE(
1213 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
1214 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));