Chromium Code Reviews| 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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "chrome/browser/extensions/app_shortcut_manager.h" | 15 #include "chrome/browser/extensions/app_shortcut_manager.h" |
| 16 #include "chrome/browser/extensions/component_loader.h" | 16 #include "chrome/browser/extensions/component_loader.h" |
| 17 #include "chrome/browser/extensions/crx_installer.h" | 17 #include "chrome/browser/extensions/crx_installer.h" |
| 18 #include "chrome/browser/extensions/extension_creator.h" | 18 #include "chrome/browser/extensions/extension_creator.h" |
| 19 #include "chrome/browser/extensions/extension_error_reporter.h" | 19 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 20 #include "chrome/browser/extensions/extension_host.h" | |
| 21 #include "chrome/browser/extensions/extension_install_ui.h" | 20 #include "chrome/browser/extensions/extension_install_ui.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/unpacked_installer.h" | 22 #include "chrome/browser/extensions/unpacked_installer.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/browser/ui/omnibox/location_bar.h" | 26 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 32 #include "content/public/browser/notification_registrar.h" | 31 #include "content/public/browser/notification_registrar.h" |
| 33 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/render_view_host.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 extension_load_errors_observed_(0), |
| 40 target_page_action_count_(-1), | 40 target_page_action_count_(-1), |
| 41 target_visible_page_action_count_(-1) { | 41 target_visible_page_action_count_(-1) { |
| 42 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 42 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 43 AppShortcutManager::SetShortcutCreationDisabledForTesting(true); | 43 AppShortcutManager::SetShortcutCreationDisabledForTesting(true); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 CHECK(service->AllowFileAccess(extension)); | 127 CHECK(service->AllowFileAccess(extension)); |
| 128 | 128 |
| 129 if (!fileaccess_enabled) { | 129 if (!fileaccess_enabled) { |
| 130 service->SetAllowFileAccess(extension, fileaccess_enabled); | 130 service->SetAllowFileAccess(extension, fileaccess_enabled); |
| 131 load_signal.Wait(); | 131 load_signal.Wait(); |
| 132 extension = service->GetExtensionById(extension_id, false); | 132 extension = service->GetExtensionById(extension_id, false); |
| 133 CHECK(extension) << extension_id << " not found after reloading."; | 133 CHECK(extension) << extension_id << " not found after reloading."; |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 if (!WaitForExtensionHostsToLoad()) | 137 if (!WaitForExtensionViewsToLoad()) |
| 138 return NULL; | 138 return NULL; |
| 139 | 139 |
| 140 return extension; | 140 return extension; |
| 141 } | 141 } |
| 142 | 142 |
| 143 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) { | 143 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) { |
| 144 return LoadExtensionWithOptions(path, false, true); | 144 return LoadExtensionWithOptions(path, false, true); |
| 145 } | 145 } |
| 146 | 146 |
| 147 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( | 147 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 VLOG(1) << "Errors follow:"; | 323 VLOG(1) << "Errors follow:"; |
| 324 const std::vector<string16>* errors = | 324 const std::vector<string16>* errors = |
| 325 ExtensionErrorReporter::GetInstance()->GetErrors(); | 325 ExtensionErrorReporter::GetInstance()->GetErrors(); |
| 326 for (std::vector<string16>::const_iterator iter = errors->begin(); | 326 for (std::vector<string16>::const_iterator iter = errors->begin(); |
| 327 iter != errors->end(); ++iter) | 327 iter != errors->end(); ++iter) |
| 328 VLOG(1) << *iter; | 328 VLOG(1) << *iter; |
| 329 | 329 |
| 330 return NULL; | 330 return NULL; |
| 331 } | 331 } |
| 332 | 332 |
| 333 if (!WaitForExtensionHostsToLoad()) | 333 if (!WaitForExtensionViewsToLoad()) |
| 334 return NULL; | 334 return NULL; |
| 335 return service->GetExtensionById(last_loaded_extension_id_, false); | 335 return service->GetExtensionById(last_loaded_extension_id_, false); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { | 338 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { |
| 339 ExtensionService* service = browser()->profile()->GetExtensionService(); | 339 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 340 service->ReloadExtension(extension_id); | 340 service->ReloadExtension(extension_id); |
| 341 ui_test_utils::RegisterAndWait(this, | 341 ui_test_utils::RegisterAndWait(this, |
| 342 chrome::NOTIFICATION_EXTENSION_LOADED, | 342 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 343 content::NotificationService::AllSources()); | 343 content::NotificationService::AllSources()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); | 380 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 381 if (location_bar->PageActionVisibleCount() != count) { | 381 if (location_bar->PageActionVisibleCount() != count) { |
| 382 target_visible_page_action_count_ = count; | 382 target_visible_page_action_count_ = count; |
| 383 ui_test_utils::RegisterAndWait(this, | 383 ui_test_utils::RegisterAndWait(this, |
| 384 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 384 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 385 content::NotificationService::AllSources()); | 385 content::NotificationService::AllSources()); |
| 386 } | 386 } |
| 387 return location_bar->PageActionVisibleCount() == count; | 387 return location_bar->PageActionVisibleCount() == count; |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool ExtensionBrowserTest::WaitForExtensionHostsToLoad() { | 390 bool ExtensionBrowserTest::WaitForExtensionViewsToLoad() { |
| 391 // Wait for all the extension hosts that exist to finish loading. | 391 // Wait for all the extension render view hosts that exist to finish loading. |
| 392 content::NotificationRegistrar registrar; | 392 content::NotificationRegistrar registrar; |
| 393 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 393 registrar.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 394 content::NotificationService::AllSources()); | 394 content::NotificationService::AllSources()); |
| 395 | 395 |
| 396 ExtensionProcessManager* manager = | 396 ExtensionProcessManager* manager = |
| 397 browser()->profile()->GetExtensionProcessManager(); | 397 browser()->profile()->GetExtensionProcessManager(); |
| 398 for (ExtensionProcessManager::const_iterator iter = manager->begin(); | 398 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews(); |
| 399 iter != manager->end();) { | 399 for (ExtensionProcessManager::ViewSet::const_iterator iter = |
| 400 if ((*iter)->did_stop_loading()) { | 400 all_views.begin(); |
| 401 iter != all_views.end();) { | |
| 402 if (!(*iter)->IsLoading()) { | |
| 401 ++iter; | 403 ++iter; |
| 402 } else { | 404 } else { |
| 403 ui_test_utils::RunMessageLoop(); | 405 ui_test_utils::RunMessageLoop(); |
| 404 | 406 |
| 405 // Test activity may have modified the set of extension processes during | 407 // Test activity may have modified the set of extension processes during |
| 406 // message processing, so re-start the iteration to catch added/removed | 408 // message processing, so re-start the iteration to catch added/removed |
| 407 // processes. | 409 // processes. |
| 408 iter = manager->begin(); | 410 iter = all_views.begin(); |
|
Matt Perry
2012/04/23 21:53:04
Given the comment, this should be:
all_views = man
benwells
2012/04/24 04:31:27
Done.
| |
| 409 } | 411 } |
| 410 } | 412 } |
| 411 return true; | 413 return true; |
| 412 } | 414 } |
| 413 | 415 |
| 414 bool ExtensionBrowserTest::WaitForExtensionInstall() { | 416 bool ExtensionBrowserTest::WaitForExtensionInstall() { |
| 415 int before = extension_installs_observed_; | 417 int before = extension_installs_observed_; |
| 416 ui_test_utils::RegisterAndWait(this, | 418 ui_test_utils::RegisterAndWait(this, |
| 417 chrome::NOTIFICATION_EXTENSION_INSTALLED, | 419 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 418 content::NotificationService::AllSources()); | 420 content::NotificationService::AllSources()); |
| 419 return extension_installs_observed_ == (before + 1); | 421 return extension_installs_observed_ == (before + 1); |
| 420 } | 422 } |
| 421 | 423 |
| 422 bool ExtensionBrowserTest::WaitForExtensionInstallError() { | 424 bool ExtensionBrowserTest::WaitForExtensionInstallError() { |
| 423 int before = extension_installs_observed_; | 425 int before = extension_installs_observed_; |
| 424 ui_test_utils::RegisterAndWait(this, | 426 ui_test_utils::RegisterAndWait(this, |
| 425 chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 427 chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| 426 content::NotificationService::AllSources()); | 428 content::NotificationService::AllSources()); |
| 427 return extension_installs_observed_ == before; | 429 return extension_installs_observed_ == before; |
| 428 } | 430 } |
| 429 | 431 |
| 430 void ExtensionBrowserTest::WaitForExtensionLoad() { | 432 void ExtensionBrowserTest::WaitForExtensionLoad() { |
| 431 ui_test_utils::RegisterAndWait(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 433 ui_test_utils::RegisterAndWait(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 432 content::NotificationService::AllSources()); | 434 content::NotificationService::AllSources()); |
| 433 WaitForExtensionHostsToLoad(); | 435 WaitForExtensionViewsToLoad(); |
| 434 } | 436 } |
| 435 | 437 |
| 436 bool ExtensionBrowserTest::WaitForExtensionLoadError() { | 438 bool ExtensionBrowserTest::WaitForExtensionLoadError() { |
| 437 int before = extension_load_errors_observed_; | 439 int before = extension_load_errors_observed_; |
| 438 ui_test_utils::RegisterAndWait(this, | 440 ui_test_utils::RegisterAndWait(this, |
| 439 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, | 441 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 440 content::NotificationService::AllSources()); | 442 content::NotificationService::AllSources()); |
| 441 return extension_load_errors_observed_ != before; | 443 return extension_load_errors_observed_ != before; |
| 442 } | 444 } |
| 443 | 445 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 473 const Extension* extension = | 475 const Extension* extension = |
| 474 content::Details<const Extension>(details).ptr(); | 476 content::Details<const Extension>(details).ptr(); |
| 475 if (extension) | 477 if (extension) |
| 476 last_loaded_extension_id_ = extension->id(); | 478 last_loaded_extension_id_ = extension->id(); |
| 477 else | 479 else |
| 478 last_loaded_extension_id_ = ""; | 480 last_loaded_extension_id_ = ""; |
| 479 } | 481 } |
| 480 MessageLoopForUI::current()->Quit(); | 482 MessageLoopForUI::current()->Quit(); |
| 481 break; | 483 break; |
| 482 | 484 |
| 483 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: | |
| 484 VLOG(1) << "Got EXTENSION_HOST_DID_STOP_LOADING notification."; | |
| 485 MessageLoopForUI::current()->Quit(); | |
| 486 break; | |
| 487 | |
| 488 case chrome::NOTIFICATION_EXTENSION_INSTALLED: | 485 case chrome::NOTIFICATION_EXTENSION_INSTALLED: |
| 489 VLOG(1) << "Got EXTENSION_INSTALLED notification."; | 486 VLOG(1) << "Got EXTENSION_INSTALLED notification."; |
| 490 ++extension_installs_observed_; | 487 ++extension_installs_observed_; |
| 491 MessageLoopForUI::current()->Quit(); | 488 MessageLoopForUI::current()->Quit(); |
| 492 break; | 489 break; |
| 493 | 490 |
| 494 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: | 491 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: |
| 495 VLOG(1) << "Got EXTENSION_INSTALL_ERROR notification."; | 492 VLOG(1) << "Got EXTENSION_INSTALL_ERROR notification."; |
| 496 MessageLoopForUI::current()->Quit(); | 493 MessageLoopForUI::current()->Quit(); |
| 497 break; | 494 break; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 527 "Number of visible page actions: " | 524 "Number of visible page actions: " |
| 528 << location_bar->PageActionVisibleCount(); | 525 << location_bar->PageActionVisibleCount(); |
| 529 if (location_bar->PageActionVisibleCount() == | 526 if (location_bar->PageActionVisibleCount() == |
| 530 target_visible_page_action_count_) { | 527 target_visible_page_action_count_) { |
| 531 target_visible_page_action_count_ = -1; | 528 target_visible_page_action_count_ = -1; |
| 532 MessageLoopForUI::current()->Quit(); | 529 MessageLoopForUI::current()->Quit(); |
| 533 } | 530 } |
| 534 break; | 531 break; |
| 535 } | 532 } |
| 536 | 533 |
| 534 case content::NOTIFICATION_LOAD_STOP: | |
| 535 VLOG(1) << "Got LOAD_STOP notification."; | |
| 536 MessageLoopForUI::current()->Quit(); | |
| 537 break; | |
| 538 | |
| 537 default: | 539 default: |
| 538 NOTREACHED(); | 540 NOTREACHED(); |
| 539 break; | 541 break; |
| 540 } | 542 } |
| 541 } | 543 } |
| OLD | NEW |