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" | |
22 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_navigator.h" | 22 #include "chrome/browser/ui/browser_navigator.h" |
24 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
26 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
28 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
29 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
30 #include "content/common/page_transition_types.h" | 29 #include "content/common/page_transition_types.h" |
31 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
32 #include "net/base/mock_host_resolver.h" | 31 #include "net/base/mock_host_resolver.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
35 | 34 |
36 // On Linux this is crashing intermittently http://crbug/84719 | 35 // On Linux this is crashing intermittently http://crbug/84719 |
37 // In some environments this test fails about 1/6 http://crbug/84850 | 36 // In some environments this test fails about 1/6 http://crbug/84850 |
38 #if defined(OS_LINUX) | 37 #if defined(OS_LINUX) |
39 #define MAYBE_KillExtension DISABLED_KillExtension | 38 #define MAYBE_KillExtension DISABLED_KillExtension |
40 #elif defined(TOUCH_UI) | 39 #elif defined(TOUCH_UI) |
41 #define MAYBE_KillExtension FLAKY_KillExtension | 40 #define MAYBE_KillExtension FLAKY_KillExtension |
42 #else | 41 #else |
43 #define MAYBE_KillExtension KillExtension | 42 #define MAYBE_KillExtension KillExtension |
44 #endif | 43 #endif |
45 | 44 |
46 namespace { | 45 namespace { |
47 | 46 |
48 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); | 47 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); |
49 | 48 |
| 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 |
50 } // namespace | 101 } // namespace |
51 | 102 |
52 class TaskManagerBrowserTest : public ExtensionBrowserTest { | 103 class TaskManagerBrowserTest : public ExtensionBrowserTest { |
53 public: | 104 public: |
54 TaskManagerModel* model() const { | 105 TaskManagerModel* model() const { |
55 return TaskManager::GetInstance()->model(); | 106 return TaskManager::GetInstance()->model(); |
56 } | 107 } |
57 | 108 |
58 void WaitForResourceChange(int target_count) { | 109 void WaitForResourceChange(int target_count) { |
59 TaskManagerBrowserTestUtil::WaitForResourceChange(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); |
60 } | 116 } |
61 | 117 |
62 // Wait for any pending BackgroundContents to finish starting up. | 118 // Wait for any pending BackgroundContents to finish starting up. |
63 void WaitForBackgroundContents() { | 119 void WaitForBackgroundContents() { |
64 TaskManagerBrowserTestUtil::WaitForBackgroundContents(browser()); | 120 BackgroundContentsListener listener(browser()->profile()); |
| 121 ui_test_utils::RunMessageLoop(); |
65 } | 122 } |
66 }; | 123 }; |
67 | 124 |
68 // Regression test for http://crbug.com/13361 | 125 // Regression test for http://crbug.com/13361 |
69 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) { | 126 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) { |
70 browser()->window()->ShowTaskManager(); | 127 browser()->window()->ShowTaskManager(); |
71 } | 128 } |
72 | 129 |
73 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { | 130 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { |
74 EXPECT_EQ(0, model()->ResourceCount()); | 131 EXPECT_EQ(0, model()->ResourceCount()); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 WaitForResourceChange(3); | 494 WaitForResourceChange(3); |
438 | 495 |
439 // Check that we get some value for the cache columns. | 496 // Check that we get some value for the cache columns. |
440 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), | 497 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), |
441 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 498 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
442 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), | 499 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), |
443 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 500 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
444 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), | 501 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), |
445 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 502 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
446 } | 503 } |
OLD | NEW |