| 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 | |
| 311 // Make sure that a task manager model created after the panel shows the | |
| 312 // existence of the panel and the extension. | |
| 313 ShowTaskManager(); | |
| 314 ASSERT_NO_FATAL_FAILURE( | |
| 315 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 316 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 317 1, | |
| 318 MatchExtension( | |
| 319 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 320 "french_sentence.html"))); | |
| 321 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 322 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 323 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 324 | |
| 325 // Create a second, detached panel. | |
| 326 Panel* detached_panel = PanelManager::GetInstance()->CreatePanel( | |
| 327 web_app::GenerateApplicationNameFromExtensionId( | |
| 328 last_loaded_extension_id()), | |
| 329 browser()->profile(), url, nullptr, gfx::Rect(150, 150), | |
| 330 PanelManager::CREATE_AS_DETACHED); | |
| 331 | |
| 332 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 333 2, MatchExtension("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 334 "french_sentence.html"))); | |
| 335 ASSERT_NO_FATAL_FAILURE( | |
| 336 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 337 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyExtension())); | |
| 338 | |
| 339 // Close the panels and verify that we notice. | |
| 340 docked_panel->Close(); | |
| 341 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 342 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 343 1, MatchExtension("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 344 "french_sentence.html"))); | |
| 345 ASSERT_NO_FATAL_FAILURE( | |
| 346 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 347 | |
| 348 detached_panel->Close(); | |
| 349 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension())); | |
| 350 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 351 0, | |
| 352 MatchExtension( | |
| 353 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 354 "french_sentence.html"))); | |
| 355 ASSERT_NO_FATAL_FAILURE( | |
| 356 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 357 } | |
| 358 | |
| 359 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanelChanges) { | |
| 360 ShowTaskManager(); | |
| 361 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 362 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 363 | |
| 364 ASSERT_TRUE(LoadExtension( | |
| 365 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | |
| 366 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 367 .AppendASCII("1.0.0.0"))); | |
| 368 | |
| 369 // Browser, the New Tab Page and Extension background page. | |
| 370 ASSERT_NO_FATAL_FAILURE( | |
| 371 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 372 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension())); | |
| 373 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 374 | |
| 375 // Open a new panel to an extension url and make sure we notice that. | |
| 376 GURL url( | |
| 377 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html"); | |
| 378 Panel* panel = PanelManager::GetInstance()->CreatePanel( | |
| 379 web_app::GenerateApplicationNameFromExtensionId( | |
| 380 last_loaded_extension_id()), | |
| 381 browser()->profile(), | |
| 382 url, | |
| 383 nullptr, | |
| 384 gfx::Rect(300, 400), | |
| 385 PanelManager::CREATE_AS_DOCKED); | |
| 386 ASSERT_NO_FATAL_FAILURE( | |
| 387 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 388 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 389 1, | |
| 390 MatchExtension( | |
| 391 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 392 "french_sentence.html"))); | |
| 393 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 394 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 395 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 396 | |
| 397 // Close the panel and verify that we notice. | |
| 398 panel->Close(); | |
| 399 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension())); | |
| 400 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 401 0, | |
| 402 MatchExtension( | |
| 403 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 404 "french_sentence.html"))); | |
| 405 ASSERT_NO_FATAL_FAILURE( | |
| 406 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 407 | |
| 408 // Unload extension. | |
| 409 UnloadExtension(last_loaded_extension_id()); | |
| 410 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 411 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 412 } | |
| 413 | |
| 414 // Kills a process that has more than one task manager entry. | |
| 415 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaExtensionResource) { | |
| 416 ShowTaskManager(); | |
| 417 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good") | |
| 418 .AppendASCII("Extensions") | |
| 419 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 420 .AppendASCII("1.0.0.0"))); | |
| 421 | |
| 422 // Open a new panel to an extension url. | |
| 423 GURL url( | |
| 424 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 425 "french_sentence.html"); | |
| 426 PanelManager::GetInstance()->CreatePanel( | |
| 427 web_app::GenerateApplicationNameFromExtensionId( | |
| 428 last_loaded_extension_id()), | |
| 429 browser()->profile(), | |
| 430 url, | |
| 431 nullptr, | |
| 432 gfx::Rect(300, 400), | |
| 433 PanelManager::CREATE_AS_DOCKED); | |
| 434 | |
| 435 ASSERT_NO_FATAL_FAILURE( | |
| 436 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 437 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 438 1, | |
| 439 MatchExtension( | |
| 440 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 441 "french_sentence.html"))); | |
| 442 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 443 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 444 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 445 | |
| 446 // Kill the process via the BACKGROUND PAGE (not the panel). Verify that both | |
| 447 // the background page and the panel go away from the task manager. | |
| 448 int background_page = FindResourceIndex(MatchExtension("My extension 1")); | |
| 449 ASSERT_NE(-1, background_page); | |
| 450 ASSERT_EQ(-1, model()->GetTabId(background_page)); | |
| 451 model()->Kill(background_page); | |
| 452 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 453 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 454 } | |
| 455 | |
| 456 // Kills a process that has more than one task manager entry. This test is the | |
| 457 // same as KillPanelViaExtensionResource except it does the kill via the other | |
| 458 // entry. | |
| 459 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillPanelViaPanelResource) { | |
| 460 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good") | |
| 461 .AppendASCII("Extensions") | |
| 462 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 463 .AppendASCII("1.0.0.0"))); | |
| 464 | |
| 465 // Open a new panel to an extension url. | |
| 466 GURL url( | |
| 467 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 468 "french_sentence.html"); | |
| 469 PanelManager::GetInstance()->CreatePanel( | |
| 470 web_app::GenerateApplicationNameFromExtensionId( | |
| 471 last_loaded_extension_id()), | |
| 472 browser()->profile(), | |
| 473 url, | |
| 474 nullptr, | |
| 475 gfx::Rect(300, 400), | |
| 476 PanelManager::CREATE_AS_DOCKED); | |
| 477 | |
| 478 ShowTaskManager(); | |
| 479 ASSERT_NO_FATAL_FAILURE( | |
| 480 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 481 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows( | |
| 482 1, | |
| 483 MatchExtension( | |
| 484 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 485 "french_sentence.html"))); | |
| 486 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 487 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 488 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 489 | |
| 490 int background_page = FindResourceIndex(MatchExtension("My extension 1")); | |
| 491 ASSERT_NE(-1, background_page); | |
| 492 ASSERT_EQ(-1, model()->GetTabId(background_page)); | |
| 493 | |
| 494 // Kill the process via the PANEL RESOURCE (not the background page). Verify | |
| 495 // that both the background page and the panel go away from the task manager. | |
| 496 int panel = FindResourceIndex(MatchExtension( | |
| 497 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/" | |
| 498 "french_sentence.html")); | |
| 499 ASSERT_NE(-1, panel); | |
| 500 ASSERT_NE(-1, model()->GetTabId(panel)); | |
| 501 model()->Kill(panel); | |
| 502 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 503 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 504 } | |
| 505 | |
| 506 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabChanges) { | |
| 507 ShowTaskManager(); | |
| 508 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 509 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 510 | |
| 511 ASSERT_TRUE(LoadExtension( | |
| 512 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | |
| 513 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 514 .AppendASCII("1.0.0.0"))); | |
| 515 | |
| 516 // Browser, Extension background page, and the New Tab Page. | |
| 517 ASSERT_NO_FATAL_FAILURE( | |
| 518 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 519 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyExtension())); | |
| 520 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 521 | |
| 522 // Open a new tab to an extension URL. Afterwards, the third entry (background | |
| 523 // page) should be an extension resource whose title starts with "Extension:". | |
| 524 // The fourth entry (page.html) is also of type extension and has both a | |
| 525 // WebContents and an extension. The title should start with "Extension:". | |
| 526 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); | |
| 527 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 528 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar"))); | |
| 529 ASSERT_NO_FATAL_FAILURE( | |
| 530 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 531 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 532 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 533 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 534 | |
| 535 int extension_tab = FindResourceIndex(MatchExtension("Foobar")); | |
| 536 ASSERT_NE(-1, extension_tab); | |
| 537 ASSERT_NE(-1, model()->GetTabId(extension_tab)); | |
| 538 | |
| 539 int background_page = FindResourceIndex(MatchExtension("My extension 1")); | |
| 540 ASSERT_NE(-1, background_page); | |
| 541 ASSERT_EQ(-1, model()->GetTabId(background_page)); | |
| 542 } | |
| 543 | |
| 544 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTab) { | |
| 545 // With the task manager closed, open a new tab to an extension URL. | |
| 546 // Afterwards, when we open the task manager, the third entry (background | |
| 547 // page) should be an extension resource whose title starts with "Extension:". | |
| 548 // The fourth entry (page.html) is also of type extension and has both a | |
| 549 // WebContents and an extension. The title should start with "Extension:". | |
| 550 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("good") | |
| 551 .AppendASCII("Extensions") | |
| 552 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | |
| 553 .AppendASCII("1.0.0.0"))); | |
| 554 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); | |
| 555 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 556 | |
| 557 ShowTaskManager(); | |
| 558 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchExtension("Foobar"))); | |
| 559 ASSERT_NO_FATAL_FAILURE( | |
| 560 WaitForTaskManagerRows(1, MatchExtension("My extension 1"))); | |
| 561 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyExtension())); | |
| 562 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 563 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 564 | |
| 565 int extension_tab = FindResourceIndex(MatchExtension("Foobar")); | |
| 566 ASSERT_NE(-1, extension_tab); | |
| 567 ASSERT_NE(-1, model()->GetTabId(extension_tab)); | |
| 568 | |
| 569 int background_page = FindResourceIndex(MatchExtension("My extension 1")); | |
| 570 ASSERT_NE(-1, background_page); | |
| 571 ASSERT_EQ(-1, model()->GetTabId(background_page)); | |
| 572 } | |
| 573 | |
| 574 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabChanges) { | |
| 575 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 576 // "Extension: Packaged App Test" instead of "App: Packaged App Test". | |
| 577 DisableNewTaskManagerForBrokenTest(); | |
| 578 | |
| 579 ShowTaskManager(); | |
| 580 | |
| 581 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("packaged_app"))); | |
| 582 ExtensionService* service = extensions::ExtensionSystem::Get( | |
| 583 browser()->profile())->extension_service(); | |
| 584 const extensions::Extension* extension = | |
| 585 service->GetExtensionById(last_loaded_extension_id(), false); | |
| 586 | |
| 587 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 588 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 589 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 590 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 591 | |
| 592 // Open a new tab to the app's launch URL and make sure we notice that. | |
| 593 GURL url(extension->GetResourceURL("main.html")); | |
| 594 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 595 | |
| 596 // There should be 1 "App: " tab and the original new tab page. | |
| 597 ASSERT_NO_FATAL_FAILURE( | |
| 598 WaitForTaskManagerRows(1, MatchApp("Packaged App Test"))); | |
| 599 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | |
| 600 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 601 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 602 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 603 | |
| 604 // Check that the third entry (main.html) is of type extension and has both | |
| 605 // a tab contents and an extension. | |
| 606 int app_tab = FindResourceIndex(MatchApp("Packaged App Test")); | |
| 607 ASSERT_NE(-1, app_tab); | |
| 608 ASSERT_NE(-1, model()->GetTabId(app_tab)); | |
| 609 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | |
| 610 | |
| 611 // Unload extension to make sure the tab goes away. | |
| 612 UnloadExtension(last_loaded_extension_id()); | |
| 613 | |
| 614 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 615 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 616 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 617 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 618 ASSERT_EQ(1, browser()->tab_strip_model()->count()); | |
| 619 } | |
| 620 | |
| 621 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTab) { | |
| 622 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 623 // "Extension: Packaged App Test" instead of "App: Packaged App Test". | |
| 624 DisableNewTaskManagerForBrokenTest(); | |
| 625 | |
| 626 ASSERT_TRUE(LoadExtension( | |
| 627 test_data_dir_.AppendASCII("packaged_app"))); | |
| 628 ExtensionService* service = extensions::ExtensionSystem::Get( | |
| 629 browser()->profile())->extension_service(); | |
| 630 const extensions::Extension* extension = | |
| 631 service->GetExtensionById(last_loaded_extension_id(), false); | |
| 632 | |
| 633 // Open a new tab to the app's launch URL and make sure we notice that. | |
| 634 GURL url(extension->GetResourceURL("main.html")); | |
| 635 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 636 | |
| 637 ShowTaskManager(); | |
| 638 | |
| 639 ASSERT_NO_FATAL_FAILURE( | |
| 640 WaitForTaskManagerRows(1, MatchApp("Packaged App Test"))); | |
| 641 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 642 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 643 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | |
| 644 | |
| 645 // Check that the third entry (main.html) is of type extension and has both | |
| 646 // a tab contents and an extension. | |
| 647 int app_tab = FindResourceIndex(MatchApp("Packaged App Test")); | |
| 648 ASSERT_NE(-1, app_tab); | |
| 649 ASSERT_NE(-1, model()->GetTabId(app_tab)); | |
| 650 } | |
| 651 | |
| 652 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabChanges) { | |
| 653 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 654 // "Tab: Unmodified" instead of "App: ". | |
| 655 DisableNewTaskManagerForBrokenTest(); | |
| 656 | |
| 657 ShowTaskManager(); | |
| 658 | |
| 659 // The app under test acts on URLs whose host is "localhost", | |
| 660 // so the URLs we navigate to must have host "localhost". | |
| 661 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 662 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 663 GURL::Replacements replace_host; | |
| 664 replace_host.SetHostStr("localhost"); | |
| 665 GURL base_url = embedded_test_server()->GetURL( | |
| 666 "/extensions/api_test/app_process/"); | |
| 667 base_url = base_url.ReplaceComponents(replace_host); | |
| 668 | |
| 669 // Open a new tab to an app URL before the app is loaded. | |
| 670 GURL url(base_url.Resolve("path1/empty.html")); | |
| 671 content::WindowedNotificationObserver observer( | |
| 672 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 673 content::NotificationService::AllSources()); | |
| 674 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 675 observer.Wait(); | |
| 676 | |
| 677 // Check that the new entry's title starts with "Tab:". | |
| 678 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 679 | |
| 680 // Load the hosted app and make sure it still starts with "Tab:", | |
| 681 // since it hasn't changed to an app process yet. | |
| 682 ASSERT_TRUE(LoadExtension( | |
| 683 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process"))); | |
| 684 // Force the TaskManager to query the title. | |
| 685 Refresh(); | |
| 686 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 687 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 688 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified"))); | |
| 689 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 690 | |
| 691 // Now reload and check that the last entry's title now starts with "App:". | |
| 692 ui_test_utils::NavigateToURL(browser(), url); | |
| 693 | |
| 694 // Force the TaskManager to query the title. | |
| 695 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 696 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 697 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | |
| 698 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp("Unmodified"))); | |
| 699 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 700 | |
| 701 // Disable extension. | |
| 702 DisableExtension(last_loaded_extension_id()); | |
| 703 | |
| 704 // The hosted app should now show up as a normal "Tab: ". | |
| 705 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 706 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 707 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified"))); | |
| 708 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 709 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 710 | |
| 711 // Reload the page. | |
| 712 ui_test_utils::NavigateToURL(browser(), url); | |
| 713 | |
| 714 // No change expected. | |
| 715 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 716 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab())); | |
| 717 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("Unmodified"))); | |
| 718 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 719 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 720 } | |
| 721 | |
| 722 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabAfterReload) { | |
| 723 // TODO(nick, afakhry): This fails on the new task manager (we never | |
| 724 // reclassify the tab as an app). Remove when fixed. | |
| 725 DisableNewTaskManagerForBrokenTest(); | |
| 726 | |
| 727 // The app under test acts on URLs whose host is "localhost", | |
| 728 // so the URLs we navigate to must have host "localhost". | |
| 729 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 730 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 731 GURL::Replacements replace_host; | |
| 732 replace_host.SetHostStr("localhost"); | |
| 733 GURL base_url = | |
| 734 embedded_test_server()->GetURL("/extensions/api_test/app_process/"); | |
| 735 base_url = base_url.ReplaceComponents(replace_host); | |
| 736 | |
| 737 // Open a new tab to an app URL before the app is loaded. | |
| 738 GURL url(base_url.Resolve("path1/empty.html")); | |
| 739 content::WindowedNotificationObserver observer( | |
| 740 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 741 content::NotificationService::AllSources()); | |
| 742 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 743 observer.Wait(); | |
| 744 | |
| 745 // Load the hosted app and make sure it still starts with "Tab:", | |
| 746 // since it hasn't changed to an app process yet. | |
| 747 ASSERT_TRUE(LoadExtension( | |
| 748 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process"))); | |
| 749 | |
| 750 // Now reload, which should transition this tab to being an App. | |
| 751 ui_test_utils::NavigateToURL(browser(), url); | |
| 752 | |
| 753 ShowTaskManager(); | |
| 754 | |
| 755 // The TaskManager should show this as an "App: " | |
| 756 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 757 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp())); | |
| 758 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 759 } | |
| 760 | |
| 761 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabBeforeReload) { | |
| 762 // The app under test acts on URLs whose host is "localhost", | |
| 763 // so the URLs we navigate to must have host "localhost". | |
| 764 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 765 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 766 GURL::Replacements replace_host; | |
| 767 replace_host.SetHostStr("localhost"); | |
| 768 GURL base_url = | |
| 769 embedded_test_server()->GetURL("/extensions/api_test/app_process/"); | |
| 770 base_url = base_url.ReplaceComponents(replace_host); | |
| 771 | |
| 772 // Open a new tab to an app URL before the app is loaded. | |
| 773 GURL url(base_url.Resolve("path1/empty.html")); | |
| 774 content::WindowedNotificationObserver observer( | |
| 775 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 776 content::NotificationService::AllSources()); | |
| 777 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | |
| 778 observer.Wait(); | |
| 779 | |
| 780 // Load the hosted app and make sure it still starts with "Tab:", | |
| 781 // since it hasn't changed to an app process yet. | |
| 782 ASSERT_TRUE(LoadExtension( | |
| 783 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process"))); | |
| 784 | |
| 785 ShowTaskManager(); | |
| 786 | |
| 787 // The TaskManager should show this as a "Tab: " because the page hasn't been | |
| 788 // reloaded since the hosted app was installed. | |
| 789 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 790 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyApp())); | |
| 791 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnyExtension())); | |
| 792 } | |
| 793 | |
| 794 // Regression test for http://crbug.com/18693. | |
| 795 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) { | |
| 796 ShowTaskManager(); | |
| 797 ASSERT_TRUE(LoadExtension( | |
| 798 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | |
| 799 | |
| 800 // Wait until we see the loaded extension in the task manager (the three | |
| 801 // resources are: the browser process, New Tab Page, and the extension). | |
| 802 ASSERT_NO_FATAL_FAILURE( | |
| 803 WaitForTaskManagerRows(1, MatchExtension("background_page"))); | |
| 804 | |
| 805 // Reload the extension a few times and make sure our resource count doesn't | |
| 806 // increase. | |
| 807 std::string extension_id = last_loaded_extension_id(); | |
| 808 for (int i = 1; i <= 5; i++) { | |
| 809 SCOPED_TRACE(testing::Message() << "Reloading extension for the " << i | |
| 810 << "th time."); | |
| 811 ReloadExtension(extension_id); | |
| 812 ASSERT_NO_FATAL_FAILURE( | |
| 813 WaitForTaskManagerRows(1, MatchExtension("background_page"))); | |
| 814 } | |
| 815 } | |
| 816 | |
| 817 // Checks that task manager counts a worker thread JS heap size. | |
| 818 // http://crbug.com/241066 | |
| 819 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, WebWorkerJSHeapMemory) { | |
| 820 ShowTaskManager(); | |
| 821 model()->ToggleColumnVisibility(ColumnSpecifier::V8_MEMORY); | |
| 822 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 823 size_t minimal_heap_size = 4 * 1024 * 1024 * sizeof(void*); | |
| 824 std::string test_js = base::StringPrintf( | |
| 825 "var blob = new Blob([\n" | |
| 826 " 'mem = new Array(%lu);',\n" | |
| 827 " 'for (var i = 0; i < mem.length; i += 16)'," | |
| 828 " ' mem[i] = i;',\n" | |
| 829 " 'postMessage(\"okay\");']);\n" | |
| 830 "blobURL = window.URL.createObjectURL(blob);\n" | |
| 831 "var worker = new Worker(blobURL);\n" | |
| 832 "worker.addEventListener('message', function(e) {\n" | |
| 833 " window.domAutomationController.send(e.data);\n" // e.data == "okay" | |
| 834 "});\n" | |
| 835 "worker.postMessage('go');\n", | |
| 836 static_cast<unsigned long>(minimal_heap_size)); | |
| 837 std::string ok; | |
| 838 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 839 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok)); | |
| 840 ASSERT_EQ("okay", ok); | |
| 841 | |
| 842 // The worker has allocated objects of at least |minimal_heap_size| bytes. | |
| 843 // Wait for the heap stats to reflect this. | |
| 844 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 845 MatchTab("title1.html"), ColumnSpecifier::V8_MEMORY, minimal_heap_size)); | |
| 846 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 847 MatchTab("title1.html"), ColumnSpecifier::V8_MEMORY_USED, | |
| 848 minimal_heap_size)); | |
| 849 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 850 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html"))); | |
| 851 } | |
| 852 | |
| 853 // Checks that task manager counts renderer JS heap size. | |
| 854 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, JSHeapMemory) { | |
| 855 ShowTaskManager(); | |
| 856 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 857 size_t minimal_heap_size = 4 * 1024 * 1024 * sizeof(void*); | |
| 858 std::string test_js = base::StringPrintf( | |
| 859 "mem = new Array(%lu);\n" | |
| 860 "for (var i = 0; i < mem.length; i += 16)\n" | |
| 861 " mem[i] = i;\n" | |
| 862 "window.domAutomationController.send(\"okay\");\n", | |
| 863 static_cast<unsigned long>(minimal_heap_size)); | |
| 864 std::string ok; | |
| 865 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 866 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok)); | |
| 867 ASSERT_EQ("okay", ok); | |
| 868 | |
| 869 model()->ToggleColumnVisibility(ColumnSpecifier::V8_MEMORY); | |
| 870 | |
| 871 // The page's js has allocated objects of at least |minimal_heap_size| bytes. | |
| 872 // Wait for the heap stats to reflect this. | |
| 873 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 874 MatchTab("title1.html"), ColumnSpecifier::V8_MEMORY, minimal_heap_size)); | |
| 875 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 876 MatchTab("title1.html"), ColumnSpecifier::V8_MEMORY_USED, | |
| 877 minimal_heap_size)); | |
| 878 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 879 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("title1.html"))); | |
| 880 } | |
| 881 | |
| 882 // Checks that task manager counts utility process JS heap size. | |
| 883 IN_PROC_BROWSER_TEST_F(TaskManagerUtilityProcessBrowserTest, | |
| 884 UtilityJSHeapMemory) { | |
| 885 ShowTaskManager(); | |
| 886 model()->ToggleColumnVisibility(ColumnSpecifier::V8_MEMORY); | |
| 887 | |
| 888 auto proxy_resolver_name = | |
| 889 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_PROXY_RESOLVER_NAME); | |
| 890 ui_test_utils::NavigateToURL(browser(), GetTestURL()); | |
| 891 // The PAC script is trivial, so don't expect a large heap. | |
| 892 size_t minimal_heap_size = 1024; | |
| 893 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 894 MatchUtility(proxy_resolver_name), ColumnSpecifier::V8_MEMORY, | |
| 895 minimal_heap_size)); | |
| 896 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerStatToExceed( | |
| 897 MatchUtility(proxy_resolver_name), ColumnSpecifier::V8_MEMORY_USED, | |
| 898 minimal_heap_size)); | |
| 899 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyUtility())); | |
| 900 ASSERT_NO_FATAL_FAILURE( | |
| 901 WaitForTaskManagerRows(1, MatchUtility(proxy_resolver_name))); | |
| 902 } | |
| 903 | |
| 904 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewDockedWindow) { | |
| 905 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 906 // a long chrome-devtools:// URL without a prefix (expecting "Tab: *"). | |
| 907 DisableNewTaskManagerForBrokenTest(); | |
| 908 | |
| 909 ShowTaskManager(); // Task manager shown BEFORE dev tools window. | |
| 910 | |
| 911 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 912 DevToolsWindow* devtools = | |
| 913 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true); | |
| 914 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 915 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 916 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
| 917 } | |
| 918 | |
| 919 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsNewUndockedWindow) { | |
| 920 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 921 // a long chrome-devtools:// URL without a prefix (expecting "Tab: *"). | |
| 922 DisableNewTaskManagerForBrokenTest(); | |
| 923 | |
| 924 ShowTaskManager(); // Task manager shown BEFORE dev tools window. | |
| 925 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 926 DevToolsWindow* devtools = | |
| 927 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); | |
| 928 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); | |
| 929 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); | |
| 930 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
| 931 } | |
| 932 | |
| 933 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldDockedWindow) { | |
| 934 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 935 // a long chrome-devtools:// URL without a prefix (expecting "Tab: *"). | |
| 936 DisableNewTaskManagerForBrokenTest(); | |
| 937 | |
| 938 DevToolsWindow* devtools = | |
| 939 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true); | |
| 940 ShowTaskManager(); // Task manager shown AFTER dev tools window. | |
| 941 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 942 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnyTab())); | |
| 943 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
| 944 } | |
| 945 | |
| 946 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DevToolsOldUndockedWindow) { | |
| 947 // TODO(nick, afakhry): Broken on new task manager because we show | |
| 948 // a long chrome-devtools:// URL without a prefix (expecting "Tab: *"). | |
| 949 DisableNewTaskManagerForBrokenTest(); | |
| 950 | |
| 951 DevToolsWindow* devtools = | |
| 952 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); | |
| 953 ShowTaskManager(); // Task manager shown AFTER dev tools window. | |
| 954 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); | |
| 955 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(3, MatchAnyTab())); | |
| 956 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools); | |
| 957 } | |
| 958 | |
| 959 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, KillSubframe) { | |
| 960 ShowTaskManager(); | |
| 961 | |
| 962 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 963 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 964 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 965 | |
| 966 GURL main_url(embedded_test_server()->GetURL( | |
| 967 "/cross-site/a.com/iframe_cross_site.html")); | |
| 968 browser()->OpenURL(content::OpenURLParams(main_url, content::Referrer(), | |
| 969 CURRENT_TAB, | |
| 970 ui::PAGE_TRANSITION_TYPED, false)); | |
| 971 | |
| 972 ASSERT_NO_FATAL_FAILURE( | |
| 973 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 974 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 975 | |
| 976 if (!ShouldExpectSubframes()) { | |
| 977 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 978 } else { | |
| 979 ASSERT_NO_FATAL_FAILURE( | |
| 980 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 981 ASSERT_NO_FATAL_FAILURE( | |
| 982 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 983 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 984 int subframe_b = FindResourceIndex(MatchSubframe("http://b.com/")); | |
| 985 ASSERT_NE(-1, subframe_b); | |
| 986 ASSERT_NE(-1, model()->GetTabId(subframe_b)); | |
| 987 | |
| 988 model()->Kill(subframe_b); | |
| 989 | |
| 990 ASSERT_NO_FATAL_FAILURE( | |
| 991 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); | |
| 992 ASSERT_NO_FATAL_FAILURE( | |
| 993 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 994 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); | |
| 995 ASSERT_NO_FATAL_FAILURE( | |
| 996 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 997 } | |
| 998 | |
| 999 HideTaskManager(); | |
| 1000 ShowTaskManager(); | |
| 1001 | |
| 1002 if (!ShouldExpectSubframes()) { | |
| 1003 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1004 } else { | |
| 1005 ASSERT_NO_FATAL_FAILURE( | |
| 1006 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); | |
| 1007 ASSERT_NO_FATAL_FAILURE( | |
| 1008 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1009 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); | |
| 1010 ASSERT_NO_FATAL_FAILURE( | |
| 1011 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1012 } | |
| 1013 } | |
| 1014 | |
| 1015 // Tests what happens when a tab navigates to a site (a.com) that it previously | |
| 1016 // has a cross-process subframe into (b.com). | |
| 1017 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, NavigateToSubframeProcess) { | |
| 1018 ShowTaskManager(); | |
| 1019 | |
| 1020 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 1021 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1022 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 1023 | |
| 1024 // Navigate the tab to a page on a.com with cross-process subframes to | |
| 1025 // b.com and c.com. | |
| 1026 GURL a_dotcom(embedded_test_server()->GetURL( | |
| 1027 "/cross-site/a.com/iframe_cross_site.html")); | |
| 1028 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(), | |
| 1029 CURRENT_TAB, | |
| 1030 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1031 | |
| 1032 ASSERT_NO_FATAL_FAILURE( | |
| 1033 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1034 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1035 | |
| 1036 if (!ShouldExpectSubframes()) { | |
| 1037 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1038 } else { | |
| 1039 ASSERT_NO_FATAL_FAILURE( | |
| 1040 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1041 ASSERT_NO_FATAL_FAILURE( | |
| 1042 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1043 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1044 } | |
| 1045 | |
| 1046 // Now navigate to a page on b.com with a simple (same-site) iframe. | |
| 1047 // This should not show any subframe resources in the task manager. | |
| 1048 GURL b_dotcom( | |
| 1049 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html")); | |
| 1050 | |
| 1051 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(), | |
| 1052 CURRENT_TAB, | |
| 1053 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1054 | |
| 1055 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test"))); | |
| 1056 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1057 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1058 HideTaskManager(); | |
| 1059 ShowTaskManager(); | |
| 1060 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test"))); | |
| 1061 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1062 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1063 } | |
| 1064 | |
| 1065 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, | |
| 1066 NavigateToSiteWithSubframeToOriginalSite) { | |
| 1067 ShowTaskManager(); | |
| 1068 | |
| 1069 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 1070 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1071 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 1072 | |
| 1073 // Navigate to a page on b.com with a simple (same-site) iframe. | |
| 1074 // This should not show any subframe resources in the task manager. | |
| 1075 GURL b_dotcom( | |
| 1076 embedded_test_server()->GetURL("/cross-site/b.com/iframe.html")); | |
| 1077 | |
| 1078 browser()->OpenURL(content::OpenURLParams(b_dotcom, content::Referrer(), | |
| 1079 CURRENT_TAB, | |
| 1080 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1081 | |
| 1082 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("iframe test"))); | |
| 1083 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1084 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1085 | |
| 1086 // Now navigate the tab to a page on a.com with cross-process subframes to | |
| 1087 // b.com and c.com. | |
| 1088 GURL a_dotcom(embedded_test_server()->GetURL( | |
| 1089 "/cross-site/a.com/iframe_cross_site.html")); | |
| 1090 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(), | |
| 1091 CURRENT_TAB, | |
| 1092 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1093 | |
| 1094 ASSERT_NO_FATAL_FAILURE( | |
| 1095 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1096 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1097 | |
| 1098 if (!ShouldExpectSubframes()) { | |
| 1099 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1100 } else { | |
| 1101 ASSERT_NO_FATAL_FAILURE( | |
| 1102 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1103 ASSERT_NO_FATAL_FAILURE( | |
| 1104 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1105 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1106 } | |
| 1107 | |
| 1108 HideTaskManager(); | |
| 1109 ShowTaskManager(); | |
| 1110 | |
| 1111 if (!ShouldExpectSubframes()) { | |
| 1112 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1113 } else { | |
| 1114 ASSERT_NO_FATAL_FAILURE( | |
| 1115 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1116 ASSERT_NO_FATAL_FAILURE( | |
| 1117 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1118 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1119 } | |
| 1120 } | |
| 1121 | |
| 1122 // Tests what happens when a tab navigates a cross-frame iframe (to b.com) | |
| 1123 // back to the site of the parent document (a.com). | |
| 1124 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, | |
| 1125 CrossSiteIframeBecomesSameSite) { | |
| 1126 ShowTaskManager(); | |
| 1127 | |
| 1128 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 1129 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1130 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 1131 | |
| 1132 // Navigate the tab to a page on a.com with cross-process subframes to | |
| 1133 // b.com and c.com. | |
| 1134 GURL a_dotcom(embedded_test_server()->GetURL( | |
| 1135 "/cross-site/a.com/iframe_cross_site.html")); | |
| 1136 browser()->OpenURL(content::OpenURLParams(a_dotcom, content::Referrer(), | |
| 1137 CURRENT_TAB, | |
| 1138 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1139 | |
| 1140 ASSERT_NO_FATAL_FAILURE( | |
| 1141 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1142 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1143 | |
| 1144 if (!ShouldExpectSubframes()) { | |
| 1145 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1146 } else { | |
| 1147 ASSERT_NO_FATAL_FAILURE( | |
| 1148 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1149 ASSERT_NO_FATAL_FAILURE( | |
| 1150 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1151 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1152 } | |
| 1153 | |
| 1154 // Navigate the b.com frame back to a.com. It is no longer a cross-site iframe | |
| 1155 ASSERT_TRUE(content::ExecuteScript( | |
| 1156 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | |
| 1157 "document.getElementById('frame1').src='/title1.html';" | |
| 1158 "document.title='aac';")); | |
| 1159 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac"))); | |
| 1160 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1161 if (!ShouldExpectSubframes()) { | |
| 1162 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1163 } else { | |
| 1164 ASSERT_NO_FATAL_FAILURE( | |
| 1165 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); | |
| 1166 ASSERT_NO_FATAL_FAILURE( | |
| 1167 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1168 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); | |
| 1169 } | |
| 1170 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac"))); | |
| 1171 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1172 | |
| 1173 HideTaskManager(); | |
| 1174 ShowTaskManager(); | |
| 1175 | |
| 1176 if (!ShouldExpectSubframes()) { | |
| 1177 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1178 } else { | |
| 1179 ASSERT_NO_FATAL_FAILURE( | |
| 1180 WaitForTaskManagerRows(0, MatchSubframe("http://b.com/"))); | |
| 1181 ASSERT_NO_FATAL_FAILURE( | |
| 1182 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1183 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnySubframe())); | |
| 1184 } | |
| 1185 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchTab("aac"))); | |
| 1186 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1187 } | |
| 1188 | |
| 1189 IN_PROC_BROWSER_TEST_P(TaskManagerOOPIFBrowserTest, | |
| 1190 LeavePageWithCrossSiteIframes) { | |
| 1191 ShowTaskManager(); | |
| 1192 | |
| 1193 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 1194 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1195 content::SetupCrossSiteRedirector(embedded_test_server()); | |
| 1196 | |
| 1197 // Navigate the tab to a page on a.com with cross-process subframes. | |
| 1198 GURL a_dotcom_with_iframes(embedded_test_server()->GetURL( | |
| 1199 "/cross-site/a.com/iframe_cross_site.html")); | |
| 1200 browser()->OpenURL(content::OpenURLParams(a_dotcom_with_iframes, | |
| 1201 content::Referrer(), CURRENT_TAB, | |
| 1202 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1203 | |
| 1204 ASSERT_NO_FATAL_FAILURE( | |
| 1205 WaitForTaskManagerRows(1, MatchTab("cross-site iframe test"))); | |
| 1206 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab())); | |
| 1207 | |
| 1208 if (!ShouldExpectSubframes()) { | |
| 1209 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1210 } else { | |
| 1211 ASSERT_NO_FATAL_FAILURE( | |
| 1212 WaitForTaskManagerRows(1, MatchSubframe("http://b.com/"))); | |
| 1213 ASSERT_NO_FATAL_FAILURE( | |
| 1214 WaitForTaskManagerRows(1, MatchSubframe("http://c.com/"))); | |
| 1215 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(2, MatchAnySubframe())); | |
| 1216 } | |
| 1217 | |
| 1218 // Navigate the tab to a page on a.com without cross-process subframes, and | |
| 1219 // the subframe processes should disappear. | |
| 1220 GURL a_dotcom_simple( | |
| 1221 embedded_test_server()->GetURL("/cross-site/a.com/title2.html")); | |
| 1222 browser()->OpenURL(content::OpenURLParams(a_dotcom_simple, | |
| 1223 content::Referrer(), CURRENT_TAB, | |
| 1224 ui::PAGE_TRANSITION_TYPED, false)); | |
| 1225 ASSERT_NO_FATAL_FAILURE( | |
| 1226 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness"))); | |
| 1227 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1228 | |
| 1229 HideTaskManager(); | |
| 1230 ShowTaskManager(); | |
| 1231 | |
| 1232 ASSERT_NO_FATAL_FAILURE( | |
| 1233 WaitForTaskManagerRows(1, MatchTab("Title Of Awesomeness"))); | |
| 1234 ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(0, MatchAnySubframe())); | |
| 1235 } | |
| OLD | NEW |