Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / task_manager / task_manager_browsertest.cc
blob6a17cf043ce7b4be59570a85aff1b1135c6ce784
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 "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/devtools/devtools_window_testing.h"
12 #include "chrome/browser/extensions/extension_browsertest.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/browser/notifications/desktop_notification_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/common/content_switches.h"
41 #include "content/public/test/browser_test_utils.h"
42 #include "content/public/test/content_browser_test_utils.h"
43 #include "extensions/browser/extension_system.h"
44 #include "extensions/common/extension.h"
45 #include "net/dns/mock_host_resolver.h"
46 #include "net/test/embedded_test_server/embedded_test_server.h"
47 #include "testing/gtest/include/gtest/gtest.h"
48 #include "ui/base/l10n/l10n_util.h"
49 #include "ui/base/page_transition_types.h"
51 using content::WebContents;
52 using task_manager::browsertest_util::MatchAboutBlankTab;
53 using task_manager::browsertest_util::MatchAnyApp;
54 using task_manager::browsertest_util::MatchAnyExtension;
55 using task_manager::browsertest_util::MatchAnySubframe;
56 using task_manager::browsertest_util::MatchAnyTab;
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::WaitForTaskManagerRows;
63 namespace {
65 const base::FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
67 } // namespace
69 class TaskManagerBrowserTest : public ExtensionBrowserTest {
70 public:
71 TaskManagerBrowserTest() {}
72 ~TaskManagerBrowserTest() override {}
74 TaskManagerModel* model() const {
75 return TaskManager::GetInstance()->model();
78 void ShowTaskManager() {
79 EXPECT_EQ(0, model()->ResourceCount());
81 // Show the task manager. This populates the model, and helps with debugging
82 // (you see the task manager).
83 chrome::ShowTaskManager(browser());
86 void HideTaskManager() {
87 // Hide the task manager, and wait for the model to be depopulated.
88 chrome::HideTaskManager();
89 base::RunLoop().RunUntilIdle(); // OnWindowClosed happens asynchronously.
90 EXPECT_EQ(0, model()->ResourceCount());
93 void Refresh() {
94 model()->Refresh();
97 int GetUpdateTimeMs() {
98 return TaskManagerModel::kUpdateTimeMs;
101 GURL GetTestURL() {
102 return ui_test_utils::GetTestUrl(
103 base::FilePath(base::FilePath::kCurrentDirectory),
104 base::FilePath(kTitle1File));
107 int FindResourceIndex(const base::string16& title) {
108 for (int i = 0; i < model()->ResourceCount(); ++i) {
109 if (title == model()->GetResourceTitle(i))
110 return i;
112 return -1;
115 protected:
116 void SetUpCommandLine(CommandLine* command_line) override {
117 ExtensionBrowserTest::SetUpCommandLine(command_line);
119 // Do not launch device discovery process.
120 command_line->AppendSwitch(switches::kDisableDeviceDiscoveryNotifications);
123 private:
124 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest);
127 // Parameterized variant of TaskManagerBrowserTest which runs with/without
128 // --site-per-process, which enables out of process iframes (OOPIFs).
129 class TaskManagerOOPIFBrowserTest : public TaskManagerBrowserTest,
130 public testing::WithParamInterface<bool> {
131 public:
132 TaskManagerOOPIFBrowserTest() {}
134 protected:
135 void SetUpCommandLine(CommandLine* command_line) override {
136 TaskManagerBrowserTest::SetUpCommandLine(command_line);
137 if (GetParam())
138 command_line->AppendSwitch(switches::kSitePerProcess);
141 bool ShouldExpectSubframes() {
142 return CommandLine::ForCurrentProcess()->HasSwitch(
143 switches::kSitePerProcess);
146 private:
147 DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest);
150 INSTANTIATE_TEST_CASE_P(, TaskManagerOOPIFBrowserTest, ::testing::Bool());
152 #if defined(OS_MACOSX) || defined(OS_LINUX)
153 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen
154 #else
155 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen
156 #endif
158 // Regression test for http://crbug.com/13361
159 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) {
160 ShowTaskManager();
163 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
164 ShowTaskManager();
165 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
166 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
167 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
169 // Open a new tab and make sure the task manager notices it.
170 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
172 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
173 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
175 // Close the tab and verify that we notice.
176 browser()->tab_strip_model()->CloseWebContentsAt(0,
177 TabStripModel::CLOSE_NONE);
178 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
179 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
182 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillTab) {
183 ShowTaskManager();
184 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
185 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
186 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
188 // Open a new tab and make sure the task manager notices it.
189 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
191 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
192 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
194 // Killing the tab via task manager should remove the row.
195 int tab = FindResourceIndex(MatchTab("title1.html"));
196 ASSERT_NE(-1, tab);
197 ASSERT_TRUE(model()->GetResourceWebContents(tab) != NULL);
198 ASSERT_TRUE(model()->CanActivate(tab));
199 TaskManager::GetInstance()->KillProcess(tab);
200 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html")));
201 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
203 // Tab should reappear in task manager upon reload.
204 chrome::Reload(browser(), CURRENT_TAB);
205 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html")));
206 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
209 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanel) {
210 ASSERT_TRUE(LoadExtension(
211 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
212 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
213 .AppendASCII("1.0.0.0")));
215 // Open a new panel to an extension url.
216 GURL url(
217 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
218 Panel* panel = PanelManager::GetInstance()->CreatePanel(
219 web_app::GenerateApplicationNameFromExtensionId(
220 last_loaded_extension_id()),
221 browser()->profile(),
222 url,
223 gfx::Rect(300, 400),
224 PanelManager::CREATE_AS_DOCKED);
226 // Make sure that a task manager model created after the panel shows the
227 // existence of the panel and the extension.
228 ShowTaskManager();
229 ASSERT_NO_FATAL_FAILURE(
230 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
231 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
233 MatchExtension(
234 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
235 "french_sentence.html")));
236 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
237 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
238 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
240 // Close the panel and verify that we notice.
241 panel->Close();
242 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
243 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
245 MatchExtension(
246 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
247 "french_sentence.html")));
248 ASSERT_NO_FATAL_FAILURE(
249 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
252 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanelChanges) {
253 ShowTaskManager();
254 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
255 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
257 ASSERT_TRUE(LoadExtension(
258 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
259 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
260 .AppendASCII("1.0.0.0")));
262 // Browser, the New Tab Page and Extension background page.
263 ASSERT_NO_FATAL_FAILURE(
264 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
265 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
266 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
268 // Open a new panel to an extension url and make sure we notice that.
269 GURL url(
270 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
271 Panel* panel = PanelManager::GetInstance()->CreatePanel(
272 web_app::GenerateApplicationNameFromExtensionId(
273 last_loaded_extension_id()),
274 browser()->profile(),
275 url,
276 gfx::Rect(300, 400),
277 PanelManager::CREATE_AS_DOCKED);
278 ASSERT_NO_FATAL_FAILURE(
279 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
280 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
282 MatchExtension(
283 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
284 "french_sentence.html")));
285 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
286 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
287 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
289 // Close the panel and verify that we notice.
290 panel->Close();
291 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
292 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
294 MatchExtension(
295 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
296 "french_sentence.html")));
297 ASSERT_NO_FATAL_FAILURE(
298 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
300 // Unload extension.
301 UnloadExtension(last_loaded_extension_id());
302 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
303 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
306 // Kills a process that has more than one task manager entry.
307 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaExtensionResource) {
308 ShowTaskManager();
309 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
310 .AppendASCII("Extensions")
311 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
312 .AppendASCII("1.0.0.0")));
314 // Open a new panel to an extension url.
315 GURL url(
316 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
317 "french_sentence.html");
318 PanelManager::GetInstance()->CreatePanel(
319 web_app::GenerateApplicationNameFromExtensionId(
320 last_loaded_extension_id()),
321 browser()->profile(),
322 url,
323 gfx::Rect(300, 400),
324 PanelManager::CREATE_AS_DOCKED);
326 ASSERT_NO_FATAL_FAILURE(
327 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
328 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
330 MatchExtension(
331 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
332 "french_sentence.html")));
333 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
334 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
335 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
337 // Kill the process via the BACKGROUND PAGE (not the panel). Verify that both
338 // the background page and the panel go away from the task manager.
339 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
340 ASSERT_NE(-1, background_page);
341 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
342 ASSERT_FALSE(model()->CanActivate(background_page));
343 TaskManager::GetInstance()->KillProcess(background_page);
344 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
345 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
348 // Kills a process that has more than one task manager entry. This test is the
349 // same as KillPanelViaExtensionResource except it does the kill via the other
350 // entry.
351 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaPanelResource) {
352 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
353 .AppendASCII("Extensions")
354 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
355 .AppendASCII("1.0.0.0")));
357 // Open a new panel to an extension url.
358 GURL url(
359 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
360 "french_sentence.html");
361 PanelManager::GetInstance()->CreatePanel(
362 web_app::GenerateApplicationNameFromExtensionId(
363 last_loaded_extension_id()),
364 browser()->profile(),
365 url,
366 gfx::Rect(300, 400),
367 PanelManager::CREATE_AS_DOCKED);
369 ShowTaskManager();
370 ASSERT_NO_FATAL_FAILURE(
371 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
372 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(
374 MatchExtension(
375 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
376 "french_sentence.html")));
377 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
378 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
379 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
381 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
382 ASSERT_NE(-1, background_page);
383 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
384 ASSERT_FALSE(model()->CanActivate(background_page));
386 // Kill the process via the PANEL RESOURCE (not the background page). Verify
387 // that both the background page and the panel go away from the task manager.
388 int panel = FindResourceIndex(MatchExtension(
389 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/"
390 "french_sentence.html"));
391 ASSERT_NE(-1, panel);
392 ASSERT_TRUE(model()->GetResourceWebContents(panel) != NULL);
393 ASSERT_TRUE(model()->CanActivate(panel));
394 TaskManager::GetInstance()->KillProcess(panel);
395 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
396 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
399 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabChanges) {
400 ShowTaskManager();
401 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
402 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
404 ASSERT_TRUE(LoadExtension(
405 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
406 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
407 .AppendASCII("1.0.0.0")));
409 // Browser, Extension background page, and the New Tab Page.
410 ASSERT_NO_FATAL_FAILURE(
411 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
412 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension()));
413 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
415 // Open a new tab to an extension URL. Afterwards, the third entry (background
416 // page) should be an extension resource whose title starts with "Extension:".
417 // The fourth entry (page.html) is also of type extension and has both a
418 // WebContents and an extension. The title should start with "Extension:".
419 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
420 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
421 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
422 ASSERT_NO_FATAL_FAILURE(
423 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
424 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
425 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
426 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
428 int extension_tab = FindResourceIndex(MatchExtension("Foobar"));
429 ASSERT_NE(-1, extension_tab);
430 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab) != NULL);
431 ASSERT_TRUE(model()->CanActivate(extension_tab));
433 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
434 ASSERT_NE(-1, background_page);
435 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
436 ASSERT_FALSE(model()->CanActivate(background_page));
439 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTab) {
440 // With the task manager closed, open a new tab to an extension URL.
441 // Afterwards, when we open the task manager, the third entry (background
442 // page) should be an extension resource whose title starts with "Extension:".
443 // The fourth entry (page.html) is also of type extension and has both a
444 // WebContents and an extension. The title should start with "Extension:".
445 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good")
446 .AppendASCII("Extensions")
447 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
448 .AppendASCII("1.0.0.0")));
449 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
450 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
452 ShowTaskManager();
453 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar")));
454 ASSERT_NO_FATAL_FAILURE(
455 WaitForTaskManagerRows(1, MatchExtension("My extension 1")));
456 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension()));
457 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
458 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
460 int extension_tab = FindResourceIndex(MatchExtension("Foobar"));
461 ASSERT_NE(-1, extension_tab);
462 ASSERT_TRUE(model()->GetResourceWebContents(extension_tab) != NULL);
463 ASSERT_TRUE(model()->CanActivate(extension_tab));
465 int background_page = FindResourceIndex(MatchExtension("My extension 1"));
466 ASSERT_NE(-1, background_page);
467 ASSERT_TRUE(model()->GetResourceWebContents(background_page) == NULL);
468 ASSERT_FALSE(model()->CanActivate(background_page));
471 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabChanges) {
472 ShowTaskManager();
474 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app")));
475 ExtensionService* service = extensions::ExtensionSystem::Get(
476 browser()->profile())->extension_service();
477 const extensions::Extension* extension =
478 service->GetExtensionById(last_loaded_extension_id(), false);
480 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
481 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
482 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
483 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
485 // Open a new tab to the app's launch URL and make sure we notice that.
486 GURL url(extension->GetResourceURL("main.html"));
487 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
489 // There should be 1 "App: " tab and the original new tab page.
490 ASSERT_NO_FATAL_FAILURE(
491 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
492 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
493 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
494 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
495 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
497 // Check that the third entry (main.html) is of type extension and has both
498 // a tab contents and an extension.
499 int app_tab = FindResourceIndex(MatchApp("Packaged App Test"));
500 ASSERT_NE(-1, app_tab);
501 ASSERT_TRUE(model()->GetResourceWebContents(app_tab) != NULL);
502 ASSERT_TRUE(model()->CanActivate(app_tab));
503 ASSERT_EQ(task_manager::Resource::EXTENSION,
504 model()->GetResourceType(app_tab));
505 ASSERT_EQ(2, browser()->tab_strip_model()->count());
507 // Unload extension to make sure the tab goes away.
508 UnloadExtension(last_loaded_extension_id());
510 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
511 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
512 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
513 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
514 ASSERT_EQ(1, browser()->tab_strip_model()->count());
517 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTab) {
518 ASSERT_TRUE(LoadExtension(
519 test_data_dir_.AppendASCII("packaged_app")));
520 ExtensionService* service = extensions::ExtensionSystem::Get(
521 browser()->profile())->extension_service();
522 const extensions::Extension* extension =
523 service->GetExtensionById(last_loaded_extension_id(), false);
525 // Open a new tab to the app's launch URL and make sure we notice that.
526 GURL url(extension->GetResourceURL("main.html"));
527 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
529 ShowTaskManager();
531 ASSERT_NO_FATAL_FAILURE(
532 WaitForTaskManagerRows(1, MatchApp("Packaged App Test")));
533 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
534 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
535 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
537 // Check that the third entry (main.html) is of type extension and has both
538 // a tab contents and an extension.
539 int app_tab = FindResourceIndex(MatchApp("Packaged App Test"));
540 ASSERT_NE(-1, app_tab);
541 ASSERT_TRUE(model()->GetResourceWebContents(app_tab) != NULL);
542 ASSERT_TRUE(model()->CanActivate(app_tab));
543 ASSERT_EQ(task_manager::Resource::EXTENSION,
544 model()->GetResourceType(app_tab));
547 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabChanges) {
548 ShowTaskManager();
550 // The app under test acts on URLs whose host is "localhost",
551 // so the URLs we navigate to must have host "localhost".
552 host_resolver()->AddRule("*", "127.0.0.1");
553 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
554 GURL::Replacements replace_host;
555 std::string host_str("localhost"); // must stay in scope with replace_host
556 replace_host.SetHostStr(host_str);
557 GURL base_url = embedded_test_server()->GetURL(
558 "/extensions/api_test/app_process/");
559 base_url = base_url.ReplaceComponents(replace_host);
561 // Open a new tab to an app URL before the app is loaded.
562 GURL url(base_url.Resolve("path1/empty.html"));
563 content::WindowedNotificationObserver observer(
564 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
565 content::NotificationService::AllSources());
566 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
567 observer.Wait();
569 // Check that the new entry's title starts with "Tab:".
570 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
572 // Load the hosted app and make sure it still starts with "Tab:",
573 // since it hasn't changed to an app process yet.
574 ASSERT_TRUE(LoadExtension(
575 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
576 // Force the TaskManager to query the title.
577 Refresh();
578 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
579 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
580 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
581 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
583 // Now reload and check that the last entry's title now starts with "App:".
584 ui_test_utils::NavigateToURL(browser(), url);
586 // Force the TaskManager to query the title.
587 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
588 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
589 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
590 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp("Unmodified")));
591 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
593 // Disable extension.
594 DisableExtension(last_loaded_extension_id());
596 // The hosted app should now show up as a normal "Tab: ".
597 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
598 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
599 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
600 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
601 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
603 // Reload the page.
604 ui_test_utils::NavigateToURL(browser(), url);
606 // No change expected.
607 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
608 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
609 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified")));
610 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
611 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
614 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabAfterReload) {
615 // The app under test acts on URLs whose host is "localhost",
616 // so the URLs we navigate to must have host "localhost".
617 host_resolver()->AddRule("*", "127.0.0.1");
618 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
619 GURL::Replacements replace_host;
620 std::string host_str("localhost"); // must stay in scope with replace_host
621 replace_host.SetHostStr(host_str);
622 GURL base_url =
623 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
624 base_url = base_url.ReplaceComponents(replace_host);
626 // Open a new tab to an app URL before the app is loaded.
627 GURL url(base_url.Resolve("path1/empty.html"));
628 content::WindowedNotificationObserver observer(
629 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
630 content::NotificationService::AllSources());
631 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
632 observer.Wait();
634 // Load the hosted app and make sure it still starts with "Tab:",
635 // since it hasn't changed to an app process yet.
636 ASSERT_TRUE(LoadExtension(
637 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
639 // Now reload, which should transition this tab to being an App.
640 ui_test_utils::NavigateToURL(browser(), url);
642 ShowTaskManager();
644 // The TaskManager should show this as an "App: "
645 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
646 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
647 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
650 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabBeforeReload) {
651 // The app under test acts on URLs whose host is "localhost",
652 // so the URLs we navigate to must have host "localhost".
653 host_resolver()->AddRule("*", "127.0.0.1");
654 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
655 GURL::Replacements replace_host;
656 std::string host_str("localhost"); // must stay in scope with replace_host
657 replace_host.SetHostStr(host_str);
658 GURL base_url =
659 embedded_test_server()->GetURL("/extensions/api_test/app_process/");
660 base_url = base_url.ReplaceComponents(replace_host);
662 // Open a new tab to an app URL before the app is loaded.
663 GURL url(base_url.Resolve("path1/empty.html"));
664 content::WindowedNotificationObserver observer(
665 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
666 content::NotificationService::AllSources());
667 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
668 observer.Wait();
670 // Load the hosted app and make sure it still starts with "Tab:",
671 // since it hasn't changed to an app process yet.
672 ASSERT_TRUE(LoadExtension(
673 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
675 ShowTaskManager();
677 // The TaskManager should show this as a "Tab: " because the page hasn't been
678 // reloaded since the hosted app was installed.
679 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
680 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp()));
681 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension()));
684 // Regression test for http://crbug.com/18693.
685 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) {
686 ShowTaskManager();
687 ASSERT_TRUE(LoadExtension(
688 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
690 // Wait until we see the loaded extension in the task manager (the three
691 // resources are: the browser process, New Tab Page, and the extension).
692 ASSERT_NO_FATAL_FAILURE(
693 WaitForTaskManagerRows(1, MatchExtension("background_page")));
695 // Reload the extension a few times and make sure our resource count doesn't
696 // increase.
697 std::string extension_id = last_loaded_extension_id();
698 for (int i = 1; i <= 5; i++) {
699 SCOPED_TRACE(testing::Message() << "Reloading extension for the " << i
700 << "th time.");
701 ReloadExtension(extension_id);
702 ASSERT_NO_FATAL_FAILURE(
703 WaitForTaskManagerRows(1, MatchExtension("background_page")));
707 // Crashy, http://crbug.com/42301.
708 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
709 DISABLED_PopulateWebCacheFields) {
710 ShowTaskManager();
711 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
713 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
715 // Open a new tab and make sure we notice that.
716 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED);
717 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
719 // Check that we get some value for the cache columns.
720 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count),
721 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
722 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count),
723 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
724 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count),
725 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
728 // Checks that task manager counts a worker thread JS heap size.
729 // http://crbug.com/241066
730 // Flaky, http://crbug.com/259368
731 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DISABLED_WebWorkerJSHeapMemory) {
732 ui_test_utils::NavigateToURL(browser(), GetTestURL());
733 const int extra_timeout_ms = 500;
734 size_t minimal_heap_size = 2 * 1024 * 1024 * sizeof(void*);
735 std::string test_js = base::StringPrintf(
736 "var blob = new Blob([\n"
737 " 'mem = new Array(%lu);',\n"
738 " 'for (var i = 0; i < mem.length; i += 16) mem[i] = i;',\n"
739 " 'postMessage();']);\n"
740 "blobURL = window.URL.createObjectURL(blob);\n"
741 "worker = new Worker(blobURL);\n"
742 "// Give the task manager few seconds to poll for JS heap sizes.\n"
743 "worker.onmessage = setTimeout.bind(\n"
744 " this,\n"
745 " function () { window.domAutomationController.send(true); },\n"
746 " %d);\n"
747 "worker.postMessage();\n",
748 static_cast<unsigned long>(minimal_heap_size),
749 GetUpdateTimeMs() + extra_timeout_ms);
750 bool ok;
751 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
752 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok));
753 ASSERT_TRUE(ok);
755 int resource_index = TaskManager::GetInstance()->model()->ResourceCount() - 1;
756 size_t result;
758 ASSERT_TRUE(model()->GetV8Memory(resource_index, &result));
759 LOG(INFO) << "Got V8 Heap Size " << result << " bytes";
760 EXPECT_GE(result, minimal_heap_size);
762 ASSERT_TRUE(model()->GetV8MemoryUsed(resource_index, &result));
763 LOG(INFO) << "Got V8 Used Heap Size " << result << " bytes";
764 EXPECT_GE(result, minimal_heap_size);
767 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewDockedWindow) {
768 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
770 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
771 DevToolsWindow* devtools =
772 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
773 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
774 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
775 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
778 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewUndockedWindow) {
779 ShowTaskManager(); // Task manager shown BEFORE dev tools window.
780 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
781 DevToolsWindow* devtools =
782 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
783 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
784 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
785 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
788 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldDockedWindow) {
789 DevToolsWindow* devtools =
790 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
791 ShowTaskManager(); // Task manager shown AFTER dev tools window.
792 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
793 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab()));
794 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
797 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldUnockedWindow) {
798 DevToolsWindow* devtools =
799 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false);
800 ShowTaskManager(); // Task manager shown AFTER dev tools window.
801 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
802 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab()));
803 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
806 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, KillSubframe) {
807 ShowTaskManager();
809 host_resolver()->AddRule("*", "127.0.0.1");
810 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
811 content::SetupCrossSiteRedirector(embedded_test_server());
813 GURL main_url(embedded_test_server()->GetURL(
814 "/cross-site/a.com/iframe_cross_site.html"));
815 browser()->OpenURL(content::OpenURLParams(main_url, content::Referrer(),
816 CURRENT_TAB,
817 ui::PAGE_TRANSITION_TYPED, false));
819 ASSERT_NO_FATAL_FAILURE(
820 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
821 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
823 if (!ShouldExpectSubframes()) {
824 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
825 } else {
826 ASSERT_NO_FATAL_FAILURE(
827 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
828 ASSERT_NO_FATAL_FAILURE(
829 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
830 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
831 int subframe_b = FindResourceIndex(MatchSubframe("http://b.com/"));
832 ASSERT_NE(-1, subframe_b);
833 ASSERT_TRUE(model()->GetResourceWebContents(subframe_b) != NULL);
834 ASSERT_TRUE(model()->CanActivate(subframe_b));
836 TaskManager::GetInstance()->KillProcess(subframe_b);
838 ASSERT_NO_FATAL_FAILURE(
839 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
840 ASSERT_NO_FATAL_FAILURE(
841 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
842 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
843 ASSERT_NO_FATAL_FAILURE(
844 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
847 HideTaskManager();
848 ShowTaskManager();
850 if (!ShouldExpectSubframes()) {
851 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
852 } else {
853 ASSERT_NO_FATAL_FAILURE(
854 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
855 ASSERT_NO_FATAL_FAILURE(
856 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
857 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
858 ASSERT_NO_FATAL_FAILURE(
859 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
863 // Tests what happens when a tab navigates to a site (a.com) that it previously
864 // has a cross-process subframe into (b.com).
866 // TODO(nick): Disabled because the second navigation hits an ASSERT(frame()) in
867 // WebLocalFrameImpl::loadRequest under --site-per-process.
868 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
869 DISABLED_NavigateToSubframeProcess) {
870 ShowTaskManager();
872 host_resolver()->AddRule("*", "127.0.0.1");
873 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
874 content::SetupCrossSiteRedirector(embedded_test_server());
876 // Navigate the tab to a page on a.com with cross-process subframes to
877 // b.com and c.com.
878 GURL a_dotcom(embedded_test_server()->GetURL(
879 "/cross-site/a.com/iframe_cross_site.html"));
880 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
881 CURRENT_TAB,
882 ui::PAGE_TRANSITION_TYPED, false));
884 ASSERT_NO_FATAL_FAILURE(
885 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
886 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
888 if (!ShouldExpectSubframes()) {
889 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
890 } else {
891 ASSERT_NO_FATAL_FAILURE(
892 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
893 ASSERT_NO_FATAL_FAILURE(
894 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
895 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
898 // Now navigate to a page on b.com with a simple (same-site) iframe.
899 // This should not show any subframe resources in the task manager.
900 GURL b_dotcom(
901 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
903 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(),
904 CURRENT_TAB,
905 ui::PAGE_TRANSITION_TYPED, false));
907 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
908 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
909 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
910 HideTaskManager();
911 ShowTaskManager();
912 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
913 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
914 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
917 // TODO(nick): Fails flakily under OOPIF due to a ASSERT_NOT_REACHED in
918 // WebRemoteFrame, at least under debug OSX. http://crbug.com/437956
919 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
920 DISABLED_NavigateToSiteWithSubframeToOriginalSite) {
921 ShowTaskManager();
923 host_resolver()->AddRule("*", "127.0.0.1");
924 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
925 content::SetupCrossSiteRedirector(embedded_test_server());
927 // Navigate to a page on b.com with a simple (same-site) iframe.
928 // This should not show any subframe resources in the task manager.
929 GURL b_dotcom(
930 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html"));
932 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(),
933 CURRENT_TAB,
934 ui::PAGE_TRANSITION_TYPED, false));
936 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test")));
937 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
938 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
940 // Now navigate the tab to a page on a.com with cross-process subframes to
941 // b.com and c.com.
942 GURL a_dotcom(embedded_test_server()->GetURL(
943 "/cross-site/a.com/iframe_cross_site.html"));
944 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
945 CURRENT_TAB,
946 ui::PAGE_TRANSITION_TYPED, false));
948 ASSERT_NO_FATAL_FAILURE(
949 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
950 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
952 if (!ShouldExpectSubframes()) {
953 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
954 } else {
955 ASSERT_NO_FATAL_FAILURE(
956 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
957 ASSERT_NO_FATAL_FAILURE(
958 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
959 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
962 HideTaskManager();
963 ShowTaskManager();
965 if (!ShouldExpectSubframes()) {
966 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
967 } else {
968 ASSERT_NO_FATAL_FAILURE(
969 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
970 ASSERT_NO_FATAL_FAILURE(
971 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
972 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
976 // Tests what happens when a tab navigates a cross-frame iframe (to b.com)
977 // back to the site of the parent document (a.com).
979 // TODO(nick): Disabled because the second navigation crashes the renderer
980 // under --site-per-process during blink::Frame::detach().
981 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest,
982 DISABLED_CrossSiteIframeBecomesSameSite) {
983 ShowTaskManager();
985 host_resolver()->AddRule("*", "127.0.0.1");
986 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
987 content::SetupCrossSiteRedirector(embedded_test_server());
989 // Navigate the tab to a page on a.com with cross-process subframes to
990 // b.com and c.com.
991 GURL a_dotcom(embedded_test_server()->GetURL(
992 "/cross-site/a.com/iframe_cross_site.html"));
993 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(),
994 CURRENT_TAB,
995 ui::PAGE_TRANSITION_TYPED, false));
997 ASSERT_NO_FATAL_FAILURE(
998 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test")));
999 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1001 if (!ShouldExpectSubframes()) {
1002 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1003 } else {
1004 ASSERT_NO_FATAL_FAILURE(
1005 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/")));
1006 ASSERT_NO_FATAL_FAILURE(
1007 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1008 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe()));
1011 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe
1012 ASSERT_TRUE(content::ExecuteScript(
1013 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
1014 "document.getElementById('frame1').src='/title1.html';"
1015 "document.title='aac';"));
1016 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1017 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1018 if (!ShouldExpectSubframes()) {
1019 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1020 } else {
1021 ASSERT_NO_FATAL_FAILURE(
1022 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1023 ASSERT_NO_FATAL_FAILURE(
1024 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1025 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1027 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1028 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1030 HideTaskManager();
1031 ShowTaskManager();
1033 if (!ShouldExpectSubframes()) {
1034 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe()));
1035 } else {
1036 ASSERT_NO_FATAL_FAILURE(
1037 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/")));
1038 ASSERT_NO_FATAL_FAILURE(
1039 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/")));
1040 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe()));
1042 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac")));
1043 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));