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 |
206 BackgroundContentsService* service = | 140 BackgroundContentsService* service = |
207 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); | 141 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); |
208 string16 application_id(ASCIIToUTF16("test_app_id")); | 142 string16 application_id(ASCIIToUTF16("test_app_id")); |
209 service->LoadBackgroundContents(browser()->profile(), | 143 service->LoadBackgroundContents(browser()->profile(), |
210 url, | 144 url, |
211 ASCIIToUTF16("background_page"), | 145 ASCIIToUTF16("background_page"), |
212 application_id); | 146 application_id); |
213 // Wait for the background contents process to finish loading. | 147 // Wait for the background contents process to finish loading. |
214 WaitForBackgroundContents(); | 148 TaskManagerBrowserTestUtil::WaitForBackgroundContents(browser()); |
215 EXPECT_EQ(3, model()->ResourceCount()); | 149 EXPECT_EQ(3, model()->ResourceCount()); |
216 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | 150 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); |
217 | 151 |
218 // Kill the background contents process and verify that it disappears from the | 152 // Kill the background contents process and verify that it disappears from the |
219 // model. | 153 // model. |
220 bool found = false; | 154 bool found = false; |
221 for (int i = 0; i < model()->ResourceCount(); ++i) { | 155 for (int i = 0; i < model()->ResourceCount(); ++i) { |
222 if (model()->IsBackgroundResource(i)) { | 156 if (model()->IsBackgroundResource(i)) { |
223 TaskManager::GetInstance()->KillProcess(i); | 157 TaskManager::GetInstance()->KillProcess(i); |
224 found = true; | 158 found = true; |
225 break; | 159 break; |
226 } | 160 } |
227 } | 161 } |
228 ASSERT_TRUE(found); | 162 ASSERT_TRUE(found); |
229 WaitForResourceChange(2); | 163 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
230 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 164 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
231 } | 165 } |
232 | 166 |
233 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { | 167 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { |
234 EXPECT_EQ(0, model()->ResourceCount()); | 168 EXPECT_EQ(0, model()->ResourceCount()); |
235 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 169 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
236 | 170 |
237 // Show the task manager. This populates the model, and helps with debugging | 171 // Show the task manager. This populates the model, and helps with debugging |
238 // (you see the task manager). | 172 // (you see the task manager). |
239 browser()->window()->ShowTaskManager(); | 173 browser()->window()->ShowTaskManager(); |
240 | 174 |
241 // Browser and the New Tab Page. | 175 // Browser and the New Tab Page. |
242 WaitForResourceChange(2); | 176 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
243 | 177 |
244 // Loading an extension with a background page should result in a new | 178 // Loading an extension with a background page should result in a new |
245 // resource being created for it. | 179 // resource being created for it. |
246 ASSERT_TRUE(LoadExtension( | 180 ASSERT_TRUE(LoadExtension( |
247 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 181 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
248 WaitForResourceChange(3); | 182 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
249 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | 183 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); |
250 | 184 |
251 // Unload extension to avoid crash on Windows (see http://crbug.com/31663). | 185 // Unload extension to avoid crash on Windows (see http://crbug.com/31663). |
252 UnloadExtension(last_loaded_extension_id_); | 186 UnloadExtension(last_loaded_extension_id_); |
253 WaitForResourceChange(2); | 187 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
254 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 188 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
255 } | 189 } |
256 | 190 |
257 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { | 191 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { |
258 // Show the task manager. This populates the model, and helps with debugging | 192 // Show the task manager. This populates the model, and helps with debugging |
259 // (you see the task manager). | 193 // (you see the task manager). |
260 browser()->window()->ShowTaskManager(); | 194 browser()->window()->ShowTaskManager(); |
261 | 195 |
262 ASSERT_TRUE(LoadExtension( | 196 ASSERT_TRUE(LoadExtension( |
263 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | 197 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
264 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 198 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
265 .AppendASCII("1.0.0.0"))); | 199 .AppendASCII("1.0.0.0"))); |
266 | 200 |
267 // Browser, Extension background page, and the New Tab Page. | 201 // Browser, Extension background page, and the New Tab Page. |
268 WaitForResourceChange(3); | 202 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
269 | 203 |
270 // Open a new tab to an extension URL and make sure we notice that. | 204 // Open a new tab to an extension URL and make sure we notice that. |
271 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); | 205 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); |
272 AddTabAtIndex(0, url, PageTransition::TYPED); | 206 AddTabAtIndex(0, url, PageTransition::TYPED); |
273 WaitForResourceChange(4); | 207 TaskManagerBrowserTestUtil::WaitForResourceChange(4); |
274 | 208 |
275 // Check that the third entry (background) is an extension resource whose | 209 // Check that the third entry (background) is an extension resource whose |
276 // title starts with "Extension:". | 210 // title starts with "Extension:". |
277 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); | 211 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); |
278 ASSERT_TRUE(model()->GetResourceTabContents(2) == NULL); | 212 ASSERT_TRUE(model()->GetResourceTabContents(2) == NULL); |
279 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 213 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
280 string16 prefix = l10n_util::GetStringFUTF16( | 214 string16 prefix = l10n_util::GetStringFUTF16( |
281 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); | 215 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); |
282 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 216 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
283 | 217 |
284 // Check that the fourth entry (page.html) is of type extension and has both | 218 // 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:". | 219 // a tab contents and an extension. The title should start with "Extension:". |
286 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); | 220 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); |
287 ASSERT_TRUE(model()->GetResourceTabContents(3) != NULL); | 221 ASSERT_TRUE(model()->GetResourceTabContents(3) != NULL); |
288 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); | 222 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); |
289 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); | 223 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); |
290 | 224 |
291 // Unload extension to avoid crash on Windows. | 225 // Unload extension to avoid crash on Windows. |
292 UnloadExtension(last_loaded_extension_id_); | 226 UnloadExtension(last_loaded_extension_id_); |
293 WaitForResourceChange(2); | 227 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
294 } | 228 } |
295 | 229 |
296 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { | 230 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { |
297 // Show the task manager. This populates the model, and helps with debugging | 231 // Show the task manager. This populates the model, and helps with debugging |
298 // (you see the task manager). | 232 // (you see the task manager). |
299 browser()->window()->ShowTaskManager(); | 233 browser()->window()->ShowTaskManager(); |
300 | 234 |
301 ASSERT_TRUE(LoadExtension( | 235 ASSERT_TRUE(LoadExtension( |
302 test_data_dir_.AppendASCII("packaged_app"))); | 236 test_data_dir_.AppendASCII("packaged_app"))); |
303 ExtensionService* service = browser()->profile()->GetExtensionService(); | 237 ExtensionService* service = browser()->profile()->GetExtensionService(); |
304 const Extension* extension = | 238 const Extension* extension = |
305 service->GetExtensionById(last_loaded_extension_id_, false); | 239 service->GetExtensionById(last_loaded_extension_id_, false); |
306 | 240 |
307 // Browser and the New Tab Page. | 241 // Browser and the New Tab Page. |
308 WaitForResourceChange(2); | 242 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
309 | 243 |
310 // Open a new tab to the app's launch URL and make sure we notice that. | 244 // Open a new tab to the app's launch URL and make sure we notice that. |
311 GURL url(extension->GetResourceURL("main.html")); | 245 GURL url(extension->GetResourceURL("main.html")); |
312 AddTabAtIndex(0, url, PageTransition::TYPED); | 246 AddTabAtIndex(0, url, PageTransition::TYPED); |
313 WaitForResourceChange(3); | 247 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
314 | 248 |
315 // Check that the third entry (main.html) is of type extension and has both | 249 // 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:". | 250 // a tab contents and an extension. The title should start with "App:". |
317 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); | 251 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); |
318 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); | 252 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); |
319 ASSERT_TRUE(model()->GetResourceExtension(2) == extension); | 253 ASSERT_TRUE(model()->GetResourceExtension(2) == extension); |
320 string16 prefix = l10n_util::GetStringFUTF16( | 254 string16 prefix = l10n_util::GetStringFUTF16( |
321 IDS_TASK_MANAGER_APP_PREFIX, string16()); | 255 IDS_TASK_MANAGER_APP_PREFIX, string16()); |
322 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); | 256 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
323 | 257 |
324 // Unload extension to avoid crash on Windows. | 258 // Unload extension to avoid crash on Windows. |
325 UnloadExtension(last_loaded_extension_id_); | 259 UnloadExtension(last_loaded_extension_id_); |
326 WaitForResourceChange(2); | 260 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
327 } | 261 } |
328 | 262 |
329 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { | 263 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { |
330 // Show the task manager. This populates the model, and helps with debugging | 264 // Show the task manager. This populates the model, and helps with debugging |
331 // (you see the task manager). | 265 // (you see the task manager). |
332 browser()->window()->ShowTaskManager(); | 266 browser()->window()->ShowTaskManager(); |
333 | 267 |
334 // Browser and the New Tab Page. | 268 // Browser and the New Tab Page. |
335 WaitForResourceChange(2); | 269 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
336 | 270 |
337 // The app under test acts on URLs whose host is "localhost", | 271 // The app under test acts on URLs whose host is "localhost", |
338 // so the URLs we navigate to must have host "localhost". | 272 // so the URLs we navigate to must have host "localhost". |
339 host_resolver()->AddRule("*", "127.0.0.1"); | 273 host_resolver()->AddRule("*", "127.0.0.1"); |
340 ASSERT_TRUE(test_server()->Start()); | 274 ASSERT_TRUE(test_server()->Start()); |
341 GURL::Replacements replace_host; | 275 GURL::Replacements replace_host; |
342 std::string host_str("localhost"); // must stay in scope with replace_host | 276 std::string host_str("localhost"); // must stay in scope with replace_host |
343 replace_host.SetHostStr(host_str); | 277 replace_host.SetHostStr(host_str); |
344 GURL base_url = test_server()->GetURL( | 278 GURL base_url = test_server()->GetURL( |
345 "files/extensions/api_test/app_process/"); | 279 "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()); | 314 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
381 // Show the task manager. This populates the model, and helps with debugging | 315 // Show the task manager. This populates the model, and helps with debugging |
382 // (you see the task manager). | 316 // (you see the task manager). |
383 browser()->window()->ShowTaskManager(); | 317 browser()->window()->ShowTaskManager(); |
384 | 318 |
385 ASSERT_TRUE(LoadExtension( | 319 ASSERT_TRUE(LoadExtension( |
386 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 320 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
387 | 321 |
388 // Wait until we see the loaded extension in the task manager (the three | 322 // 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). | 323 // resources are: the browser process, New Tab Page, and the extension). |
390 WaitForResourceChange(3); | 324 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
391 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); | 325 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); |
392 | 326 |
393 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); | 327 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); |
394 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); | 328 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); |
395 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 329 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
396 | 330 |
397 // Kill the extension process and make sure we notice it. | 331 // Kill the extension process and make sure we notice it. |
398 TaskManager::GetInstance()->KillProcess(2); | 332 TaskManager::GetInstance()->KillProcess(2); |
399 WaitForResourceChange(2); | 333 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
400 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); | 334 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); |
401 } | 335 } |
402 | 336 |
403 // Disabled, http://crbug.com/66957. | 337 // Disabled, http://crbug.com/66957. |
404 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, | 338 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, |
405 DISABLED_KillExtensionAndReload) { | 339 DISABLED_KillExtensionAndReload) { |
406 // Show the task manager. This populates the model, and helps with debugging | 340 // Show the task manager. This populates the model, and helps with debugging |
407 // (you see the task manager). | 341 // (you see the task manager). |
408 browser()->window()->ShowTaskManager(); | 342 browser()->window()->ShowTaskManager(); |
409 | 343 |
410 ASSERT_TRUE(LoadExtension( | 344 ASSERT_TRUE(LoadExtension( |
411 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 345 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
412 | 346 |
413 // Wait until we see the loaded extension in the task manager (the three | 347 // 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). | 348 // resources are: the browser process, New Tab Page, and the extension). |
415 WaitForResourceChange(3); | 349 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
416 | 350 |
417 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); | 351 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); |
418 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); | 352 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); |
419 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 353 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
420 | 354 |
421 // Kill the extension process and make sure we notice it. | 355 // Kill the extension process and make sure we notice it. |
422 TaskManager::GetInstance()->KillProcess(2); | 356 TaskManager::GetInstance()->KillProcess(2); |
423 WaitForResourceChange(2); | 357 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
424 | 358 |
425 // Reload the extension using the "crashed extension" infobar while the task | 359 // 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 | 360 // manager is still visible. Make sure we don't crash and the extension |
427 // gets reloaded and noticed in the task manager. | 361 // gets reloaded and noticed in the task manager. |
428 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); | 362 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
429 ASSERT_EQ(1U, current_tab->infobar_count()); | 363 ASSERT_EQ(1U, current_tab->infobar_count()); |
430 ConfirmInfoBarDelegate* delegate = | 364 ConfirmInfoBarDelegate* delegate = |
431 current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 365 current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
432 ASSERT_TRUE(delegate); | 366 ASSERT_TRUE(delegate); |
433 delegate->Accept(); | 367 delegate->Accept(); |
434 WaitForResourceChange(3); | 368 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
435 } | 369 } |
436 | 370 |
437 // Regression test for http://crbug.com/18693. | 371 // Regression test for http://crbug.com/18693. |
438 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) { | 372 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) { |
439 // Show the task manager. This populates the model, and helps with debugging | 373 // Show the task manager. This populates the model, and helps with debugging |
440 // (you see the task manager). | 374 // (you see the task manager). |
441 browser()->window()->ShowTaskManager(); | 375 browser()->window()->ShowTaskManager(); |
442 | 376 |
443 LOG(INFO) << "loading extension"; | 377 LOG(INFO) << "loading extension"; |
444 ASSERT_TRUE(LoadExtension( | 378 ASSERT_TRUE(LoadExtension( |
445 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 379 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
446 | 380 |
447 // Wait until we see the loaded extension in the task manager (the three | 381 // 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). | 382 // resources are: the browser process, New Tab Page, and the extension). |
449 LOG(INFO) << "waiting for resource change"; | 383 LOG(INFO) << "waiting for resource change"; |
450 WaitForResourceChange(3); | 384 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
451 | 385 |
452 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); | 386 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); |
453 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); | 387 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); |
454 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); | 388 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
455 | 389 |
456 const Extension* extension = model()->GetResourceExtension(2); | 390 const Extension* extension = model()->GetResourceExtension(2); |
457 ASSERT_TRUE(extension != NULL); | 391 ASSERT_TRUE(extension != NULL); |
458 | 392 |
459 // Reload the extension a few times and make sure our resource count | 393 // Reload the extension a few times and make sure our resource count |
460 // doesn't increase. | 394 // doesn't increase. |
461 LOG(INFO) << "First extension reload"; | 395 LOG(INFO) << "First extension reload"; |
462 ReloadExtension(extension->id()); | 396 ReloadExtension(extension->id()); |
463 WaitForResourceChange(3); | 397 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
464 extension = model()->GetResourceExtension(2); | 398 extension = model()->GetResourceExtension(2); |
465 ASSERT_TRUE(extension != NULL); | 399 ASSERT_TRUE(extension != NULL); |
466 | 400 |
467 LOG(INFO) << "Second extension reload"; | 401 LOG(INFO) << "Second extension reload"; |
468 ReloadExtension(extension->id()); | 402 ReloadExtension(extension->id()); |
469 WaitForResourceChange(3); | 403 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
470 extension = model()->GetResourceExtension(2); | 404 extension = model()->GetResourceExtension(2); |
471 ASSERT_TRUE(extension != NULL); | 405 ASSERT_TRUE(extension != NULL); |
472 | 406 |
473 LOG(INFO) << "Third extension reload"; | 407 LOG(INFO) << "Third extension reload"; |
474 ReloadExtension(extension->id()); | 408 ReloadExtension(extension->id()); |
475 WaitForResourceChange(3); | 409 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
476 } | 410 } |
477 | 411 |
478 // Crashy, http://crbug.com/42301. | 412 // Crashy, http://crbug.com/42301. |
479 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, | 413 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, |
480 DISABLED_PopulateWebCacheFields) { | 414 DISABLED_PopulateWebCacheFields) { |
481 EXPECT_EQ(0, model()->ResourceCount()); | 415 EXPECT_EQ(0, model()->ResourceCount()); |
482 | 416 |
483 // Show the task manager. This populates the model, and helps with debugging | 417 // Show the task manager. This populates the model, and helps with debugging |
484 // (you see the task manager). | 418 // (you see the task manager). |
485 browser()->window()->ShowTaskManager(); | 419 browser()->window()->ShowTaskManager(); |
486 | 420 |
487 // Browser and the New Tab Page. | 421 // Browser and the New Tab Page. |
488 WaitForResourceChange(2); | 422 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
489 | 423 |
490 // Open a new tab and make sure we notice that. | 424 // Open a new tab and make sure we notice that. |
491 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 425 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
492 FilePath(kTitle1File))); | 426 FilePath(kTitle1File))); |
493 AddTabAtIndex(0, url, PageTransition::TYPED); | 427 AddTabAtIndex(0, url, PageTransition::TYPED); |
494 WaitForResourceChange(3); | 428 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
495 | 429 |
496 // Check that we get some value for the cache columns. | 430 // Check that we get some value for the cache columns. |
497 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), | 431 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), |
498 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 432 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
499 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), | 433 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), |
500 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 434 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
501 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), | 435 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), |
502 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 436 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
503 } | 437 } |
OLD | NEW |