Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / task_manager / task_manager_browsertest.cc
blob888da368a205ba95fd8e8e6a91c908d2f9f75f8e
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;
65 namespace {
67 const base::FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
69 } // namespace
71 class TaskManagerBrowserTest : public ExtensionBrowserTest {
72 public:
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());
95 void Refresh() {
96 model()->Refresh();
99 int GetUpdateTimeMs() {
100 return TaskManagerModel::kUpdateTimeMs;
103 GURL GetTestURL() {
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))
112 return i;
114 return -1;
117 protected:
118 void SetUpCommandLine(base::CommandLine* command_line) override {
119 ExtensionBrowserTest::SetUpCommandLine(command_line);
121 // Do not launch device discovery process.
122 command_line->AppendSwitch(switches::kDisableDeviceDiscoveryNotifications);
125 private:
126 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest);
129 class TaskManagerUtilityProcessBrowserTest : public TaskManagerBrowserTest {
130 public:
131 TaskManagerUtilityProcessBrowserTest() {}
133 protected:
134 void SetUpCommandLine(base::CommandLine* command_line) override {
135 TaskManagerBrowserTest::SetUpCommandLine(command_line);
137 // Enable out-of-process proxy resolver. Use a trivial PAC script to ensure
138 // that some javascript is being executed.
139 command_line->AppendSwitch(switches::kV8PacMojoOutOfProcess);
140 command_line->AppendSwitchASCII(
141 switches::kProxyPacUrl,
142 "data:,function FindProxyForURL(url, host){return \"DIRECT;\";}");
145 private:
146 DISALLOW_COPY_AND_ASSIGN(TaskManagerUtilityProcessBrowserTest);
149 // Parameterized variant of TaskManagerBrowserTest which runs with/without
150 // --site-per-process, which enables out of process iframes (OOPIFs).
151 class TaskManagerOOPIFBrowserTest : public TaskManagerBrowserTest,
152 public testing::WithParamInterface<bool> {
153 public:
154 TaskManagerOOPIFBrowserTest() {}
156 protected:
157 void SetUpCommandLine(base::CommandLine* command_line) override {
158 TaskManagerBrowserTest::SetUpCommandLine(command_line);
159 if (GetParam())
160 content::IsolateAllSitesForTesting(command_line);
163 bool ShouldExpectSubframes() {
164 return content::AreAllSitesIsolatedForTesting();
167 private:
168 DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest);
171 INSTANTIATE_TEST_CASE_P(, TaskManagerOOPIFBrowserTest, ::testing::Bool());
173 #if defined(OS_MACOSX) || defined(OS_LINUX)
174 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen
175 #else
176 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen
177 #endif
179 // Regression test for http://crbug.com/13361
180 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) {
181 ShowTaskManager();
184 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
185 ShowTaskManager();
186 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
187 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
188 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
190 // Open a new tab and make sure the task manager notices it.
191 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
193 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
194 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
196 // Close the tab and verify that we notice.
197 browser()->tab_strip_model()->CloseWebContentsAt(0,
198 TabStripModel::CLOSE_NONE);
199 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
200 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
203 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillTab) {
204 ShowTaskManager();
205 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
206 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
207 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
209 // Open a new tab and make sure the task manager notices it.
210 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
212 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
213 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
215 // Killing the tab via task manager should remove the row.
216 int tab = FindResourceIndex(MatchTab("title1.html"));
217 ASSERT_NE(-1, tab);
218 ASSERT_TRUE(model()->GetResourceWebContents(tab) != NULL);
219 ASSERT_TRUE(model()->CanActivate(tab));
220 TaskManager::GetInstance()->KillProcess(tab);
221 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
222 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
224 // Tab should reappear in task manager upon reload.
225 chrome::Reload(browser(), CURRENT_TAB);
226 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
227 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
230 // Test for http://crbug.com/444945, which is not fixed yet.
231 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
232 DISABLED_NavigateAwayFromHungRenderer) {
233 host_resolver()->AddRule("*", "127.0.0.1");
234 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
235 ShowTaskManager();
237 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
238 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
240 GURL url1(embedded_test_server()->GetURL("/title2.html"));
241 GURL url3(embedded_test_server()->GetURL("a.com", "/iframe.html"));
243 // Open a new tab and make sure the task manager notices it.
244 AddTabAtIndex(0, url1, ui::PAGE_TRANSITION_TYPED);
245 ASSERT_NO_FATAL_FAILURE(
246 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
247 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
248 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
249 WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
251 // Initiate a navigation that will create a new WebContents in the same
252 // SiteInstace...
253 content::WebContentsAddedObserver web_contents_added_observer;
254 tab1->GetMainFrame()->ExecuteJavaScriptWithUserGestureForTests(
255 base::ASCIIToUTF16("window.open('title3.html', '_blank');"));
256 // ... then immediately hang the renderer so that title3.html can't load.
257 tab1->GetMainFrame()->ExecuteJavaScriptForTests(
258 base::ASCIIToUTF16("while(1);"));
260 // Blocks until a new WebContents appears.
261 WebContents* tab2 = web_contents_added_observer.GetWebContents();
263 // Make sure the new WebContents is in tab1's hung renderer process.
264 ASSERT_NE(nullptr, tab2);
265 ASSERT_NE(tab1, tab2);
266 ASSERT_EQ(tab1->GetMainFrame()->GetProcess(),
267 tab2->GetMainFrame()->GetProcess())
268 << "New WebContents must be in the same process as the old WebContents, "
269 << "so that the new tab doesn't finish loading (what this test is all "
270 << "about)";
271 ASSERT_EQ(tab1->GetSiteInstance(), tab2->GetSiteInstance())
272 << "New WebContents must initially be in the same site instance as the "
273 << "old WebContents";
275 // Now navigate this tab to a different site. This should wind up in a
276 // different renderer process, so it should complete and show up in the task
277 // manager.
278 tab2->OpenURL(content::OpenURLParams(url3, content::Referrer(), CURRENT_TAB,
279 ui::PAGE_TRANSITION_TYPED, false));
281 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
284 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanel) {
285 ASSERT_TRUE(LoadExtension(
286 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
287 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
288 .AppendASCII("1.0.0.0")));
290 // Open a new panel to an extension url.
291 GURL url(
292 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
293 Panel* panel = PanelManager::GetInstance()->CreatePanel(
294 web_app::GenerateApplicationNameFromExtensionId(
295 last_loaded_extension_id()),
296 browser()->profile(),
297 url,
298 gfx::Rect(300, 400),
299 PanelManager::CREATE_AS_DOCKED);
301 // Make sure that a task manager model created after the panel shows the
302 // existence of the panel and the extension.
303 ShowTaskManager();
304 ASSERT_NO_FATAL_FAILURE(
305 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
306 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
308 MatchExtension(
309 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
310 "french_sentence.html")));
311 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
312 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
313 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
315 // Close the panel and verify that we notice.
316 panel->Close();
317 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
318 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
320 MatchExtension(
321 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
322 "french_sentence.html")));
323 ASSERT_NO_FATAL_FAILURE(
324 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
327 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanelChanges) {
328 ShowTaskManager();
329 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
330 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
332 ASSERT_TRUE(LoadExtension(
333 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
334 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
335 .AppendASCII("1.0.0.0")));
337 // Browser, the New Tab Page and Extension background page.
338 ASSERT_NO_FATAL_FAILURE(
339 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
340 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
341 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
343 // Open a new panel to an extension url and make sure we notice that.
344 GURL url(
345 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
346 Panel* panel = PanelManager::GetInstance()->CreatePanel(
347 web_app::GenerateApplicationNameFromExtensionId(
348 last_loaded_extension_id()),
349 browser()->profile(),
350 url,
351 gfx::Rect(300, 400),
352 PanelManager::CREATE_AS_DOCKED);
353 ASSERT_NO_FATAL_FAILURE(
354 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
355 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
357 MatchExtension(
358 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
359 "french_sentence.html")));
360 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
361 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
362 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
364 // Close the panel and verify that we notice.
365 panel->Close();
366 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
367 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
369 MatchExtension(
370 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
371 "french_sentence.html")));
372 ASSERT_NO_FATAL_FAILURE(
373 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
375 // Unload extension.
376 UnloadExtension(last_loaded_extension_id());
377 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
378 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
381 // Kills a process that has more than one task manager entry.
382 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaExtensionResource) {
383 ShowTaskManager();
384 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
385 .AppendASCII("Extensions")
386 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
387 .AppendASCII("1.0.0.0")));
389 // Open a new panel to an extension url.
390 GURL url(
391 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
392 "french_sentence.html");
393 PanelManager::GetInstance()->CreatePanel(
394 web_app::GenerateApplicationNameFromExtensionId(
395 last_loaded_extension_id()),
396 browser()->profile(),
397 url,
398 gfx::Rect(300, 400),
399 PanelManager::CREATE_AS_DOCKED);
401 ASSERT_NO_FATAL_FAILURE(
402 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
403 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
405 MatchExtension(
406 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
407 "french_sentence.html")));
408 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
409 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
410 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
412 // Kill the process via the BACKGROUND PAGE (not the panel). Verify that both
413 // the background page and the panel go away from the task manager.
414 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
415 ASSERT_NE(-1, background_page);
416 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
417 ASSERT_FALSE(model()->CanActivate(background_page));
418 TaskManager::GetInstance()->KillProcess(background_page);
419 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
420 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
423 // Kills a process that has more than one task manager entry. This test is the
424 // same as KillPanelViaExtensionResource except it does the kill via the other
425 // entry.
426 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaPanelResource) {
427 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
428 .AppendASCII("Extensions")
429 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
430 .AppendASCII("1.0.0.0")));
432 // Open a new panel to an extension url.
433 GURL url(
434 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
435 "french_sentence.html");
436 PanelManager::GetInstance()->CreatePanel(
437 web_app::GenerateApplicationNameFromExtensionId(
438 last_loaded_extension_id()),
439 browser()->profile(),
440 url,
441 gfx::Rect(300, 400),
442 PanelManager::CREATE_AS_DOCKED);
444 ShowTaskManager();
445 ASSERT_NO_FATAL_FAILURE(
446 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
447 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
449 MatchExtension(
450 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
451 "french_sentence.html")));
452 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
453 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
454 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
456 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
457 ASSERT_NE(-1, background_page);
458 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
459 ASSERT_FALSE(model()->CanActivate(background_page));
461 // Kill the process via the PANEL RESOURCE (not the background page). Verify
462 // that both the background page and the panel go away from the task manager.
463 int panel = FindResourceIndex(MatchExtension(
464 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
465 "french_sentence.html"));
466 ASSERT_NE(-1, panel);
467 ASSERT_TRUE(model()->GetResourceWebContents(panel) != NULL);
468 ASSERT_TRUE(model()->CanActivate(panel));
469 TaskManager::GetInstance()->KillProcess(panel);
470 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
471 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
474 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabChanges) {
475 ShowTaskManager();
476 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
477 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
479 ASSERT_TRUE(LoadExtension(
480 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
481 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
482 .AppendASCII("1.0.0.0")));
484 // Browser, Extension background page, and the New Tab Page.
485 ASSERT_NO_FATAL_FAILURE(
486 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
487 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
488 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
490 // Open a new tab to an extension URL. Afterwards, the third entry (background
491 // page) should be an extension resource whose title starts with "Extension:".
492 // The fourth entry (page.html) is also of type extension and has both a
493 // WebContents and an extension. The title should start with "Extension:".
494 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
495 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
496 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
497 ASSERT_NO_FATAL_FAILURE(
498 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
499 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
500 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
501 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
503 int extension_tab = FindResourceIndex(MatchExtension("Foobar"));
504 ASSERT_NE(-1, extension_tab);
505 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab) != NULL);
506 ASSERT_TRUE(model()->CanActivate(extension_tab));
508 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
509 ASSERT_NE(-1, background_page);
510 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
511 ASSERT_FALSE(model()->CanActivate(background_page));
514 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTab) {
515 // With the task manager closed, open a new tab to an extension URL.
516 // Afterwards, when we open the task manager, the third entry (background
517 // page) should be an extension resource whose title starts with "Extension:".
518 // The fourth entry (page.html) is also of type extension and has both a
519 // WebContents and an extension. The title should start with "Extension:".
520 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
521 .AppendASCII("Extensions")
522 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
523 .AppendASCII("1.0.0.0")));
524 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
525 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
527 ShowTaskManager();
528 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
529 ASSERT_NO_FATAL_FAILURE(
530 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
531 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
532 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
533 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
535 int extension_tab = FindResourceIndex(MatchExtension("Foobar"));
536 ASSERT_NE(-1, extension_tab);
537 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab) != NULL);
538 ASSERT_TRUE(model()->CanActivate(extension_tab));
540 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
541 ASSERT_NE(-1, background_page);
542 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
543 ASSERT_FALSE(model()->CanActivate(background_page));
546 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabChanges) {
547 ShowTaskManager();
549 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app")));
550 ExtensionService* service = extensions::ExtensionSystem::Get(
551 browser()->profile())->extension_service();
552 const extensions::Extension* extension =
553 service->GetExtensionById(last_loaded_extension_id(), false);
555 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
556 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
557 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
558 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
560 // Open a new tab to the app's launch URL and make sure we notice that.
561 GURL url(extension->GetResourceURL("main.html"));
562 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
564 // There should be 1 "App: " tab and the original new tab page.
565 ASSERT_NO_FATAL_FAILURE(
566 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
567 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
568 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
569 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
570 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
572 // Check that the third entry (main.html) is of type extension and has both
573 // a tab contents and an extension.
574 int app_tab = FindResourceIndex(MatchApp("Packaged App Test"));
575 ASSERT_NE(-1, app_tab);
576 ASSERT_TRUE(model()->GetResourceWebContents(app_tab) != NULL);
577 ASSERT_TRUE(model()->CanActivate(app_tab));
578 ASSERT_EQ(task_manager::Resource::EXTENSION,
579 model()->GetResourceType(app_tab));
580 ASSERT_EQ(2, browser()->tab_strip_model()->count());
582 // Unload extension to make sure the tab goes away.
583 UnloadExtension(last_loaded_extension_id());
585 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
586 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
587 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
588 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
589 ASSERT_EQ(1, browser()->tab_strip_model()->count());
592 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTab) {
593 ASSERT_TRUE(LoadExtension(
594 test_data_dir_.AppendASCII("packaged_app")));
595 ExtensionService* service = extensions::ExtensionSystem::Get(
596 browser()->profile())->extension_service();
597 const extensions::Extension* extension =
598 service->GetExtensionById(last_loaded_extension_id(), false);
600 // Open a new tab to the app's launch URL and make sure we notice that.
601 GURL url(extension->GetResourceURL("main.html"));
602 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
604 ShowTaskManager();
606 ASSERT_NO_FATAL_FAILURE(
607 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
608 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
609 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
610 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
612 // Check that the third entry (main.html) is of type extension and has both
613 // a tab contents and an extension.
614 int app_tab = FindResourceIndex(MatchApp("Packaged App Test"));
615 ASSERT_NE(-1, app_tab);
616 ASSERT_TRUE(model()->GetResourceWebContents(app_tab) != NULL);
617 ASSERT_TRUE(model()->CanActivate(app_tab));
618 ASSERT_EQ(task_manager::Resource::EXTENSION,
619 model()->GetResourceType(app_tab));
622 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabChanges) {
623 ShowTaskManager();
625 // The app under test acts on URLs whose host is "localhost",
626 // so the URLs we navigate to must have host "localhost".
627 host_resolver()->AddRule("*", "127.0.0.1");
628 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
629 GURL::Replacements replace_host;
630 replace_host.SetHostStr("localhost");
631 GURL base_url = embedded_test_server()->GetURL(
632 "/extensions/api_test/app_process/");
633 base_url = base_url.ReplaceComponents(replace_host);
635 // Open a new tab to an app URL before the app is loaded.
636 GURL url(base_url.Resolve("path1/empty.html"));
637 content::WindowedNotificationObserver observer(
638 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
639 content::NotificationService::AllSources());
640 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
641 observer.Wait();
643 // Check that the new entry's title starts with "Tab:".
644 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
646 // Load the hosted app and make sure it still starts with "Tab:",
647 // since it hasn't changed to an app process yet.
648 ASSERT_TRUE(LoadExtension(
649 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
650 // Force the TaskManager to query the title.
651 Refresh();
652 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
653 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
654 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
655 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
657 // Now reload and check that the last entry's title now starts with "App:".
658 ui_test_utils::NavigateToURL(browser(), url);
660 // Force the TaskManager to query the title.
661 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
662 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
663 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
664 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp("Unmodified")));
665 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
667 // Disable extension.
668 DisableExtension(last_loaded_extension_id());
670 // The hosted app should now show up as a normal "Tab: ".
671 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
672 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
673 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
674 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
675 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
677 // Reload the page.
678 ui_test_utils::NavigateToURL(browser(), url);
680 // No change expected.
681 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
682 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
683 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
684 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
685 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
688 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabAfterReload) {
689 // The app under test acts on URLs whose host is "localhost",
690 // so the URLs we navigate to must have host "localhost".
691 host_resolver()->AddRule("*", "127.0.0.1");
692 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
693 GURL::Replacements replace_host;
694 replace_host.SetHostStr("localhost");
695 GURL base_url =
696 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
697 base_url = base_url.ReplaceComponents(replace_host);
699 // Open a new tab to an app URL before the app is loaded.
700 GURL url(base_url.Resolve("path1/empty.html"));
701 content::WindowedNotificationObserver observer(
702 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
703 content::NotificationService::AllSources());
704 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
705 observer.Wait();
707 // Load the hosted app and make sure it still starts with "Tab:",
708 // since it hasn't changed to an app process yet.
709 ASSERT_TRUE(LoadExtension(
710 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
712 // Now reload, which should transition this tab to being an App.
713 ui_test_utils::NavigateToURL(browser(), url);
715 ShowTaskManager();
717 // The TaskManager should show this as an "App: "
718 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
719 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
720 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
723 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabBeforeReload) {
724 // The app under test acts on URLs whose host is "localhost",
725 // so the URLs we navigate to must have host "localhost".
726 host_resolver()->AddRule("*", "127.0.0.1");
727 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
728 GURL::Replacements replace_host;
729 replace_host.SetHostStr("localhost");
730 GURL base_url =
731 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
732 base_url = base_url.ReplaceComponents(replace_host);
734 // Open a new tab to an app URL before the app is loaded.
735 GURL url(base_url.Resolve("path1/empty.html"));
736 content::WindowedNotificationObserver observer(
737 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
738 content::NotificationService::AllSources());
739 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
740 observer.Wait();
742 // Load the hosted app and make sure it still starts with "Tab:",
743 // since it hasn't changed to an app process yet.
744 ASSERT_TRUE(LoadExtension(
745 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
747 ShowTaskManager();
749 // The TaskManager should show this as a "Tab: " because the page hasn't been
750 // reloaded since the hosted app was installed.
751 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
752 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
753 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
756 // Regression test for http://crbug.com/18693.
757 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) {
758 ShowTaskManager();
759 ASSERT_TRUE(LoadExtension(
760 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
762 // Wait until we see the loaded extension in the task manager (the three
763 // resources are: the browser process, New Tab Page, and the extension).
764 ASSERT_NO_FATAL_FAILURE(
765 WaitForTaskManagerRows(1, MatchExtension("background_page")));
767 // Reload the extension a few times and make sure our resource count doesn't
768 // increase.
769 std::string extension_id = last_loaded_extension_id();
770 for (int i = 1; i <= 5; i++) {
771 SCOPED_TRACE(testing::Message() << "Reloading extension for the " << i
772 << "th time.");
773 ReloadExtension(extension_id);
774 ASSERT_NO_FATAL_FAILURE(
775 WaitForTaskManagerRows(1, MatchExtension("background_page")));
779 // Crashy, http://crbug.com/42301.
780 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
781 DISABLED_PopulateWebCacheFields) {
782 ShowTaskManager();
783 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
785 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
787 // Open a new tab and make sure we notice that.
788 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
789 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
791 // Check that we get some value for the cache columns.
792 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count),
793 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
794 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count),
795 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
796 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count),
797 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
800 // Checks that task manager counts a worker thread JS heap size.
801 // http://crbug.com/241066
802 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, WebWorkerJSHeapMemory) {
803 ShowTaskManager();
804 ui_test_utils::NavigateToURL(browser(), GetTestURL());
805 size_t minimal_heap_size = 4 * 1024 * 1024 * sizeof(void*);
806 std::string test_js = base::StringPrintf(
807 "var blob = new Blob([\n"
808 " 'mem = new Array(%lu);',\n"
809 " 'for (var i = 0; i < mem.length; i += 16)',"
810 " ' mem[i] = i;',\n"
811 " 'postMessage(\"okay\");']);\n"
812 "blobURL = window.URL.createObjectURL(blob);\n"
813 "var worker = new Worker(blobURL);\n"
814 "worker.addEventListener('message', function(e) {\n"
815 " window.domAutomationController.send(e.data);\n" // e.data == "okay"
816 "});\n"
817 "worker.postMessage('go');\n",
818 static_cast<unsigned long>(minimal_heap_size));
819 std::string ok;
820 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
821 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok));
822 ASSERT_EQ("okay", ok);
824 // The worker has allocated objects of at least |minimal_heap_size| bytes.
825 // Wait for the heap stats to reflect this.
826 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
827 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY,
828 minimal_heap_size));
829 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
830 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY_USED,
831 minimal_heap_size));
832 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
833 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
836 // Checks that task manager counts renderer JS heap size.
837 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, JSHeapMemory) {
838 ShowTaskManager();
839 ui_test_utils::NavigateToURL(browser(), GetTestURL());
840 size_t minimal_heap_size = 4 * 1024 * 1024 * sizeof(void*);
841 std::string test_js = base::StringPrintf(
842 "mem = new Array(%lu);\n"
843 "for (var i = 0; i < mem.length; i += 16)\n"
844 " mem[i] = i;\n"
845 "window.domAutomationController.send(\"okay\");\n",
846 static_cast<unsigned long>(minimal_heap_size));
847 std::string ok;
848 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
849 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok));
850 ASSERT_EQ("okay", ok);
852 // The page's js has allocated objects of at least |minimal_heap_size| bytes.
853 // Wait for the heap stats to reflect this.
854 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
855 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY,
856 minimal_heap_size));
857 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
858 MatchTab("title1.html"), task_manager::browsertest_util::V8_MEMORY_USED,
859 minimal_heap_size));
860 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
861 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
864 // Checks that task manager counts utility process JS heap size.
865 IN_PROC_BROWSER_TEST_F(TaskManagerUtilityProcessBrowserTest,
866 UtilityJSHeapMemory) {
867 ShowTaskManager();
868 ui_test_utils::NavigateToURL(browser(), GetTestURL());
869 // The PAC script is trivial, so don't expect a large heap.
870 size_t minimal_heap_size = 1024;
871 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
872 MatchUtility(
873 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME)),
874 task_manager::browsertest_util::V8_MEMORY,
875 minimal_heap_size));
876 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed(
877 MatchUtility(
878 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME)),
879 task_manager::browsertest_util::V8_MEMORY_USED,
880 minimal_heap_size));
881 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyUtility()));
882 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
883 1, MatchUtility(l10n_util::GetStringUTF16(
884 IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME))));
887 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewDockedWindow) {
888 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
890 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
891 DevToolsWindow* devtools =
892 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
893 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
894 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
895 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
898 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewUndockedWindow) {
899 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
900 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
901 DevToolsWindow* devtools =
902 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
903 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
904 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
905 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
908 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldDockedWindow) {
909 DevToolsWindow* devtools =
910 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
911 ShowTaskManager(); // Task manager shown AFTER dev tools window.
912 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
913 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
914 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
917 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldUnockedWindow) {
918 DevToolsWindow* devtools =
919 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
920 ShowTaskManager(); // Task manager shown AFTER dev tools window.
921 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
922 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
923 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
926 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, KillSubframe) {
927 ShowTaskManager();
929 host_resolver()->AddRule("*", "127.0.0.1");
930 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
931 content::SetupCrossSiteRedirector(embedded_test_server());
933 GURL main_url(embedded_test_server()->GetURL(
934 "/cross-site/a.com/iframe_cross_site.html"));
935 browser()->OpenURL(content::OpenURLParams(main_url, content::Referrer(),
936 CURRENT_TAB,
937 ui::PAGE_TRANSITION_TYPED, false));
939 ASSERT_NO_FATAL_FAILURE(
940 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
941 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
943 if (!ShouldExpectSubframes()) {
944 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
945 } else {
946 ASSERT_NO_FATAL_FAILURE(
947 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
948 ASSERT_NO_FATAL_FAILURE(
949 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
950 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
951 int subframe_b = FindResourceIndex(MatchSubframe("http://b.com/"));
952 ASSERT_NE(-1, subframe_b);
953 ASSERT_TRUE(model()->GetResourceWebContents(subframe_b) != NULL);
954 ASSERT_TRUE(model()->CanActivate(subframe_b));
956 TaskManager::GetInstance()->KillProcess(subframe_b);
958 ASSERT_NO_FATAL_FAILURE(
959 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
960 ASSERT_NO_FATAL_FAILURE(
961 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
962 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
963 ASSERT_NO_FATAL_FAILURE(
964 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
967 HideTaskManager();
968 ShowTaskManager();
970 if (!ShouldExpectSubframes()) {
971 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
972 } else {
973 ASSERT_NO_FATAL_FAILURE(
974 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
975 ASSERT_NO_FATAL_FAILURE(
976 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
977 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
978 ASSERT_NO_FATAL_FAILURE(
979 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
983 // Tests what happens when a tab navigates to a site (a.com) that it previously
984 // has a cross-process subframe into (b.com).
986 // TODO(nick): http://crbug.com/442532. Disabled because the second navigation
987 // hits an ASSERT(frame()) in WebLocalFrameImpl::loadRequest under --site-per-
988 // process.
989 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
990 DISABLED_NavigateToSubframeProcess) {
991 ShowTaskManager();
993 host_resolver()->AddRule("*", "127.0.0.1");
994 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
995 content::SetupCrossSiteRedirector(embedded_test_server());
997 // Navigate the tab to a page on a.com with cross-process subframes to
998 // b.com and c.com.
999 GURL a_dotcom(embedded_test_server()->GetURL(
1000 "/cross-site/a.com/iframe_cross_site.html"));
1001 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
1002 CURRENT_TAB,
1003 ui::PAGE_TRANSITION_TYPED, false));
1005 ASSERT_NO_FATAL_FAILURE(
1006 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1007 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1009 if (!ShouldExpectSubframes()) {
1010 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1011 } else {
1012 ASSERT_NO_FATAL_FAILURE(
1013 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1014 ASSERT_NO_FATAL_FAILURE(
1015 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1016 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1019 // Now navigate to a page on b.com with a simple (same-site) iframe.
1020 // This should not show any subframe resources in the task manager.
1021 GURL b_dotcom(
1022 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
1024 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(),
1025 CURRENT_TAB,
1026 ui::PAGE_TRANSITION_TYPED, false));
1028 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1029 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1030 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1031 HideTaskManager();
1032 ShowTaskManager();
1033 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1034 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1035 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1038 // TODO(nick): Fails flakily under OOPIF due to a ASSERT_NOT_REACHED in
1039 // WebRemoteFrame, at least under debug OSX. http://crbug.com/437956
1040 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
1041 DISABLED_NavigateToSiteWithSubframeToOriginalSite) {
1042 ShowTaskManager();
1044 host_resolver()->AddRule("*", "127.0.0.1");
1045 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1046 content::SetupCrossSiteRedirector(embedded_test_server());
1048 // Navigate to a page on b.com with a simple (same-site) iframe.
1049 // This should not show any subframe resources in the task manager.
1050 GURL b_dotcom(
1051 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
1053 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(),
1054 CURRENT_TAB,
1055 ui::PAGE_TRANSITION_TYPED, false));
1057 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
1058 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1059 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1061 // Now navigate the tab to a page on a.com with cross-process subframes to
1062 // b.com and c.com.
1063 GURL a_dotcom(embedded_test_server()->GetURL(
1064 "/cross-site/a.com/iframe_cross_site.html"));
1065 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
1066 CURRENT_TAB,
1067 ui::PAGE_TRANSITION_TYPED, false));
1069 ASSERT_NO_FATAL_FAILURE(
1070 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1071 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1073 if (!ShouldExpectSubframes()) {
1074 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1075 } else {
1076 ASSERT_NO_FATAL_FAILURE(
1077 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1078 ASSERT_NO_FATAL_FAILURE(
1079 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1080 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1083 HideTaskManager();
1084 ShowTaskManager();
1086 if (!ShouldExpectSubframes()) {
1087 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1088 } else {
1089 ASSERT_NO_FATAL_FAILURE(
1090 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1091 ASSERT_NO_FATAL_FAILURE(
1092 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1093 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1097 // Tests what happens when a tab navigates a cross-frame iframe (to b.com)
1098 // back to the site of the parent document (a.com).
1099 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
1100 CrossSiteIframeBecomesSameSite) {
1101 ShowTaskManager();
1103 host_resolver()->AddRule("*", "127.0.0.1");
1104 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1105 content::SetupCrossSiteRedirector(embedded_test_server());
1107 // Navigate the tab to a page on a.com with cross-process subframes to
1108 // b.com and c.com.
1109 GURL a_dotcom(embedded_test_server()->GetURL(
1110 "/cross-site/a.com/iframe_cross_site.html"));
1111 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
1112 CURRENT_TAB,
1113 ui::PAGE_TRANSITION_TYPED, false));
1115 ASSERT_NO_FATAL_FAILURE(
1116 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1117 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1119 if (!ShouldExpectSubframes()) {
1120 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1121 } else {
1122 ASSERT_NO_FATAL_FAILURE(
1123 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1124 ASSERT_NO_FATAL_FAILURE(
1125 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1126 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1129 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe
1130 ASSERT_TRUE(content::ExecuteScript(
1131 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
1132 "document.getElementById('frame1').src='/title1.html';"
1133 "document.title='aac';"));
1134 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1135 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1136 if (!ShouldExpectSubframes()) {
1137 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1138 } else {
1139 ASSERT_NO_FATAL_FAILURE(
1140 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1141 ASSERT_NO_FATAL_FAILURE(
1142 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1143 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1145 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1146 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1148 HideTaskManager();
1149 ShowTaskManager();
1151 if (!ShouldExpectSubframes()) {
1152 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1153 } else {
1154 ASSERT_NO_FATAL_FAILURE(
1155 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1156 ASSERT_NO_FATAL_FAILURE(
1157 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1158 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1160 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1161 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1164 // Tests what happens when a tab does a same-site navigation away from a page
1165 // with cross-site iframes.
1166 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
1167 LeavePageWithCrossSiteIframes) {
1168 ShowTaskManager();
1170 host_resolver()->AddRule("*", "127.0.0.1");
1171 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1172 content::SetupCrossSiteRedirector(embedded_test_server());
1174 // Navigate the tab to a page on a.com with cross-process subframes.
1175 GURL a_dotcom_with_iframes(embedded_test_server()->GetURL(
1176 "/cross-site/a.com/iframe_cross_site.html"));
1177 browser()->OpenURL(content::OpenURLParams(a_dotcom_with_iframes,
1178 content::Referrer(), CURRENT_TAB,
1179 ui::PAGE_TRANSITION_TYPED, false));
1181 ASSERT_NO_FATAL_FAILURE(
1182 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1183 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1185 if (!ShouldExpectSubframes()) {
1186 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1187 } else {
1188 ASSERT_NO_FATAL_FAILURE(
1189 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1190 ASSERT_NO_FATAL_FAILURE(
1191 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1192 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1195 // Navigate the tab to a page on a.com without cross-process subframes, and
1196 // the subframe processes should disappear.
1197 GURL a_dotcom_simple(
1198 embedded_test_server()->GetURL("/cross-site/a.com/title2.html"));
1199 browser()->OpenURL(content::OpenURLParams(a_dotcom_simple,
1200 content::Referrer(), CURRENT_TAB,
1201 ui::PAGE_TRANSITION_TYPED, false));
1202 ASSERT_NO_FATAL_FAILURE(
1203 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
1204 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1206 HideTaskManager();
1207 ShowTaskManager();
1209 ASSERT_NO_FATAL_FAILURE(
1210 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
1211 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));