| 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/in_process_browser_test.h" | 28 #include "chrome/test/in_process_browser_test.h" |
| 28 #include "chrome/test/ui_test_utils.h" | 29 #include "chrome/test/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 | 57 |
| 109 void WaitForResourceChange(int target_count) { | 58 void WaitForResourceChange(int target_count) { |
| 110 if (model()->ResourceCount() == target_count) | 59 TaskManagerBrowserTestUtil::WaitForResourceChange(target_count); |
| 111 return; | |
| 112 ResourceChangeObserver observer(model(), target_count); | |
| 113 model()->AddObserver(&observer); | |
| 114 ui_test_utils::RunMessageLoop(); | |
| 115 model()->RemoveObserver(&observer); | |
| 116 } | 60 } |
| 117 | 61 |
| 118 // Wait for any pending BackgroundContents to finish starting up. | 62 // Wait for any pending BackgroundContents to finish starting up. |
| 119 void WaitForBackgroundContents() { | 63 void WaitForBackgroundContents() { |
| 120 BackgroundContentsListener listener(browser()->profile()); | 64 TaskManagerBrowserTestUtil::WaitForBackgroundContents(browser()); |
| 121 ui_test_utils::RunMessageLoop(); | |
| 122 } | 65 } |
| 123 }; | 66 }; |
| 124 | 67 |
| 125 // Regression test for http://crbug.com/13361 | 68 // Regression test for http://crbug.com/13361 |
| 126 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) { | 69 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) { |
| 127 browser()->window()->ShowTaskManager(); | 70 browser()->window()->ShowTaskManager(); |
| 128 } | 71 } |
| 129 | 72 |
| 130 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { | 73 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { |
| 131 EXPECT_EQ(0, model()->ResourceCount()); | 74 EXPECT_EQ(0, model()->ResourceCount()); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 WaitForResourceChange(3); | 439 WaitForResourceChange(3); |
| 497 | 440 |
| 498 // Check that we get some value for the cache columns. | 441 // Check that we get some value for the cache columns. |
| 499 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), | 442 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), |
| 500 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 443 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 501 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), | 444 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), |
| 502 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 445 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 503 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), | 446 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), |
| 504 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 447 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
| 505 } | 448 } |
| OLD | NEW |