| 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/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| 11 #include "chrome/browser/background/background_contents_service.h" | 11 #include "chrome/browser/background/background_contents_service.h" |
| 12 #include "chrome/browser/background/background_contents_service_factory.h" | 12 #include "chrome/browser/background/background_contents_service_factory.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/extension_browsertest.h" | 14 #include "chrome/browser/extensions/extension_browsertest.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 17 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 18 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 16 #include "chrome/browser/infobars/infobar_tab_helper.h" | 19 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 17 #include "chrome/browser/notifications/desktop_notification_service.h" | 20 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 18 #include "chrome/browser/notifications/notification.h" | 21 #include "chrome/browser/notifications/notification.h" |
| 19 #include "chrome/browser/notifications/notification_test_util.h" | 22 #include "chrome/browser/notifications/notification_test_util.h" |
| 20 #include "chrome/browser/notifications/notification_ui_manager.h" | 23 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 25 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 23 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_navigator.h" | 27 #include "chrome/browser/ui/browser_navigator.h" |
| 25 #include "chrome/browser/ui/browser_tabstrip.h" | 28 #include "chrome/browser/ui/browser_tabstrip.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 70 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 68 ExtensionBrowserTest::SetUpCommandLine(command_line); | 71 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 69 | 72 |
| 70 // Do not prelaunch the GPU process and disable accelerated compositing | 73 // Do not prelaunch the GPU process and disable accelerated compositing |
| 71 // for these tests as the GPU process will show up in task manager but | 74 // for these tests as the GPU process will show up in task manager but |
| 72 // whether it appears before or after the new tab renderer process is not | 75 // whether it appears before or after the new tab renderer process is not |
| 73 // well defined. | 76 // well defined. |
| 74 command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); | 77 command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); |
| 75 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); | 78 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); |
| 76 } | 79 } |
| 80 |
| 81 int GetResourceCountAfterLoad() { |
| 82 // Show the task manager. This populates the model, and helps with debugging |
| 83 // (you see the task manager). |
| 84 browser()->window()->ShowTaskManager(); |
| 85 // Wait for loading of task manager. |
| 86 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 87 return TaskManager::GetInstance()->model()->ResourceCount(); |
| 88 } |
| 77 }; | 89 }; |
| 78 | 90 |
| 79 #if defined(OS_MACOSX) || defined(OS_LINUX) | 91 #if defined(OS_MACOSX) || defined(OS_LINUX) |
| 80 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen | 92 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen |
| 81 #else | 93 #else |
| 82 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen | 94 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen |
| 83 #endif | 95 #endif |
| 84 | 96 |
| 85 // Regression test for http://crbug.com/13361 | 97 // Regression test for http://crbug.com/13361 |
| 86 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) { | 98 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 string16 prefix = l10n_util::GetStringFUTF16( | 366 string16 prefix = l10n_util::GetStringFUTF16( |
| 355 IDS_TASK_MANAGER_APP_PREFIX, string16()); | 367 IDS_TASK_MANAGER_APP_PREFIX, string16()); |
| 356 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), | 368 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), |
| 357 prefix, true)); | 369 prefix, true)); |
| 358 | 370 |
| 359 // Unload extension to avoid crash on Windows. | 371 // Unload extension to avoid crash on Windows. |
| 360 UnloadExtension(last_loaded_extension_id_); | 372 UnloadExtension(last_loaded_extension_id_); |
| 361 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 373 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 362 } | 374 } |
| 363 | 375 |
| 376 namespace { |
| 377 class PlatformAppTestContext : public extensions::PlatformAppBrowserTest { |
| 378 public: |
| 379 PlatformAppTestContext(Browser* browser, NotificationObserver* observer, |
| 380 FilePath test_data_dir) |
| 381 : browser_(browser), observer_(observer), |
| 382 test_data_dir_(test_data_dir) { |
| 383 } |
| 384 virtual void TestBody() {} |
| 385 virtual void RunTestOnMainThread() {} |
| 386 const extensions::Extension* Launch(const char* name) { |
| 387 return LoadAndLaunchPlatformApp( |
| 388 browser_, observer_, test_data_dir_, name); |
| 389 } |
| 390 private: |
| 391 Browser* browser_; |
| 392 NotificationObserver* observer_; |
| 393 FilePath test_data_dir_; |
| 394 }; |
| 395 } // namespace |
| 396 |
| 397 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticePlatformAppTabs) { |
| 398 int resource_count = GetResourceCountAfterLoad(); |
| 399 |
| 400 PlatformAppTestContext platform_app_test_context( |
| 401 browser(), this, test_data_dir_); |
| 402 ExtensionTestMessageListener launched_listener("Launched", false); |
| 403 const extensions::Extension* extension = |
| 404 platform_app_test_context.Launch("minimal"); |
| 405 (void)extension; |
| 406 |
| 407 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 408 |
| 409 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 410 string16 prefix; |
| 411 |
| 412 |
| 413 // First new entry should be the background page. The title should start with |
| 414 // "Background Page:". |
| 415 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType( |
| 416 resource_count)); |
| 417 |
| 418 // TODO(tapted) Can we get the background page when not loaded via |
| 419 // TabContents? |
| 420 // ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL); |
| 421 // ASSERT_TRUE(model()->GetResourceExtension(resource_count) == extension); |
| 422 |
| 423 prefix = l10n_util::GetStringFUTF16( |
| 424 IDS_TASK_MANAGER_BACKGROUND_PREFIX, string16()); |
| 425 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), |
| 426 prefix, true)); |
| 427 |
| 428 ++resource_count; |
| 429 // Second new entry should be the App Window background page. The title should |
| 430 // start with "Background Page:". |
| 431 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType( |
| 432 resource_count)); |
| 433 // ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL); |
| 434 // ASSERT_TRUE(model()->GetResourceExtension(resource_count) == extension); |
| 435 |
| 436 prefix = l10n_util::GetStringFUTF16( |
| 437 IDS_TASK_MANAGER_APP_PREFIX, string16()); |
| 438 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), |
| 439 prefix, true)); |
| 440 |
| 441 // Unload extension to avoid crash on Windows. |
| 442 UnloadExtension(last_loaded_extension_id_); |
| 443 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 444 } |
| 445 |
| 364 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { | 446 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { |
| 365 // Show the task manager. This populates the model, and helps with debugging | 447 // Show the task manager. This populates the model, and helps with debugging |
| 366 // (you see the task manager). | 448 // (you see the task manager). |
| 367 browser()->window()->ShowTaskManager(); | 449 browser()->window()->ShowTaskManager(); |
| 368 | 450 |
| 369 // New Tab Page. | 451 // New Tab Page. |
| 370 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 452 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 371 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 453 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| 372 | 454 |
| 373 // The app under test acts on URLs whose host is "localhost", | 455 // The app under test acts on URLs whose host is "localhost", |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 637 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 556 | 638 |
| 557 // Check that we get some value for the cache columns. | 639 // Check that we get some value for the cache columns. |
| 558 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count), | 640 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count), |
| 559 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 641 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 560 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count), | 642 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count), |
| 561 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 643 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 562 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count), | 644 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count), |
| 563 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 645 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 564 } | 646 } |
| OLD | NEW |