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

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

Issue 17038002: Separate the NTP app ordering from the app list app ordering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 2 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
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 5212209225a3cf1b696f82626aa8f6022a331e6a..4aae3c32227d5e0bb043017a90214e3d7169929e 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -1239,7 +1239,6 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
EXPECT_TRUE(service_->GetExtensionById(loaded_[0]->id(), false));
EXPECT_EQ(expected_num_extensions, service_->extensions()->size());
- ValidatePrefKeyCount(3);
ValidateIntegerPref(good0, "state", Extension::ENABLED);
ValidateIntegerPref(good0, "location", Manifest::INTERNAL);
ValidateIntegerPref(good1, "state", Extension::ENABLED);
@@ -1550,6 +1549,7 @@ TEST_F(ExtensionServiceTest, PendingImports) {
// them, throw away the key used and change the id's above.
TEST_F(ExtensionServiceTest, InstallExtension) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
// Extensions not enabled.
set_extensions_enabled(false);
@@ -1557,45 +1557,44 @@ TEST_F(ExtensionServiceTest, InstallExtension) {
InstallCRX(path, INSTALL_FAILED);
set_extensions_enabled(true);
- ValidatePrefKeyCount(0);
+ ValidatePrefKeyCount(expected_pref_count);
// A simple extension that should install without error.
path = data_dir_.AppendASCII("good.crx");
InstallCRX(path, INSTALL_NEW);
// TODO(erikkay): verify the contents of the installed extension.
- int pref_count = 0;
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
// An extension with page actions.
path = data_dir_.AppendASCII("page_action.crx");
InstallCRX(path, INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(page_action, "state", Extension::ENABLED);
ValidateIntegerPref(page_action, "location", Manifest::INTERNAL);
// Bad signature.
path = data_dir_.AppendASCII("bad_signature.crx");
InstallCRX(path, INSTALL_FAILED);
- ValidatePrefKeyCount(pref_count);
+ ValidatePrefKeyCount(expected_pref_count);
// 0-length extension file.
path = data_dir_.AppendASCII("not_an_extension.crx");
InstallCRX(path, INSTALL_FAILED);
- ValidatePrefKeyCount(pref_count);
+ ValidatePrefKeyCount(expected_pref_count);
// Bad magic number.
path = data_dir_.AppendASCII("bad_magic.crx");
InstallCRX(path, INSTALL_FAILED);
- ValidatePrefKeyCount(pref_count);
+ ValidatePrefKeyCount(expected_pref_count);
// Packed extensions may have folders or files that have underscores.
// This will only cause a warning, rather than a fatal error.
path = data_dir_.AppendASCII("bad_underscore.crx");
InstallCRX(path, INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
// TODO(erikkay): add more tests for many of the failure cases.
// TODO(erikkay): add tests for upgrade cases.
@@ -1637,7 +1636,7 @@ struct MockInstallObserver : public extensions::InstallObserver {
last_extension_uninstalled = extension->id();
}
- virtual void OnAppsReordered() OVERRIDE {
+ virtual void OnAppListReordered() OVERRIDE {
}
virtual void OnAppInstalledToAppList(
@@ -2348,12 +2347,12 @@ TEST_F(ExtensionServiceTest, PackExtensionOpenSSLKey) {
TEST_F(ExtensionServiceTest, InstallTheme) {
InitializeEmptyExtensionService();
service_->Init();
+ int expected_pref_count = GetPrefKeyCount();
// A theme.
base::FilePath path = data_dir_.AppendASCII("theme.crx");
InstallCRX(path, INSTALL_NEW);
- int pref_count = 0;
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(theme_crx, "state", Extension::ENABLED);
ValidateIntegerPref(theme_crx, "location", Manifest::INTERNAL);
@@ -2362,7 +2361,7 @@ TEST_F(ExtensionServiceTest, InstallTheme) {
set_extensions_enabled(false);
path = data_dir_.AppendASCII("theme2.crx");
InstallCRX(path, INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(theme2_crx, "state", Extension::ENABLED);
ValidateIntegerPref(theme2_crx, "location", Manifest::INTERNAL);
@@ -2372,7 +2371,7 @@ TEST_F(ExtensionServiceTest, InstallTheme) {
{
path = data_dir_.AppendASCII("theme_with_extension.crx");
const Extension* extension = InstallCRX(path, INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ASSERT_TRUE(extension);
EXPECT_TRUE(extension->is_theme());
EXPECT_EQ(
@@ -2383,7 +2382,7 @@ TEST_F(ExtensionServiceTest, InstallTheme) {
// A theme with image resources missing (misspelt path).
path = data_dir_.AppendASCII("theme_missing_image.crx");
InstallCRX(path, INSTALL_FAILED);
- ValidatePrefKeyCount(pref_count);
+ ValidatePrefKeyCount(expected_pref_count);
}
TEST_F(ExtensionServiceTest, LoadLocalizedTheme) {
@@ -2516,23 +2515,23 @@ TEST_F(ExtensionServiceTest, InstallLocalizedTheme) {
TEST_F(ExtensionServiceTest, InstallApps) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
// An empty app.
const Extension* app = PackAndInstallCRX(data_dir_.AppendASCII("app1"),
INSTALL_NEW);
- int pref_count = 0;
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ASSERT_EQ(1u, service_->extensions()->size());
ValidateIntegerPref(app->id(), "state", Extension::ENABLED);
ValidateIntegerPref(app->id(), "location", Manifest::INTERNAL);
// Another app with non-overlapping extent. Should succeed.
PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
// A third app whose extent overlaps the first. Should fail.
PackAndInstallCRX(data_dir_.AppendASCII("app3"), INSTALL_FAILED);
- ValidatePrefKeyCount(pref_count);
+ ValidatePrefKeyCount(expected_pref_count);
}
// Tests that file access is OFF by default.
@@ -2617,12 +2616,12 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
InitializeEmptyExtensionService();
EXPECT_TRUE(service_->extensions()->is_empty());
- int pref_count = 0;
+ int expected_pref_count = GetPrefKeyCount();
// Install app1 with unlimited storage.
const Extension* extension =
PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ASSERT_EQ(1u, service_->extensions()->size());
const std::string id1 = extension->id();
EXPECT_TRUE(extension->HasAPIPermission(
@@ -2636,7 +2635,7 @@ TEST_F(ExtensionServiceTest, InstallAppsWithUnlimitedStorage) {
// Install app2 from the same origin with unlimited storage.
extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ASSERT_EQ(2u, service_->extensions()->size());
const std::string id2 = extension->id();
EXPECT_TRUE(extension->HasAPIPermission(
@@ -2668,11 +2667,11 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
InitializeEmptyExtensionService();
EXPECT_TRUE(service_->extensions()->is_empty());
- int pref_count = 0;
+ int expected_pref_count = GetPrefKeyCount();
const Extension* extension =
PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ASSERT_EQ(1u, service_->extensions()->size());
EXPECT_TRUE(extension->is_app());
const std::string id1 = extension->id();
@@ -2683,7 +2682,7 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
// App 4 has a different origin (maps.google.com).
extension = PackAndInstallCRX(data_dir_.AppendASCII("app4"), INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ASSERT_EQ(2u, service_->extensions()->size());
const std::string id2 = extension->id();
const GURL origin2(
@@ -2707,19 +2706,20 @@ TEST_F(ExtensionServiceTest, InstallAppsAndCheckStorageProtection) {
// Test that when an extension version is reinstalled, nothing happens.
TEST_F(ExtensionServiceTest, Reinstall) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
// A simple extension that should install without error.
base::FilePath path = data_dir_.AppendASCII("good.crx");
InstallCRX(path, INSTALL_NEW);
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
// Reinstall the same version, it should overwrite the previous one.
InstallCRX(path, INSTALL_UPDATED);
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
}
@@ -2728,6 +2728,7 @@ TEST_F(ExtensionServiceTest, Reinstall) {
// Chrome web store.
TEST_F(ExtensionServiceTest, FromWebStore) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
// A simple extension that should install without error.
base::FilePath path = data_dir_.AppendASCII("good.crx");
@@ -2735,14 +2736,14 @@ TEST_F(ExtensionServiceTest, FromWebStore) {
const Extension* extension = InstallCRX(path, INSTALL_NEW);
std::string id = extension->id();
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateBooleanPref(good_crx, "from_webstore", false);
ASSERT_FALSE(extension->from_webstore());
// Test install from web store.
InstallCRXFromWebStore(path, INSTALL_UPDATED); // From web store.
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(expected_pref_count);
ValidateBooleanPref(good_crx, "from_webstore", true);
// Reload so extension gets reinitialized with new value.
@@ -2753,7 +2754,7 @@ TEST_F(ExtensionServiceTest, FromWebStore) {
// Upgrade to version 2.0
path = data_dir_.AppendASCII("good2.crx");
UpdateExtension(good_crx, path, ENABLED);
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(expected_pref_count);
ValidateBooleanPref(good_crx, "from_webstore", true);
}
@@ -4190,14 +4191,14 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) {
// Verifies app state is removed upon uninstall.
TEST_F(ExtensionServiceTest, ClearAppData) {
InitializeEmptyExtensionService();
- ExtensionCookieCallback callback;
+ int expected_pref_count = GetPrefKeyCount();
- int pref_count = 0;
+ ExtensionCookieCallback callback;
// Install app1 with unlimited storage.
const Extension* extension =
PackAndInstallCRX(data_dir_.AppendASCII("app1"), INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ASSERT_EQ(1u, service_->extensions()->size());
const std::string id1 = extension->id();
EXPECT_TRUE(extension->HasAPIPermission(
@@ -4210,7 +4211,7 @@ TEST_F(ExtensionServiceTest, ClearAppData) {
// Install app2 from the same origin with unlimited storage.
extension = PackAndInstallCRX(data_dir_.AppendASCII("app2"), INSTALL_NEW);
- ValidatePrefKeyCount(++pref_count);
+ ValidatePrefKeyCount(++expected_pref_count);
ASSERT_EQ(2u, service_->extensions()->size());
const std::string id2 = extension->id();
EXPECT_TRUE(extension->HasAPIPermission(
@@ -4324,6 +4325,7 @@ TEST_F(ExtensionServiceTest, ClearAppData) {
// Flaky crashes. http://crbug.com/231806
TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
base::FilePath ext1 = data_dir_
.AppendASCII("good")
@@ -4337,7 +4339,7 @@ TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) {
EXPECT_EQ(Manifest::UNPACKED, loaded_[0]->location());
EXPECT_EQ(1u, service_->extensions()->size());
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(++expected_pref_count);
base::FilePath no_manifest = data_dir_
.AppendASCII("bad")
@@ -4364,6 +4366,7 @@ TEST_F(ExtensionServiceTest, DISABLED_LoadExtension) {
// --load-extension.
TEST_F(ExtensionServiceTest, GenerateID) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
base::FilePath no_id_ext = data_dir_.AppendASCII("no_id");
extensions::UnpackedInstaller::Create(service_)->Load(no_id_ext);
@@ -4373,7 +4376,7 @@ TEST_F(ExtensionServiceTest, GenerateID) {
ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id()));
EXPECT_EQ(loaded_[0]->location(), Manifest::UNPACKED);
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(++expected_pref_count);
std::string previous_id = loaded_[0]->id();
@@ -4407,6 +4410,8 @@ void ExtensionServiceTest::TestExternalProvider(
service_->Init();
ASSERT_EQ(0u, loaded_.size());
+ int expected_pref_count = GetPrefKeyCount();
+
provider->set_visit_count(0);
// Register a test extension externally using the mock registry provider.
@@ -4426,7 +4431,7 @@ void ExtensionServiceTest::TestExternalProvider(
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ(location, loaded_[0]->location());
ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", location);
@@ -4437,7 +4442,7 @@ void ExtensionServiceTest::TestExternalProvider(
base::RunLoop().RunUntilIdle();
ASSERT_EQ(0u, GetErrors().size());
ASSERT_EQ(1u, loaded_.size());
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", location);
@@ -4453,7 +4458,7 @@ void ExtensionServiceTest::TestExternalProvider(
ASSERT_EQ(0u, GetErrors().size());
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ("1.0.0.1", loaded_[0]->version()->GetString());
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", location);
@@ -4476,7 +4481,7 @@ void ExtensionServiceTest::TestExternalProvider(
service_->CheckForExternalUpdates();
base::RunLoop().RunUntilIdle();
ASSERT_EQ(0u, loaded_.size());
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(expected_pref_count);
ValidateIntegerPref(good_crx, "state",
Extension::EXTERNAL_EXTENSION_UNINSTALLED);
ValidateIntegerPref(good_crx, "location", location);
@@ -4491,7 +4496,7 @@ void ExtensionServiceTest::TestExternalProvider(
content::NotificationService::AllSources()).Wait();
ASSERT_EQ(1u, loaded_.size());
}
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", location);
@@ -4506,7 +4511,7 @@ void ExtensionServiceTest::TestExternalProvider(
service_->OnExternalProviderReady(provider);
base::RunLoop().RunUntilIdle();
ASSERT_EQ(0u, loaded_.size());
- ValidatePrefKeyCount(0);
+ ValidatePrefKeyCount(--expected_pref_count);
// The extension should also be gone from the install directory.
ASSERT_FALSE(base::PathExists(install_path));
@@ -4536,7 +4541,7 @@ void ExtensionServiceTest::TestExternalProvider(
extensions::InstalledLoader(service_).LoadAllExtensions();
base::RunLoop().RunUntilIdle();
ASSERT_EQ(0u, loaded_.size());
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(++expected_pref_count);
EXPECT_EQ(5, provider->visit_count());
}
@@ -4639,6 +4644,7 @@ TEST_F(ExtensionServiceTest, ExternalUninstall) {
// keep the update from succeeding.
TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
MockExtensionProvider* provider =
new MockExtensionProvider(service_, Manifest::EXTERNAL_PREF);
@@ -4676,7 +4682,7 @@ TEST_F(ExtensionServiceTest, MultipleExternalUpdateCheck) {
ASSERT_EQ(1u, loaded_.size());
ASSERT_EQ(Manifest::EXTERNAL_PREF, loaded_[0]->location());
ASSERT_EQ("1.0.0.0", loaded_[0]->version()->GetString());
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Manifest::EXTERNAL_PREF);
@@ -5056,6 +5062,7 @@ TEST_F(ExtensionServiceTest, StorageQuota) {
// Tests ComponentLoader::Add().
TEST_F(ExtensionServiceTest, ComponentExtensions) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
// Component extensions should work even when extensions are disabled.
set_extensions_enabled(false);
@@ -5082,7 +5089,7 @@ TEST_F(ExtensionServiceTest, ComponentExtensions) {
EXPECT_EQ(1u, service_->extensions()->size());
// Component extensions get a prefs entry on first install.
- ValidatePrefKeyCount(1);
+ ValidatePrefKeyCount(++expected_pref_count);
// Reload all extensions, and make sure it comes back.
std::string extension_id = (*service_->extensions()->begin())->id();
@@ -5759,10 +5766,11 @@ TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) {
TEST_F(ExtensionServiceTest, InstallPriorityExternalUpdateUrl) {
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
base::FilePath path = data_dir_.AppendASCII("good.crx");
InstallCRX(path, INSTALL_NEW);
- ValidatePrefKeyCount(1u);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);
@@ -5812,6 +5820,7 @@ TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) {
const bool kDontMarkAcknowledged = false;
InitializeEmptyExtensionService();
+ int expected_pref_count = GetPrefKeyCount();
// The test below uses install source constants to test that
// priority is enforced. It assumes a specific ranking of install
@@ -5890,7 +5899,7 @@ TEST_F(ExtensionServiceTest, InstallPriorityExternalLocalFile) {
// Install the extension.
base::FilePath path = data_dir_.AppendASCII("good.crx");
const Extension* ext = InstallCRX(path, INSTALL_NEW);
- ValidatePrefKeyCount(1u);
+ ValidatePrefKeyCount(++expected_pref_count);
ValidateIntegerPref(good_crx, "state", Extension::ENABLED);
ValidateIntegerPref(good_crx, "location", Manifest::INTERNAL);

Powered by Google App Engine
This is Rietveld 408576698