OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/background_contents_service.h" | 10 #include "chrome/browser/background_contents_service.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/extensions/crashed_extension_infobar.h" | 12 #include "chrome/browser/extensions/crashed_extension_infobar.h" |
13 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
| 14 #include "chrome/browser/extensions/extensions_service.h" |
14 #include "chrome/browser/notifications/desktop_notification_service.h" | 15 #include "chrome/browser/notifications/desktop_notification_service.h" |
15 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
16 #include "chrome/browser/notifications/notification_test_util.h" | 17 #include "chrome/browser/notifications/notification_test_util.h" |
17 #include "chrome/browser/notifications/notification_ui_manager.h" | 18 #include "chrome/browser/notifications/notification_ui_manager.h" |
18 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
19 #include "chrome/browser/tab_contents/infobar_delegate.h" | 20 #include "chrome/browser/tab_contents/infobar_delegate.h" |
20 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
21 #include "chrome/browser/tabs/tab_strip_model.h" | 22 #include "chrome/browser/tabs/tab_strip_model.h" |
22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_navigator.h" | 24 #include "chrome/browser/ui/browser_navigator.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 100 |
100 // Browser and the New Tab Page. | 101 // Browser and the New Tab Page. |
101 EXPECT_EQ(2, model()->ResourceCount()); | 102 EXPECT_EQ(2, model()->ResourceCount()); |
102 | 103 |
103 // Open a new tab and make sure we notice that. | 104 // Open a new tab and make sure we notice that. |
104 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), | 105 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
105 FilePath(kTitle1File))); | 106 FilePath(kTitle1File))); |
106 AddTabAtIndex(0, url, PageTransition::TYPED); | 107 AddTabAtIndex(0, url, PageTransition::TYPED); |
107 WaitForResourceChange(3); | 108 WaitForResourceChange(3); |
108 | 109 |
| 110 // Check that the third entry is a tab contents resource whose title starts |
| 111 // starts with "Tab:". |
| 112 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); |
| 113 string16 prefix = WideToUTF16Hack(l10n_util::GetStringF( |
| 114 IDS_TASK_MANAGER_TAB_PREFIX, L"")); |
| 115 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 116 |
109 // Close the tab and verify that we notice. | 117 // Close the tab and verify that we notice. |
110 TabContents* first_tab = browser()->GetTabContentsAt(0); | 118 TabContents* first_tab = browser()->GetTabContentsAt(0); |
111 ASSERT_TRUE(first_tab); | 119 ASSERT_TRUE(first_tab); |
112 browser()->CloseTabContents(first_tab); | 120 browser()->CloseTabContents(first_tab); |
113 WaitForResourceChange(2); | 121 WaitForResourceChange(2); |
114 } | 122 } |
115 | 123 |
116 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { | 124 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { |
117 EXPECT_EQ(0, model()->ResourceCount()); | 125 EXPECT_EQ(0, model()->ResourceCount()); |
118 | 126 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // Browser and the New Tab Page. | 167 // Browser and the New Tab Page. |
160 EXPECT_EQ(2, model()->ResourceCount()); | 168 EXPECT_EQ(2, model()->ResourceCount()); |
161 | 169 |
162 // Loading an extension with a background page should result in a new | 170 // Loading an extension with a background page should result in a new |
163 // resource being created for it. | 171 // resource being created for it. |
164 ASSERT_TRUE(LoadExtension( | 172 ASSERT_TRUE(LoadExtension( |
165 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 173 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
166 WaitForResourceChange(3); | 174 WaitForResourceChange(3); |
167 } | 175 } |
168 | 176 |
| 177 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { |
| 178 // Show the task manager. This populates the model, and helps with debugging |
| 179 // (you see the task manager). |
| 180 browser()->window()->ShowTaskManager(); |
| 181 |
| 182 ASSERT_TRUE(LoadExtension( |
| 183 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 184 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 185 .AppendASCII("1.0.0.0"))); |
| 186 |
| 187 // Browser, Extension background page, and the New Tab Page. |
| 188 WaitForResourceChange(3); |
| 189 |
| 190 // Open a new tab to an extension URL and make sure we notice that. |
| 191 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); |
| 192 AddTabAtIndex(0, url, PageTransition::TYPED); |
| 193 WaitForResourceChange(4); |
| 194 |
| 195 // Check that the third entry (background) is an extension resource whose |
| 196 // title starts with "Extension:". |
| 197 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); |
| 198 ASSERT_TRUE(model()->GetResourceTabContents(2) == NULL); |
| 199 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
| 200 string16 prefix = WideToUTF16Hack(l10n_util::GetStringF( |
| 201 IDS_TASK_MANAGER_EXTENSION_PREFIX, L"")); |
| 202 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 203 |
| 204 // Check that the fourth entry (page.html) is of type extension and has both |
| 205 // a tab contents and an extension. The title should start with "Extension:". |
| 206 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); |
| 207 ASSERT_TRUE(model()->GetResourceTabContents(3) != NULL); |
| 208 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); |
| 209 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); |
| 210 |
| 211 // Unload extension to avoid crash on Windows. |
| 212 UnloadExtension(last_loaded_extension_id_); |
| 213 WaitForResourceChange(2); |
| 214 } |
| 215 |
| 216 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { |
| 217 // Show the task manager. This populates the model, and helps with debugging |
| 218 // (you see the task manager). |
| 219 browser()->window()->ShowTaskManager(); |
| 220 |
| 221 ASSERT_TRUE(LoadExtension( |
| 222 test_data_dir_.AppendASCII("packaged_app"))); |
| 223 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
| 224 const Extension* extension = |
| 225 service->GetExtensionById(last_loaded_extension_id_, false); |
| 226 |
| 227 // Browser and the New Tab Page. |
| 228 WaitForResourceChange(2); |
| 229 |
| 230 // Open a new tab to the app's launch URL and make sure we notice that. |
| 231 GURL url(extension->GetResourceURL("main.html")); |
| 232 AddTabAtIndex(0, url, PageTransition::TYPED); |
| 233 WaitForResourceChange(3); |
| 234 |
| 235 // Check that the third entry (main.html) is of type extension and has both |
| 236 // a tab contents and an extension. The title should start with "App:". |
| 237 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); |
| 238 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); |
| 239 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); |
| 240 string16 prefix = WideToUTF16Hack(l10n_util::GetStringF( |
| 241 IDS_TASK_MANAGER_APP_PREFIX, L"")); |
| 242 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); |
| 243 |
| 244 // Unload extension to avoid crash on Windows. |
| 245 UnloadExtension(last_loaded_extension_id_); |
| 246 WaitForResourceChange(2); |
| 247 } |
| 248 |
169 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeNotificationChanges) { | 249 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeNotificationChanges) { |
170 EXPECT_EQ(0, model()->ResourceCount()); | 250 EXPECT_EQ(0, model()->ResourceCount()); |
171 | 251 |
172 // Show the task manager. | 252 // Show the task manager. |
173 browser()->window()->ShowTaskManager(); | 253 browser()->window()->ShowTaskManager(); |
174 // Expect to see the browser and the New Tab Page renderer. | 254 // Expect to see the browser and the New Tab Page renderer. |
175 EXPECT_EQ(2, model()->ResourceCount()); | 255 EXPECT_EQ(2, model()->ResourceCount()); |
176 | 256 |
177 // Show a notification. | 257 // Show a notification. |
178 NotificationUIManager* notifications = | 258 NotificationUIManager* notifications = |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 WaitForResourceChange(3); | 386 WaitForResourceChange(3); |
307 | 387 |
308 // Check that we get some value for the cache columns. | 388 // Check that we get some value for the cache columns. |
309 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), | 389 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), |
310 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 390 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
311 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), | 391 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), |
312 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 392 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
313 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), | 393 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), |
314 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); | 394 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); |
315 } | 395 } |
OLD | NEW |