| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/task_manager/task_manager.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/strings/stringprintf.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | |
| 13 #include "build/build_config.h" | |
| 14 #include "chrome/browser/browser_process.h" | |
| 15 #include "chrome/browser/chrome_notification_types.h" | |
| 16 #include "chrome/browser/devtools/devtools_window_testing.h" | |
| 17 #include "chrome/browser/extensions/extension_browsertest.h" | |
| 18 #include "chrome/browser/extensions/extension_service.h" | |
| 19 #include "chrome/browser/infobars/infobar_service.h" | |
| 20 #include "chrome/browser/notifications/notification.h" | |
| 21 #include "chrome/browser/notifications/notification_test_util.h" | |
| 22 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 23 #include "chrome/browser/profiles/profile.h" | |
| 24 #include "chrome/browser/task_management/task_manager_tester.h" | |
| 25 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | |
| 26 #include "chrome/browser/ui/browser.h" | |
| 27 #include "chrome/browser/ui/browser_commands.h" | |
| 28 #include "chrome/browser/ui/browser_dialogs.h" | |
| 29 #include "chrome/browser/ui/browser_window.h" | |
| 30 #include "chrome/browser/ui/panels/panel.h" | |
| 31 #include "chrome/browser/ui/panels/panel_manager.h" | |
| 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 33 #include "chrome/browser/web_applications/web_app.h" | |
| 34 #include "chrome/common/chrome_switches.h" | |
| 35 #include "chrome/grit/generated_resources.h" | |
| 36 #include "chrome/test/base/in_process_browser_test.h" | |
| 37 #include "chrome/test/base/ui_test_utils.h" | |
| 38 #include "components/infobars/core/confirm_infobar_delegate.h" | |
| 39 #include "components/infobars/core/infobar.h" | |
| 40 #include "content/public/browser/notification_service.h" | |
| 41 #include "content/public/browser/page_navigator.h" | |
| 42 #include "content/public/browser/render_frame_host.h" | |
| 43 #include "content/public/test/browser_test_utils.h" | |
| 44 #include "content/public/test/content_browser_test_utils.h" | |
| 45 #include "extensions/browser/extension_system.h" | |
| 46 #include "extensions/common/extension.h" | |
| 47 #include "net/dns/mock_host_resolver.h" | |
| 48 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 49 #include "testing/gtest/include/gtest/gtest.h" | |
| 50 #include "ui/base/l10n/l10n_util.h" | |
| 51 #include "ui/base/page_transition_types.h" | |
| 52 | |
| 53 using content::WebContents; | |
| 54 using task_manager::browsertest_util::ColumnSpecifier; | |
| 55 using task_manager::browsertest_util::MatchAboutBlankTab; | |
| 56 using task_manager::browsertest_util::MatchAnyApp; | |
| 57 using task_manager::browsertest_util::MatchAnyExtension; | |
| 58 using task_manager::browsertest_util::MatchAnySubframe; | |
| 59 using task_manager::browsertest_util::MatchAnyTab; | |
| 60 using task_manager::browsertest_util::MatchAnyUtility; | |
| 61 using task_manager::browsertest_util::MatchApp; | |
| 62 using task_manager::browsertest_util::MatchExtension; | |
| 63 using task_manager::browsertest_util::MatchSubframe; | |
| 64 using task_manager::browsertest_util::MatchTab; | |
| 65 using task_manager::browsertest_util::MatchUtility; | |
| 66 using task_manager::browsertest_util::WaitForTaskManagerRows; | |
| 67 using task_manager::browsertest_util::WaitForTaskManagerStatToExceed; | |
| 68 | |
| 69 namespace { | |
| 70 | |
| 71 const base::FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); | |
| 72 | |
| 73 } // namespace | |
| 74 | |
| 75 // TODO(nick): Move this file into task_management. https://crbug.com/606963 | |
| 76 class TaskManagerBrowserTest : public ExtensionBrowserTest { | |
| 77 public: | |
| 78 TaskManagerBrowserTest() {} | |
| 79 ~TaskManagerBrowserTest() override {} | |
| 80 | |
| 81 task_management::TaskManagerTester* model() { return model_.get(); } | |
| 82 | |
| 83 void ShowTaskManager() { | |
| 84 // Show the task manager. This populates the model, and helps with debugging | |
| 85 // (you see the task manager). | |
| 86 chrome::ShowTaskManager(browser()); | |
| 87 model_ = task_management::TaskManagerTester::Create(base::Closure()); | |
| 88 } | |
| 89 | |
| 90 void HideTaskManager() { | |
| 91 model_.reset(); | |
| 92 | |
| 93 // Hide the task manager, and wait for it to go. | |
| 94 chrome::HideTaskManager(); | |
| 95 base::RunLoop().RunUntilIdle(); // OnWindowClosed happens asynchronously. | |
| 96 } | |
| 97 | |
| 98 void Refresh() { | |
| 99 // Refresh() isn't ever needed on the new task manager. | |
| 100 if (switches::NewTaskManagerEnabled()) | |
| 101 return; | |
| 102 TaskManager::GetInstance()->model()->Refresh(); | |
| 103 } | |
| 104 | |
| 105 GURL GetTestURL() { | |
| 106 return ui_test_utils::GetTestUrl( | |
| 107 base::FilePath(base::FilePath::kCurrentDirectory), | |
| 108 base::FilePath(kTitle1File)); | |
| 109 } | |
| 110 | |
| 111 int FindResourceIndex(const base::string16& title) { | |
| 112 for (int i = 0; i < model_->GetRowCount(); ++i) { | |
| 113 if (title == model_->GetRowTitle(i)) | |
| 114 return i; | |
| 115 } | |
| 116 return -1; | |
| 117 } | |
| 118 | |
| 119 // TODO(nick, afakhry): Remove this function. https://crbug.com/606963 | |
| 120 void DisableNewTaskManagerForBrokenTest() { | |
| 121 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 122 switches::kDisableNewTaskManager); | |
| 123 } | |
| 124 | |
| 125 protected: | |
| 126 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 127 ExtensionBrowserTest::SetUpCommandLine(command_line); | |
| 128 | |
| 129 // Do not launch device discovery process. | |
| 130 command_line->AppendSwitch(switches::kDisableDeviceDiscoveryNotifications); | |
| 131 } | |
| 132 | |
| 133 void TearDownOnMainThread() override { model_.reset(); } | |
| 134 | |
| 135 private: | |
| 136 std::unique_ptr<task_management::TaskManagerTester> model_; | |
| 137 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest); | |
| 138 }; | |
| 139 | |
| 140 class TaskManagerUtilityProcessBrowserTest : public TaskManagerBrowserTest { | |
| 141 public: | |
| 142 TaskManagerUtilityProcessBrowserTest() {} | |
| 143 | |
| 144 protected: | |
| 145 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 146 TaskManagerBrowserTest::SetUpCommandLine(command_line); | |
| 147 | |
| 148 // Enable out-of-process proxy resolver. Use a trivial PAC script to ensure | |
| 149 // that some javascript is being executed. | |
| 150 command_line->AppendSwitch(switches::kV8PacMojoOutOfProcess); | |
| 151 command_line->AppendSwitchASCII( | |
| 152 switches::kProxyPacUrl, | |
| 153 "data:,function FindProxyForURL(url, host){return \"DIRECT;\";}"); | |
| 154 } | |
| 155 | |
| 156 private: | |
| 157 DISALLOW_COPY_AND_ASSIGN(TaskManagerUtilityProcessBrowserTest); | |
| 158 }; | |
| 159 | |
| 160 // Parameterized variant of TaskManagerBrowserTest which runs with/without | |
| 161 // --site-per-process, which enables out of process iframes (OOPIFs). | |
| 162 class TaskManagerOOPIFBrowserTest : public TaskManagerBrowserTest, | |
| 163 public testing::WithParamInterface<bool> { | |
| 164 public: | |
| 165 TaskManagerOOPIFBrowserTest() {} | |
| 166 | |
| 167 protected: | |
| 168 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 169 TaskManagerBrowserTest::SetUpCommandLine(command_line); | |
| 170 if (GetParam()) | |
| 171 content::IsolateAllSitesForTesting(command_line); | |
| 172 } | |
| 173 | |
| 174 bool ShouldExpectSubframes() { | |
| 175 return content::AreAllSitesIsolatedForTesting(); | |
| 176 } | |
| 177 | |
| 178 private: | |
| 179 DISALLOW_COPY_AND_ASSIGN(TaskManagerOOPIFBrowserTest); | |
| 180 }; | |
| 181 | |
| 182 INSTANTIATE_TEST_CASE_P(, TaskManagerOOPIFBrowserTest, ::testing::Bool()); | |
| 183 | |
| 184 #if defined(OS_MACOSX) || defined(OS_LINUX) | |
| 185 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen | |
| 186 #else | |
| 187 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen | |
| 188 #endif | |
| 189 | |
| 190 // Regression test for http://crbug.com/13361 | |
| 191 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) { | |
| 192 ShowTaskManager(); | |
| 193 } | |
| 194 | |
| 195 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { | |
| 196 ShowTaskManager(); | |
| 197 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 198 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 199 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html"))); | |
| 200 | |
| 201 // Open a new tab and make sure the task manager notices it. | |
| 202 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED); | |
| 203 | |
| 204 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html"))); | |
| 205 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 206 | |
| 207 // Close the tab and verify that we notice. | |
| 208 browser()->tab_strip_model()->CloseWebContentsAt(0, | |
| 209 TabStripModel::CLOSE_NONE); | |
| 210 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html"))); | |
| 211 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 212 } | |
| 213 | |
| 214 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillTab) { | |
| 215 ShowTaskManager(); | |
| 216 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 217 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 218 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html"))); | |
| 219 | |
| 220 // Open a new tab and make sure the task manager notices it. | |
| 221 AddTabAtIndex(0, GetTestURL(), ui::PAGE_TRANSITION_TYPED); | |
| 222 | |
| 223 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html"))); | |
| 224 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 225 | |
| 226 // Killing the tab via task manager should remove the row. | |
| 227 int tab = FindResourceIndex(MatchTab("title1.html")); | |
| 228 ASSERT_NE(-1, tab); | |
| 229 ASSERT_NE(-1, model()->GetTabId(tab)); | |
| 230 model()->Kill(tab); | |
| 231 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchTab("title1.html"))); | |
| 232 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 233 | |
| 234 // Tab should reappear in task manager upon reload. | |
| 235 chrome::Reload(browser(), CURRENT_TAB); | |
| 236 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html"))); | |
| 237 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 238 } | |
| 239 | |
| 240 // Regression test for http://crbug.com/444945. | |
| 241 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NavigateAwayFromHungRenderer) { | |
| 242 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 243 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 244 ShowTaskManager(); | |
| 245 | |
| 246 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 247 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 248 | |
| 249 GURL url1(embedded_test_server()->GetURL("/title2.html")); | |
| 250 GURL url3(embedded_test_server()->GetURL("a.com", "/iframe.html")); | |
| 251 | |
| 252 // Open a new tab and make sure the task manager notices it. | |
| 253 AddTabAtIndex(0, url1, ui::PAGE_TRANSITION_TYPED); | |
| 254 ASSERT_NO_FATAL_FAILURE( | |
| 255 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness"))); | |
| 256 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 257 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 258 WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 259 | |
| 260 // Initiate a navigation that will create a new WebContents in the same | |
| 261 // SiteInstance. Then immediately hang the renderer so that title3.html can't | |
| 262 // load in this process. | |
| 263 content::WebContentsAddedObserver web_contents_added_observer; | |
| 264 int dummy_value = 0; | |
| 265 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 266 tab1->GetMainFrame(), | |
| 267 "window.open('title3.html', '_blank');\n" | |
| 268 "window.domAutomationController.send(55);\n" | |
| 269 "while(1);", | |
| 270 &dummy_value)); | |
| 271 | |
| 272 // Blocks until a new WebContents appears as a result of window.open(). | |
| 273 WebContents* tab2 = web_contents_added_observer.GetWebContents(); | |
| 274 | |
| 275 // Make sure the new WebContents is in tab1's hung renderer process. | |
| 276 ASSERT_NE(nullptr, tab2); | |
| 277 ASSERT_NE(tab1, tab2); | |
| 278 ASSERT_EQ(tab1->GetMainFrame()->GetProcess(), | |
| 279 tab2->GetMainFrame()->GetProcess()) | |
| 280 << "New WebContents must be in the same process as the old WebContents, " | |
| 281 << "so that the new tab doesn't finish loading (what this test is all " | |
| 282 << "about)"; | |
| 283 ASSERT_EQ(tab1->GetSiteInstance(), tab2->GetSiteInstance()) | |
| 284 << "New WebContents must initially be in the same site instance as the " | |
| 285 << "old WebContents"; | |
| 286 | |
| 287 // Now navigate this tab to a different site. This should wind up in a | |
| 288 // different renderer process, so it should complete and show up in the task | |
| 289 // manager. | |
| 290 tab2->OpenURL(content::OpenURLParams(url3, content::Referrer(), CURRENT_TAB, | |
| 291 ui::PAGE_TRANSITION_TYPED, false)); | |
| 292 | |
| 293 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test"))); | |
| 294 } | |
| 295 | |
| 296 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanel) { | |
| 297 ASSERT_TRUE(LoadExtension( | |
| 298 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | |
| 299 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 300 .AppendASCII("1.0.0.0"))); | |
| 301 | |
| 302 // Open a new panel to an extension url. | |
| 303 GURL url( | |
| 304 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html"); | |
| 305 Panel* docked_panel = PanelManager::GetInstance()->CreatePanel( | |
| 306 web_app::GenerateApplicationNameFromExtensionId( | |
| 307 last_loaded_extension_id()), | |
| 308 browser()->profile(), url, nullptr, gfx::Rect(300, 400), | |
| 309 PanelManager::CREATE_AS_DOCKED); | |
| 310 docked_panel->Show(); | |
| 311 | |
| 312 // Make sure that a task manager model created after the panel shows the | |
| 313 // existence of the panel and the extension. | |
| 314 ShowTaskManager(); | |
| 315 ASSERT_NO_FATAL_FAILURE( | |
| 316 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 317 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 318 1, | |
| 319 MatchExtension( | |
| 320 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 321 "french_sentence.html"))); | |
| 322 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 323 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 324 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 325 | |
| 326 // Create a second, detached panel. | |
| 327 Panel* detached_panel = PanelManager::GetInstance()->CreatePanel( | |
| 328 web_app::GenerateApplicationNameFromExtensionId( | |
| 329 last_loaded_extension_id()), | |
| 330 browser()->profile(), url, nullptr, gfx::Rect(150, 150), | |
| 331 PanelManager::CREATE_AS_DETACHED); | |
| 332 detached_panel->ShowInactive(); | |
| 333 | |
| 334 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 335 2, MatchExtension("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 336 "french_sentence.html"))); | |
| 337 ASSERT_NO_FATAL_FAILURE( | |
| 338 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 339 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyExtension())); | |
| 340 | |
| 341 // Close the panels and verify that we notice. | |
| 342 docked_panel->Close(); | |
| 343 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 344 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 345 1, MatchExtension("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 346 "french_sentence.html"))); | |
| 347 ASSERT_NO_FATAL_FAILURE( | |
| 348 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 349 | |
| 350 detached_panel->Close(); | |
| 351 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension())); | |
| 352 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 353 0, | |
| 354 MatchExtension( | |
| 355 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 356 "french_sentence.html"))); | |
| 357 ASSERT_NO_FATAL_FAILURE( | |
| 358 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 359 } | |
| 360 | |
| 361 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanelChanges) { | |
| 362 ShowTaskManager(); | |
| 363 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 364 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 365 | |
| 366 ASSERT_TRUE(LoadExtension( | |
| 367 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | |
| 368 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 369 .AppendASCII("1.0.0.0"))); | |
| 370 | |
| 371 // Browser, the New Tab Page and Extension background page. | |
| 372 ASSERT_NO_FATAL_FAILURE( | |
| 373 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 374 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension())); | |
| 375 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 376 | |
| 377 // Open a new panel to an extension url and make sure we notice that. | |
| 378 GURL url( | |
| 379 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html"); | |
| 380 Panel* panel = PanelManager::GetInstance()->CreatePanel( | |
| 381 web_app::GenerateApplicationNameFromExtensionId( | |
| 382 last_loaded_extension_id()), | |
| 383 browser()->profile(), | |
| 384 url, | |
| 385 nullptr, | |
| 386 gfx::Rect(300, 400), | |
| 387 PanelManager::CREATE_AS_DOCKED); | |
| 388 panel->ShowInactive(); | |
| 389 | |
| 390 ASSERT_NO_FATAL_FAILURE( | |
| 391 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 392 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 393 1, | |
| 394 MatchExtension( | |
| 395 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 396 "french_sentence.html"))); | |
| 397 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 398 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 399 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 400 | |
| 401 // Close the panel and verify that we notice. | |
| 402 panel->Close(); | |
| 403 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension())); | |
| 404 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 405 0, | |
| 406 MatchExtension( | |
| 407 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 408 "french_sentence.html"))); | |
| 409 ASSERT_NO_FATAL_FAILURE( | |
| 410 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 411 | |
| 412 // Unload extension. | |
| 413 UnloadExtension(last_loaded_extension_id()); | |
| 414 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 415 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 416 } | |
| 417 | |
| 418 // Kills a process that has more than one task manager entry. | |
| 419 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaExtensionResource) { | |
| 420 ShowTaskManager(); | |
| 421 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good") | |
| 422 .AppendASCII("Extensions") | |
| 423 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 424 .AppendASCII("1.0.0.0"))); | |
| 425 | |
| 426 // Open a new panel to an extension url. | |
| 427 GURL url( | |
| 428 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 429 "french_sentence.html"); | |
| 430 Panel* panel = PanelManager::GetInstance()->CreatePanel( | |
| 431 web_app::GenerateApplicationNameFromExtensionId( | |
| 432 last_loaded_extension_id()), | |
| 433 browser()->profile(), | |
| 434 url, | |
| 435 nullptr, | |
| 436 gfx::Rect(300, 400), | |
| 437 PanelManager::CREATE_AS_DETACHED); | |
| 438 panel->Show(); | |
| 439 | |
| 440 ASSERT_NO_FATAL_FAILURE( | |
| 441 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 442 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 443 1, | |
| 444 MatchExtension( | |
| 445 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 446 "french_sentence.html"))); | |
| 447 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 448 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 449 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 450 | |
| 451 // Kill the process via the BACKGROUND PAGE (not the panel). Verify that both | |
| 452 // the background page and the panel go away from the task manager. | |
| 453 int background_page = FindResourceIndex(MatchExtension("My extension 1")); | |
| 454 ASSERT_NE(-1, background_page); | |
| 455 ASSERT_EQ(-1, model()->GetTabId(background_page)); | |
| 456 model()->Kill(background_page); | |
| 457 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 458 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 459 } | |
| 460 | |
| 461 // Kills a process that has more than one task manager entry. This test is the | |
| 462 // same as KillPanelViaExtensionResource except it does the kill via the other | |
| 463 // entry. | |
| 464 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaPanelResource) { | |
| 465 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good") | |
| 466 .AppendASCII("Extensions") | |
| 467 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 468 .AppendASCII("1.0.0.0"))); | |
| 469 | |
| 470 // Open a new panel to an extension url. | |
| 471 GURL url( | |
| 472 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 473 "french_sentence.html"); | |
| 474 Panel* panel = PanelManager::GetInstance()->CreatePanel( | |
| 475 web_app::GenerateApplicationNameFromExtensionId( | |
| 476 last_loaded_extension_id()), | |
| 477 browser()->profile(), | |
| 478 url, | |
| 479 nullptr, | |
| 480 gfx::Rect(300, 400), | |
| 481 PanelManager::CREATE_AS_DETACHED); | |
| 482 panel->ShowInactive(); | |
| 483 | |
| 484 ShowTaskManager(); | |
| 485 ASSERT_NO_FATAL_FAILURE( | |
| 486 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 487 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 488 1, | |
| 489 MatchExtension( | |
| 490 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 491 "french_sentence.html"))); | |
| 492 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 493 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 494 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 495 | |
| 496 int background_page = FindResourceIndex(MatchExtension("My extension 1")); | |
| 497 ASSERT_NE(-1, background_page); | |
| 498 ASSERT_EQ(-1, model()->GetTabId(background_page)); | |
| 499 | |
| 500 // Kill the process via the PANEL RESOURCE (not the background page). Verify | |
| 501 // that both the background page and the panel go away from the task manager. | |
| 502 int panel_index = FindResourceIndex(MatchExtension( | |
| 503 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 504 "french_sentence.html")); | |
| 505 ASSERT_NE(-1, panel_index); | |
| 506 ASSERT_NE(-1, model()->GetTabId(panel_index)); | |
| 507 model()->Kill(panel_index); | |
| 508 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 509 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 510 } | |
| 511 | |
| 512 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabChanges) { | |
| 513 ShowTaskManager(); | |
| 514 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 515 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 516 | |
| 517 ASSERT_TRUE(LoadExtension( | |
| 518 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | |
| 519 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 520 .AppendASCII("1.0.0.0"))); | |
| 521 | |
| 522 // Browser, Extension background page, and the New Tab Page. | |
| 523 ASSERT_NO_FATAL_FAILURE( | |
| 524 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 525 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension())); | |
| 526 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 527 | |
| 528 // Open a new tab to an extension URL. Afterwards, the third entry (background | |
| 529 // page) should be an extension resource whose title starts with "Extension:". | |
| 530 // The fourth entry (page.html) is also of type extension and has both a | |
| 531 // WebContents and an extension. The title should start with "Extension:". | |
| 532 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); | |
| 533 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 534 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar"))); | |
| 535 ASSERT_NO_FATAL_FAILURE( | |
| 536 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 537 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 538 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 539 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 540 | |
| 541 int extension_tab = FindResourceIndex(MatchExtension("Foobar")); | |
| 542 ASSERT_NE(-1, extension_tab); | |
| 543 ASSERT_NE(-1, model()->GetTabId(extension_tab)); | |
| 544 | |
| 545 int background_page = FindResourceIndex(MatchExtension("My extension 1")); | |
| 546 ASSERT_NE(-1, background_page); | |
| 547 ASSERT_EQ(-1, model()->GetTabId(background_page)); | |
| 548 } | |
| 549 | |
| 550 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTab) { | |
| 551 // With the task manager closed, open a new tab to an extension URL. | |
| 552 // Afterwards, when we open the task manager, the third entry (background | |
| 553 // page) should be an extension resource whose title starts with "Extension:". | |
| 554 // The fourth entry (page.html) is also of type extension and has both a | |
| 555 // WebContents and an extension. The title should start with "Extension:". | |
| 556 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good") | |
| 557 .AppendASCII("Extensions") | |
| 558 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 559 .AppendASCII("1.0.0.0"))); | |
| 560 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); | |
| 561 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 562 | |
| 563 ShowTaskManager(); | |
| 564 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar"))); | |
| 565 ASSERT_NO_FATAL_FAILURE( | |
| 566 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 567 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 568 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 569 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 570 | |
| 571 int extension_tab = FindResourceIndex(MatchExtension("Foobar")); | |
| 572 ASSERT_NE(-1, extension_tab); | |
| 573 ASSERT_NE(-1, model()->GetTabId(extension_tab)); | |
| 574 | |
| 575 int background_page = FindResourceIndex(MatchExtension("My extension 1")); | |
| 576 ASSERT_NE(-1, background_page); | |
| 577 ASSERT_EQ(-1, model()->GetTabId(background_page)); | |
| 578 } | |
| 579 | |
| 580 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabChanges) { | |
| 581 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 582 // "Extension: Packaged App Test" instead of "App: Packaged App Test". | |
| 583 DisableNewTaskManagerForBrokenTest(); | |
| 584 | |
| 585 ShowTaskManager(); | |
| 586 | |
| 587 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app"))); | |
| 588 ExtensionService* service = extensions::ExtensionSystem::Get( | |
| 589 browser()->profile())->extension_service(); | |
| 590 const extensions::Extension* extension = | |
| 591 service->GetExtensionById(last_loaded_extension_id(), false); | |
| 592 | |
| 593 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 594 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 595 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 596 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 597 | |
| 598 // Open a new tab to the app's launch URL and make sure we notice that. | |
| 599 GURL url(extension->GetResourceURL("main.html")); | |
| 600 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 601 | |
| 602 // There should be 1 "App: " tab and the original new tab page. | |
| 603 ASSERT_NO_FATAL_FAILURE( | |
| 604 WaitForTaskManagerRows(1, MatchApp("Packaged App Test"))); | |
| 605 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | |
| 606 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 607 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 608 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 609 | |
| 610 // Check that the third entry (main.html) is of type extension and has both | |
| 611 // a tab contents and an extension. | |
| 612 int app_tab = FindResourceIndex(MatchApp("Packaged App Test")); | |
| 613 ASSERT_NE(-1, app_tab); | |
| 614 ASSERT_NE(-1, model()->GetTabId(app_tab)); | |
| 615 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | |
| 616 | |
| 617 // Unload extension to make sure the tab goes away. | |
| 618 UnloadExtension(last_loaded_extension_id()); | |
| 619 | |
| 620 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 621 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 622 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 623 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 624 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | |
| 625 } | |
| 626 | |
| 627 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTab) { | |
| 628 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 629 // "Extension: Packaged App Test" instead of "App: Packaged App Test". | |
| 630 DisableNewTaskManagerForBrokenTest(); | |
| 631 | |
| 632 ASSERT_TRUE(LoadExtension( | |
| 633 test_data_dir_.AppendASCII("packaged_app"))); | |
| 634 ExtensionService* service = extensions::ExtensionSystem::Get( | |
| 635 browser()->profile())->extension_service(); | |
| 636 const extensions::Extension* extension = | |
| 637 service->GetExtensionById(last_loaded_extension_id(), false); | |
| 638 | |
| 639 // Open a new tab to the app's launch URL and make sure we notice that. | |
| 640 GURL url(extension->GetResourceURL("main.html")); | |
| 641 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 642 | |
| 643 ShowTaskManager(); | |
| 644 | |
| 645 ASSERT_NO_FATAL_FAILURE( | |
| 646 WaitForTaskManagerRows(1, MatchApp("Packaged App Test"))); | |
| 647 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 648 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 649 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | |
| 650 | |
| 651 // Check that the third entry (main.html) is of type extension and has both | |
| 652 // a tab contents and an extension. | |
| 653 int app_tab = FindResourceIndex(MatchApp("Packaged App Test")); | |
| 654 ASSERT_NE(-1, app_tab); | |
| 655 ASSERT_NE(-1, model()->GetTabId(app_tab)); | |
| 656 } | |
| 657 | |
| 658 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabChanges) { | |
| 659 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 660 // "Tab: Unmodified" instead of "App: ". | |
| 661 DisableNewTaskManagerForBrokenTest(); | |
| 662 | |
| 663 ShowTaskManager(); | |
| 664 | |
| 665 // The app under test acts on URLs whose host is "localhost", | |
| 666 // so the URLs we navigate to must have host "localhost". | |
| 667 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 668 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 669 GURL::Replacements replace_host; | |
| 670 replace_host.SetHostStr("localhost"); | |
| 671 GURL base_url = embedded_test_server()->GetURL( | |
| 672 "/extensions/api_test/app_process/"); | |
| 673 base_url = base_url.ReplaceComponents(replace_host); | |
| 674 | |
| 675 // Open a new tab to an app URL before the app is loaded. | |
| 676 GURL url(base_url.Resolve("path1/empty.html")); | |
| 677 content::WindowedNotificationObserver observer( | |
| 678 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 679 content::NotificationService::AllSources()); | |
| 680 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 681 observer.Wait(); | |
| 682 | |
| 683 // Check that the new entry's title starts with "Tab:". | |
| 684 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 685 | |
| 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"))); | |
| 690 // Force the TaskManager to query the title. | |
| 691 Refresh(); | |
| 692 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 693 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 694 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified"))); | |
| 695 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 696 | |
| 697 // Now reload and check that the last entry's title now starts with "App:". | |
| 698 ui_test_utils::NavigateToURL(browser(), url); | |
| 699 | |
| 700 // Force the TaskManager to query the title. | |
| 701 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 702 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 703 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | |
| 704 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp("Unmodified"))); | |
| 705 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 706 | |
| 707 // Disable extension. | |
| 708 DisableExtension(last_loaded_extension_id()); | |
| 709 | |
| 710 // The hosted app should now show up as a normal "Tab: ". | |
| 711 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 712 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 713 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified"))); | |
| 714 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 715 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 716 | |
| 717 // Reload the page. | |
| 718 ui_test_utils::NavigateToURL(browser(), url); | |
| 719 | |
| 720 // No change expected. | |
| 721 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 722 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 723 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified"))); | |
| 724 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 725 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 726 } | |
| 727 | |
| 728 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabAfterReload) { | |
| 729 // TODO(nick, afakhry): This fails on the new task manager (we never | |
| 730 // reclassify the tab as an app). Remove when fixed. | |
| 731 DisableNewTaskManagerForBrokenTest(); | |
| 732 | |
| 733 // The app under test acts on URLs whose host is "localhost", | |
| 734 // so the URLs we navigate to must have host "localhost". | |
| 735 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 736 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 737 GURL::Replacements replace_host; | |
| 738 replace_host.SetHostStr("localhost"); | |
| 739 GURL base_url = | |
| 740 embedded_test_server()->GetURL("/extensions/api_test/app_process/"); | |
| 741 base_url = base_url.ReplaceComponents(replace_host); | |
| 742 | |
| 743 // Open a new tab to an app URL before the app is loaded. | |
| 744 GURL url(base_url.Resolve("path1/empty.html")); | |
| 745 content::WindowedNotificationObserver observer( | |
| 746 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 747 content::NotificationService::AllSources()); | |
| 748 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 749 observer.Wait(); | |
| 750 | |
| 751 // Load the hosted app and make sure it still starts with "Tab:", | |
| 752 // since it hasn't changed to an app process yet. | |
| 753 ASSERT_TRUE(LoadExtension( | |
| 754 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process"))); | |
| 755 | |
| 756 // Now reload, which should transition this tab to being an App. | |
| 757 ui_test_utils::NavigateToURL(browser(), url); | |
| 758 | |
| 759 ShowTaskManager(); | |
| 760 | |
| 761 // The TaskManager should show this as an "App: " | |
| 762 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 763 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | |
| 764 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 765 } | |
| 766 | |
| 767 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabBeforeReload) { | |
| 768 // The app under test acts on URLs whose host is "localhost", | |
| 769 // so the URLs we navigate to must have host "localhost". | |
| 770 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 771 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 772 GURL::Replacements replace_host; | |
| 773 replace_host.SetHostStr("localhost"); | |
| 774 GURL base_url = | |
| 775 embedded_test_server()->GetURL("/extensions/api_test/app_process/"); | |
| 776 base_url = base_url.ReplaceComponents(replace_host); | |
| 777 | |
| 778 // Open a new tab to an app URL before the app is loaded. | |
| 779 GURL url(base_url.Resolve("path1/empty.html")); | |
| 780 content::WindowedNotificationObserver observer( | |
| 781 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 782 content::NotificationService::AllSources()); | |
| 783 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 784 observer.Wait(); | |
| 785 | |
| 786 // Load the hosted app and make sure it still starts with "Tab:", | |
| 787 // since it hasn't changed to an app process yet. | |
| 788 ASSERT_TRUE(LoadExtension( | |
| 789 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process"))); | |
| 790 | |
| 791 ShowTaskManager(); | |
| 792 | |
| 793 // The TaskManager should show this as a "Tab: " because the page hasn't been | |
| 794 // reloaded since the hosted app was installed. | |
| 795 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 796 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 797 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 798 } | |
| 799 | |
| 800 // Regression test for http://crbug.com/18693. | |
| 801 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) { | |
| 802 ShowTaskManager(); | |
| 803 ASSERT_TRUE(LoadExtension( | |
| 804 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | |
| 805 | |
| 806 // Wait until we see the loaded extension in the task manager (the three | |
| 807 // resources are: the browser process, New Tab Page, and the extension). | |
| 808 ASSERT_NO_FATAL_FAILURE( | |
| 809 WaitForTaskManagerRows(1, MatchExtension("background_page"))); | |
| 810 | |
| 811 // Reload the extension a few times and make sure our resource count doesn't | |
| 812 // increase. | |
| 813 std::string extension_id = last_loaded_extension_id(); | |
| 814 for (int i = 1; i <= 5; i++) { | |
| 815 SCOPED_TRACE(testing::Message() << "Reloading extension for the " << i | |
| 816 << "th time."); | |
| 817 ReloadExtension(extension_id); | |
| 818 ASSERT_NO_FATAL_FAILURE( | |
| 819 WaitForTaskManagerRows(1, MatchExtension("background_page"))); | |
| 820 } | |
| 821 } | |
| 822 | |
| 823 // Checks that task manager counts a worker thread JS heap size. | |
| 824 // http://crbug.com/241066 | |
| 825 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, WebWorkerJSHeapMemory) { | |
| 826 ShowTaskManager(); | |
| 827 model()->ToggleColumnVisibility(ColumnSpecifier::V8_MEMORY); | |
| 828 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 829 size_t minimal_heap_size = 4 * 1024 * 1024 * sizeof(void*); | |
| 830 std::string test_js = base::StringPrintf( | |
| 831 "var blob = new Blob([\n" | |
| 832 " 'mem = new Array(%lu);',\n" | |
| 833 " 'for (var i = 0; i < mem.length; i += 16)'," | |
| 834 " ' mem[i] = i;',\n" | |
| 835 " 'postMessage(\"okay\");']);\n" | |
| 836 "blobURL = window.URL.createObjectURL(blob);\n" | |
| 837 "var worker = new Worker(blobURL);\n" | |
| 838 "worker.addEventListener('message', function(e) {\n" | |
| 839 " window.domAutomationController.send(e.data);\n" // e.data == "okay" | |
| 840 "});\n" | |
| 841 "worker.postMessage('go');\n", | |
| 842 static_cast<unsigned long>(minimal_heap_size)); | |
| 843 std::string ok; | |
| 844 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 845 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok)); | |
| 846 ASSERT_EQ("okay", ok); | |
| 847 | |
| 848 // The worker has allocated objects of at least |minimal_heap_size| bytes. | |
| 849 // Wait for the heap stats to reflect this. | |
| 850 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 851 MatchTab("title1.html"), ColumnSpecifier::V8_MEMORY, minimal_heap_size)); | |
| 852 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 853 MatchTab("title1.html"), ColumnSpecifier::V8_MEMORY_USED, | |
| 854 minimal_heap_size)); | |
| 855 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 856 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html"))); | |
| 857 } | |
| 858 | |
| 859 // Checks that task manager counts renderer JS heap size. | |
| 860 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, JSHeapMemory) { | |
| 861 ShowTaskManager(); | |
| 862 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 863 size_t minimal_heap_size = 4 * 1024 * 1024 * sizeof(void*); | |
| 864 std::string test_js = base::StringPrintf( | |
| 865 "mem = new Array(%lu);\n" | |
| 866 "for (var i = 0; i < mem.length; i += 16)\n" | |
| 867 " mem[i] = i;\n" | |
| 868 "window.domAutomationController.send(\"okay\");\n", | |
| 869 static_cast<unsigned long>(minimal_heap_size)); | |
| 870 std::string ok; | |
| 871 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 872 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok)); | |
| 873 ASSERT_EQ("okay", ok); | |
| 874 | |
| 875 model()->ToggleColumnVisibility(ColumnSpecifier::V8_MEMORY); | |
| 876 | |
| 877 // The page's js has allocated objects of at least |minimal_heap_size| bytes. | |
| 878 // Wait for the heap stats to reflect this. | |
| 879 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 880 MatchTab("title1.html"), ColumnSpecifier::V8_MEMORY, minimal_heap_size)); | |
| 881 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 882 MatchTab("title1.html"), ColumnSpecifier::V8_MEMORY_USED, | |
| 883 minimal_heap_size)); | |
| 884 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 885 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html"))); | |
| 886 } | |
| 887 | |
| 888 // Checks that task manager counts utility process JS heap size. | |
| 889 IN_PROC_BROWSER_TEST_F(TaskManagerUtilityProcessBrowserTest, | |
| 890 UtilityJSHeapMemory) { | |
| 891 ShowTaskManager(); | |
| 892 model()->ToggleColumnVisibility(ColumnSpecifier::V8_MEMORY); | |
| 893 | |
| 894 auto proxy_resolver_name = | |
| 895 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME); | |
| 896 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 897 // The PAC script is trivial, so don't expect a large heap. | |
| 898 size_t minimal_heap_size = 1024; | |
| 899 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 900 MatchUtility(proxy_resolver_name), ColumnSpecifier::V8_MEMORY, | |
| 901 minimal_heap_size)); | |
| 902 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 903 MatchUtility(proxy_resolver_name), ColumnSpecifier::V8_MEMORY_USED, | |
| 904 minimal_heap_size)); | |
| 905 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyUtility())); | |
| 906 ASSERT_NO_FATAL_FAILURE( | |
| 907 WaitForTaskManagerRows(1, MatchUtility(proxy_resolver_name))); | |
| 908 } | |
| 909 | |
| 910 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewDockedWindow) { | |
| 911 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 912 // a long chrome-devtools:// URL without a prefix (expecting "Tab: *"). | |
| 913 DisableNewTaskManagerForBrokenTest(); | |
| 914 | |
| 915 ShowTaskManager(); // Task manager shown BEFORE dev tools window. | |
| 916 | |
| 917 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 918 DevToolsWindow* devtools = | |
| 919 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true); | |
| 920 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 921 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 922 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
| 923 } | |
| 924 | |
| 925 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewUndockedWindow) { | |
| 926 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 927 // a long chrome-devtools:// URL without a prefix (expecting "Tab: *"). | |
| 928 DisableNewTaskManagerForBrokenTest(); | |
| 929 | |
| 930 ShowTaskManager(); // Task manager shown BEFORE dev tools window. | |
| 931 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 932 DevToolsWindow* devtools = | |
| 933 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); | |
| 934 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); | |
| 935 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); | |
| 936 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
| 937 } | |
| 938 | |
| 939 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldDockedWindow) { | |
| 940 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 941 // a long chrome-devtools:// URL without a prefix (expecting "Tab: *"). | |
| 942 DisableNewTaskManagerForBrokenTest(); | |
| 943 | |
| 944 DevToolsWindow* devtools = | |
| 945 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true); | |
| 946 ShowTaskManager(); // Task manager shown AFTER dev tools window. | |
| 947 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 948 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 949 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
| 950 } | |
| 951 | |
| 952 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldUndockedWindow) { | |
| 953 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 954 // a long chrome-devtools:// URL without a prefix (expecting "Tab: *"). | |
| 955 DisableNewTaskManagerForBrokenTest(); | |
| 956 | |
| 957 DevToolsWindow* devtools = | |
| 958 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); | |
| 959 ShowTaskManager(); // Task manager shown AFTER dev tools window. | |
| 960 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); | |
| 961 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); | |
| 962 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
| 963 } | |
| 964 | |
| 965 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, KillSubframe) { | |
| 966 ShowTaskManager(); | |
| 967 | |
| 968 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 969 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 970 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 971 | |
| 972 GURL main_url(embedded_test_server()->GetURL( | |
| 973 "/cross-site/a.com/iframe_cross_site.html")); | |
| 974 browser()->OpenURL(content::OpenURLParams(main_url, content::Referrer(), | |
| 975 CURRENT_TAB, | |
| 976 ui::PAGE_TRANSITION_TYPED, false)); | |
| 977 | |
| 978 ASSERT_NO_FATAL_FAILURE( | |
| 979 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 980 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 981 | |
| 982 if (!ShouldExpectSubframes()) { | |
| 983 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 984 } else { | |
| 985 ASSERT_NO_FATAL_FAILURE( | |
| 986 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 987 ASSERT_NO_FATAL_FAILURE( | |
| 988 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 989 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 990 int subframe_b = FindResourceIndex(MatchSubframe("http://b.com/")); | |
| 991 ASSERT_NE(-1, subframe_b); | |
| 992 ASSERT_NE(-1, model()->GetTabId(subframe_b)); | |
| 993 | |
| 994 model()->Kill(subframe_b); | |
| 995 | |
| 996 ASSERT_NO_FATAL_FAILURE( | |
| 997 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); | |
| 998 ASSERT_NO_FATAL_FAILURE( | |
| 999 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1000 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); | |
| 1001 ASSERT_NO_FATAL_FAILURE( | |
| 1002 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1003 } | |
| 1004 | |
| 1005 HideTaskManager(); | |
| 1006 ShowTaskManager(); | |
| 1007 | |
| 1008 if (!ShouldExpectSubframes()) { | |
| 1009 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1010 } else { | |
| 1011 ASSERT_NO_FATAL_FAILURE( | |
| 1012 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); | |
| 1013 ASSERT_NO_FATAL_FAILURE( | |
| 1014 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1015 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); | |
| 1016 ASSERT_NO_FATAL_FAILURE( | |
| 1017 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1018 } | |
| 1019 } | |
| 1020 | |
| 1021 // Tests what happens when a tab navigates to a site (a.com) that it previously | |
| 1022 // has a cross-process subframe into (b.com). | |
| 1023 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, NavigateToSubframeProcess) { | |
| 1024 ShowTaskManager(); | |
| 1025 | |
| 1026 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 1027 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1028 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 1029 | |
| 1030 // Navigate the tab to a page on a.com with cross-process subframes to | |
| 1031 // b.com and c.com. | |
| 1032 GURL a_dotcom(embedded_test_server()->GetURL( | |
| 1033 "/cross-site/a.com/iframe_cross_site.html")); | |
| 1034 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(), | |
| 1035 CURRENT_TAB, | |
| 1036 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1037 | |
| 1038 ASSERT_NO_FATAL_FAILURE( | |
| 1039 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1040 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1041 | |
| 1042 if (!ShouldExpectSubframes()) { | |
| 1043 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1044 } else { | |
| 1045 ASSERT_NO_FATAL_FAILURE( | |
| 1046 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1047 ASSERT_NO_FATAL_FAILURE( | |
| 1048 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1049 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1050 } | |
| 1051 | |
| 1052 // Now navigate to a page on b.com with a simple (same-site) iframe. | |
| 1053 // This should not show any subframe resources in the task manager. | |
| 1054 GURL b_dotcom( | |
| 1055 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html")); | |
| 1056 | |
| 1057 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(), | |
| 1058 CURRENT_TAB, | |
| 1059 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1060 | |
| 1061 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test"))); | |
| 1062 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1063 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1064 HideTaskManager(); | |
| 1065 ShowTaskManager(); | |
| 1066 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test"))); | |
| 1067 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1068 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1069 } | |
| 1070 | |
| 1071 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, | |
| 1072 NavigateToSiteWithSubframeToOriginalSite) { | |
| 1073 ShowTaskManager(); | |
| 1074 | |
| 1075 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 1076 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1077 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 1078 | |
| 1079 // Navigate to a page on b.com with a simple (same-site) iframe. | |
| 1080 // This should not show any subframe resources in the task manager. | |
| 1081 GURL b_dotcom( | |
| 1082 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html")); | |
| 1083 | |
| 1084 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(), | |
| 1085 CURRENT_TAB, | |
| 1086 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1087 | |
| 1088 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test"))); | |
| 1089 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1090 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1091 | |
| 1092 // Now navigate the tab to a page on a.com with cross-process subframes to | |
| 1093 // b.com and c.com. | |
| 1094 GURL a_dotcom(embedded_test_server()->GetURL( | |
| 1095 "/cross-site/a.com/iframe_cross_site.html")); | |
| 1096 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(), | |
| 1097 CURRENT_TAB, | |
| 1098 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1099 | |
| 1100 ASSERT_NO_FATAL_FAILURE( | |
| 1101 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1102 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1103 | |
| 1104 if (!ShouldExpectSubframes()) { | |
| 1105 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1106 } else { | |
| 1107 ASSERT_NO_FATAL_FAILURE( | |
| 1108 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1109 ASSERT_NO_FATAL_FAILURE( | |
| 1110 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1111 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1112 } | |
| 1113 | |
| 1114 HideTaskManager(); | |
| 1115 ShowTaskManager(); | |
| 1116 | |
| 1117 if (!ShouldExpectSubframes()) { | |
| 1118 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1119 } else { | |
| 1120 ASSERT_NO_FATAL_FAILURE( | |
| 1121 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1122 ASSERT_NO_FATAL_FAILURE( | |
| 1123 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1124 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1125 } | |
| 1126 } | |
| 1127 | |
| 1128 // Tests what happens when a tab navigates a cross-frame iframe (to b.com) | |
| 1129 // back to the site of the parent document (a.com). | |
| 1130 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, | |
| 1131 CrossSiteIframeBecomesSameSite) { | |
| 1132 ShowTaskManager(); | |
| 1133 | |
| 1134 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 1135 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1136 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 1137 | |
| 1138 // Navigate the tab to a page on a.com with cross-process subframes to | |
| 1139 // b.com and c.com. | |
| 1140 GURL a_dotcom(embedded_test_server()->GetURL( | |
| 1141 "/cross-site/a.com/iframe_cross_site.html")); | |
| 1142 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(), | |
| 1143 CURRENT_TAB, | |
| 1144 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1145 | |
| 1146 ASSERT_NO_FATAL_FAILURE( | |
| 1147 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1148 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1149 | |
| 1150 if (!ShouldExpectSubframes()) { | |
| 1151 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1152 } else { | |
| 1153 ASSERT_NO_FATAL_FAILURE( | |
| 1154 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1155 ASSERT_NO_FATAL_FAILURE( | |
| 1156 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1157 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1158 } | |
| 1159 | |
| 1160 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe | |
| 1161 ASSERT_TRUE(content::ExecuteScript( | |
| 1162 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | |
| 1163 "document.getElementById('frame1').src='/title1.html';" | |
| 1164 "document.title='aac';")); | |
| 1165 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac"))); | |
| 1166 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1167 if (!ShouldExpectSubframes()) { | |
| 1168 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1169 } else { | |
| 1170 ASSERT_NO_FATAL_FAILURE( | |
| 1171 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); | |
| 1172 ASSERT_NO_FATAL_FAILURE( | |
| 1173 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1174 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); | |
| 1175 } | |
| 1176 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac"))); | |
| 1177 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1178 | |
| 1179 HideTaskManager(); | |
| 1180 ShowTaskManager(); | |
| 1181 | |
| 1182 if (!ShouldExpectSubframes()) { | |
| 1183 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1184 } else { | |
| 1185 ASSERT_NO_FATAL_FAILURE( | |
| 1186 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); | |
| 1187 ASSERT_NO_FATAL_FAILURE( | |
| 1188 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1189 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); | |
| 1190 } | |
| 1191 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac"))); | |
| 1192 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1193 } | |
| 1194 | |
| 1195 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, | |
| 1196 LeavePageWithCrossSiteIframes) { | |
| 1197 ShowTaskManager(); | |
| 1198 | |
| 1199 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 1200 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1201 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 1202 | |
| 1203 // Navigate the tab to a page on a.com with cross-process subframes. | |
| 1204 GURL a_dotcom_with_iframes(embedded_test_server()->GetURL( | |
| 1205 "/cross-site/a.com/iframe_cross_site.html")); | |
| 1206 browser()->OpenURL(content::OpenURLParams(a_dotcom_with_iframes, | |
| 1207 content::Referrer(), CURRENT_TAB, | |
| 1208 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1209 | |
| 1210 ASSERT_NO_FATAL_FAILURE( | |
| 1211 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1212 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1213 | |
| 1214 if (!ShouldExpectSubframes()) { | |
| 1215 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1216 } else { | |
| 1217 ASSERT_NO_FATAL_FAILURE( | |
| 1218 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1219 ASSERT_NO_FATAL_FAILURE( | |
| 1220 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1221 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1222 } | |
| 1223 | |
| 1224 // Navigate the tab to a page on a.com without cross-process subframes, and | |
| 1225 // the subframe processes should disappear. | |
| 1226 GURL a_dotcom_simple( | |
| 1227 embedded_test_server()->GetURL("/cross-site/a.com/title2.html")); | |
| 1228 browser()->OpenURL(content::OpenURLParams(a_dotcom_simple, | |
| 1229 content::Referrer(), CURRENT_TAB, | |
| 1230 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1231 ASSERT_NO_FATAL_FAILURE( | |
| 1232 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness"))); | |
| 1233 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1234 | |
| 1235 HideTaskManager(); | |
| 1236 ShowTaskManager(); | |
| 1237 | |
| 1238 ASSERT_NO_FATAL_FAILURE( | |
| 1239 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness"))); | |
| 1240 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1241 } | |
| OLD | NEW |