Chromium Code Reviews| Index: chrome/browser/extensions/component_loader_unittest.cc |
| diff --git a/chrome/browser/extensions/component_loader_unittest.cc b/chrome/browser/extensions/component_loader_unittest.cc |
| index 3e3d8c81166f775f8e76461e27b5490e7b2fe4a0..276adc287cb474af1c27972a1d19bba70647b8fc 100644 |
| --- a/chrome/browser/extensions/component_loader_unittest.cc |
| +++ b/chrome/browser/extensions/component_loader_unittest.cc |
| @@ -21,12 +21,24 @@ class MockExtensionService : public TestExtensionService { |
| private: |
| bool ready_; |
| ExtensionList extension_list_; |
| + size_t unloaded_; |
|
Aaron Boodman
2011/12/05 22:11:26
This is not a good name. It should be unloaded_cou
SeRya
2011/12/06 08:19:27
Done.
|
| + |
| + bool find(std::string id) { |
|
Aaron Boodman
2011/12/05 22:11:26
Methods are supposed to be ordered before fields.
SeRya
2011/12/06 08:19:27
Done.
|
| + for (ExtensionList::iterator it = extension_list_.begin(); |
| + it != extension_list_.end(); |
| + ++it) |
| + if ((*it)->id() == id) |
| + return true; |
| + |
| + return false; |
| + } |
| public: |
| - MockExtensionService() : ready_(false) { |
| + MockExtensionService() : ready_(false), unloaded_(0) { |
| } |
| virtual void AddExtension(const Extension* extension) OVERRIDE { |
| + ASSERT_FALSE(find(extension->id())); |
| // ExtensionService must become the owner of the extension object. |
| extension_list_.push_back(extension); |
| } |
| @@ -34,12 +46,14 @@ class MockExtensionService : public TestExtensionService { |
| virtual void UnloadExtension( |
| const std::string& extension_id, |
| extension_misc::UnloadedExtensionReason reason) OVERRIDE { |
| + ASSERT_TRUE(find(extension_id)); |
| // Remove the extension with the matching id. |
| for (ExtensionList::iterator it = extension_list_.begin(); |
| it != extension_list_.end(); |
| ++it) { |
| if ((*it)->id() == extension_id) { |
| extension_list_.erase(it); |
| + unloaded_++; |
| return; |
| } |
| } |
| @@ -57,6 +71,10 @@ class MockExtensionService : public TestExtensionService { |
| ready_ = ready; |
| } |
| + size_t get_unloaded_count() const { |
|
Aaron Boodman
2011/12/05 22:11:26
getters in Chrome do not have the 'get_' prefix.
SeRya
2011/12/06 08:19:27
Done.
|
| + return unloaded_; |
| + } |
| + |
| void clear_extension_list() { |
| extension_list_.clear(); |
| } |
| @@ -109,6 +127,17 @@ class ComponentLoaderTest : public testing::Test { |
| // The contents of the text extension's manifest file. |
| std::string manifest_contents_; |
| + |
| + FilePath get_extension_path(std::string name) { |
|
Aaron Boodman
2011/12/05 22:11:26
Since this does significant work, it should be nam
SeRya
2011/12/06 08:19:27
Done.
|
| + FilePath test_data_dir; |
| + PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| + return |
| + test_data_dir.AppendASCII("extensions") |
|
Aaron Boodman
2011/12/05 22:11:26
Line 135 looks like it can fit with line 134.
SeRya
2011/12/06 08:19:27
Done.
|
| + .AppendASCII("good") |
| + .AppendASCII("Extensions") |
| + .AppendASCII(name.c_str()); |
| + |
| + } |
| }; |
| TEST_F(ComponentLoaderTest, ParseManifest) { |
| @@ -249,4 +278,32 @@ TEST_F(ComponentLoaderTest, EnterpriseWebStore) { |
| ASSERT_EQ(default_count + 1, extension_service_.extensions()->size()); |
| } |
| +TEST_F(ComponentLoaderTest, AddOrReplace) { |
| + ASSERT_EQ(0U, component_loader_.GetRegisteredExtensionsCount()); |
|
Aaron Boodman
2011/12/05 22:11:26
Chrome uses lower-case 'u'.
SeRya
2011/12/06 08:19:27
Done.
|
| + component_loader_.AddDefaultComponentExtensions(); |
| + size_t const default_count = component_loader_.GetRegisteredExtensionsCount(); |
| + |
| + // Replace a default component extension. |
| + component_loader_.AddOrReplace(get_extension_path("hhaomjibdihmijegdhdafkllkbggdgoj")); |
|
Aaron Boodman
2011/12/05 22:11:26
line length
SeRya
2011/12/06 08:19:27
Done.
|
| + ASSERT_EQ(default_count, |
| + component_loader_.GetRegisteredExtensionsCount()); |
| + |
| + // Add a new component extension. |
| + component_loader_.AddOrReplace( |
| + get_extension_path("hpiknbiabeeppbpihjehijgoemciehgk/2")); |
| + ASSERT_EQ(default_count + 1, |
| + component_loader_.GetRegisteredExtensionsCount()); |
| + |
| + extension_service_.set_ready(true); |
| + component_loader_.LoadAll(); |
| + |
| + ASSERT_EQ(default_count + 1, extension_service_.extensions()->size()); |
| + ASSERT_EQ(0U, extension_service_.get_unloaded_count()); |
| + |
| + // replace loaded component extension. |
| + component_loader_.AddOrReplace(get_extension_path("hhaomjibdihmijegdhdafkllkbggdgoj")); |
|
Aaron Boodman
2011/12/05 22:11:26
line length
SeRya
2011/12/06 08:19:27
Done.
|
| + ASSERT_EQ(default_count + 1, extension_service_.extensions()->size()); |
| + ASSERT_EQ(1U, extension_service_.get_unloaded_count()); |
| +} |
| + |
| } // namespace extensions |