OLD | NEW |
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/extensions/extension_browsertest.h" | 5 #include "chrome/browser/extensions/extension_browsertest.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
32 #include "content/public/browser/notification_registrar.h" | 32 #include "content/public/browser/notification_registrar.h" |
33 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
34 | 34 |
35 ExtensionBrowserTest::ExtensionBrowserTest() | 35 ExtensionBrowserTest::ExtensionBrowserTest() |
36 : loaded_(false), | 36 : loaded_(false), |
37 installed_(false), | 37 installed_(false), |
38 extension_installs_observed_(0), | 38 extension_installs_observed_(0), |
| 39 extension_load_errors_observed_(0), |
39 target_page_action_count_(-1), | 40 target_page_action_count_(-1), |
40 target_visible_page_action_count_(-1) { | 41 target_visible_page_action_count_(-1) { |
41 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 42 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
42 AppShortcutManager::SetShortcutCreationDisabledForTesting(true); | 43 AppShortcutManager::SetShortcutCreationDisabledForTesting(true); |
43 } | 44 } |
44 | 45 |
45 ExtensionBrowserTest::~ExtensionBrowserTest() { | 46 ExtensionBrowserTest::~ExtensionBrowserTest() { |
46 AppShortcutManager::SetShortcutCreationDisabledForTesting(false); | 47 AppShortcutManager::SetShortcutCreationDisabledForTesting(false); |
47 } | 48 } |
48 | 49 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 content::NotificationService::AllSources()); | 419 content::NotificationService::AllSources()); |
419 return extension_installs_observed_ == before; | 420 return extension_installs_observed_ == before; |
420 } | 421 } |
421 | 422 |
422 void ExtensionBrowserTest::WaitForExtensionLoad() { | 423 void ExtensionBrowserTest::WaitForExtensionLoad() { |
423 ui_test_utils::RegisterAndWait(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 424 ui_test_utils::RegisterAndWait(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
424 content::NotificationService::AllSources()); | 425 content::NotificationService::AllSources()); |
425 WaitForExtensionHostsToLoad(); | 426 WaitForExtensionHostsToLoad(); |
426 } | 427 } |
427 | 428 |
| 429 bool ExtensionBrowserTest::WaitForExtensionLoadError() { |
| 430 int before = extension_load_errors_observed_; |
| 431 ui_test_utils::RegisterAndWait(this, |
| 432 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 433 content::NotificationService::AllSources()); |
| 434 WaitForExtensionHostsToLoad(); |
| 435 return extension_load_errors_observed_ != before; |
| 436 } |
| 437 |
428 bool ExtensionBrowserTest::WaitForExtensionCrash( | 438 bool ExtensionBrowserTest::WaitForExtensionCrash( |
429 const std::string& extension_id) { | 439 const std::string& extension_id) { |
430 ExtensionService* service = browser()->profile()->GetExtensionService(); | 440 ExtensionService* service = browser()->profile()->GetExtensionService(); |
431 | 441 |
432 if (!service->GetExtensionById(extension_id, true)) { | 442 if (!service->GetExtensionById(extension_id, true)) { |
433 // The extension is already unloaded, presumably due to a crash. | 443 // The extension is already unloaded, presumably due to a crash. |
434 return true; | 444 return true; |
435 } | 445 } |
436 ui_test_utils::RegisterAndWait( | 446 ui_test_utils::RegisterAndWait( |
437 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, | 447 this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: | 488 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: |
479 VLOG(1) << "Got EXTENSION_INSTALL_ERROR notification."; | 489 VLOG(1) << "Got EXTENSION_INSTALL_ERROR notification."; |
480 MessageLoopForUI::current()->Quit(); | 490 MessageLoopForUI::current()->Quit(); |
481 break; | 491 break; |
482 | 492 |
483 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: | 493 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: |
484 VLOG(1) << "Got EXTENSION_PROCESS_TERMINATED notification."; | 494 VLOG(1) << "Got EXTENSION_PROCESS_TERMINATED notification."; |
485 MessageLoopForUI::current()->Quit(); | 495 MessageLoopForUI::current()->Quit(); |
486 break; | 496 break; |
487 | 497 |
| 498 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: |
| 499 VLOG(1) << "Got EXTENSION_LOAD_ERROR notification."; |
| 500 ++extension_load_errors_observed_; |
| 501 MessageLoopForUI::current()->Quit(); |
| 502 break; |
| 503 |
488 case chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED: { | 504 case chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED: { |
489 LocationBarTesting* location_bar = | 505 LocationBarTesting* location_bar = |
490 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); | 506 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); |
491 VLOG(1) << "Got EXTENSION_PAGE_ACTION_COUNT_CHANGED notification. Number " | 507 VLOG(1) << "Got EXTENSION_PAGE_ACTION_COUNT_CHANGED notification. Number " |
492 "of page actions: " << location_bar->PageActionCount(); | 508 "of page actions: " << location_bar->PageActionCount(); |
493 if (location_bar->PageActionCount() == | 509 if (location_bar->PageActionCount() == |
494 target_page_action_count_) { | 510 target_page_action_count_) { |
495 target_page_action_count_ = -1; | 511 target_page_action_count_ = -1; |
496 MessageLoopForUI::current()->Quit(); | 512 MessageLoopForUI::current()->Quit(); |
497 } | 513 } |
(...skipping 12 matching lines...) Expand all Loading... |
510 MessageLoopForUI::current()->Quit(); | 526 MessageLoopForUI::current()->Quit(); |
511 } | 527 } |
512 break; | 528 break; |
513 } | 529 } |
514 | 530 |
515 default: | 531 default: |
516 NOTREACHED(); | 532 NOTREACHED(); |
517 break; | 533 break; |
518 } | 534 } |
519 } | 535 } |
OLD | NEW |