Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / task_manager / task_manager_browsertest.cc
blobd923ff12104a24126ef6c64516f74b9131609e3c
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::MatchApp;
59 using task_manager::browsertest_util::MatchExtension;
60 using task_manager::browsertest_util::MatchSubframe;
61 using task_manager::browsertest_util::MatchTab;
62 using task_manager::browsertest_util::WaitForTaskManagerRows;
64 namespace {
66 const base::FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
68 } // namespace
70 class TaskManagerBrowserTest : public ExtensionBrowserTest {
71 public:
72 TaskManagerBrowserTest() {}
73 ~TaskManagerBrowserTest() override {}
75 TaskManagerModel* model() const {
76 return TaskManager::GetInstance()->model();
79 void ShowTaskManager() {
80 EXPECT_EQ(0, model()->ResourceCount());
82 // Show the task manager. This populates the model, and helps with debugging
83 // (you see the task manager).
84 chrome::ShowTaskManager(browser());
87 void HideTaskManager() {
88 // Hide the task manager, and wait for the model to be depopulated.
89 chrome::HideTaskManager();
90 base::RunLoop().RunUntilIdle(); // OnWindowClosed happens asynchronously.
91 EXPECT_EQ(0, model()->ResourceCount());
94 void Refresh() {
95 model()->Refresh();
98 int GetUpdateTimeMs() {
99 return TaskManagerModel::kUpdateTimeMs;
102 GURL GetTestURL() {
103 return ui_test_utils::GetTestUrl(
104 base::FilePath(base::FilePath::kCurrentDirectory),
105 base::FilePath(kTitle1File));
108 int FindResourceIndex(const base::string16& title) {
109 for (int i = 0; i < model()->ResourceCount(); ++i) {
110 if (title == model()->GetResourceTitle(i))
111 return i;
113 return -1;
116 protected:
117 void SetUpCommandLine(base::CommandLine* command_line) override {
118 ExtensionBrowserTest::SetUpCommandLine(command_line);
120 // Do not launch device discovery process.
121 command_line->AppendSwitch(switches::kDisableDeviceDiscoveryNotifications);
124 private:
125 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest);
128 // Parameterized variant of TaskManagerBrowserTest which runs with/without
129 // --site-per-process, which enables out of process iframes (OOPIFs).
130 class TaskManagerOOPIFBrowserTest : public TaskManagerBrowserTest,
131 public testing::WithParamInterface<bool> {
132 public:
133 TaskManagerOOPIFBrowserTest() {}
135 protected:
136 void SetUpCommandLine(base::CommandLine* command_line) override {
137 TaskManagerBrowserTest::SetUpCommandLine(command_line);
138 if (GetParam())
139 command_line->AppendSwitch(switches::kSitePerProcess);
142 bool ShouldExpectSubframes() {
143 return base::CommandLine::ForCurrentProcess()->HasSwitch(
144 switches::kSitePerProcess);
147 private:
148 DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest);
151 INSTANTIATE_TEST_CASE_P(, TaskManagerOOPIFBrowserTest, ::testing::Bool());
153 #if defined(OS_MACOSX) || defined(OS_LINUX)
154 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen
155 #else
156 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen
157 #endif
159 // Regression test for http://crbug.com/13361
160 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) {
161 ShowTaskManager();
164 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
165 ShowTaskManager();
166 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
167 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
168 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
170 // Open a new tab and make sure the task manager notices it.
171 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
173 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
174 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
176 // Close the tab and verify that we notice.
177 browser()->tab_strip_model()->CloseWebContentsAt(0,
178 TabStripModel::CLOSE_NONE);
179 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
180 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
183 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillTab) {
184 ShowTaskManager();
185 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
186 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
187 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
189 // Open a new tab and make sure the task manager notices it.
190 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
192 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
193 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
195 // Killing the tab via task manager should remove the row.
196 int tab = FindResourceIndex(MatchTab("title1.html"));
197 ASSERT_NE(-1, tab);
198 ASSERT_TRUE(model()->GetResourceWebContents(tab) != NULL);
199 ASSERT_TRUE(model()->CanActivate(tab));
200 TaskManager::GetInstance()->KillProcess(tab);
201 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
202 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
204 // Tab should reappear in task manager upon reload.
205 chrome::Reload(browser(), CURRENT_TAB);
206 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
207 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
210 // Test for http://crbug.com/444945, which is not fixed yet.
211 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
212 DISABLED_NavigateAwayFromHungRenderer) {
213 host_resolver()->AddRule("*", "127.0.0.1");
214 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
215 ShowTaskManager();
217 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
218 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
220 GURL url1(embedded_test_server()->GetURL("/title2.html"));
221 GURL url3(embedded_test_server()->GetURL("a.com", "/iframe.html"));
223 // Open a new tab and make sure the task manager notices it.
224 AddTabAtIndex(0, url1, ui::PAGE_TRANSITION_TYPED);
225 ASSERT_NO_FATAL_FAILURE(
226 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness")));
227 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
228 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
229 WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
231 // Initiate a navigation that will create a new WebContents in the same
232 // SiteInstace...
233 content::WebContentsAddedObserver web_contents_added_observer;
234 tab1->GetMainFrame()->ExecuteJavaScriptForTests(
235 base::ASCIIToUTF16("window.open('title3.html', '_blank');"));
236 // ... then immediately hang the renderer so that title3.html can't load.
237 tab1->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16("while(1);"));
239 // Blocks until a new WebContents appears.
240 WebContents* tab2 = web_contents_added_observer.GetWebContents();
242 // Make sure the new WebContents is in tab1's hung renderer process.
243 ASSERT_NE(nullptr, tab2);
244 ASSERT_NE(tab1, tab2);
245 ASSERT_EQ(tab1->GetMainFrame()->GetProcess(),
246 tab2->GetMainFrame()->GetProcess())
247 << "New WebContents must be in the same process as the old WebContents, "
248 << "so that the new tab doesn't finish loading (what this test is all "
249 << "about)";
250 ASSERT_EQ(tab1->GetSiteInstance(), tab2->GetSiteInstance())
251 << "New WebContents must initially be in the same site instance as the "
252 << "old WebContents";
254 // Now navigate this tab to a different site. This should wind up in a
255 // different renderer process, so it should complete and show up in the task
256 // manager.
257 tab2->OpenURL(content::OpenURLParams(url3, content::Referrer(), CURRENT_TAB,
258 ui::PAGE_TRANSITION_TYPED, false));
260 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
263 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanel) {
264 ASSERT_TRUE(LoadExtension(
265 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
266 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
267 .AppendASCII("1.0.0.0")));
269 // Open a new panel to an extension url.
270 GURL url(
271 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
272 Panel* panel = PanelManager::GetInstance()->CreatePanel(
273 web_app::GenerateApplicationNameFromExtensionId(
274 last_loaded_extension_id()),
275 browser()->profile(),
276 url,
277 gfx::Rect(300, 400),
278 PanelManager::CREATE_AS_DOCKED);
280 // Make sure that a task manager model created after the panel shows the
281 // existence of the panel and the extension.
282 ShowTaskManager();
283 ASSERT_NO_FATAL_FAILURE(
284 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
285 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
287 MatchExtension(
288 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
289 "french_sentence.html")));
290 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
291 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
292 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
294 // Close the panel and verify that we notice.
295 panel->Close();
296 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
297 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
299 MatchExtension(
300 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
301 "french_sentence.html")));
302 ASSERT_NO_FATAL_FAILURE(
303 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
306 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanelChanges) {
307 ShowTaskManager();
308 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
309 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
311 ASSERT_TRUE(LoadExtension(
312 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
313 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
314 .AppendASCII("1.0.0.0")));
316 // Browser, the New Tab Page and Extension background page.
317 ASSERT_NO_FATAL_FAILURE(
318 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
319 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
320 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
322 // Open a new panel to an extension url and make sure we notice that.
323 GURL url(
324 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
325 Panel* panel = PanelManager::GetInstance()->CreatePanel(
326 web_app::GenerateApplicationNameFromExtensionId(
327 last_loaded_extension_id()),
328 browser()->profile(),
329 url,
330 gfx::Rect(300, 400),
331 PanelManager::CREATE_AS_DOCKED);
332 ASSERT_NO_FATAL_FAILURE(
333 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
334 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
336 MatchExtension(
337 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
338 "french_sentence.html")));
339 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
340 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
341 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
343 // Close the panel and verify that we notice.
344 panel->Close();
345 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
346 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
348 MatchExtension(
349 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
350 "french_sentence.html")));
351 ASSERT_NO_FATAL_FAILURE(
352 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
354 // Unload extension.
355 UnloadExtension(last_loaded_extension_id());
356 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
357 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
360 // Kills a process that has more than one task manager entry.
361 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaExtensionResource) {
362 ShowTaskManager();
363 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
364 .AppendASCII("Extensions")
365 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
366 .AppendASCII("1.0.0.0")));
368 // Open a new panel to an extension url.
369 GURL url(
370 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
371 "french_sentence.html");
372 PanelManager::GetInstance()->CreatePanel(
373 web_app::GenerateApplicationNameFromExtensionId(
374 last_loaded_extension_id()),
375 browser()->profile(),
376 url,
377 gfx::Rect(300, 400),
378 PanelManager::CREATE_AS_DOCKED);
380 ASSERT_NO_FATAL_FAILURE(
381 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
382 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
384 MatchExtension(
385 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
386 "french_sentence.html")));
387 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
388 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
389 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
391 // Kill the process via the BACKGROUND PAGE (not the panel). Verify that both
392 // the background page and the panel go away from the task manager.
393 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
394 ASSERT_NE(-1, background_page);
395 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
396 ASSERT_FALSE(model()->CanActivate(background_page));
397 TaskManager::GetInstance()->KillProcess(background_page);
398 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
399 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
402 // Kills a process that has more than one task manager entry. This test is the
403 // same as KillPanelViaExtensionResource except it does the kill via the other
404 // entry.
405 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaPanelResource) {
406 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
407 .AppendASCII("Extensions")
408 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
409 .AppendASCII("1.0.0.0")));
411 // Open a new panel to an extension url.
412 GURL url(
413 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
414 "french_sentence.html");
415 PanelManager::GetInstance()->CreatePanel(
416 web_app::GenerateApplicationNameFromExtensionId(
417 last_loaded_extension_id()),
418 browser()->profile(),
419 url,
420 gfx::Rect(300, 400),
421 PanelManager::CREATE_AS_DOCKED);
423 ShowTaskManager();
424 ASSERT_NO_FATAL_FAILURE(
425 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
426 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
428 MatchExtension(
429 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
430 "french_sentence.html")));
431 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
432 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
433 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
435 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
436 ASSERT_NE(-1, background_page);
437 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
438 ASSERT_FALSE(model()->CanActivate(background_page));
440 // Kill the process via the PANEL RESOURCE (not the background page). Verify
441 // that both the background page and the panel go away from the task manager.
442 int panel = FindResourceIndex(MatchExtension(
443 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
444 "french_sentence.html"));
445 ASSERT_NE(-1, panel);
446 ASSERT_TRUE(model()->GetResourceWebContents(panel) != NULL);
447 ASSERT_TRUE(model()->CanActivate(panel));
448 TaskManager::GetInstance()->KillProcess(panel);
449 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
450 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
453 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabChanges) {
454 ShowTaskManager();
455 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
456 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
458 ASSERT_TRUE(LoadExtension(
459 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
460 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
461 .AppendASCII("1.0.0.0")));
463 // Browser, Extension background page, and the New Tab Page.
464 ASSERT_NO_FATAL_FAILURE(
465 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
466 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
467 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
469 // Open a new tab to an extension URL. Afterwards, the third entry (background
470 // page) should be an extension resource whose title starts with "Extension:".
471 // The fourth entry (page.html) is also of type extension and has both a
472 // WebContents and an extension. The title should start with "Extension:".
473 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
474 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
475 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
476 ASSERT_NO_FATAL_FAILURE(
477 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
478 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
479 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
480 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
482 int extension_tab = FindResourceIndex(MatchExtension("Foobar"));
483 ASSERT_NE(-1, extension_tab);
484 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab) != NULL);
485 ASSERT_TRUE(model()->CanActivate(extension_tab));
487 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
488 ASSERT_NE(-1, background_page);
489 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
490 ASSERT_FALSE(model()->CanActivate(background_page));
493 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTab) {
494 // With the task manager closed, open a new tab to an extension URL.
495 // Afterwards, when we open the task manager, the third entry (background
496 // page) should be an extension resource whose title starts with "Extension:".
497 // The fourth entry (page.html) is also of type extension and has both a
498 // WebContents and an extension. The title should start with "Extension:".
499 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
500 .AppendASCII("Extensions")
501 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
502 .AppendASCII("1.0.0.0")));
503 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
504 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
506 ShowTaskManager();
507 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
508 ASSERT_NO_FATAL_FAILURE(
509 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
510 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
511 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
512 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
514 int extension_tab = FindResourceIndex(MatchExtension("Foobar"));
515 ASSERT_NE(-1, extension_tab);
516 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab) != NULL);
517 ASSERT_TRUE(model()->CanActivate(extension_tab));
519 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
520 ASSERT_NE(-1, background_page);
521 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
522 ASSERT_FALSE(model()->CanActivate(background_page));
525 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabChanges) {
526 ShowTaskManager();
528 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app")));
529 ExtensionService* service = extensions::ExtensionSystem::Get(
530 browser()->profile())->extension_service();
531 const extensions::Extension* extension =
532 service->GetExtensionById(last_loaded_extension_id(), false);
534 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
535 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
536 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
537 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
539 // Open a new tab to the app's launch URL and make sure we notice that.
540 GURL url(extension->GetResourceURL("main.html"));
541 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
543 // There should be 1 "App: " tab and the original new tab page.
544 ASSERT_NO_FATAL_FAILURE(
545 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
546 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
547 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
548 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
549 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
551 // Check that the third entry (main.html) is of type extension and has both
552 // a tab contents and an extension.
553 int app_tab = FindResourceIndex(MatchApp("Packaged App Test"));
554 ASSERT_NE(-1, app_tab);
555 ASSERT_TRUE(model()->GetResourceWebContents(app_tab) != NULL);
556 ASSERT_TRUE(model()->CanActivate(app_tab));
557 ASSERT_EQ(task_manager::Resource::EXTENSION,
558 model()->GetResourceType(app_tab));
559 ASSERT_EQ(2, browser()->tab_strip_model()->count());
561 // Unload extension to make sure the tab goes away.
562 UnloadExtension(last_loaded_extension_id());
564 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
565 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
566 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
567 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
568 ASSERT_EQ(1, browser()->tab_strip_model()->count());
571 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTab) {
572 ASSERT_TRUE(LoadExtension(
573 test_data_dir_.AppendASCII("packaged_app")));
574 ExtensionService* service = extensions::ExtensionSystem::Get(
575 browser()->profile())->extension_service();
576 const extensions::Extension* extension =
577 service->GetExtensionById(last_loaded_extension_id(), false);
579 // Open a new tab to the app's launch URL and make sure we notice that.
580 GURL url(extension->GetResourceURL("main.html"));
581 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
583 ShowTaskManager();
585 ASSERT_NO_FATAL_FAILURE(
586 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
587 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
588 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
589 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
591 // Check that the third entry (main.html) is of type extension and has both
592 // a tab contents and an extension.
593 int app_tab = FindResourceIndex(MatchApp("Packaged App Test"));
594 ASSERT_NE(-1, app_tab);
595 ASSERT_TRUE(model()->GetResourceWebContents(app_tab) != NULL);
596 ASSERT_TRUE(model()->CanActivate(app_tab));
597 ASSERT_EQ(task_manager::Resource::EXTENSION,
598 model()->GetResourceType(app_tab));
601 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabChanges) {
602 ShowTaskManager();
604 // The app under test acts on URLs whose host is "localhost",
605 // so the URLs we navigate to must have host "localhost".
606 host_resolver()->AddRule("*", "127.0.0.1");
607 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
608 GURL::Replacements replace_host;
609 replace_host.SetHostStr("localhost");
610 GURL base_url = embedded_test_server()->GetURL(
611 "/extensions/api_test/app_process/");
612 base_url = base_url.ReplaceComponents(replace_host);
614 // Open a new tab to an app URL before the app is loaded.
615 GURL url(base_url.Resolve("path1/empty.html"));
616 content::WindowedNotificationObserver observer(
617 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
618 content::NotificationService::AllSources());
619 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
620 observer.Wait();
622 // Check that the new entry's title starts with "Tab:".
623 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
625 // Load the hosted app and make sure it still starts with "Tab:",
626 // since it hasn't changed to an app process yet.
627 ASSERT_TRUE(LoadExtension(
628 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
629 // Force the TaskManager to query the title.
630 Refresh();
631 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
632 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
633 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
634 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
636 // Now reload and check that the last entry's title now starts with "App:".
637 ui_test_utils::NavigateToURL(browser(), url);
639 // Force the TaskManager to query the title.
640 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
641 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
642 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
643 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp("Unmodified")));
644 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
646 // Disable extension.
647 DisableExtension(last_loaded_extension_id());
649 // The hosted app should now show up as a normal "Tab: ".
650 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
651 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
652 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
653 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
654 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
656 // Reload the page.
657 ui_test_utils::NavigateToURL(browser(), url);
659 // No change expected.
660 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
661 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
662 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
663 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
664 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
667 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabAfterReload) {
668 // The app under test acts on URLs whose host is "localhost",
669 // so the URLs we navigate to must have host "localhost".
670 host_resolver()->AddRule("*", "127.0.0.1");
671 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
672 GURL::Replacements replace_host;
673 replace_host.SetHostStr("localhost");
674 GURL base_url =
675 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
676 base_url = base_url.ReplaceComponents(replace_host);
678 // Open a new tab to an app URL before the app is loaded.
679 GURL url(base_url.Resolve("path1/empty.html"));
680 content::WindowedNotificationObserver observer(
681 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
682 content::NotificationService::AllSources());
683 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
684 observer.Wait();
686 // Load the hosted app and make sure it still starts with "Tab:",
687 // since it hasn't changed to an app process yet.
688 ASSERT_TRUE(LoadExtension(
689 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
691 // Now reload, which should transition this tab to being an App.
692 ui_test_utils::NavigateToURL(browser(), url);
694 ShowTaskManager();
696 // The TaskManager should show this as an "App: "
697 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
698 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
699 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
702 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabBeforeReload) {
703 // The app under test acts on URLs whose host is "localhost",
704 // so the URLs we navigate to must have host "localhost".
705 host_resolver()->AddRule("*", "127.0.0.1");
706 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
707 GURL::Replacements replace_host;
708 replace_host.SetHostStr("localhost");
709 GURL base_url =
710 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
711 base_url = base_url.ReplaceComponents(replace_host);
713 // Open a new tab to an app URL before the app is loaded.
714 GURL url(base_url.Resolve("path1/empty.html"));
715 content::WindowedNotificationObserver observer(
716 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
717 content::NotificationService::AllSources());
718 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
719 observer.Wait();
721 // Load the hosted app and make sure it still starts with "Tab:",
722 // since it hasn't changed to an app process yet.
723 ASSERT_TRUE(LoadExtension(
724 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
726 ShowTaskManager();
728 // The TaskManager should show this as a "Tab: " because the page hasn't been
729 // reloaded since the hosted app was installed.
730 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
731 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
732 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
735 // Regression test for http://crbug.com/18693.
736 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) {
737 ShowTaskManager();
738 ASSERT_TRUE(LoadExtension(
739 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
741 // Wait until we see the loaded extension in the task manager (the three
742 // resources are: the browser process, New Tab Page, and the extension).
743 ASSERT_NO_FATAL_FAILURE(
744 WaitForTaskManagerRows(1, MatchExtension("background_page")));
746 // Reload the extension a few times and make sure our resource count doesn't
747 // increase.
748 std::string extension_id = last_loaded_extension_id();
749 for (int i = 1; i <= 5; i++) {
750 SCOPED_TRACE(testing::Message() << "Reloading extension for the " << i
751 << "th time.");
752 ReloadExtension(extension_id);
753 ASSERT_NO_FATAL_FAILURE(
754 WaitForTaskManagerRows(1, MatchExtension("background_page")));
758 // Crashy, http://crbug.com/42301.
759 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
760 DISABLED_PopulateWebCacheFields) {
761 ShowTaskManager();
762 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
764 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
766 // Open a new tab and make sure we notice that.
767 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
768 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
770 // Check that we get some value for the cache columns.
771 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count),
772 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
773 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count),
774 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
775 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count),
776 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
779 // Checks that task manager counts a worker thread JS heap size.
780 // http://crbug.com/241066
781 // Disabled because this test is inherently flaky: http://crbug.com/259368
782 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DISABLED_WebWorkerJSHeapMemory) {
783 ShowTaskManager();
784 ui_test_utils::NavigateToURL(browser(), GetTestURL());
785 const int extra_timeout_ms = 500;
786 size_t minimal_heap_size = 2 * 1024 * 1024 * sizeof(void*);
787 std::string test_js = base::StringPrintf(
788 "var blob = new Blob([\n"
789 " 'mem = new Array(%lu);',\n"
790 " 'for (var i = 0; i < mem.length; i += 16) mem[i] = i;',\n"
791 " 'postMessage(i);']);\n"
792 "blobURL = window.URL.createObjectURL(blob);\n"
793 "worker = new Worker(blobURL);\n"
794 "// Give the task manager few seconds to poll for JS heap sizes.\n"
795 "worker.onmessage = setTimeout.bind(\n"
796 " this,\n"
797 " function () { window.domAutomationController.send(true); },\n"
798 " %d);\n"
799 "worker.postMessage('go');\n",
800 static_cast<unsigned long>(minimal_heap_size),
801 GetUpdateTimeMs() + extra_timeout_ms);
802 bool ok;
803 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
804 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok));
805 ASSERT_TRUE(ok);
807 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
808 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
809 int resource_index = FindResourceIndex(MatchTab("title1.html"));
810 size_t result;
812 ASSERT_TRUE(model()->GetV8Memory(resource_index, &result));
813 LOG(INFO) << "Got V8 Heap Size " << result << " bytes";
814 EXPECT_GE(result, minimal_heap_size);
816 ASSERT_TRUE(model()->GetV8MemoryUsed(resource_index, &result));
817 LOG(INFO) << "Got V8 Used Heap Size " << result << " bytes";
818 EXPECT_GE(result, minimal_heap_size);
821 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewDockedWindow) {
822 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
824 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
825 DevToolsWindow* devtools =
826 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
827 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
828 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
829 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
832 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewUndockedWindow) {
833 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
834 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
835 DevToolsWindow* devtools =
836 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
837 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
838 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
839 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
842 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldDockedWindow) {
843 DevToolsWindow* devtools =
844 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
845 ShowTaskManager(); // Task manager shown AFTER dev tools window.
846 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
847 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
848 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
851 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldUnockedWindow) {
852 DevToolsWindow* devtools =
853 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
854 ShowTaskManager(); // Task manager shown AFTER dev tools window.
855 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
856 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
857 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
860 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, KillSubframe) {
861 ShowTaskManager();
863 host_resolver()->AddRule("*", "127.0.0.1");
864 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
865 content::SetupCrossSiteRedirector(embedded_test_server());
867 GURL main_url(embedded_test_server()->GetURL(
868 "/cross-site/a.com/iframe_cross_site.html"));
869 browser()->OpenURL(content::OpenURLParams(main_url, content::Referrer(),
870 CURRENT_TAB,
871 ui::PAGE_TRANSITION_TYPED, false));
873 ASSERT_NO_FATAL_FAILURE(
874 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
875 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
877 if (!ShouldExpectSubframes()) {
878 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
879 } else {
880 ASSERT_NO_FATAL_FAILURE(
881 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
882 ASSERT_NO_FATAL_FAILURE(
883 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
884 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
885 int subframe_b = FindResourceIndex(MatchSubframe("http://b.com/"));
886 ASSERT_NE(-1, subframe_b);
887 ASSERT_TRUE(model()->GetResourceWebContents(subframe_b) != NULL);
888 ASSERT_TRUE(model()->CanActivate(subframe_b));
890 TaskManager::GetInstance()->KillProcess(subframe_b);
892 ASSERT_NO_FATAL_FAILURE(
893 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
894 ASSERT_NO_FATAL_FAILURE(
895 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
896 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
897 ASSERT_NO_FATAL_FAILURE(
898 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
901 HideTaskManager();
902 ShowTaskManager();
904 if (!ShouldExpectSubframes()) {
905 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
906 } else {
907 ASSERT_NO_FATAL_FAILURE(
908 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
909 ASSERT_NO_FATAL_FAILURE(
910 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
911 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
912 ASSERT_NO_FATAL_FAILURE(
913 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
917 // Tests what happens when a tab navigates to a site (a.com) that it previously
918 // has a cross-process subframe into (b.com).
920 // TODO(nick): http://crbug.com/442532. Disabled because the second navigation
921 // hits an ASSERT(frame()) in WebLocalFrameImpl::loadRequest under --site-per-
922 // process.
923 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
924 DISABLED_NavigateToSubframeProcess) {
925 ShowTaskManager();
927 host_resolver()->AddRule("*", "127.0.0.1");
928 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
929 content::SetupCrossSiteRedirector(embedded_test_server());
931 // Navigate the tab to a page on a.com with cross-process subframes to
932 // b.com and c.com.
933 GURL a_dotcom(embedded_test_server()->GetURL(
934 "/cross-site/a.com/iframe_cross_site.html"));
935 browser()->OpenURL(content::OpenURLParams(a_dotcom, 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()));
953 // Now navigate to a page on b.com with a simple (same-site) iframe.
954 // This should not show any subframe resources in the task manager.
955 GURL b_dotcom(
956 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
958 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(),
959 CURRENT_TAB,
960 ui::PAGE_TRANSITION_TYPED, false));
962 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
963 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
964 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
965 HideTaskManager();
966 ShowTaskManager();
967 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
968 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
969 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
972 // TODO(nick): Fails flakily under OOPIF due to a ASSERT_NOT_REACHED in
973 // WebRemoteFrame, at least under debug OSX. http://crbug.com/437956
974 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
975 DISABLED_NavigateToSiteWithSubframeToOriginalSite) {
976 ShowTaskManager();
978 host_resolver()->AddRule("*", "127.0.0.1");
979 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
980 content::SetupCrossSiteRedirector(embedded_test_server());
982 // Navigate to a page on b.com with a simple (same-site) iframe.
983 // This should not show any subframe resources in the task manager.
984 GURL b_dotcom(
985 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
987 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(),
988 CURRENT_TAB,
989 ui::PAGE_TRANSITION_TYPED, false));
991 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
992 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
993 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
995 // Now navigate the tab to a page on a.com with cross-process subframes to
996 // b.com and c.com.
997 GURL a_dotcom(embedded_test_server()->GetURL(
998 "/cross-site/a.com/iframe_cross_site.html"));
999 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
1000 CURRENT_TAB,
1001 ui::PAGE_TRANSITION_TYPED, false));
1003 ASSERT_NO_FATAL_FAILURE(
1004 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1005 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1007 if (!ShouldExpectSubframes()) {
1008 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1009 } else {
1010 ASSERT_NO_FATAL_FAILURE(
1011 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1012 ASSERT_NO_FATAL_FAILURE(
1013 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1014 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1017 HideTaskManager();
1018 ShowTaskManager();
1020 if (!ShouldExpectSubframes()) {
1021 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1022 } else {
1023 ASSERT_NO_FATAL_FAILURE(
1024 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1025 ASSERT_NO_FATAL_FAILURE(
1026 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1027 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1031 // Tests what happens when a tab navigates a cross-frame iframe (to b.com)
1032 // back to the site of the parent document (a.com).
1033 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
1034 CrossSiteIframeBecomesSameSite) {
1035 ShowTaskManager();
1037 host_resolver()->AddRule("*", "127.0.0.1");
1038 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
1039 content::SetupCrossSiteRedirector(embedded_test_server());
1041 // Navigate the tab to a page on a.com with cross-process subframes to
1042 // b.com and c.com.
1043 GURL a_dotcom(embedded_test_server()->GetURL(
1044 "/cross-site/a.com/iframe_cross_site.html"));
1045 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
1046 CURRENT_TAB,
1047 ui::PAGE_TRANSITION_TYPED, false));
1049 ASSERT_NO_FATAL_FAILURE(
1050 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
1051 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1053 if (!ShouldExpectSubframes()) {
1054 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1055 } else {
1056 ASSERT_NO_FATAL_FAILURE(
1057 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1058 ASSERT_NO_FATAL_FAILURE(
1059 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1060 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1063 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe
1064 ASSERT_TRUE(content::ExecuteScript(
1065 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
1066 "document.getElementById('frame1').src='/title1.html';"
1067 "document.title='aac';"));
1068 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1069 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1070 if (!ShouldExpectSubframes()) {
1071 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1072 } else {
1073 ASSERT_NO_FATAL_FAILURE(
1074 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1075 ASSERT_NO_FATAL_FAILURE(
1076 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1077 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1079 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1080 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1082 HideTaskManager();
1083 ShowTaskManager();
1085 if (!ShouldExpectSubframes()) {
1086 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1087 } else {
1088 ASSERT_NO_FATAL_FAILURE(
1089 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1090 ASSERT_NO_FATAL_FAILURE(
1091 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1092 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1094 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1095 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));