| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/task_manager/task_manager.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/background/background_contents_service.h" | 9 #include "chrome/browser/background/background_contents_service.h" |
| 10 #include "chrome/browser/background/background_contents_service_factory.h" | 10 #include "chrome/browser/background/background_contents_service_factory.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/infobars/infobar_tab_helper.h" | 14 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 15 #include "chrome/browser/notifications/desktop_notification_service.h" | 15 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 17 #include "chrome/browser/notifications/notification_test_util.h" | 17 #include "chrome/browser/notifications/notification_test_util.h" |
| 18 #include "chrome/browser/notifications/notification_ui_manager.h" | 18 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 20 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 21 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 21 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_navigator.h" |
| 24 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
| 25 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| 26 #include "chrome/browser/ui/panels/panel.h" |
| 27 #include "chrome/browser/ui/panels/panel_manager.h" |
| 26 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 28 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 30 #include "chrome/browser/web_applications/web_app.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/extensions/extension.h" | 33 #include "chrome/common/extensions/extension.h" |
| 30 #include "chrome/test/base/in_process_browser_test.h" | 34 #include "chrome/test/base/in_process_browser_test.h" |
| 31 #include "chrome/test/base/ui_test_utils.h" | 35 #include "chrome/test/base/ui_test_utils.h" |
| 32 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/common/content_switches.h" | 37 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/common/page_transition_types.h" | 38 #include "content/public/common/page_transition_types.h" |
| 35 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 36 #include "net/base/mock_host_resolver.h" | 40 #include "net/base/mock_host_resolver.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 59 return TaskManager::GetInstance()->model(); | 63 return TaskManager::GetInstance()->model(); |
| 60 } | 64 } |
| 61 protected: | 65 protected: |
| 62 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 66 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 63 ExtensionBrowserTest::SetUpCommandLine(command_line); | 67 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 64 | 68 |
| 65 // Do not prelaunch the GPU process for these tests because it will show | 69 // Do not prelaunch the GPU process for these tests because it will show |
| 66 // up in task manager but whether it appears before or after the new tab | 70 // up in task manager but whether it appears before or after the new tab |
| 67 // renderer process is not well defined. | 71 // renderer process is not well defined. |
| 68 command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); | 72 command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); |
| 73 #if !defined(USE_AURA) && (defined(OS_MACOSX) || defined(OS_WIN)) |
| 74 // Browserless panels refactor not completed for Linux yet. |
| 75 command_line->AppendSwitch(switches::kBrowserlessPanels); |
| 76 #endif |
| 69 } | 77 } |
| 70 }; | 78 }; |
| 71 | 79 |
| 72 #if defined(OS_MACOSX) || defined(OS_LINUX) | 80 #if defined(OS_MACOSX) || defined(OS_LINUX) |
| 73 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen | 81 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen |
| 74 #else | 82 #else |
| 75 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen | 83 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen |
| 76 #endif | 84 #endif |
| 77 | 85 |
| 78 // Regression test for http://crbug.com/13361 | 86 // Regression test for http://crbug.com/13361 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 91 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 99 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 92 | 100 |
| 93 // Open a new tab and make sure we notice that. | 101 // Open a new tab and make sure we notice that. |
| 94 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 102 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 95 FilePath(kTitle1File))); | 103 FilePath(kTitle1File))); |
| 96 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); | 104 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); |
| 97 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 105 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 98 | 106 |
| 99 // Check that the third entry is a tab contents resource whose title starts | 107 // Check that the third entry is a tab contents resource whose title starts |
| 100 // starts with "Tab:". | 108 // starts with "Tab:". |
| 101 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); | 109 ASSERT_TRUE(model()->GetResourceWebContents(2) != NULL); |
| 102 string16 prefix = l10n_util::GetStringFUTF16( | 110 string16 prefix = l10n_util::GetStringFUTF16( |
| 103 IDS_TASK_MANAGER_TAB_PREFIX, string16()); | 111 IDS_TASK_MANAGER_TAB_PREFIX, string16()); |
| 104 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 112 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 105 | 113 |
| 106 // Close the tab and verify that we notice. | 114 // Close the tab and verify that we notice. |
| 107 WebContents* first_tab = | 115 WebContents* first_tab = |
| 108 chrome::GetTabContentsAt(browser(), 0)->web_contents(); | 116 chrome::GetTabContentsAt(browser(), 0)->web_contents(); |
| 109 ASSERT_TRUE(first_tab); | 117 ASSERT_TRUE(first_tab); |
| 110 chrome::CloseWebContents(browser(), first_tab); | 118 chrome::CloseWebContents(browser(), first_tab); |
| 111 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 119 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 112 } | 120 } |
| 113 | 121 |
| 122 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePanelChanges) { |
| 123 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 124 switches::kBrowserlessPanels)) |
| 125 return; |
| 126 |
| 127 EXPECT_EQ(0, model()->ResourceCount()); |
| 128 |
| 129 // Show the task manager. This populates the model, and helps with debugging |
| 130 // (you see the task manager). |
| 131 browser()->window()->ShowTaskManager(); |
| 132 |
| 133 // Browser and the New Tab Page. |
| 134 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 135 |
| 136 ASSERT_TRUE(LoadExtension( |
| 137 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 138 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 139 .AppendASCII("1.0.0.0"))); |
| 140 |
| 141 // Browser, the New Tab Page and Extension background page. |
| 142 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 143 |
| 144 // Open a new panel to an extension url and make sure we notice that. |
| 145 GURL url( |
| 146 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html"); |
| 147 Panel* panel = PanelManager::GetInstance()->CreatePanel( |
| 148 web_app::GenerateApplicationNameFromExtensionId( |
| 149 last_loaded_extension_id_), |
| 150 browser()->profile(), |
| 151 url, |
| 152 gfx::Size(300, 400)); |
| 153 TaskManagerBrowserTestUtil::WaitForResourceChange(4); |
| 154 |
| 155 // Check that the fourth entry is a resource with the panel's web contents |
| 156 // and whose title starts with "Extension:". |
| 157 ASSERT_EQ(panel->GetWebContents(), model()->GetResourceWebContents(3)); |
| 158 string16 prefix = l10n_util::GetStringFUTF16( |
| 159 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); |
| 160 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); |
| 161 |
| 162 // Close the panel and verify that we notice. |
| 163 panel->Close(); |
| 164 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 165 |
| 166 // Unload extension to avoid crash on Windows. |
| 167 UnloadExtension(last_loaded_extension_id_); |
| 168 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 169 } |
| 170 |
| 114 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { | 171 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { |
| 115 EXPECT_EQ(0, model()->ResourceCount()); | 172 EXPECT_EQ(0, model()->ResourceCount()); |
| 116 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 173 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 117 | 174 |
| 118 // Show the task manager. This populates the model, and helps with debugging | 175 // Show the task manager. This populates the model, and helps with debugging |
| 119 // (you see the task manager). | 176 // (you see the task manager). |
| 120 browser()->window()->ShowTaskManager(); | 177 browser()->window()->ShowTaskManager(); |
| 121 | 178 |
| 122 // Browser and the New Tab Page. | 179 // Browser and the New Tab Page. |
| 123 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 180 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 287 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 231 | 288 |
| 232 // Open a new tab to an extension URL and make sure we notice that. | 289 // Open a new tab to an extension URL and make sure we notice that. |
| 233 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); | 290 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); |
| 234 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); | 291 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); |
| 235 TaskManagerBrowserTestUtil::WaitForResourceChange(4); | 292 TaskManagerBrowserTestUtil::WaitForResourceChange(4); |
| 236 | 293 |
| 237 // Check that the third entry (background) is an extension resource whose | 294 // Check that the third entry (background) is an extension resource whose |
| 238 // title starts with "Extension:". | 295 // title starts with "Extension:". |
| 239 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); | 296 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); |
| 240 ASSERT_TRUE(model()->GetResourceTabContents(2) == NULL); | 297 ASSERT_TRUE(model()->GetResourceWebContents(2) == NULL); |
| 241 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 298 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
| 242 string16 prefix = l10n_util::GetStringFUTF16( | 299 string16 prefix = l10n_util::GetStringFUTF16( |
| 243 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); | 300 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); |
| 244 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 301 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 245 | 302 |
| 246 // Check that the fourth entry (page.html) is of type extension and has both | 303 // Check that the fourth entry (page.html) is of type extension and has both |
| 247 // a tab contents and an extension. The title should start with "Extension:". | 304 // a tab contents and an extension. The title should start with "Extension:". |
| 248 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); | 305 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); |
| 249 ASSERT_TRUE(model()->GetResourceTabContents(3) != NULL); | 306 ASSERT_TRUE(model()->GetResourceWebContents(3) != NULL); |
| 250 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); | 307 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); |
| 251 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); | 308 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); |
| 252 | 309 |
| 253 // Unload extension to avoid crash on Windows. | 310 // Unload extension to avoid crash on Windows. |
| 254 UnloadExtension(last_loaded_extension_id_); | 311 UnloadExtension(last_loaded_extension_id_); |
| 255 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 312 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 256 } | 313 } |
| 257 | 314 |
| 258 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { | 315 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { |
| 259 // Show the task manager. This populates the model, and helps with debugging | 316 // Show the task manager. This populates the model, and helps with debugging |
| (...skipping 12 matching lines...) Expand all Loading... |
| 272 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 329 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 273 | 330 |
| 274 // Open a new tab to the app's launch URL and make sure we notice that. | 331 // Open a new tab to the app's launch URL and make sure we notice that. |
| 275 GURL url(extension->GetResourceURL("main.html")); | 332 GURL url(extension->GetResourceURL("main.html")); |
| 276 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); | 333 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); |
| 277 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 334 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 278 | 335 |
| 279 // Check that the third entry (main.html) is of type extension and has both | 336 // Check that the third entry (main.html) is of type extension and has both |
| 280 // a tab contents and an extension. The title should start with "App:". | 337 // a tab contents and an extension. The title should start with "App:". |
| 281 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); | 338 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); |
| 282 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); | 339 ASSERT_TRUE(model()->GetResourceWebContents(2) != NULL); |
| 283 ASSERT_TRUE(model()->GetResourceExtension(2) == extension); | 340 ASSERT_TRUE(model()->GetResourceExtension(2) == extension); |
| 284 string16 prefix = l10n_util::GetStringFUTF16( | 341 string16 prefix = l10n_util::GetStringFUTF16( |
| 285 IDS_TASK_MANAGER_APP_PREFIX, string16()); | 342 IDS_TASK_MANAGER_APP_PREFIX, string16()); |
| 286 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 343 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 287 | 344 |
| 288 // Unload extension to avoid crash on Windows. | 345 // Unload extension to avoid crash on Windows. |
| 289 UnloadExtension(last_loaded_extension_id_); | 346 UnloadExtension(last_loaded_extension_id_); |
| 290 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 347 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 291 } | 348 } |
| 292 | 349 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 531 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 475 | 532 |
| 476 // Check that we get some value for the cache columns. | 533 // Check that we get some value for the cache columns. |
| 477 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), | 534 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), |
| 478 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 535 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 479 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), | 536 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), |
| 480 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 537 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 481 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), | 538 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), |
| 482 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 539 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 483 } | 540 } |
| OLD | NEW |