Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: chrome/browser/task_manager/task_manager_browsertest.cc

Issue 10882071: Fixes for bunch of browser tests that are trying to load content from file: schema. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
10 #include "chrome/browser/background/background_contents_service.h" 11 #include "chrome/browser/background/background_contents_service.h"
11 #include "chrome/browser/background/background_contents_service_factory.h" 12 #include "chrome/browser/background/background_contents_service_factory.h"
12 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/extension_browsertest.h" 14 #include "chrome/browser/extensions/extension_browsertest.h"
14 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/infobars/infobar_tab_helper.h" 16 #include "chrome/browser/infobars/infobar_tab_helper.h"
16 #include "chrome/browser/notifications/desktop_notification_service.h" 17 #include "chrome/browser/notifications/desktop_notification_service.h"
17 #include "chrome/browser/notifications/notification.h" 18 #include "chrome/browser/notifications/notification.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 browser()->window()->ShowTaskManager(); 85 browser()->window()->ShowTaskManager();
85 } 86 }
86 87
87 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { 88 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
88 EXPECT_EQ(0, model()->ResourceCount()); 89 EXPECT_EQ(0, model()->ResourceCount());
89 90
90 // Show the task manager. This populates the model, and helps with debugging 91 // Show the task manager. This populates the model, and helps with debugging
91 // (you see the task manager). 92 // (you see the task manager).
92 browser()->window()->ShowTaskManager(); 93 browser()->window()->ShowTaskManager();
93 94
94 // Browser and the New Tab Page. 95 // New Tab Page.
95 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 96 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
96 97
98 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
97 // Open a new tab and make sure we notice that. 99 // Open a new tab and make sure we notice that.
98 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 100 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
99 FilePath(kTitle1File))); 101 FilePath(kTitle1File)));
100 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 102 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
101 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 103 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
102 104
103 // Check that the third entry is a tab contents resource whose title starts 105 // Check that the last entry is a tab contents resource whose title starts
104 // starts with "Tab:". 106 // starts with "Tab:".
105 ASSERT_TRUE(model()->GetResourceWebContents(2) != NULL); 107 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL);
106 string16 prefix = l10n_util::GetStringFUTF16( 108 string16 prefix = l10n_util::GetStringFUTF16(
107 IDS_TASK_MANAGER_TAB_PREFIX, string16()); 109 IDS_TASK_MANAGER_TAB_PREFIX, string16());
108 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); 110 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), prefix,
111 true));
109 112
110 // Close the tab and verify that we notice. 113 // Close the tab and verify that we notice.
111 WebContents* first_tab = 114 WebContents* first_tab =
112 chrome::GetTabContentsAt(browser(), 0)->web_contents(); 115 chrome::GetTabContentsAt(browser(), 0)->web_contents();
113 ASSERT_TRUE(first_tab); 116 ASSERT_TRUE(first_tab);
114 chrome::CloseWebContents(browser(), first_tab); 117 chrome::CloseWebContents(browser(), first_tab);
115 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 118 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
116 } 119 }
117 120
118 #if defined(USE_ASH) 121 #if defined(USE_ASH)
119 // This test fails on Ash because task manager treats view type 122 // This test fails on Ash because task manager treats view type
120 // Panels differently for Ash. 123 // Panels differently for Ash.
121 #define MAYBE_NoticePanelChanges FAILS_NoticePanelChanges 124 #define MAYBE_NoticePanelChanges FAILS_NoticePanelChanges
122 #else 125 #else
123 #define MAYBE_NoticePanelChanges NoticePanelChanges 126 #define MAYBE_NoticePanelChanges NoticePanelChanges
124 #endif 127 #endif
125 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_NoticePanelChanges) { 128 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_NoticePanelChanges) {
126 if (!PanelManager::UseBrowserlessPanels()) 129 if (!PanelManager::UseBrowserlessPanels())
127 return; 130 return;
128 131
129 EXPECT_EQ(0, model()->ResourceCount()); 132 EXPECT_EQ(0, model()->ResourceCount());
130 133
131 // Show the task manager. This populates the model, and helps with debugging 134 // Show the task manager. This populates the model, and helps with debugging
132 // (you see the task manager). 135 // (you see the task manager).
133 browser()->window()->ShowTaskManager(); 136 browser()->window()->ShowTaskManager();
134 137
135 // Browser and the New Tab Page. 138 // New Tab Page.
136 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 139 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
137 140
138 ASSERT_TRUE(LoadExtension( 141 ASSERT_TRUE(LoadExtension(
139 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") 142 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
140 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 143 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
141 .AppendASCII("1.0.0.0"))); 144 .AppendASCII("1.0.0.0")));
142 145
143 // Browser, the New Tab Page and Extension background page. 146 // Browser, the New Tab Page and Extension background page.
144 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 147 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
145 148
146 // Open a new panel to an extension url and make sure we notice that. 149 // Open a new panel to an extension url and make sure we notice that.
147 GURL url( 150 GURL url(
148 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html"); 151 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html");
149 Panel* panel = PanelManager::GetInstance()->CreatePanel( 152 Panel* panel = PanelManager::GetInstance()->CreatePanel(
150 web_app::GenerateApplicationNameFromExtensionId( 153 web_app::GenerateApplicationNameFromExtensionId(
151 last_loaded_extension_id_), 154 last_loaded_extension_id_),
152 browser()->profile(), 155 browser()->profile(),
153 url, 156 url,
154 gfx::Rect(300, 400), 157 gfx::Rect(300, 400),
155 PanelManager::CREATE_AS_DOCKED); 158 PanelManager::CREATE_AS_DOCKED);
156 TaskManagerBrowserTestUtil::WaitForResourceChange(4); 159 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
157 160
158 // Check that the fourth entry is a resource with the panel's web contents 161 // Check that the fourth entry is a resource with the panel's web contents
159 // and whose title starts with "Extension:". 162 // and whose title starts with "Extension:".
160 ASSERT_EQ(panel->GetWebContents(), model()->GetResourceWebContents(3)); 163 ASSERT_EQ(panel->GetWebContents(), model()->GetResourceWebContents(3));
161 string16 prefix = l10n_util::GetStringFUTF16( 164 string16 prefix = l10n_util::GetStringFUTF16(
162 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); 165 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16());
163 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); 166 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true));
164 167
165 // Close the panel and verify that we notice. 168 // Close the panel and verify that we notice.
166 panel->Close(); 169 panel->Close();
167 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 170 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
168 171
169 // Unload extension to avoid crash on Windows. 172 // Unload extension to avoid crash on Windows.
170 UnloadExtension(last_loaded_extension_id_); 173 UnloadExtension(last_loaded_extension_id_);
171 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 174 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
172 } 175 }
173 176
174 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { 177 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
175 EXPECT_EQ(0, model()->ResourceCount()); 178 EXPECT_EQ(0, model()->ResourceCount());
176 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 179 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
177 180
178 // Show the task manager. This populates the model, and helps with debugging 181 // Show the task manager. This populates the model, and helps with debugging
179 // (you see the task manager). 182 // (you see the task manager).
180 browser()->window()->ShowTaskManager(); 183 browser()->window()->ShowTaskManager();
181 184
182 // Browser and the New Tab Page. 185 // New Tab Page.
183 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 186 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
184 187
185 // Open a new background contents and make sure we notice that. 188 // Open a new background contents and make sure we notice that.
186 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 189 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
187 FilePath(kTitle1File))); 190 FilePath(kTitle1File)));
188 191
189 BackgroundContentsService* service = 192 BackgroundContentsService* service =
190 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); 193 BackgroundContentsServiceFactory::GetForProfile(browser()->profile());
191 string16 application_id(ASCIIToUTF16("test_app_id")); 194 string16 application_id(ASCIIToUTF16("test_app_id"));
192 service->LoadBackgroundContents(browser()->profile(), 195 service->LoadBackgroundContents(browser()->profile(),
193 url, 196 url,
194 ASCIIToUTF16("background_page"), 197 ASCIIToUTF16("background_page"),
195 application_id); 198 application_id);
196 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 199 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
197 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 200 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
198 201
199 // Close the background contents and verify that we notice. 202 // Close the background contents and verify that we notice.
200 service->ShutdownAssociatedBackgroundContents(application_id); 203 service->ShutdownAssociatedBackgroundContents(application_id);
201 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 204 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
202 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 205 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
203 } 206 }
204 207
205 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) { 208 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) {
206 EXPECT_EQ(0, model()->ResourceCount()); 209 EXPECT_EQ(0, model()->ResourceCount());
207 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 210 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
208 211
209 // Show the task manager. This populates the model, and helps with debugging 212 // Show the task manager. This populates the model, and helps with debugging
210 // (you see the task manager). 213 // (you see the task manager).
211 browser()->window()->ShowTaskManager(); 214 browser()->window()->ShowTaskManager();
212 215
213 // Browser and the New Tab Page. 216 // New Tab Page.
214 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 217 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
218 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
215 219
216 // Open a new background contents and make sure we notice that. 220 // Open a new background contents and make sure we notice that.
217 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 221 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
218 FilePath(kTitle1File))); 222 FilePath(kTitle1File)));
219 223
220 content::WindowedNotificationObserver observer( 224 content::WindowedNotificationObserver observer(
221 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, 225 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
222 content::Source<Profile>(browser()->profile())); 226 content::Source<Profile>(browser()->profile()));
223 227
224 BackgroundContentsService* service = 228 BackgroundContentsService* service =
225 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); 229 BackgroundContentsServiceFactory::GetForProfile(browser()->profile());
226 string16 application_id(ASCIIToUTF16("test_app_id")); 230 string16 application_id(ASCIIToUTF16("test_app_id"));
227 service->LoadBackgroundContents(browser()->profile(), 231 service->LoadBackgroundContents(browser()->profile(),
228 url, 232 url,
229 ASCIIToUTF16("background_page"), 233 ASCIIToUTF16("background_page"),
230 application_id); 234 application_id);
231 235
232 // Wait for the background contents process to finish loading. 236 // Wait for the background contents process to finish loading.
233 observer.Wait(); 237 observer.Wait();
234 238
235 EXPECT_EQ(3, model()->ResourceCount()); 239 EXPECT_EQ(resource_count + 1, model()->ResourceCount());
236 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 240 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
237 241
238 // Kill the background contents process and verify that it disappears from the 242 // Kill the background contents process and verify that it disappears from the
239 // model. 243 // model.
240 bool found = false; 244 bool found = false;
241 for (int i = 0; i < model()->ResourceCount(); ++i) { 245 for (int i = 0; i < model()->ResourceCount(); ++i) {
242 if (model()->IsBackgroundResource(i)) { 246 if (model()->IsBackgroundResource(i)) {
243 TaskManager::GetInstance()->KillProcess(i); 247 TaskManager::GetInstance()->KillProcess(i);
244 found = true; 248 found = true;
245 break; 249 break;
246 } 250 }
247 } 251 }
248 ASSERT_TRUE(found); 252 ASSERT_TRUE(found);
249 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 253 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
250 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 254 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
251 } 255 }
252 256
253 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { 257 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) {
254 EXPECT_EQ(0, model()->ResourceCount()); 258 EXPECT_EQ(0, model()->ResourceCount());
255 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 259 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
256 260
257 // Show the task manager. This populates the model, and helps with debugging 261 // Show the task manager. This populates the model, and helps with debugging
258 // (you see the task manager). 262 // (you see the task manager).
259 browser()->window()->ShowTaskManager(); 263 browser()->window()->ShowTaskManager();
260 264
261 // Browser and the New Tab Page. 265 // New Tab Page.
262 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 266 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
263 267
264 // Loading an extension with a background page should result in a new 268 // Loading an extension with a background page should result in a new
265 // resource being created for it. 269 // resource being created for it.
266 ASSERT_TRUE(LoadExtension( 270 ASSERT_TRUE(LoadExtension(
267 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 271 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
268 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 272 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
269 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 273 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
270 274
271 // Unload extension to avoid crash on Windows (see http://crbug.com/31663). 275 // Unload extension to avoid crash on Windows (see http://crbug.com/31663).
272 UnloadExtension(last_loaded_extension_id_); 276 UnloadExtension(last_loaded_extension_id_);
273 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 277 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
274 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 278 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
275 } 279 }
276 280
277 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { 281 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) {
278 // Show the task manager. This populates the model, and helps with debugging 282 // Show the task manager. This populates the model, and helps with debugging
279 // (you see the task manager). 283 // (you see the task manager).
280 browser()->window()->ShowTaskManager(); 284 browser()->window()->ShowTaskManager();
281 // Wait for loading of task manager. 285 // Wait for loading of task manager.
282 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 286 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
283 287
288 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
284 ASSERT_TRUE(LoadExtension( 289 ASSERT_TRUE(LoadExtension(
285 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") 290 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
286 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 291 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
287 .AppendASCII("1.0.0.0"))); 292 .AppendASCII("1.0.0.0")));
288 293
289 // Browser, Extension background page, and the New Tab Page. 294 // Browser, Extension background page, and the New Tab Page.
290 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 295 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
291 296
292 // Open a new tab to an extension URL and make sure we notice that. 297 // Open a new tab to an extension URL and make sure we notice that.
293 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); 298 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
294 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 299 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
295 TaskManagerBrowserTestUtil::WaitForResourceChange(4); 300 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
296 301
297 // Check that the third entry (background) is an extension resource whose 302 // Check that the third entry (background) is an extension resource whose
298 // title starts with "Extension:". 303 // title starts with "Extension:".
299 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); 304 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(
300 ASSERT_TRUE(model()->GetResourceWebContents(2) == NULL); 305 resource_count));
301 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 306 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) == NULL);
307 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL);
302 string16 prefix = l10n_util::GetStringFUTF16( 308 string16 prefix = l10n_util::GetStringFUTF16(
303 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); 309 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16());
304 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); 310 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
311 prefix, true));
305 312
306 // Check that the fourth entry (page.html) is of type extension and has both 313 // Check that the fourth entry (page.html) is of type extension and has both
307 // a tab contents and an extension. The title should start with "Extension:". 314 // a tab contents and an extension. The title should start with "Extension:".
308 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); 315 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(
309 ASSERT_TRUE(model()->GetResourceWebContents(3) != NULL); 316 resource_count + 1));
310 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); 317 ASSERT_TRUE(model()->GetResourceWebContents(resource_count + 1) != NULL);
311 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); 318 ASSERT_TRUE(model()->GetResourceExtension(resource_count + 1) != NULL);
319 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count + 1),
320 prefix, true));
312 321
313 // Unload extension to avoid crash on Windows. 322 // Unload extension to avoid crash on Windows.
314 UnloadExtension(last_loaded_extension_id_); 323 UnloadExtension(last_loaded_extension_id_);
315 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 324 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
316 } 325 }
317 326
318 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { 327 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) {
319 // Show the task manager. This populates the model, and helps with debugging 328 // Show the task manager. This populates the model, and helps with debugging
320 // (you see the task manager). 329 // (you see the task manager).
321 browser()->window()->ShowTaskManager(); 330 browser()->window()->ShowTaskManager();
322 // Wait for loading of task manager. 331 // Wait for loading of task manager.
323 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 332 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
324 333
334 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
325 ASSERT_TRUE(LoadExtension( 335 ASSERT_TRUE(LoadExtension(
326 test_data_dir_.AppendASCII("packaged_app"))); 336 test_data_dir_.AppendASCII("packaged_app")));
327 ExtensionService* service = browser()->profile()->GetExtensionService(); 337 ExtensionService* service = browser()->profile()->GetExtensionService();
328 const extensions::Extension* extension = 338 const extensions::Extension* extension =
329 service->GetExtensionById(last_loaded_extension_id_, false); 339 service->GetExtensionById(last_loaded_extension_id_, false);
330 340
331 // Browser and the New Tab Page. 341 // New Tab Page.
332 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 342 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
333 343
334 // Open a new tab to the app's launch URL and make sure we notice that. 344 // Open a new tab to the app's launch URL and make sure we notice that.
335 GURL url(extension->GetResourceURL("main.html")); 345 GURL url(extension->GetResourceURL("main.html"));
336 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 346 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
337 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 347 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
338 348
339 // Check that the third entry (main.html) is of type extension and has both 349 // Check that the third entry (main.html) is of type extension and has both
340 // a tab contents and an extension. The title should start with "App:". 350 // a tab contents and an extension. The title should start with "App:".
341 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); 351 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(
342 ASSERT_TRUE(model()->GetResourceWebContents(2) != NULL); 352 resource_count));
343 ASSERT_TRUE(model()->GetResourceExtension(2) == extension); 353 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL);
354 ASSERT_TRUE(model()->GetResourceExtension(resource_count) == extension);
344 string16 prefix = l10n_util::GetStringFUTF16( 355 string16 prefix = l10n_util::GetStringFUTF16(
345 IDS_TASK_MANAGER_APP_PREFIX, string16()); 356 IDS_TASK_MANAGER_APP_PREFIX, string16());
346 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); 357 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
358 prefix, true));
347 359
348 // Unload extension to avoid crash on Windows. 360 // Unload extension to avoid crash on Windows.
349 UnloadExtension(last_loaded_extension_id_); 361 UnloadExtension(last_loaded_extension_id_);
350 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 362 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
351 } 363 }
352 364
353 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { 365 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) {
354 // Show the task manager. This populates the model, and helps with debugging 366 // Show the task manager. This populates the model, and helps with debugging
355 // (you see the task manager). 367 // (you see the task manager).
356 browser()->window()->ShowTaskManager(); 368 browser()->window()->ShowTaskManager();
357 369
358 // Browser and the New Tab Page. 370 // New Tab Page.
359 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 371 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
372 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
360 373
361 // The app under test acts on URLs whose host is "localhost", 374 // The app under test acts on URLs whose host is "localhost",
362 // so the URLs we navigate to must have host "localhost". 375 // so the URLs we navigate to must have host "localhost".
363 host_resolver()->AddRule("*", "127.0.0.1"); 376 host_resolver()->AddRule("*", "127.0.0.1");
364 ASSERT_TRUE(test_server()->Start()); 377 ASSERT_TRUE(test_server()->Start());
365 GURL::Replacements replace_host; 378 GURL::Replacements replace_host;
366 std::string host_str("localhost"); // must stay in scope with replace_host 379 std::string host_str("localhost"); // must stay in scope with replace_host
367 replace_host.SetHostStr(host_str); 380 replace_host.SetHostStr(host_str);
368 GURL base_url = test_server()->GetURL( 381 GURL base_url = test_server()->GetURL(
369 "files/extensions/api_test/app_process/"); 382 "files/extensions/api_test/app_process/");
370 base_url = base_url.ReplaceComponents(replace_host); 383 base_url = base_url.ReplaceComponents(replace_host);
371 384
372 // Open a new tab to an app URL before the app is loaded. 385 // Open a new tab to an app URL before the app is loaded.
373 GURL url(base_url.Resolve("path1/empty.html")); 386 GURL url(base_url.Resolve("path1/empty.html"));
374 content::WindowedNotificationObserver observer( 387 content::WindowedNotificationObserver observer(
375 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 388 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
376 content::NotificationService::AllSources()); 389 content::NotificationService::AllSources());
377 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 390 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
378 observer.Wait(); 391 observer.Wait();
379 392
380 // Check that the third entry's title starts with "Tab:". 393 // Check that the third entry's title starts with "Tab:".
381 string16 tab_prefix = l10n_util::GetStringFUTF16( 394 string16 tab_prefix = l10n_util::GetStringFUTF16(
382 IDS_TASK_MANAGER_TAB_PREFIX, string16()); 395 IDS_TASK_MANAGER_TAB_PREFIX, string16());
383 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), tab_prefix, true)); 396 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
397 tab_prefix, true));
384 398
385 // Load the hosted app and make sure it still starts with "Tab:", 399 // Load the hosted app and make sure it still starts with "Tab:",
386 // since it hasn't changed to an app process yet. 400 // since it hasn't changed to an app process yet.
387 ASSERT_TRUE(LoadExtension( 401 ASSERT_TRUE(LoadExtension(
388 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process"))); 402 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process")));
389 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), tab_prefix, true)); 403 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
404 tab_prefix, true));
390 405
391 // Now reload and check that the third entry's title now starts with "App:". 406 // Now reload and check that the last entry's title now starts with "App:".
392 ui_test_utils::NavigateToURL(browser(), url); 407 ui_test_utils::NavigateToURL(browser(), url);
393 string16 app_prefix = l10n_util::GetStringFUTF16( 408 string16 app_prefix = l10n_util::GetStringFUTF16(
394 IDS_TASK_MANAGER_APP_PREFIX, string16()); 409 IDS_TASK_MANAGER_APP_PREFIX, string16());
395 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), app_prefix, true)); 410 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
411 app_prefix, true));
396 412
397 // Disable extension and reload page. 413 // Disable extension and reload page.
398 DisableExtension(last_loaded_extension_id_); 414 DisableExtension(last_loaded_extension_id_);
399 ui_test_utils::NavigateToURL(browser(), url); 415 ui_test_utils::NavigateToURL(browser(), url);
400 416
401 // The third entry's title should be back to a normal tab. 417 // The third entry's title should be back to a normal tab.
402 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), tab_prefix, true)); 418 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count),
419 tab_prefix, true));
403 } 420 }
404 421
405 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillExtension) { 422 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillExtension) {
406 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 423 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
407 // Show the task manager. This populates the model, and helps with debugging 424 // Show the task manager. This populates the model, and helps with debugging
408 // (you see the task manager). 425 // (you see the task manager).
409 browser()->window()->ShowTaskManager(); 426 browser()->window()->ShowTaskManager();
410 // Wait for loading of task manager. 427 // Wait for loading of task manager.
411 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 428 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
429
430 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
412 431
413 ASSERT_TRUE(LoadExtension( 432 ASSERT_TRUE(LoadExtension(
414 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 433 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
415 434
416 // Wait until we see the loaded extension in the task manager (the three 435 // Wait until we see the loaded extension in the task manager (the three
417 // resources are: the browser process, New Tab Page, and the extension). 436 // resources are: the browser process, New Tab Page, and the extension).
418 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 437 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
419 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 438 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
420 439
421 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 440 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
422 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 441 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
423 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 442 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL);
424 443
425 // Kill the extension process and make sure we notice it. 444 // Kill the extension process and make sure we notice it.
426 TaskManager::GetInstance()->KillProcess(2); 445 TaskManager::GetInstance()->KillProcess(resource_count);
427 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 446 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
428 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 447 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
429 } 448 }
430 449
431 // Disabled, http://crbug.com/66957. 450 // Disabled, http://crbug.com/66957.
432 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, 451 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
433 DISABLED_KillExtensionAndReload) { 452 DISABLED_KillExtensionAndReload) {
434 // Show the task manager. This populates the model, and helps with debugging 453 // Show the task manager. This populates the model, and helps with debugging
435 // (you see the task manager). 454 // (you see the task manager).
436 browser()->window()->ShowTaskManager(); 455 browser()->window()->ShowTaskManager();
437 // Wait for loading of task manager. 456 // Wait for loading of task manager.
438 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 457 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
439 458
440 ASSERT_TRUE(LoadExtension( 459 ASSERT_TRUE(LoadExtension(
441 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 460 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
442 461
443 // Wait until we see the loaded extension in the task manager (the three 462 // Wait until we see the loaded extension in the task manager (the three
444 // resources are: the browser process, New Tab Page, and the extension). 463 // resources are: the browser process, New Tab Page, and the extension).
445 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 464 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
446 465
447 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 466 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
448 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 467 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
449 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 468 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL);
450 469
451 // Kill the extension process and make sure we notice it. 470 // Kill the extension process and make sure we notice it.
452 TaskManager::GetInstance()->KillProcess(2); 471 TaskManager::GetInstance()->KillProcess(2);
453 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 472 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
454 473
455 // Reload the extension using the "crashed extension" infobar while the task 474 // Reload the extension using the "crashed extension" infobar while the task
456 // manager is still visible. Make sure we don't crash and the extension 475 // manager is still visible. Make sure we don't crash and the extension
457 // gets reloaded and noticed in the task manager. 476 // gets reloaded and noticed in the task manager.
458 InfoBarTabHelper* infobar_helper = 477 InfoBarTabHelper* infobar_helper =
459 chrome::GetActiveTabContents(browser())->infobar_tab_helper(); 478 chrome::GetActiveTabContents(browser())->infobar_tab_helper();
460 ASSERT_EQ(1U, infobar_helper->GetInfoBarCount()); 479 ASSERT_EQ(1U, infobar_helper->GetInfoBarCount());
461 ConfirmInfoBarDelegate* delegate = infobar_helper-> 480 ConfirmInfoBarDelegate* delegate = infobar_helper->
462 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 481 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
463 ASSERT_TRUE(delegate); 482 ASSERT_TRUE(delegate);
464 delegate->Accept(); 483 delegate->Accept();
465 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 484 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
466 } 485 }
467 486
468 #if defined(OS_WIN) 487 #if defined(OS_WIN)
469 // http://crbug.com/93158. 488 // http://crbug.com/93158.
470 #define MAYBE_ReloadExtension DISABLED_ReloadExtension 489 #define MAYBE_ReloadExtension DISABLED_ReloadExtension
471 #else 490 #else
472 #define MAYBE_ReloadExtension ReloadExtension 491 #define MAYBE_ReloadExtension ReloadExtension
473 #endif 492 #endif
474 493
475 // Regression test for http://crbug.com/18693. 494 // Regression test for http://crbug.com/18693.
476 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ReloadExtension) { 495 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ReloadExtension) {
477 // Show the task manager. This populates the model, and helps with debugging 496 // Show the task manager. This populates the model, and helps with debugging
478 // (you see the task manager). 497 // (you see the task manager).
479 browser()->window()->ShowTaskManager(); 498 browser()->window()->ShowTaskManager();
480 // Wait for loading of task manager. 499 // Wait for loading of task manager.
481 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 500 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
482 501
502 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
483 LOG(INFO) << "loading extension"; 503 LOG(INFO) << "loading extension";
484 ASSERT_TRUE(LoadExtension( 504 ASSERT_TRUE(LoadExtension(
485 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 505 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
486 506
487 // Wait until we see the loaded extension in the task manager (the three 507 // Wait until we see the loaded extension in the task manager (the three
488 // resources are: the browser process, New Tab Page, and the extension). 508 // resources are: the browser process, New Tab Page, and the extension).
489 LOG(INFO) << "waiting for resource change"; 509 LOG(INFO) << "waiting for resource change";
490 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 510 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
491 511
492 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 512 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
493 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 513 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
494 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 514 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL);
495 515
496 const extensions::Extension* extension = model()->GetResourceExtension(2); 516 const extensions::Extension* extension = model()->GetResourceExtension(
517 resource_count);
497 ASSERT_TRUE(extension != NULL); 518 ASSERT_TRUE(extension != NULL);
498 519
499 // Reload the extension a few times and make sure our resource count 520 // Reload the extension a few times and make sure our resource count
500 // doesn't increase. 521 // doesn't increase.
501 LOG(INFO) << "First extension reload"; 522 LOG(INFO) << "First extension reload";
502 ReloadExtension(extension->id()); 523 ReloadExtension(extension->id());
503 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 524 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
504 extension = model()->GetResourceExtension(2); 525 extension = model()->GetResourceExtension(resource_count);
505 ASSERT_TRUE(extension != NULL); 526 ASSERT_TRUE(extension != NULL);
506 527
507 LOG(INFO) << "Second extension reload"; 528 LOG(INFO) << "Second extension reload";
508 ReloadExtension(extension->id()); 529 ReloadExtension(extension->id());
509 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 530 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
510 extension = model()->GetResourceExtension(2); 531 extension = model()->GetResourceExtension(resource_count);
511 ASSERT_TRUE(extension != NULL); 532 ASSERT_TRUE(extension != NULL);
512 533
513 LOG(INFO) << "Third extension reload"; 534 LOG(INFO) << "Third extension reload";
514 ReloadExtension(extension->id()); 535 ReloadExtension(extension->id());
515 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 536 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
516 } 537 }
517 538
518 // Crashy, http://crbug.com/42301. 539 // Crashy, http://crbug.com/42301.
519 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, 540 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
520 DISABLED_PopulateWebCacheFields) { 541 DISABLED_PopulateWebCacheFields) {
521 EXPECT_EQ(0, model()->ResourceCount()); 542 EXPECT_EQ(0, model()->ResourceCount());
522 543
523 // Show the task manager. This populates the model, and helps with debugging 544 // Show the task manager. This populates the model, and helps with debugging
524 // (you see the task manager). 545 // (you see the task manager).
525 browser()->window()->ShowTaskManager(); 546 browser()->window()->ShowTaskManager();
526 547
527 // Browser and the New Tab Page. 548 // New Tab Page.
528 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 549 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
550 int resource_count = TaskManager::GetInstance()->model()->ResourceCount();
529 551
530 // Open a new tab and make sure we notice that. 552 // Open a new tab and make sure we notice that.
531 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 553 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
532 FilePath(kTitle1File))); 554 FilePath(kTitle1File)));
533 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 555 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED);
534 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 556 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
535 557
536 // Check that we get some value for the cache columns. 558 // Check that we get some value for the cache columns.
537 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), 559 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count),
538 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 560 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
539 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), 561 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count),
540 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 562 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
541 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), 563 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count),
542 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 564 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
543 } 565 }
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_browsertest.cc ('k') | chrome/browser/task_manager/task_manager_browsertest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698