| 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/background/background_contents_service.h" | |
| 11 #include "chrome/browser/background/background_contents_service_factory.h" | |
| 12 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
| 16 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 14 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
| 18 #include "chrome/browser/notifications/desktop_notification_service.h" | 16 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 19 #include "chrome/browser/notifications/notification.h" | 17 #include "chrome/browser/notifications/notification.h" |
| 20 #include "chrome/browser/notifications/notification_test_util.h" | 18 #include "chrome/browser/notifications/notification_test_util.h" |
| 21 #include "chrome/browser/notifications/notification_ui_manager.h" | 19 #include "chrome/browser/notifications/notification_ui_manager.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 69 |
| 72 TaskManagerModel* model() const { | 70 TaskManagerModel* model() const { |
| 73 return TaskManager::GetInstance()->model(); | 71 return TaskManager::GetInstance()->model(); |
| 74 } | 72 } |
| 75 | 73 |
| 76 virtual void SetUpOnMainThread() OVERRIDE { | 74 virtual void SetUpOnMainThread() OVERRIDE { |
| 77 ExtensionBrowserTest::SetUpOnMainThread(); | 75 ExtensionBrowserTest::SetUpOnMainThread(); |
| 78 | 76 |
| 79 EXPECT_EQ(0, model()->ResourceCount()); | 77 EXPECT_EQ(0, model()->ResourceCount()); |
| 80 | 78 |
| 81 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | |
| 82 | |
| 83 // Show the task manager. This populates the model, and helps with debugging | 79 // Show the task manager. This populates the model, and helps with debugging |
| 84 // (you see the task manager). | 80 // (you see the task manager). |
| 85 chrome::ShowTaskManager(browser(), false); | 81 chrome::ShowTaskManager(browser()); |
| 86 | 82 |
| 87 // New Tab Page. | 83 // New Tab Page. |
| 88 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 84 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 89 } | 85 } |
| 90 | 86 |
| 91 void Refresh() { | 87 void Refresh() { |
| 92 model()->Refresh(); | 88 model()->Refresh(); |
| 93 } | 89 } |
| 94 | 90 |
| 95 int GetUpdateTimeMs() { | 91 int GetUpdateTimeMs() { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 178 |
| 183 // Close the panel and verify that we notice. | 179 // Close the panel and verify that we notice. |
| 184 panel->Close(); | 180 panel->Close(); |
| 185 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 181 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 186 | 182 |
| 187 // Unload extension to avoid crash on Windows. | 183 // Unload extension to avoid crash on Windows. |
| 188 UnloadExtension(last_loaded_extension_id_); | 184 UnloadExtension(last_loaded_extension_id_); |
| 189 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 185 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 190 } | 186 } |
| 191 | 187 |
| 192 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { | |
| 193 // Open a new background contents and make sure we notice that. | |
| 194 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | |
| 195 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); | |
| 196 | |
| 197 BackgroundContentsService* service = | |
| 198 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); | |
| 199 string16 application_id(ASCIIToUTF16("test_app_id")); | |
| 200 service->LoadBackgroundContents(browser()->profile(), | |
| 201 url, | |
| 202 ASCIIToUTF16("background_page"), | |
| 203 application_id); | |
| 204 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | |
| 205 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | |
| 206 | |
| 207 // Close the background contents and verify that we notice. | |
| 208 service->ShutdownAssociatedBackgroundContents(application_id); | |
| 209 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | |
| 210 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | |
| 211 } | |
| 212 | |
| 213 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) { | |
| 214 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | |
| 215 | |
| 216 // Open a new background contents and make sure we notice that. | |
| 217 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | |
| 218 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); | |
| 219 | |
| 220 content::WindowedNotificationObserver observer( | |
| 221 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, | |
| 222 content::Source<Profile>(browser()->profile())); | |
| 223 | |
| 224 BackgroundContentsService* service = | |
| 225 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); | |
| 226 string16 application_id(ASCIIToUTF16("test_app_id")); | |
| 227 service->LoadBackgroundContents(browser()->profile(), | |
| 228 url, | |
| 229 ASCIIToUTF16("background_page"), | |
| 230 application_id); | |
| 231 | |
| 232 // Wait for the background contents process to finish loading. | |
| 233 observer.Wait(); | |
| 234 | |
| 235 EXPECT_EQ(resource_count + 1, model()->ResourceCount()); | |
| 236 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | |
| 237 | |
| 238 // Kill the background contents process and verify that it disappears from the | |
| 239 // model. | |
| 240 bool found = false; | |
| 241 for (int i = 0; i < model()->ResourceCount(); ++i) { | |
| 242 if (model()->IsBackgroundResource(i)) { | |
| 243 TaskManager::GetInstance()->KillProcess(i); | |
| 244 found = true; | |
| 245 break; | |
| 246 } | |
| 247 } | |
| 248 ASSERT_TRUE(found); | |
| 249 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | |
| 250 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | |
| 251 } | |
| 252 | |
| 253 #if defined(USE_ASH) || defined(OS_WIN) | 188 #if defined(USE_ASH) || defined(OS_WIN) |
| 254 // This test fails on Ash because task manager treats view type | 189 // This test fails on Ash because task manager treats view type |
| 255 // Panels differently for Ash. | 190 // Panels differently for Ash. |
| 256 // This test also fails on Windows, win_rel trybot. http://crbug.com/166322 | 191 // This test also fails on Windows, win_rel trybot. http://crbug.com/166322 |
| 257 #define MAYBE_KillPanelExtension DISABLED_KillPanelExtension | 192 #define MAYBE_KillPanelExtension DISABLED_KillPanelExtension |
| 258 #else | 193 #else |
| 259 #define MAYBE_KillPanelExtension KillPanelExtension | 194 #define MAYBE_KillPanelExtension KillPanelExtension |
| 260 #endif | 195 #endif |
| 261 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillPanelExtension) { | 196 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillPanelExtension) { |
| 262 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 197 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 281 PanelManager::CREATE_AS_DOCKED); | 216 PanelManager::CREATE_AS_DOCKED); |
| 282 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); | 217 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 283 | 218 |
| 284 // Kill the panel extension process and verify that it disappears from the | 219 // Kill the panel extension process and verify that it disappears from the |
| 285 // model along with its panel. | 220 // model along with its panel. |
| 286 ASSERT_TRUE(model()->IsBackgroundResource(resource_count)); | 221 ASSERT_TRUE(model()->IsBackgroundResource(resource_count)); |
| 287 TaskManager::GetInstance()->KillProcess(resource_count); | 222 TaskManager::GetInstance()->KillProcess(resource_count); |
| 288 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 223 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 289 } | 224 } |
| 290 | 225 |
| 291 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { | |
| 292 // Loading an extension with a background page should result in a new | |
| 293 // resource being created for it. | |
| 294 ASSERT_TRUE(LoadExtension( | |
| 295 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | |
| 296 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | |
| 297 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | |
| 298 | |
| 299 // Unload extension to avoid crash on Windows (see http://crbug.com/31663). | |
| 300 UnloadExtension(last_loaded_extension_id_); | |
| 301 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | |
| 302 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | |
| 303 } | |
| 304 | |
| 305 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { | 226 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { |
| 306 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 227 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| 307 ASSERT_TRUE(LoadExtension( | 228 ASSERT_TRUE(LoadExtension( |
| 308 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | 229 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 309 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 230 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 310 .AppendASCII("1.0.0.0"))); | 231 .AppendASCII("1.0.0.0"))); |
| 311 | 232 |
| 312 // Browser, Extension background page, and the New Tab Page. | 233 // Browser, Extension background page, and the New Tab Page. |
| 313 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 234 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 314 | 235 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 ui_test_utils::NavigateToURL(browser(), url); | 350 ui_test_utils::NavigateToURL(browser(), url); |
| 430 | 351 |
| 431 // Force the TaskManager to query the title. | 352 // Force the TaskManager to query the title. |
| 432 Refresh(); | 353 Refresh(); |
| 433 | 354 |
| 434 // The third entry's title should be back to a normal tab. | 355 // The third entry's title should be back to a normal tab. |
| 435 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), | 356 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), |
| 436 tab_prefix, true)); | 357 tab_prefix, true)); |
| 437 } | 358 } |
| 438 | 359 |
| 439 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillExtension) { | |
| 440 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | |
| 441 | |
| 442 ASSERT_TRUE(LoadExtension( | |
| 443 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | |
| 444 | |
| 445 // Wait until we see the loaded extension in the task manager (the three | |
| 446 // resources are: the browser process, New Tab Page, and the extension). | |
| 447 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | |
| 448 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | |
| 449 | |
| 450 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); | |
| 451 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); | |
| 452 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL); | |
| 453 | |
| 454 // Kill the extension process and make sure we notice it. | |
| 455 TaskManager::GetInstance()->KillProcess(resource_count); | |
| 456 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | |
| 457 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | |
| 458 } | |
| 459 | |
| 460 // Disabled, http://crbug.com/66957. | 360 // Disabled, http://crbug.com/66957. |
| 461 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, | 361 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, |
| 462 DISABLED_KillExtensionAndReload) { | 362 DISABLED_KillExtensionAndReload) { |
| 463 ASSERT_TRUE(LoadExtension( | 363 ASSERT_TRUE(LoadExtension( |
| 464 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 364 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
| 465 | 365 |
| 466 // Wait until we see the loaded extension in the task manager (the three | 366 // Wait until we see the loaded extension in the task manager (the three |
| 467 // resources are: the browser process, New Tab Page, and the extension). | 367 // resources are: the browser process, New Tab Page, and the extension). |
| 468 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); | 368 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 469 | 369 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 ASSERT_TRUE(model()->GetV8Memory(resource_index, &result)); | 488 ASSERT_TRUE(model()->GetV8Memory(resource_index, &result)); |
| 589 LOG(INFO) << "Got V8 Heap Size " << result << " bytes"; | 489 LOG(INFO) << "Got V8 Heap Size " << result << " bytes"; |
| 590 EXPECT_GE(result, minimal_heap_size); | 490 EXPECT_GE(result, minimal_heap_size); |
| 591 | 491 |
| 592 ASSERT_TRUE(model()->GetV8MemoryUsed(resource_index, &result)); | 492 ASSERT_TRUE(model()->GetV8MemoryUsed(resource_index, &result)); |
| 593 LOG(INFO) << "Got V8 Used Heap Size " << result << " bytes"; | 493 LOG(INFO) << "Got V8 Used Heap Size " << result << " bytes"; |
| 594 EXPECT_GE(result, minimal_heap_size); | 494 EXPECT_GE(result, minimal_heap_size); |
| 595 } | 495 } |
| 596 | 496 |
| 597 #endif | 497 #endif |
| OLD | NEW |