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

Side by Side Diff: chrome/browser/extensions/extension_crash_recovery_browsertest.cc

Issue 11428085: Fix couple of issues in ExtensionCrashRecoveryTest. In particular the (Closed) Base URL: http://git.chromium.org/chromium/src.git@extension_crash
Patch Set: Created 8 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/process_util.h" 5 #include "base/process_util.h"
6 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/extensions/extension_browsertest.h" 7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_process_manager.h" 9 #include "chrome/browser/extensions/extension_process_manager.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 28 matching lines...) Expand all
39 protected: 39 protected:
40 ExtensionService* GetExtensionService() { 40 ExtensionService* GetExtensionService() {
41 return browser()->profile()->GetExtensionService(); 41 return browser()->profile()->GetExtensionService();
42 } 42 }
43 43
44 ExtensionProcessManager* GetExtensionProcessManager() { 44 ExtensionProcessManager* GetExtensionProcessManager() {
45 return extensions::ExtensionSystem::Get(browser()->profile())-> 45 return extensions::ExtensionSystem::Get(browser()->profile())->
46 process_manager(); 46 process_manager();
47 } 47 }
48 48
49 Balloon* GetNotificationDelegate(size_t index) {
50 NotificationUIManager* manager =
51 g_browser_process->notification_ui_manager();
52 BalloonCollection::Balloons balloons =
53 manager->balloon_collection()->GetActiveBalloons();
54 return balloons.at(index);
55 }
56
57 void AcceptNotification(size_t index) { 49 void AcceptNotification(size_t index) {
58 Balloon* balloon = GetNotificationDelegate(index); 50 Balloon* balloon = GetNotificationDelegate(index);
59 ASSERT_TRUE(balloon); 51 ASSERT_TRUE(balloon);
60 balloon->OnClick(); 52 balloon->OnClick();
61 WaitForExtensionLoad(); 53 WaitForExtensionLoad();
62 } 54 }
63 55
64 void CancelNotification(size_t index) { 56 void CancelNotification(size_t index) {
65 Balloon* balloon = GetNotificationDelegate(index); 57 Balloon* balloon = GetNotificationDelegate(index);
58 ASSERT_TRUE(balloon);
66 NotificationUIManager* manager = 59 NotificationUIManager* manager =
67 g_browser_process->notification_ui_manager(); 60 g_browser_process->notification_ui_manager();
68 ASSERT_TRUE(manager->CancelById(balloon->notification().notification_id())); 61 ASSERT_TRUE(manager->CancelById(balloon->notification().notification_id()));
69 } 62 }
70 63
71 size_t CountBalloons() { 64 size_t CountBalloons() {
72 NotificationUIManager* manager = 65 NotificationUIManager* manager =
73 g_browser_process->notification_ui_manager(); 66 g_browser_process->notification_ui_manager();
74 BalloonCollection::Balloons balloons = 67 BalloonCollection::Balloons balloons =
75 manager->balloon_collection()->GetActiveBalloons(); 68 manager->balloon_collection()->GetActiveBalloons();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void LoadSecondExtension() { 116 void LoadSecondExtension() {
124 const Extension* extension = LoadExtension( 117 const Extension* extension = LoadExtension(
125 test_data_dir_.AppendASCII("install").AppendASCII("install")); 118 test_data_dir_.AppendASCII("install").AppendASCII("install"));
126 ASSERT_TRUE(extension); 119 ASSERT_TRUE(extension);
127 second_extension_id_ = extension->id(); 120 second_extension_id_ = extension->id();
128 CheckExtensionConsistency(second_extension_id_); 121 CheckExtensionConsistency(second_extension_id_);
129 } 122 }
130 123
131 std::string first_extension_id_; 124 std::string first_extension_id_;
132 std::string second_extension_id_; 125 std::string second_extension_id_;
126
127 private:
128 Balloon* GetNotificationDelegate(size_t index) {
129 NotificationUIManager* manager =
130 g_browser_process->notification_ui_manager();
131 BalloonCollection::Balloons balloons =
132 manager->balloon_collection()->GetActiveBalloons();
133 return index < balloons.size() ? balloons.at(index) : NULL;
134 }
133 }; 135 };
134 136
135 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) { 137 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) {
136 const size_t size_before = GetExtensionService()->extensions()->size(); 138 const size_t size_before = GetExtensionService()->extensions()->size();
137 const size_t crash_size_before = 139 const size_t crash_size_before =
138 GetExtensionService()->terminated_extensions()->size(); 140 GetExtensionService()->terminated_extensions()->size();
139 LoadTestExtension(); 141 LoadTestExtension();
140 CrashExtension(first_extension_id_); 142 CrashExtension(first_extension_id_);
141 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); 143 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
142 ASSERT_EQ(crash_size_before + 1, 144 ASSERT_EQ(crash_size_before + 1,
143 GetExtensionService()->terminated_extensions()->size()); 145 GetExtensionService()->terminated_extensions()->size());
144 AcceptNotification(0); 146 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
145 147
146 SCOPED_TRACE("after clicking the balloon"); 148 SCOPED_TRACE("after clicking the balloon");
147 CheckExtensionConsistency(first_extension_id_); 149 CheckExtensionConsistency(first_extension_id_);
148 ASSERT_EQ(crash_size_before, 150 ASSERT_EQ(crash_size_before,
149 GetExtensionService()->terminated_extensions()->size()); 151 GetExtensionService()->terminated_extensions()->size());
150 } 152 }
151 153
152 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) { 154 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CloseAndReload) {
153 const size_t size_before = GetExtensionService()->extensions()->size(); 155 const size_t size_before = GetExtensionService()->extensions()->size();
154 const size_t crash_size_before = 156 const size_t crash_size_before =
155 GetExtensionService()->terminated_extensions()->size(); 157 GetExtensionService()->terminated_extensions()->size();
156 LoadTestExtension(); 158 LoadTestExtension();
157 CrashExtension(first_extension_id_); 159 CrashExtension(first_extension_id_);
158 160
159 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); 161 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
160 ASSERT_EQ(crash_size_before + 1, 162 ASSERT_EQ(crash_size_before + 1,
161 GetExtensionService()->terminated_extensions()->size()); 163 GetExtensionService()->terminated_extensions()->size());
162 164
163 CancelNotification(0); 165 ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
164 ReloadExtension(first_extension_id_); 166 ReloadExtension(first_extension_id_);
165 167
166 SCOPED_TRACE("after reloading"); 168 SCOPED_TRACE("after reloading");
167 CheckExtensionConsistency(first_extension_id_); 169 CheckExtensionConsistency(first_extension_id_);
168 ASSERT_EQ(crash_size_before, 170 ASSERT_EQ(crash_size_before,
169 GetExtensionService()->terminated_extensions()->size()); 171 GetExtensionService()->terminated_extensions()->size());
170 } 172 }
171 173
172 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) { 174 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) {
173 const size_t size_before = GetExtensionService()->extensions()->size(); 175 const size_t size_before = GetExtensionService()->extensions()->size();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 CrashExtension(first_extension_id_); 262 CrashExtension(first_extension_id_);
261 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); 263 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
262 } 264 }
263 265
264 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) { 266 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) {
265 const size_t size_before = GetExtensionService()->extensions()->size(); 267 const size_t size_before = GetExtensionService()->extensions()->size();
266 LoadTestExtension(); 268 LoadTestExtension();
267 LoadSecondExtension(); 269 LoadSecondExtension();
268 CrashExtension(first_extension_id_); 270 CrashExtension(first_extension_id_);
269 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); 271 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
270 AcceptNotification(0); 272 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
271 273
272 SCOPED_TRACE("after clicking the balloon"); 274 SCOPED_TRACE("after clicking the balloon");
273 CheckExtensionConsistency(first_extension_id_); 275 CheckExtensionConsistency(first_extension_id_);
274 CheckExtensionConsistency(second_extension_id_); 276 CheckExtensionConsistency(second_extension_id_);
275 } 277 }
276 278
277 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) { 279 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) {
278 const size_t size_before = GetExtensionService()->extensions()->size(); 280 const size_t size_before = GetExtensionService()->extensions()->size();
279 LoadTestExtension(); 281 LoadTestExtension();
280 LoadSecondExtension(); 282 LoadSecondExtension();
281 CrashExtension(second_extension_id_); 283 CrashExtension(second_extension_id_);
282 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); 284 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
283 AcceptNotification(0); 285 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
284 286
285 SCOPED_TRACE("after clicking the balloon"); 287 SCOPED_TRACE("after clicking the balloon");
286 CheckExtensionConsistency(first_extension_id_); 288 CheckExtensionConsistency(first_extension_id_);
287 CheckExtensionConsistency(second_extension_id_); 289 CheckExtensionConsistency(second_extension_id_);
288 } 290 }
289 291
290 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, 292 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
291 TwoExtensionsCrashBothAtOnce) { 293 TwoExtensionsCrashBothAtOnce) {
292 const size_t size_before = GetExtensionService()->extensions()->size(); 294 const size_t size_before = GetExtensionService()->extensions()->size();
293 const size_t crash_size_before = 295 const size_t crash_size_before =
294 GetExtensionService()->terminated_extensions()->size(); 296 GetExtensionService()->terminated_extensions()->size();
295 LoadTestExtension(); 297 LoadTestExtension();
296 LoadSecondExtension(); 298 LoadSecondExtension();
297 CrashExtension(first_extension_id_); 299 CrashExtension(first_extension_id_);
298 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); 300 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
299 ASSERT_EQ(crash_size_before + 1, 301 ASSERT_EQ(crash_size_before + 1,
300 GetExtensionService()->terminated_extensions()->size()); 302 GetExtensionService()->terminated_extensions()->size());
301 CrashExtension(second_extension_id_); 303 CrashExtension(second_extension_id_);
302 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); 304 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
303 ASSERT_EQ(crash_size_before + 2, 305 ASSERT_EQ(crash_size_before + 2,
304 GetExtensionService()->terminated_extensions()->size()); 306 GetExtensionService()->terminated_extensions()->size());
305 307
306 { 308 {
307 SCOPED_TRACE("first balloon"); 309 SCOPED_TRACE("first balloon");
308 AcceptNotification(0); 310 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
309 CheckExtensionConsistency(first_extension_id_); 311 CheckExtensionConsistency(first_extension_id_);
310 } 312 }
311 313
312 { 314 {
313 SCOPED_TRACE("second balloon"); 315 SCOPED_TRACE("second balloon");
314 AcceptNotification(0); 316 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
315 CheckExtensionConsistency(first_extension_id_); 317 CheckExtensionConsistency(first_extension_id_);
316 CheckExtensionConsistency(second_extension_id_); 318 CheckExtensionConsistency(second_extension_id_);
317 } 319 }
318 } 320 }
319 321
320 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) { 322 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) {
321 const size_t size_before = GetExtensionService()->extensions()->size(); 323 const size_t size_before = GetExtensionService()->extensions()->size();
322 LoadTestExtension(); 324 LoadTestExtension();
323 CrashExtension(first_extension_id_); 325 CrashExtension(first_extension_id_);
324 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); 326 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
325 LoadSecondExtension(); 327 LoadSecondExtension();
326 CrashExtension(second_extension_id_); 328 CrashExtension(second_extension_id_);
327 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); 329 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
328 330
329 { 331 {
330 SCOPED_TRACE("first balloon"); 332 SCOPED_TRACE("first balloon");
331 AcceptNotification(0); 333 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
332 CheckExtensionConsistency(first_extension_id_); 334 CheckExtensionConsistency(first_extension_id_);
333 } 335 }
334 336
335 { 337 {
336 SCOPED_TRACE("second balloon"); 338 SCOPED_TRACE("second balloon");
337 AcceptNotification(0); 339 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
338 CheckExtensionConsistency(first_extension_id_); 340 CheckExtensionConsistency(first_extension_id_);
339 CheckExtensionConsistency(second_extension_id_); 341 CheckExtensionConsistency(second_extension_id_);
340 } 342 }
341 } 343 }
342 344
343 // http://crbug.com/84719 345 // http://crbug.com/84719
344 #if defined(OS_LINUX) 346 #if defined(OS_LINUX)
345 #define MAYBE_TwoExtensionsShutdownWhileCrashed \ 347 #define MAYBE_TwoExtensionsShutdownWhileCrashed \
346 DISABLED_TwoExtensionsShutdownWhileCrashed 348 DISABLED_TwoExtensionsShutdownWhileCrashed
347 #else 349 #else
(...skipping 21 matching lines...) Expand all
369 LoadTestExtension(); 371 LoadTestExtension();
370 LoadSecondExtension(); 372 LoadSecondExtension();
371 CrashExtension(first_extension_id_); 373 CrashExtension(first_extension_id_);
372 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); 374 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
373 CrashExtension(second_extension_id_); 375 CrashExtension(second_extension_id_);
374 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size()); 376 ASSERT_EQ(size_before, GetExtensionService()->extensions()->size());
375 377
376 // Accept notification 1 before canceling notification 0. 378 // Accept notification 1 before canceling notification 0.
377 // Otherwise, on Linux and Windows, there is a race here, in which 379 // Otherwise, on Linux and Windows, there is a race here, in which
378 // canceled notifications do not immediately go away. 380 // canceled notifications do not immediately go away.
379 AcceptNotification(1); 381 ASSERT_NO_FATAL_FAILURE(AcceptNotification(1));
380 CancelNotification(0); 382 ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
381 383
382 SCOPED_TRACE("balloons done"); 384 SCOPED_TRACE("balloons done");
383 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); 385 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
384 CheckExtensionConsistency(second_extension_id_); 386 CheckExtensionConsistency(second_extension_id_);
385 } 387 }
386 388
387 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, 389 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
388 TwoExtensionsReloadIndependently) { 390 TwoExtensionsReloadIndependently) {
389 const size_t size_before = GetExtensionService()->extensions()->size(); 391 const size_t size_before = GetExtensionService()->extensions()->size();
390 LoadTestExtension(); 392 LoadTestExtension();
(...skipping 10 matching lines...) Expand all
401 // At the beginning we should have one balloon displayed for each extension. 403 // At the beginning we should have one balloon displayed for each extension.
402 ASSERT_EQ(2U, CountBalloons()); 404 ASSERT_EQ(2U, CountBalloons());
403 ReloadExtension(first_extension_id_); 405 ReloadExtension(first_extension_id_);
404 // One of the balloons should hide after the extension is reloaded. 406 // One of the balloons should hide after the extension is reloaded.
405 ASSERT_EQ(1U, CountBalloons()); 407 ASSERT_EQ(1U, CountBalloons());
406 CheckExtensionConsistency(first_extension_id_); 408 CheckExtensionConsistency(first_extension_id_);
407 } 409 }
408 410
409 { 411 {
410 SCOPED_TRACE("second: balloon"); 412 SCOPED_TRACE("second: balloon");
411 AcceptNotification(0); 413 ASSERT_NO_FATAL_FAILURE(AcceptNotification(0));
412 CheckExtensionConsistency(first_extension_id_); 414 CheckExtensionConsistency(first_extension_id_);
413 CheckExtensionConsistency(second_extension_id_); 415 CheckExtensionConsistency(second_extension_id_);
414 } 416 }
415 } 417 }
416 418
417 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) { 419 IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) {
418 const size_t size_before = GetExtensionService()->extensions()->size(); 420 const size_t size_before = GetExtensionService()->extensions()->size();
419 const size_t crash_size_before = 421 const size_t crash_size_before =
420 GetExtensionService()->terminated_extensions()->size(); 422 GetExtensionService()->terminated_extensions()->size();
421 LoadTestExtension(); 423 LoadTestExtension();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 observer.Wait(); 496 observer.Wait();
495 } 497 }
496 // Extension should now be loaded. 498 // Extension should now be loaded.
497 SCOPED_TRACE("after reloading the tab"); 499 SCOPED_TRACE("after reloading the tab");
498 CheckExtensionConsistency(first_extension_id_); 500 CheckExtensionConsistency(first_extension_id_);
499 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size()); 501 ASSERT_EQ(size_before + 1, GetExtensionService()->extensions()->size());
500 ASSERT_EQ(0U, CountBalloons()); 502 ASSERT_EQ(0U, CountBalloons());
501 } 503 }
502 504
503 #endif 505 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698