diff options
Diffstat (limited to 'chrome/browser/extensions/component_loader_unittest.cc')
-rw-r--r-- | chrome/browser/extensions/component_loader_unittest.cc | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/chrome/browser/extensions/component_loader_unittest.cc b/chrome/browser/extensions/component_loader_unittest.cc index a608afb..55d592c 100644 --- a/chrome/browser/extensions/component_loader_unittest.cc +++ b/chrome/browser/extensions/component_loader_unittest.cc @@ -16,6 +16,7 @@ #include "chrome/test/base/testing_profile.h" #include "components/pref_registry/pref_registry_syncable.h" #include "content/public/test/test_browser_thread_bundle.h" +#include "extensions/browser/extension_registry.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" #include "extensions/common/extension_set.h" @@ -30,23 +31,25 @@ class MockExtensionService : public TestExtensionService { private: bool ready_; size_t unloaded_count_; - ExtensionSet extension_set_; + ExtensionRegistry* registry_; public: - MockExtensionService() : ready_(false), unloaded_count_(0) { - } + explicit MockExtensionService(Profile* profile) + : ready_(false), + unloaded_count_(0), + registry_(ExtensionRegistry::Get(profile)) {} void AddComponentExtension(const Extension* extension) override { - EXPECT_FALSE(extension_set_.Contains(extension->id())); + EXPECT_FALSE(registry_->enabled_extensions().Contains(extension->id())); // ExtensionService must become the owner of the extension object. - extension_set_.Insert(extension); + registry_->AddEnabled(extension); } void UnloadExtension(const std::string& extension_id, UnloadedExtensionInfo::Reason reason) override { - ASSERT_TRUE(extension_set_.Contains(extension_id)); + ASSERT_TRUE(registry_->enabled_extensions().Contains(extension_id)); // Remove the extension with the matching id. - extension_set_.Remove(extension_id); + registry_->RemoveEnabled(extension_id); unloaded_count_++; } @@ -56,8 +59,6 @@ class MockExtensionService : public TestExtensionService { bool is_ready() override { return ready_; } - const ExtensionSet* extensions() const override { return &extension_set_; } - void set_ready(bool ready) { ready_ = ready; } @@ -66,9 +67,7 @@ class MockExtensionService : public TestExtensionService { return unloaded_count_; } - void clear_extensions() { - extension_set_.Clear(); - } + void clear_extensions() { registry_->ClearAll(); } }; } // namespace @@ -78,11 +77,11 @@ class ComponentLoaderTest : public testing::Test { ComponentLoaderTest() // Note: we pass the same pref service here, to stand in for both // user prefs and local state. - : component_loader_(&extension_service_, + : extension_service_(&profile_), + component_loader_(&extension_service_, &prefs_, &local_state_, - &profile_) { - } + &profile_) {} void SetUp() override { extension_path_ = @@ -104,10 +103,10 @@ class ComponentLoaderTest : public testing::Test { } protected: + TestingProfile profile_; MockExtensionService extension_service_; TestingPrefServiceSyncable prefs_; TestingPrefServiceSimple local_state_; - TestingProfile profile_; ComponentLoader component_loader_; // The root directory of the text extension. @@ -180,7 +179,8 @@ TEST_F(ComponentLoaderTest, AddWhenNotReady) { std::string extension_id = component_loader_.Add(manifest_contents_, extension_path_); EXPECT_NE("", extension_id); - EXPECT_EQ(0u, extension_service_.extensions()->size()); + ExtensionRegistry* registry = ExtensionRegistry::Get(&profile_); + EXPECT_EQ(0u, registry->enabled_extensions().size()); } // Test that it *is* loaded when the extension service *is* ready. @@ -189,54 +189,57 @@ TEST_F(ComponentLoaderTest, AddWhenReady) { std::string extension_id = component_loader_.Add(manifest_contents_, extension_path_); EXPECT_NE("", extension_id); - EXPECT_EQ(1u, extension_service_.extensions()->size()); - EXPECT_TRUE(extension_service_.extensions()->GetByID(extension_id)); + ExtensionRegistry* registry = ExtensionRegistry::Get(&profile_); + EXPECT_EQ(1u, registry->enabled_extensions().size()); + EXPECT_TRUE(registry->enabled_extensions().GetByID(extension_id)); } TEST_F(ComponentLoaderTest, Remove) { extension_service_.set_ready(false); + ExtensionRegistry* registry = ExtensionRegistry::Get(&profile_); // Removing an extension that was never added should be ok. component_loader_.Remove(extension_path_); - EXPECT_EQ(0u, extension_service_.extensions()->size()); + EXPECT_EQ(0u, registry->enabled_extensions().size()); // Try adding and removing before LoadAll() is called. component_loader_.Add(manifest_contents_, extension_path_); component_loader_.Remove(extension_path_); component_loader_.LoadAll(); - EXPECT_EQ(0u, extension_service_.extensions()->size()); + EXPECT_EQ(0u, registry->enabled_extensions().size()); // Load an extension, and check that it's unloaded when Remove() is called. extension_service_.set_ready(true); std::string extension_id = component_loader_.Add(manifest_contents_, extension_path_); - EXPECT_EQ(1u, extension_service_.extensions()->size()); + EXPECT_EQ(1u, registry->enabled_extensions().size()); component_loader_.Remove(extension_path_); - EXPECT_EQ(0u, extension_service_.extensions()->size()); + EXPECT_EQ(0u, registry->enabled_extensions().size()); // And after calling LoadAll(), it shouldn't get loaded. component_loader_.LoadAll(); - EXPECT_EQ(0u, extension_service_.extensions()->size()); + EXPECT_EQ(0u, registry->enabled_extensions().size()); } TEST_F(ComponentLoaderTest, LoadAll) { extension_service_.set_ready(false); + ExtensionRegistry* registry = ExtensionRegistry::Get(&profile_); // No extensions should be loaded if none were added. component_loader_.LoadAll(); - EXPECT_EQ(0u, extension_service_.extensions()->size()); + EXPECT_EQ(0u, registry->enabled_extensions().size()); // Use LoadAll() to load the default extensions. component_loader_.AddDefaultComponentExtensions(false); component_loader_.LoadAll(); - unsigned int default_count = extension_service_.extensions()->size(); + unsigned int default_count = registry->enabled_extensions().size(); // Clear the list of loaded extensions, and reload with one more. extension_service_.clear_extensions(); component_loader_.Add(manifest_contents_, extension_path_); component_loader_.LoadAll(); - EXPECT_EQ(default_count + 1, extension_service_.extensions()->size()); + EXPECT_EQ(default_count + 1, registry->enabled_extensions().size()); } TEST_F(ComponentLoaderTest, AddOrReplace) { @@ -260,13 +263,14 @@ TEST_F(ComponentLoaderTest, AddOrReplace) { extension_service_.set_ready(true); component_loader_.LoadAll(); + ExtensionRegistry* registry = ExtensionRegistry::Get(&profile_); - EXPECT_EQ(default_count + 1, extension_service_.extensions()->size()); + EXPECT_EQ(default_count + 1, registry->enabled_extensions().size()); EXPECT_EQ(0u, extension_service_.unloaded_count()); // replace loaded component extension. component_loader_.AddOrReplace(known_extension); - EXPECT_EQ(default_count + 1, extension_service_.extensions()->size()); + EXPECT_EQ(default_count + 1, registry->enabled_extensions().size()); EXPECT_EQ(1u, extension_service_.unloaded_count()); // Add an invalid component extension. |