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

Unified Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 18119009: Make utility process run in-process when running in single-process mode. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: undo unnecessary changes Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service_unittest.cc
===================================================================
--- chrome/browser/extensions/extension_service_unittest.cc (revision 210446)
+++ chrome/browser/extensions/extension_service_unittest.cc (working copy)
@@ -82,9 +82,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 +197,11 @@
return temp_file;
}
+
+bool WaitForCountNotificationsCallback(int *count) {
+ return --(*count) == 0;
+}
+
} // namespace
class MockExtensionProvider : public extensions::ExternalProviderInterface {
@@ -577,8 +584,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:
@@ -686,6 +698,11 @@
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 +803,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 +892,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 +1612,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);
@@ -1616,10 +1647,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 +1737,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 +1766,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 +3455,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 +3635,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 +3679,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 +4305,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 +4334,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 +4373,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 +4402,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 +4555,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 +5950,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 +6037,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 +6048,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 +6069,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 +6103,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 +6144,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 +6170,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));

Powered by Google App Engine
This is Rietveld 408576698