summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extensions_service_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions/extensions_service_unittest.cc')
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc114
1 files changed, 39 insertions, 75 deletions
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 6ce579c..cc50bab 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -429,16 +429,9 @@ class ExtensionsServiceTest
ExtensionErrorReporter::GetInstance()->ClearErrors();
}
- enum UpdateState {
- FAILED_SILENTLY,
- FAILED,
- UPDATED,
- INSTALLED,
- ENABLED
- };
-
void UpdateExtension(const std::string& id, const FilePath& in_path,
- UpdateState expected_state) {
+ bool should_succeed, bool should_install,
+ bool expect_report_on_failure) {
ASSERT_TRUE(file_util::PathExists(in_path));
// We need to copy this to a temporary location because Update() will delete
@@ -447,39 +440,17 @@ class ExtensionsServiceTest
path = path.Append(in_path.BaseName());
ASSERT_TRUE(file_util::CopyFile(in_path, path));
- int previous_enabled_extension_count =
- service_->extensions()->size();
- int previous_installed_extension_count =
- previous_enabled_extension_count +
- service_->disabled_extensions()->size();
-
service_->UpdateExtension(id, path, GURL());
loop_.RunAllPending();
-
std::vector<std::string> errors = GetErrors();
- int error_count = errors.size();
- int enabled_extension_count =
- service_->extensions()->size();
- int installed_extension_count =
- enabled_extension_count + service_->disabled_extensions()->size();
-
- int expected_error_count = (expected_state == FAILED) ? 1 : 0;
- EXPECT_EQ(expected_error_count, error_count) << path.value();
-
- if (expected_state <= FAILED) {
- EXPECT_EQ(previous_enabled_extension_count,
- enabled_extension_count);
- EXPECT_EQ(previous_installed_extension_count,
- installed_extension_count);
+
+ if (should_succeed) {
+ EXPECT_EQ(0u, errors.size()) << path.value();
+ EXPECT_EQ(should_install ? 1u : 0u, service_->extensions()->size());
} else {
- int expected_installed_extension_count =
- (expected_state >= INSTALLED) ? 1 : 0;
- int expected_enabled_extension_count =
- (expected_state >= ENABLED) ? 1 : 0;
- EXPECT_EQ(expected_installed_extension_count,
- installed_extension_count);
- EXPECT_EQ(expected_enabled_extension_count,
- enabled_extension_count);
+ if (expect_report_on_failure) {
+ EXPECT_EQ(1u, errors.size()) << path.value();
+ }
}
// Update() should delete the temporary input file.
@@ -1171,7 +1142,7 @@ TEST_F(ExtensionsServiceTest, UpdateExtension) {
ASSERT_EQ(good_crx, good->id());
path = extensions_path.AppendASCII("good2.crx");
- UpdateExtension(good_crx, path, ENABLED);
+ UpdateExtension(good_crx, path, true, true, true);
ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
}
@@ -1183,7 +1154,7 @@ TEST_F(ExtensionsServiceTest, UpdateNotInstalledExtension) {
extensions_path = extensions_path.AppendASCII("extensions");
FilePath path = extensions_path.AppendASCII("good.crx");
- UpdateExtension(good_crx, path, UPDATED);
+ UpdateExtension(good_crx, path, true, false, true);
loop_.RunAllPending();
ASSERT_EQ(0u, service_->extensions()->size());
@@ -1207,7 +1178,7 @@ TEST_F(ExtensionsServiceTest, UpdateWillNotDowngrade) {
// Change path from good2.crx -> good.crx
path = extensions_path.AppendASCII("good.crx");
- UpdateExtension(good_crx, path, FAILED);
+ UpdateExtension(good_crx, path, false, false, true);
ASSERT_EQ("1.0.0.1", service_->extensions()->at(0)->VersionString());
}
@@ -1223,7 +1194,7 @@ TEST_F(ExtensionsServiceTest, UpdateToSameVersionIsNoop) {
InstallExtension(path, true);
Extension* good = service_->extensions()->at(0);
ASSERT_EQ(good_crx, good->id());
- UpdateExtension(good_crx, path, FAILED_SILENTLY);
+ UpdateExtension(good_crx, path, false, false, false);
}
// Test adding a pending extension.
@@ -1232,20 +1203,21 @@ TEST_F(ExtensionsServiceTest, AddPendingExtension) {
const std::string kFakeId("fake-id");
const GURL kFakeUpdateURL("http:://fake.update/url");
+ scoped_ptr<Version> fake_version(Version::GetVersionFromString("4.3.2.1"));
+ ASSERT_TRUE(fake_version.get());
const bool kFakeIsTheme(false);
const bool kFakeInstallSilently(true);
- const Extension::State kFakeInitialState(Extension::ENABLED);
- const bool kFakeInitialIncognitoEnabled(false);
- service_->AddPendingExtension(
- kFakeId, kFakeUpdateURL, kFakeIsTheme, kFakeInstallSilently,
- kFakeInitialState, kFakeInitialIncognitoEnabled);
+ service_->AddPendingExtension(kFakeId, kFakeUpdateURL,
+ *fake_version, kFakeIsTheme,
+ kFakeInstallSilently);
PendingExtensionMap::const_iterator it =
service_->pending_extensions().find(kFakeId);
ASSERT_TRUE(it != service_->pending_extensions().end());
EXPECT_EQ(kFakeUpdateURL, it->second.update_url);
EXPECT_EQ(kFakeIsTheme, it->second.is_theme);
EXPECT_EQ(kFakeInstallSilently, it->second.install_silently);
+ EXPECT_TRUE(it->second.version.Equals(*fake_version));
}
namespace {
@@ -1253,36 +1225,27 @@ const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
const char kGoodUpdateURL[] = "http://good.update/url";
const bool kGoodIsTheme = false;
const bool kGoodInstallSilently = true;
-const Extension::State kGoodInitialState = Extension::DISABLED;
-const bool kGoodInitialIncognitoEnabled = true;
+const char kGoodVersion[] = "1.2.3.4";
} // namespace
// Test updating a pending extension.
TEST_F(ExtensionsServiceTest, UpdatePendingExtension) {
InitializeEmptyExtensionsService();
- service_->AddPendingExtension(
- kGoodId, GURL(kGoodUpdateURL), kGoodIsTheme,
- kGoodInstallSilently, kGoodInitialState,
- kGoodInitialIncognitoEnabled);
+ scoped_ptr<Version> good_version(
+ Version::GetVersionFromString(kGoodVersion));
+ ASSERT_TRUE(good_version.get());
+ service_->AddPendingExtension(kGoodId, GURL(kGoodUpdateURL),
+ *good_version, kGoodIsTheme,
+ kGoodInstallSilently);
EXPECT_TRUE(ContainsKey(service_->pending_extensions(), kGoodId));
FilePath extensions_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
extensions_path = extensions_path.AppendASCII("extensions");
FilePath path = extensions_path.AppendASCII("good.crx");
- UpdateExtension(kGoodId, path, INSTALLED);
+ UpdateExtension(kGoodId, path, true, true, false);
EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId));
-
- Extension* extension = service_->GetExtensionById(kGoodId, true);
- ASSERT_TRUE(extension);
-
- bool enabled = service_->GetExtensionById(kGoodId, false);
- EXPECT_EQ(kGoodInitialState == Extension::ENABLED, enabled);
- EXPECT_EQ(kGoodInitialState,
- service_->extension_prefs()->GetExtensionState(extension->id()));
- EXPECT_EQ(kGoodInitialIncognitoEnabled,
- service_->IsIncognitoEnabled(extension));
}
// TODO(akalin): Test updating a pending extension non-silently once
@@ -1292,18 +1255,20 @@ TEST_F(ExtensionsServiceTest, UpdatePendingExtension) {
// Test updating a pending extension with wrong is_theme.
TEST_F(ExtensionsServiceTest, UpdatePendingExtensionWrongIsTheme) {
InitializeEmptyExtensionsService();
+ scoped_ptr<Version> good_version(
+ Version::GetVersionFromString(kGoodVersion));
+ ASSERT_TRUE(good_version.get());
// Add pending extension with a flipped is_theme.
- service_->AddPendingExtension(
- kGoodId, GURL(kGoodUpdateURL), !kGoodIsTheme,
- kGoodInstallSilently, kGoodInitialState,
- kGoodInitialIncognitoEnabled);
+ service_->AddPendingExtension(kGoodId, GURL(kGoodUpdateURL),
+ *good_version, !kGoodIsTheme,
+ kGoodInstallSilently);
EXPECT_TRUE(ContainsKey(service_->pending_extensions(), kGoodId));
FilePath extensions_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
extensions_path = extensions_path.AppendASCII("extensions");
FilePath path = extensions_path.AppendASCII("good.crx");
- UpdateExtension(kGoodId, path, UPDATED);
+ UpdateExtension(kGoodId, path, true, false, false);
// TODO(akalin): Figure out how to check that the extensions
// directory is cleaned up properly in OnExtensionInstalled().
@@ -1319,7 +1284,7 @@ TEST_F(ExtensionsServiceTest, UpdatePendingExtensionNotPending) {
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
extensions_path = extensions_path.AppendASCII("extensions");
FilePath path = extensions_path.AppendASCII("good.crx");
- UpdateExtension(kGoodId, path, UPDATED);
+ UpdateExtension(kGoodId, path, true, false, false);
EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId));
}
@@ -1340,11 +1305,10 @@ TEST_F(ExtensionsServiceTest, UpdatePendingExtensionAlreadyInstalled) {
// Use AddPendingExtensionInternal() as AddPendingExtension() would
// balk.
service_->AddPendingExtensionInternal(
- good->id(), good->update_url(), good->is_theme(),
- kGoodInstallSilently, kGoodInitialState,
- kGoodInitialIncognitoEnabled);
+ good->id(), good->update_url(), *good->version(),
+ good->is_theme(), kGoodInstallSilently);
- UpdateExtension(good->id(), path, INSTALLED);
+ UpdateExtension(good->id(), path, true, true, false);
EXPECT_FALSE(ContainsKey(service_->pending_extensions(), kGoodId));
}
@@ -1390,7 +1354,7 @@ TEST_F(ExtensionsServiceTest, UnloadBlacklistedExtension) {
InstallExtension(path, true);
Extension* good = service_->extensions()->at(0);
EXPECT_EQ(good_crx, good->id());
- UpdateExtension(good_crx, path, FAILED_SILENTLY);
+ UpdateExtension(good_crx, path, false, false, false);
std::vector<std::string> blacklist;
blacklist.push_back(good_crx);