| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/notifications/desktop_notification_service.h" | 14 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 15 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/notifications/notification_test_util.h" | 16 #include "chrome/browser/notifications/notification_test_util.h" |
| 17 #include "chrome/browser/notifications/notification_ui_manager.h" | 17 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 19 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 20 #include "chrome/browser/tabs/tab_strip_model.h" | 20 #include "chrome/browser/tabs/tab_strip_model.h" |
| 21 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_navigator.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 26 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
| 28 #include "chrome/test/base/ui_test_utils.h" | 29 #include "chrome/test/base/ui_test_utils.h" |
| 29 #include "content/common/page_transition_types.h" | 30 #include "content/common/page_transition_types.h" |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "net/base/mock_host_resolver.h" | 32 #include "net/base/mock_host_resolver.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 | 35 |
| 35 // On Linux this is crashing intermittently http://crbug/84719 | 36 // On Linux this is crashing intermittently http://crbug/84719 |
| 36 // In some environments this test fails about 1/6 http://crbug/84850 | 37 // In some environments this test fails about 1/6 http://crbug/84850 |
| 37 #if defined(OS_LINUX) | 38 #if defined(OS_LINUX) |
| 38 #define MAYBE_KillExtension DISABLED_KillExtension | 39 #define MAYBE_KillExtension DISABLED_KillExtension |
| 39 #elif defined(TOUCH_UI) | 40 #elif defined(TOUCH_UI) |
| 40 #define MAYBE_KillExtension FLAKY_KillExtension | 41 #define MAYBE_KillExtension FLAKY_KillExtension |
| 41 #else | 42 #else |
| 42 #define MAYBE_KillExtension KillExtension | 43 #define MAYBE_KillExtension KillExtension |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); | 48 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); |
| 48 | 49 |
| 49 class ResourceChangeObserver : public TaskManagerModelObserver { | |
| 50 public: | |
| 51 ResourceChangeObserver(const TaskManagerModel* model, | |
| 52 int target_resource_count) | |
| 53 : model_(model), | |
| 54 target_resource_count_(target_resource_count) { | |
| 55 } | |
| 56 | |
| 57 virtual void OnModelChanged() { | |
| 58 OnResourceChange(); | |
| 59 } | |
| 60 | |
| 61 virtual void OnItemsChanged(int start, int length) { | |
| 62 OnResourceChange(); | |
| 63 } | |
| 64 | |
| 65 virtual void OnItemsAdded(int start, int length) { | |
| 66 OnResourceChange(); | |
| 67 } | |
| 68 | |
| 69 virtual void OnItemsRemoved(int start, int length) { | |
| 70 OnResourceChange(); | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 void OnResourceChange() { | |
| 75 if (model_->ResourceCount() == target_resource_count_) | |
| 76 MessageLoopForUI::current()->Quit(); | |
| 77 } | |
| 78 | |
| 79 const TaskManagerModel* model_; | |
| 80 const int target_resource_count_; | |
| 81 }; | |
| 82 | |
| 83 // Helper class used to wait for a BackgroundContents to finish loading. | |
| 84 class BackgroundContentsListener : public NotificationObserver { | |
| 85 public: | |
| 86 explicit BackgroundContentsListener(Profile* profile) { | |
| 87 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | |
| 88 Source<Profile>(profile)); | |
| 89 } | |
| 90 virtual void Observe(int type, | |
| 91 const NotificationSource& source, | |
| 92 const NotificationDetails& details) { | |
| 93 // Quit once the BackgroundContents has been loaded. | |
| 94 if (type == chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED) | |
| 95 MessageLoopForUI::current()->Quit(); | |
| 96 } | |
| 97 private: | |
| 98 NotificationRegistrar registrar_; | |
| 99 }; | |
| 100 | |
| 101 } // namespace | 50 } // namespace |
| 102 | 51 |
| 103 class TaskManagerBrowserTest : public ExtensionBrowserTest { | 52 class TaskManagerBrowserTest : public ExtensionBrowserTest { |
| 104 public: | 53 public: |
| 105 TaskManagerModel* model() const { | 54 TaskManagerModel* model() const { |
| 106 return TaskManager::GetInstance()->model(); | 55 return TaskManager::GetInstance()->model(); |
| 107 } | 56 } |
| 108 | |
| 109 void WaitForResourceChange(int target_count) { | |
| 110 if (model()->ResourceCount() == target_count) | |
| 111 return; | |
| 112 ResourceChangeObserver observer(model(), target_count); | |
| 113 model()->AddObserver(&observer); | |
| 114 ui_test_utils::RunMessageLoop(); | |
| 115 model()->RemoveObserver(&observer); | |
| 116 } | |
| 117 | |
| 118 // Wait for any pending BackgroundContents to finish starting up. | |
| 119 void WaitForBackgroundContents() { | |
| 120 BackgroundContentsListener listener(browser()->profile()); | |
| 121 ui_test_utils::RunMessageLoop(); | |
| 122 } | |
| 123 }; | 57 }; |
| 124 | 58 |
| 125 // Regression test for http://crbug.com/13361 | 59 // Regression test for http://crbug.com/13361 |
| 126 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) { | 60 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) { |
| 127 browser()->window()->ShowTaskManager(); | 61 browser()->window()->ShowTaskManager(); |
| 128 } | 62 } |
| 129 | 63 |
| 130 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { | 64 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { |
| 131 EXPECT_EQ(0, model()->ResourceCount()); | 65 EXPECT_EQ(0, model()->ResourceCount()); |
| 132 | 66 |
| 133 // Show the task manager. This populates the model, and helps with debugging | 67 // Show the task manager. This populates the model, and helps with debugging |
| 134 // (you see the task manager). | 68 // (you see the task manager). |
| 135 browser()->window()->ShowTaskManager(); | 69 browser()->window()->ShowTaskManager(); |
| 136 | 70 |
| 137 // Browser and the New Tab Page. | 71 // Browser and the New Tab Page. |
| 138 WaitForResourceChange(2); | 72 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 139 | 73 |
| 140 // Open a new tab and make sure we notice that. | 74 // Open a new tab and make sure we notice that. |
| 141 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 75 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 142 FilePath(kTitle1File))); | 76 FilePath(kTitle1File))); |
| 143 AddTabAtIndex(0, url, PageTransition::TYPED); | 77 AddTabAtIndex(0, url, PageTransition::TYPED); |
| 144 WaitForResourceChange(3); | 78 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 145 | 79 |
| 146 // Check that the third entry is a tab contents resource whose title starts | 80 // Check that the third entry is a tab contents resource whose title starts |
| 147 // starts with "Tab:". | 81 // starts with "Tab:". |
| 148 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); | 82 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); |
| 149 string16 prefix = l10n_util::GetStringFUTF16( | 83 string16 prefix = l10n_util::GetStringFUTF16( |
| 150 IDS_TASK_MANAGER_TAB_PREFIX, string16()); | 84 IDS_TASK_MANAGER_TAB_PREFIX, string16()); |
| 151 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 85 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 152 | 86 |
| 153 // Close the tab and verify that we notice. | 87 // Close the tab and verify that we notice. |
| 154 TabContents* first_tab = browser()->GetTabContentsAt(0); | 88 TabContents* first_tab = browser()->GetTabContentsAt(0); |
| 155 ASSERT_TRUE(first_tab); | 89 ASSERT_TRUE(first_tab); |
| 156 browser()->CloseTabContents(first_tab); | 90 browser()->CloseTabContents(first_tab); |
| 157 WaitForResourceChange(2); | 91 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 158 } | 92 } |
| 159 | 93 |
| 160 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { | 94 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { |
| 161 EXPECT_EQ(0, model()->ResourceCount()); | 95 EXPECT_EQ(0, model()->ResourceCount()); |
| 162 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 96 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 163 | 97 |
| 164 // Show the task manager. This populates the model, and helps with debugging | 98 // Show the task manager. This populates the model, and helps with debugging |
| 165 // (you see the task manager). | 99 // (you see the task manager). |
| 166 browser()->window()->ShowTaskManager(); | 100 browser()->window()->ShowTaskManager(); |
| 167 | 101 |
| 168 // Browser and the New Tab Page. | 102 // Browser and the New Tab Page. |
| 169 WaitForResourceChange(2); | 103 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 170 | 104 |
| 171 // Open a new background contents and make sure we notice that. | 105 // Open a new background contents and make sure we notice that. |
| 172 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 106 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 173 FilePath(kTitle1File))); | 107 FilePath(kTitle1File))); |
| 174 | 108 |
| 175 BackgroundContentsService* service = | 109 BackgroundContentsService* service = |
| 176 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); | 110 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); |
| 177 string16 application_id(ASCIIToUTF16("test_app_id")); | 111 string16 application_id(ASCIIToUTF16("test_app_id")); |
| 178 service->LoadBackgroundContents(browser()->profile(), | 112 service->LoadBackgroundContents(browser()->profile(), |
| 179 url, | 113 url, |
| 180 ASCIIToUTF16("background_page"), | 114 ASCIIToUTF16("background_page"), |
| 181 application_id); | 115 application_id); |
| 182 WaitForResourceChange(3); | 116 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 183 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | 117 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); |
| 184 | 118 |
| 185 // Close the background contents and verify that we notice. | 119 // Close the background contents and verify that we notice. |
| 186 service->ShutdownAssociatedBackgroundContents(application_id); | 120 service->ShutdownAssociatedBackgroundContents(application_id); |
| 187 WaitForResourceChange(2); | 121 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 188 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 122 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 189 } | 123 } |
| 190 | 124 |
| 191 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) { | 125 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) { |
| 192 EXPECT_EQ(0, model()->ResourceCount()); | 126 EXPECT_EQ(0, model()->ResourceCount()); |
| 193 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 127 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 194 | 128 |
| 195 // Show the task manager. This populates the model, and helps with debugging | 129 // Show the task manager. This populates the model, and helps with debugging |
| 196 // (you see the task manager). | 130 // (you see the task manager). |
| 197 browser()->window()->ShowTaskManager(); | 131 browser()->window()->ShowTaskManager(); |
| 198 | 132 |
| 199 // Browser and the New Tab Page. | 133 // Browser and the New Tab Page. |
| 200 WaitForResourceChange(2); | 134 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 201 | 135 |
| 202 // Open a new background contents and make sure we notice that. | 136 // Open a new background contents and make sure we notice that. |
| 203 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 137 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 204 FilePath(kTitle1File))); | 138 FilePath(kTitle1File))); |
| 205 | 139 |
| 140 ui_test_utils::WindowedNotificationObserver observer( |
| 141 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
| 142 Source<Profile>(browser()->profile())); |
| 143 |
| 206 BackgroundContentsService* service = | 144 BackgroundContentsService* service = |
| 207 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); | 145 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); |
| 208 string16 application_id(ASCIIToUTF16("test_app_id")); | 146 string16 application_id(ASCIIToUTF16("test_app_id")); |
| 209 service->LoadBackgroundContents(browser()->profile(), | 147 service->LoadBackgroundContents(browser()->profile(), |
| 210 url, | 148 url, |
| 211 ASCIIToUTF16("background_page"), | 149 ASCIIToUTF16("background_page"), |
| 212 application_id); | 150 application_id); |
| 151 |
| 213 // Wait for the background contents process to finish loading. | 152 // Wait for the background contents process to finish loading. |
| 214 WaitForBackgroundContents(); | 153 observer.Wait(); |
| 154 |
| 215 EXPECT_EQ(3, model()->ResourceCount()); | 155 EXPECT_EQ(3, model()->ResourceCount()); |
| 216 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | 156 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); |
| 217 | 157 |
| 218 // Kill the background contents process and verify that it disappears from the | 158 // Kill the background contents process and verify that it disappears from the |
| 219 // model. | 159 // model. |
| 220 bool found = false; | 160 bool found = false; |
| 221 for (int i = 0; i < model()->ResourceCount(); ++i) { | 161 for (int i = 0; i < model()->ResourceCount(); ++i) { |
| 222 if (model()->IsBackgroundResource(i)) { | 162 if (model()->IsBackgroundResource(i)) { |
| 223 TaskManager::GetInstance()->KillProcess(i); | 163 TaskManager::GetInstance()->KillProcess(i); |
| 224 found = true; | 164 found = true; |
| 225 break; | 165 break; |
| 226 } | 166 } |
| 227 } | 167 } |
| 228 ASSERT_TRUE(found); | 168 ASSERT_TRUE(found); |
| 229 WaitForResourceChange(2); | 169 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 230 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 170 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 231 } | 171 } |
| 232 | 172 |
| 233 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { | 173 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { |
| 234 EXPECT_EQ(0, model()->ResourceCount()); | 174 EXPECT_EQ(0, model()->ResourceCount()); |
| 235 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 175 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 236 | 176 |
| 237 // Show the task manager. This populates the model, and helps with debugging | 177 // Show the task manager. This populates the model, and helps with debugging |
| 238 // (you see the task manager). | 178 // (you see the task manager). |
| 239 browser()->window()->ShowTaskManager(); | 179 browser()->window()->ShowTaskManager(); |
| 240 | 180 |
| 241 // Browser and the New Tab Page. | 181 // Browser and the New Tab Page. |
| 242 WaitForResourceChange(2); | 182 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 243 | 183 |
| 244 // Loading an extension with a background page should result in a new | 184 // Loading an extension with a background page should result in a new |
| 245 // resource being created for it. | 185 // resource being created for it. |
| 246 ASSERT_TRUE(LoadExtension( | 186 ASSERT_TRUE(LoadExtension( |
| 247 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 187 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
| 248 WaitForResourceChange(3); | 188 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 249 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | 189 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); |
| 250 | 190 |
| 251 // Unload extension to avoid crash on Windows (see http://crbug.com/31663). | 191 // Unload extension to avoid crash on Windows (see http://crbug.com/31663). |
| 252 UnloadExtension(last_loaded_extension_id_); | 192 UnloadExtension(last_loaded_extension_id_); |
| 253 WaitForResourceChange(2); | 193 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 254 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 194 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 255 } | 195 } |
| 256 | 196 |
| 257 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { | 197 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { |
| 258 // Show the task manager. This populates the model, and helps with debugging | 198 // Show the task manager. This populates the model, and helps with debugging |
| 259 // (you see the task manager). | 199 // (you see the task manager). |
| 260 browser()->window()->ShowTaskManager(); | 200 browser()->window()->ShowTaskManager(); |
| 261 | 201 |
| 262 ASSERT_TRUE(LoadExtension( | 202 ASSERT_TRUE(LoadExtension( |
| 263 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | 203 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 264 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 204 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 265 .AppendASCII("1.0.0.0"))); | 205 .AppendASCII("1.0.0.0"))); |
| 266 | 206 |
| 267 // Browser, Extension background page, and the New Tab Page. | 207 // Browser, Extension background page, and the New Tab Page. |
| 268 WaitForResourceChange(3); | 208 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 269 | 209 |
| 270 // Open a new tab to an extension URL and make sure we notice that. | 210 // Open a new tab to an extension URL and make sure we notice that. |
| 271 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); | 211 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); |
| 272 AddTabAtIndex(0, url, PageTransition::TYPED); | 212 AddTabAtIndex(0, url, PageTransition::TYPED); |
| 273 WaitForResourceChange(4); | 213 TaskManagerBrowserTestUtil::WaitForResourceChange(4); |
| 274 | 214 |
| 275 // Check that the third entry (background) is an extension resource whose | 215 // Check that the third entry (background) is an extension resource whose |
| 276 // title starts with "Extension:". | 216 // title starts with "Extension:". |
| 277 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); | 217 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); |
| 278 ASSERT_TRUE(model()->GetResourceTabContents(2) == NULL); | 218 ASSERT_TRUE(model()->GetResourceTabContents(2) == NULL); |
| 279 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 219 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
| 280 string16 prefix = l10n_util::GetStringFUTF16( | 220 string16 prefix = l10n_util::GetStringFUTF16( |
| 281 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); | 221 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); |
| 282 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 222 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 283 | 223 |
| 284 // Check that the fourth entry (page.html) is of type extension and has both | 224 // Check that the fourth entry (page.html) is of type extension and has both |
| 285 // a tab contents and an extension. The title should start with "Extension:". | 225 // a tab contents and an extension. The title should start with "Extension:". |
| 286 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); | 226 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); |
| 287 ASSERT_TRUE(model()->GetResourceTabContents(3) != NULL); | 227 ASSERT_TRUE(model()->GetResourceTabContents(3) != NULL); |
| 288 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); | 228 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); |
| 289 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); | 229 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); |
| 290 | 230 |
| 291 // Unload extension to avoid crash on Windows. | 231 // Unload extension to avoid crash on Windows. |
| 292 UnloadExtension(last_loaded_extension_id_); | 232 UnloadExtension(last_loaded_extension_id_); |
| 293 WaitForResourceChange(2); | 233 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 294 } | 234 } |
| 295 | 235 |
| 296 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { | 236 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { |
| 297 // Show the task manager. This populates the model, and helps with debugging | 237 // Show the task manager. This populates the model, and helps with debugging |
| 298 // (you see the task manager). | 238 // (you see the task manager). |
| 299 browser()->window()->ShowTaskManager(); | 239 browser()->window()->ShowTaskManager(); |
| 300 | 240 |
| 301 ASSERT_TRUE(LoadExtension( | 241 ASSERT_TRUE(LoadExtension( |
| 302 test_data_dir_.AppendASCII("packaged_app"))); | 242 test_data_dir_.AppendASCII("packaged_app"))); |
| 303 ExtensionService* service = browser()->profile()->GetExtensionService(); | 243 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 304 const Extension* extension = | 244 const Extension* extension = |
| 305 service->GetExtensionById(last_loaded_extension_id_, false); | 245 service->GetExtensionById(last_loaded_extension_id_, false); |
| 306 | 246 |
| 307 // Browser and the New Tab Page. | 247 // Browser and the New Tab Page. |
| 308 WaitForResourceChange(2); | 248 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 309 | 249 |
| 310 // Open a new tab to the app's launch URL and make sure we notice that. | 250 // Open a new tab to the app's launch URL and make sure we notice that. |
| 311 GURL url(extension->GetResourceURL("main.html")); | 251 GURL url(extension->GetResourceURL("main.html")); |
| 312 AddTabAtIndex(0, url, PageTransition::TYPED); | 252 AddTabAtIndex(0, url, PageTransition::TYPED); |
| 313 WaitForResourceChange(3); | 253 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 314 | 254 |
| 315 // Check that the third entry (main.html) is of type extension and has both | 255 // Check that the third entry (main.html) is of type extension and has both |
| 316 // a tab contents and an extension. The title should start with "App:". | 256 // a tab contents and an extension. The title should start with "App:". |
| 317 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); | 257 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); |
| 318 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); | 258 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); |
| 319 ASSERT_TRUE(model()->GetResourceExtension(2) == extension); | 259 ASSERT_TRUE(model()->GetResourceExtension(2) == extension); |
| 320 string16 prefix = l10n_util::GetStringFUTF16( | 260 string16 prefix = l10n_util::GetStringFUTF16( |
| 321 IDS_TASK_MANAGER_APP_PREFIX, string16()); | 261 IDS_TASK_MANAGER_APP_PREFIX, string16()); |
| 322 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 262 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 323 | 263 |
| 324 // Unload extension to avoid crash on Windows. | 264 // Unload extension to avoid crash on Windows. |
| 325 UnloadExtension(last_loaded_extension_id_); | 265 UnloadExtension(last_loaded_extension_id_); |
| 326 WaitForResourceChange(2); | 266 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 327 } | 267 } |
| 328 | 268 |
| 329 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { | 269 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { |
| 330 // Show the task manager. This populates the model, and helps with debugging | 270 // Show the task manager. This populates the model, and helps with debugging |
| 331 // (you see the task manager). | 271 // (you see the task manager). |
| 332 browser()->window()->ShowTaskManager(); | 272 browser()->window()->ShowTaskManager(); |
| 333 | 273 |
| 334 // Browser and the New Tab Page. | 274 // Browser and the New Tab Page. |
| 335 WaitForResourceChange(2); | 275 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 336 | 276 |
| 337 // The app under test acts on URLs whose host is "localhost", | 277 // The app under test acts on URLs whose host is "localhost", |
| 338 // so the URLs we navigate to must have host "localhost". | 278 // so the URLs we navigate to must have host "localhost". |
| 339 host_resolver()->AddRule("*", "127.0.0.1"); | 279 host_resolver()->AddRule("*", "127.0.0.1"); |
| 340 ASSERT_TRUE(test_server()->Start()); | 280 ASSERT_TRUE(test_server()->Start()); |
| 341 GURL::Replacements replace_host; | 281 GURL::Replacements replace_host; |
| 342 std::string host_str("localhost"); // must stay in scope with replace_host | 282 std::string host_str("localhost"); // must stay in scope with replace_host |
| 343 replace_host.SetHostStr(host_str); | 283 replace_host.SetHostStr(host_str); |
| 344 GURL base_url = test_server()->GetURL( | 284 GURL base_url = test_server()->GetURL( |
| 345 "files/extensions/api_test/app_process/"); | 285 "files/extensions/api_test/app_process/"); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 320 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 381 // Show the task manager. This populates the model, and helps with debugging | 321 // Show the task manager. This populates the model, and helps with debugging |
| 382 // (you see the task manager). | 322 // (you see the task manager). |
| 383 browser()->window()->ShowTaskManager(); | 323 browser()->window()->ShowTaskManager(); |
| 384 | 324 |
| 385 ASSERT_TRUE(LoadExtension( | 325 ASSERT_TRUE(LoadExtension( |
| 386 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 326 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
| 387 | 327 |
| 388 // Wait until we see the loaded extension in the task manager (the three | 328 // Wait until we see the loaded extension in the task manager (the three |
| 389 // resources are: the browser process, New Tab Page, and the extension). | 329 // resources are: the browser process, New Tab Page, and the extension). |
| 390 WaitForResourceChange(3); | 330 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 391 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | 331 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); |
| 392 | 332 |
| 393 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); | 333 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); |
| 394 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); | 334 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); |
| 395 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 335 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
| 396 | 336 |
| 397 // Kill the extension process and make sure we notice it. | 337 // Kill the extension process and make sure we notice it. |
| 398 TaskManager::GetInstance()->KillProcess(2); | 338 TaskManager::GetInstance()->KillProcess(2); |
| 399 WaitForResourceChange(2); | 339 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 400 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 340 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
| 401 } | 341 } |
| 402 | 342 |
| 403 // Disabled, http://crbug.com/66957. | 343 // Disabled, http://crbug.com/66957. |
| 404 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, | 344 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, |
| 405 DISABLED_KillExtensionAndReload) { | 345 DISABLED_KillExtensionAndReload) { |
| 406 // Show the task manager. This populates the model, and helps with debugging | 346 // Show the task manager. This populates the model, and helps with debugging |
| 407 // (you see the task manager). | 347 // (you see the task manager). |
| 408 browser()->window()->ShowTaskManager(); | 348 browser()->window()->ShowTaskManager(); |
| 409 | 349 |
| 410 ASSERT_TRUE(LoadExtension( | 350 ASSERT_TRUE(LoadExtension( |
| 411 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 351 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
| 412 | 352 |
| 413 // Wait until we see the loaded extension in the task manager (the three | 353 // Wait until we see the loaded extension in the task manager (the three |
| 414 // resources are: the browser process, New Tab Page, and the extension). | 354 // resources are: the browser process, New Tab Page, and the extension). |
| 415 WaitForResourceChange(3); | 355 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 416 | 356 |
| 417 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); | 357 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); |
| 418 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); | 358 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); |
| 419 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 359 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
| 420 | 360 |
| 421 // Kill the extension process and make sure we notice it. | 361 // Kill the extension process and make sure we notice it. |
| 422 TaskManager::GetInstance()->KillProcess(2); | 362 TaskManager::GetInstance()->KillProcess(2); |
| 423 WaitForResourceChange(2); | 363 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 424 | 364 |
| 425 // Reload the extension using the "crashed extension" infobar while the task | 365 // Reload the extension using the "crashed extension" infobar while the task |
| 426 // manager is still visible. Make sure we don't crash and the extension | 366 // manager is still visible. Make sure we don't crash and the extension |
| 427 // gets reloaded and noticed in the task manager. | 367 // gets reloaded and noticed in the task manager. |
| 428 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); | 368 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
| 429 ASSERT_EQ(1U, current_tab->infobar_count()); | 369 ASSERT_EQ(1U, current_tab->infobar_count()); |
| 430 ConfirmInfoBarDelegate* delegate = | 370 ConfirmInfoBarDelegate* delegate = |
| 431 current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 371 current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 432 ASSERT_TRUE(delegate); | 372 ASSERT_TRUE(delegate); |
| 433 delegate->Accept(); | 373 delegate->Accept(); |
| 434 WaitForResourceChange(3); | 374 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 435 } | 375 } |
| 436 | 376 |
| 437 // Regression test for http://crbug.com/18693. | 377 // Regression test for http://crbug.com/18693. |
| 438 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) { | 378 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) { |
| 439 // Show the task manager. This populates the model, and helps with debugging | 379 // Show the task manager. This populates the model, and helps with debugging |
| 440 // (you see the task manager). | 380 // (you see the task manager). |
| 441 browser()->window()->ShowTaskManager(); | 381 browser()->window()->ShowTaskManager(); |
| 442 | 382 |
| 443 LOG(INFO) << "loading extension"; | 383 LOG(INFO) << "loading extension"; |
| 444 ASSERT_TRUE(LoadExtension( | 384 ASSERT_TRUE(LoadExtension( |
| 445 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 385 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
| 446 | 386 |
| 447 // Wait until we see the loaded extension in the task manager (the three | 387 // Wait until we see the loaded extension in the task manager (the three |
| 448 // resources are: the browser process, New Tab Page, and the extension). | 388 // resources are: the browser process, New Tab Page, and the extension). |
| 449 LOG(INFO) << "waiting for resource change"; | 389 LOG(INFO) << "waiting for resource change"; |
| 450 WaitForResourceChange(3); | 390 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 451 | 391 |
| 452 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); | 392 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); |
| 453 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); | 393 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); |
| 454 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 394 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
| 455 | 395 |
| 456 const Extension* extension = model()->GetResourceExtension(2); | 396 const Extension* extension = model()->GetResourceExtension(2); |
| 457 ASSERT_TRUE(extension != NULL); | 397 ASSERT_TRUE(extension != NULL); |
| 458 | 398 |
| 459 // Reload the extension a few times and make sure our resource count | 399 // Reload the extension a few times and make sure our resource count |
| 460 // doesn't increase. | 400 // doesn't increase. |
| 461 LOG(INFO) << "First extension reload"; | 401 LOG(INFO) << "First extension reload"; |
| 462 ReloadExtension(extension->id()); | 402 ReloadExtension(extension->id()); |
| 463 WaitForResourceChange(3); | 403 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 464 extension = model()->GetResourceExtension(2); | 404 extension = model()->GetResourceExtension(2); |
| 465 ASSERT_TRUE(extension != NULL); | 405 ASSERT_TRUE(extension != NULL); |
| 466 | 406 |
| 467 LOG(INFO) << "Second extension reload"; | 407 LOG(INFO) << "Second extension reload"; |
| 468 ReloadExtension(extension->id()); | 408 ReloadExtension(extension->id()); |
| 469 WaitForResourceChange(3); | 409 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 470 extension = model()->GetResourceExtension(2); | 410 extension = model()->GetResourceExtension(2); |
| 471 ASSERT_TRUE(extension != NULL); | 411 ASSERT_TRUE(extension != NULL); |
| 472 | 412 |
| 473 LOG(INFO) << "Third extension reload"; | 413 LOG(INFO) << "Third extension reload"; |
| 474 ReloadExtension(extension->id()); | 414 ReloadExtension(extension->id()); |
| 475 WaitForResourceChange(3); | 415 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 476 } | 416 } |
| 477 | 417 |
| 478 // Crashy, http://crbug.com/42301. | 418 // Crashy, http://crbug.com/42301. |
| 479 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, | 419 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, |
| 480 DISABLED_PopulateWebCacheFields) { | 420 DISABLED_PopulateWebCacheFields) { |
| 481 EXPECT_EQ(0, model()->ResourceCount()); | 421 EXPECT_EQ(0, model()->ResourceCount()); |
| 482 | 422 |
| 483 // Show the task manager. This populates the model, and helps with debugging | 423 // Show the task manager. This populates the model, and helps with debugging |
| 484 // (you see the task manager). | 424 // (you see the task manager). |
| 485 browser()->window()->ShowTaskManager(); | 425 browser()->window()->ShowTaskManager(); |
| 486 | 426 |
| 487 // Browser and the New Tab Page. | 427 // Browser and the New Tab Page. |
| 488 WaitForResourceChange(2); | 428 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
| 489 | 429 |
| 490 // Open a new tab and make sure we notice that. | 430 // Open a new tab and make sure we notice that. |
| 491 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 431 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
| 492 FilePath(kTitle1File))); | 432 FilePath(kTitle1File))); |
| 493 AddTabAtIndex(0, url, PageTransition::TYPED); | 433 AddTabAtIndex(0, url, PageTransition::TYPED); |
| 494 WaitForResourceChange(3); | 434 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 495 | 435 |
| 496 // Check that we get some value for the cache columns. | 436 // Check that we get some value for the cache columns. |
| 497 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), | 437 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), |
| 498 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 438 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 499 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), | 439 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), |
| 500 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 440 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 501 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), | 441 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), |
| 502 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 442 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 503 } | 443 } |
| OLD | NEW |