| Index: chrome/browser/extensions/extension_service_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_service_unittest.cc (revision 209067)
|
| +++ chrome/browser/extensions/extension_service_unittest.cc (working copy)
|
| @@ -12,6 +12,7 @@
|
| #include "base/basictypes.h"
|
| #include "base/bind.h"
|
| #include "base/command_line.h"
|
| +#include "base/debug/trace_event_impl.h"
|
| #include "base/file_util.h"
|
| #include "base/files/file_enumerator.h"
|
| #include "base/files/scoped_temp_dir.h"
|
| @@ -82,9 +83,11 @@
|
| #include "content/public/browser/notification_registrar.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/plugin_service.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/storage_partition.h"
|
| #include "content/public/common/content_constants.h"
|
| #include "content/public/test/test_browser_thread.h"
|
| +#include "content/public/test/test_utils.h"
|
| #include "extensions/common/constants.h"
|
| #include "extensions/common/extension_resource.h"
|
| #include "extensions/common/url_pattern.h"
|
| @@ -195,6 +198,11 @@
|
| return temp_file;
|
| }
|
|
|
| +
|
| +bool WaitForCountNotificationsCallback(int *count) {
|
| + return --(*count) == 0;
|
| +}
|
| +
|
| } // namespace
|
|
|
| class MockExtensionProvider : public extensions::ExternalProviderInterface {
|
| @@ -428,6 +436,7 @@
|
| // Our message loop may be used in tests which require it to be an IO loop.
|
| ExtensionServiceTestBase::ExtensionServiceTestBase()
|
| : loop_(base::MessageLoop::TYPE_IO),
|
| + at_exit_manager_(new base::ShadowingAtExitManager),
|
| service_(NULL),
|
| management_policy_(NULL),
|
| expected_extensions_count_(0),
|
| @@ -453,6 +462,11 @@
|
| base::MessageLoop::current()->RunUntilIdle();
|
| profile_.reset(NULL);
|
| base::MessageLoop::current()->RunUntilIdle();
|
| + at_exit_manager_.reset();
|
| +
|
| + // This is needed because otherwise the next unit test which creates an
|
| + // in-process utility thread won't be able to create a TraceLog instance.
|
| + base::debug::TraceLog::Resurrect();
|
| }
|
|
|
| void ExtensionServiceTestBase::InitializeExtensionService(
|
| @@ -577,8 +591,13 @@
|
|
|
| void ExtensionServiceTestBase::SetUp() {
|
| ExtensionErrorReporter::GetInstance()->ClearErrors();
|
| + content::RenderProcessHost::SetRunRendererInProcess(true);
|
| }
|
|
|
| +void ExtensionServiceTestBase::TearDown() {
|
| + content::RenderProcessHost::SetRunRendererInProcess(false);
|
| +}
|
| +
|
| class ExtensionServiceTest
|
| : public ExtensionServiceTestBase, public content::NotificationObserver {
|
| public:
|
| @@ -681,11 +700,17 @@
|
| void StartCRXInstall(const base::FilePath& crx_path, int creation_flags) {
|
| ASSERT_TRUE(file_util::PathExists(crx_path))
|
| << "Path does not exist: "<< crx_path.value().c_str();
|
| +
|
| scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service_, NULL));
|
| installer->set_creation_flags(creation_flags);
|
| if (!(creation_flags & Extension::WAS_INSTALLED_BY_DEFAULT)) {
|
| installer->set_allow_silent_install(true);
|
| }
|
| +
|
| + content::WindowedNotificationObserver windowed_observer(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::Source<extensions::CrxInstaller>(installer));
|
| +
|
| installer->InstallCrx(crx_path);
|
| }
|
|
|
| @@ -786,7 +811,10 @@
|
| const Extension* WaitForCrxInstall(const base::FilePath& path,
|
| InstallState install_state,
|
| const std::string& expected_old_name) {
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| +
|
| std::vector<string16> errors = GetErrors();
|
| const Extension* extension = NULL;
|
| if (install_state != INSTALL_FAILED) {
|
| @@ -872,9 +900,17 @@
|
| previous_enabled_extension_count +
|
| service_->disabled_extensions()->size();
|
|
|
| - service_->UpdateExtension(id, path, GURL(), NULL);
|
| - loop_.RunUntilIdle();
|
| + extensions::CrxInstaller* installer = NULL;
|
| + service_->UpdateExtension(id, path, GURL(), &installer);
|
|
|
| + if (installer) {
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::Source<extensions::CrxInstaller>(installer)).Wait();
|
| + } else {
|
| + loop_.RunUntilIdle();
|
| + }
|
| +
|
| std::vector<string16> errors = GetErrors();
|
| int error_count = errors.size();
|
| int enabled_extension_count =
|
| @@ -1584,14 +1620,17 @@
|
|
|
| // Register and install an external extension.
|
| Version version("1.0.0.0");
|
| - service_->OnExternalExtensionFileFound(
|
| - good_crx,
|
| - &version,
|
| - path,
|
| - Manifest::EXTERNAL_PREF,
|
| - Extension::FROM_BOOKMARK,
|
| - false /* mark_acknowledged */);
|
| - loop_.RunUntilIdle();
|
| + if (service_->OnExternalExtensionFileFound(
|
| + good_crx,
|
| + &version,
|
| + path,
|
| + Manifest::EXTERNAL_PREF,
|
| + Extension::FROM_BOOKMARK,
|
| + false /* mark_acknowledged */)) {
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| + }
|
|
|
| const Extension* extension = service_->GetExtensionById(good_crx, false);
|
| ASSERT_TRUE(extension);
|
| @@ -1601,6 +1640,7 @@
|
| // Upgrade to version 2.0, the flag should be preserved.
|
| path = data_dir_.AppendASCII("good2.crx");
|
| UpdateExtension(good_crx, path, ENABLED);
|
| +
|
| ValidateBooleanPref(good_crx, kPrefFromBookmark, true);
|
| extension = service_->GetExtensionById(good_crx, false);
|
| ASSERT_TRUE(extension);
|
| @@ -1616,10 +1656,14 @@
|
|
|
| Version version("1.0.0.0");
|
| // Install an external extension.
|
| - service_->OnExternalExtensionFileFound(good_crx, &version,
|
| - path, Manifest::EXTERNAL_PREF,
|
| - Extension::NO_FLAGS, false);
|
| - loop_.RunUntilIdle();
|
| + if (service_->OnExternalExtensionFileFound(good_crx, &version,
|
| + path, Manifest::EXTERNAL_PREF,
|
| + Extension::NO_FLAGS, false)) {
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| + }
|
| +
|
| ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
|
|
|
| // Uninstall it and check that its killbit gets set.
|
| @@ -1702,14 +1746,19 @@
|
| wrong_id, &version, path, Manifest::EXTERNAL_PREF,
|
| Extension::NO_FLAGS, false);
|
|
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| ASSERT_FALSE(service_->GetExtensionById(good_crx, false));
|
|
|
| // Try again with the right ID. Expect success.
|
| - service_->OnExternalExtensionFileFound(
|
| - correct_id, &version, path, Manifest::EXTERNAL_PREF,
|
| - Extension::NO_FLAGS, false);
|
| - loop_.RunUntilIdle();
|
| + if (service_->OnExternalExtensionFileFound(
|
| + correct_id, &version, path, Manifest::EXTERNAL_PREF,
|
| + Extension::NO_FLAGS, false)) {
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| + }
|
| ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
|
| }
|
|
|
| @@ -1726,16 +1775,21 @@
|
| good_crx, &wrong_version, path, Manifest::EXTERNAL_PREF,
|
| Extension::NO_FLAGS, false);
|
|
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| ASSERT_FALSE(service_->GetExtensionById(good_crx, false));
|
|
|
| // Try again with the right version. Expect success.
|
| service_->pending_extension_manager()->Remove(good_crx);
|
| Version correct_version("1.0.0.0");
|
| - service_->OnExternalExtensionFileFound(
|
| - good_crx, &correct_version, path, Manifest::EXTERNAL_PREF,
|
| - Extension::NO_FLAGS, false);
|
| - loop_.RunUntilIdle();
|
| + if (service_->OnExternalExtensionFileFound(
|
| + good_crx, &correct_version, path, Manifest::EXTERNAL_PREF,
|
| + Extension::NO_FLAGS, false)) {
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| + }
|
| ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
|
| }
|
|
|
| @@ -3410,7 +3464,9 @@
|
| // Reloading extensions should find our externally registered extension
|
| // and install it.
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
|
|
| // Extension should be installed despite blacklist.
|
| ASSERT_EQ(1u, service_->extensions()->size());
|
| @@ -3588,8 +3644,12 @@
|
|
|
| // Providers are set up. Let them run.
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
|
|
| + int count = 2;
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + base::Bind(&WaitForCountNotificationsCallback, &count)).Wait();
|
| +
|
| ASSERT_EQ(2u, service_->extensions()->size());
|
| EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
|
| EXPECT_TRUE(service_->GetExtensionById(page_action, false));
|
| @@ -3628,14 +3688,15 @@
|
|
|
| ASSERT_EQ(0u, service_->extensions()->size());
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
|
|
| ASSERT_EQ(1u, service_->extensions()->size());
|
| EXPECT_TRUE(service_->GetExtensionById(good_crx, false));
|
| const Extension* extension = service_->GetExtensionById(good_crx, false);
|
| EXPECT_TRUE(extension->from_webstore());
|
| EXPECT_TRUE(extension->was_installed_by_default());
|
| -
|
| }
|
| #endif
|
|
|
| @@ -4253,7 +4314,9 @@
|
| // Reloading extensions should find our externally registered extension
|
| // and install it.
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
|
|
| ASSERT_EQ(0u, GetErrors().size());
|
| ASSERT_EQ(1u, loaded_.size());
|
| @@ -4280,7 +4343,9 @@
|
|
|
| loaded_.clear();
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| ASSERT_EQ(0u, GetErrors().size());
|
| ASSERT_EQ(1u, loaded_.size());
|
| ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
|
| @@ -4317,7 +4382,9 @@
|
|
|
| loaded_.clear();
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| ASSERT_EQ(1u, loaded_.size());
|
| }
|
| ValidatePrefKeyCount(1);
|
| @@ -4344,7 +4411,9 @@
|
| // from the external provider.
|
| provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
|
|
| ASSERT_EQ(1u, loaded_.size());
|
| ASSERT_EQ(0u, GetErrors().size());
|
| @@ -4495,7 +4564,9 @@
|
| provider->set_visit_count(0);
|
| service_->CheckForExternalUpdates();
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| EXPECT_EQ(2, provider->visit_count());
|
| ASSERT_EQ(0u, GetErrors().size());
|
| ASSERT_EQ(1u, loaded_.size());
|
| @@ -5888,7 +5959,7 @@
|
| ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation());
|
| ASSERT_FALSE(IsCrxInstalled());
|
|
|
| - // Another request from sync should be ignorred.
|
| + // Another request from sync should be ignored.
|
| EXPECT_FALSE(AddPendingSyncInstall());
|
| ASSERT_EQ(Manifest::EXTERNAL_PREF, GetPendingLocation());
|
| ASSERT_FALSE(IsCrxInstalled());
|
| @@ -5975,7 +6046,9 @@
|
| data_dir_.AppendASCII("hosted_app.crx"));
|
|
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| EXPECT_FALSE(extensions::HasExternalInstallError(service_));
|
|
|
| // Another normal extension, but installed externally.
|
| @@ -5984,7 +6057,9 @@
|
| data_dir_.AppendASCII("page_action.crx"));
|
|
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| EXPECT_TRUE(extensions::HasExternalInstallError(service_));
|
| }
|
|
|
| @@ -6003,7 +6078,9 @@
|
| data_dir_.AppendASCII("page_action.crx"));
|
|
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| EXPECT_TRUE(extensions::HasExternalInstallError(service_));
|
| EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
|
|
|
| @@ -6035,7 +6112,10 @@
|
| data_dir_.AppendASCII("theme.crx"));
|
|
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + int count = 3;
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + base::Bind(&WaitForCountNotificationsCallback, &count)).Wait();
|
| EXPECT_TRUE(extensions::HasExternalInstallError(service_));
|
| EXPECT_FALSE(service_->IsExtensionEnabled(page_action));
|
| EXPECT_FALSE(service_->IsExtensionEnabled(good_crx));
|
| @@ -6073,7 +6153,9 @@
|
| provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
|
|
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| EXPECT_TRUE(extensions::HasExternalInstallError(service_));
|
| EXPECT_TRUE(extensions::HasExternalInstallBubble(service_));
|
| EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore));
|
| @@ -6097,7 +6179,9 @@
|
| provider->UpdateOrAddExtension(updates_from_webstore, "1", crx_path);
|
|
|
| service_->CheckForExternalUpdates();
|
| - loop_.RunUntilIdle();
|
| + content::WindowedNotificationObserver(
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::NotificationService::AllSources()).Wait();
|
| EXPECT_TRUE(extensions::HasExternalInstallError(service_));
|
| EXPECT_FALSE(extensions::HasExternalInstallBubble(service_));
|
| EXPECT_FALSE(service_->IsExtensionEnabled(updates_from_webstore));
|
|
|