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.cc73
1 files changed, 14 insertions, 59 deletions
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 57d2cff..df29995 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -103,7 +103,7 @@ static std::vector<std::string> GetErrors() {
class MockExtensionProvider : public ExternalExtensionProvider {
public:
explicit MockExtensionProvider(Extension::Location location)
- : location_(location), visit_count_(0) {}
+ : location_(location) {}
virtual ~MockExtensionProvider() {}
void UpdateOrAddExtension(const std::string& id,
@@ -119,7 +119,6 @@ class MockExtensionProvider : public ExternalExtensionProvider {
// ExternalExtensionProvider implementation:
virtual void VisitRegisteredExtension(
Visitor* visitor, const std::set<std::string>& ids_to_ignore) const {
- visit_count_++;
for (DataMap::const_iterator i = extension_map_.begin();
i != extension_map_.end(); ++i) {
if (ids_to_ignore.find(i->first) != ids_to_ignore.end())
@@ -132,28 +131,15 @@ class MockExtensionProvider : public ExternalExtensionProvider {
}
}
- virtual bool HasExtension(const std::string& id) const {
- return extension_map_.find(id) != extension_map_.end();
- }
-
- virtual bool GetExtensionDetails(const std::string& id,
- Extension::Location* location,
- scoped_ptr<Version>* version) const {
+ virtual Version* RegisteredVersion(const std::string& id,
+ Extension::Location* location) const {
DataMap::const_iterator it = extension_map_.find(id);
if (it == extension_map_.end())
- return false;
-
- if (version)
- version->reset(Version::GetVersionFromString(it->second.first));
+ return NULL;
if (location)
*location = location_;
-
- return true;
- }
- int visit_count() const { return visit_count_; }
- void set_visit_count(int visit_count) {
- visit_count_ = visit_count;
+ return Version::GetVersionFromString(it->second.first);
}
private:
@@ -161,12 +147,6 @@ class MockExtensionProvider : public ExternalExtensionProvider {
DataMap extension_map_;
Extension::Location location_;
- // visit_count_ tracks the number of calls to VisitRegisteredExtension().
- // Mutable because it must be incremented on each call to
- // VisitRegisteredExtension(), which must be a const method to inherit
- // from the class being mocked.
- mutable int visit_count_;
-
DISALLOW_COPY_AND_ASSIGN(MockExtensionProvider);
};
@@ -217,18 +197,10 @@ class MockProviderVisitor : public ExternalExtensionProvider::Visitor {
<< "Got back ID (" << id.c_str() << ") we weren't expecting";
if (pref) {
- EXPECT_TRUE(provider_->HasExtension(id));
-
// Ask provider if the extension we got back is registered.
Extension::Location location = Extension::INVALID;
- scoped_ptr<Version> v1;
- FilePath crx_path;
-
- EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1));
- EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str());
-
- scoped_ptr<Version> v2;
- EXPECT_TRUE(provider_->GetExtensionDetails(id, &location, &v2));
+ scoped_ptr<Version> v1(provider_->RegisteredVersion(id, NULL));
+ scoped_ptr<Version> v2(provider_->RegisteredVersion(id, &location));
EXPECT_STREQ(version->GetString().c_str(), v1->GetString().c_str());
EXPECT_STREQ(version->GetString().c_str(), v2->GetString().c_str());
EXPECT_EQ(Extension::EXTERNAL_PREF, location);
@@ -249,13 +221,6 @@ class MockProviderVisitor : public ExternalExtensionProvider::Visitor {
<< L"Got back ID (" << id.c_str() << ") we weren't expecting";
if (pref) {
- EXPECT_TRUE(provider_->HasExtension(id));
-
- // External extensions with update URLs do not have versions.
- scoped_ptr<Version> v1;
- EXPECT_TRUE(provider_->GetExtensionDetails(id, NULL, &v1));
- EXPECT_FALSE(v1.get());
-
// Remove it so we won't count it again.
prefs_->Remove(id, NULL);
}
@@ -451,8 +416,9 @@ class ExtensionsServiceTest
}
}
- void AddMockExternalProvider(ExternalExtensionProvider* provider) {
- service_->AddProviderForTesting(provider);
+ void SetMockExternalProvider(Extension::Location location,
+ ExternalExtensionProvider* provider) {
+ service_->SetProviderForTesting(location, provider);
}
protected:
@@ -2261,8 +2227,6 @@ void ExtensionsServiceTest::TestExternalProvider(
loop_.RunAllPending();
ASSERT_EQ(0u, loaded_.size());
- provider->set_visit_count(0);
-
// Register a test extension externally using the mock registry provider.
FilePath source_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_path));
@@ -2378,8 +2342,6 @@ void ExtensionsServiceTest::TestExternalProvider(
loop_.RunAllPending();
ASSERT_EQ(0u, loaded_.size());
ValidatePrefKeyCount(1);
-
- EXPECT_EQ(5, provider->visit_count());
}
// Tests the external installation feature
@@ -2392,7 +2354,7 @@ TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) {
// Now add providers. Extension system takes ownership of the objects.
MockExtensionProvider* reg_provider =
new MockExtensionProvider(Extension::EXTERNAL_REGISTRY);
- AddMockExternalProvider(reg_provider);
+ SetMockExternalProvider(Extension::EXTERNAL_REGISTRY, reg_provider);
TestExternalProvider(reg_provider, Extension::EXTERNAL_REGISTRY);
}
#endif
@@ -2405,8 +2367,7 @@ TEST_F(ExtensionsServiceTest, ExternalInstallPref) {
// Now add providers. Extension system takes ownership of the objects.
MockExtensionProvider* pref_provider =
new MockExtensionProvider(Extension::EXTERNAL_PREF);
-
- AddMockExternalProvider(pref_provider);
+ SetMockExternalProvider(Extension::EXTERNAL_PREF, pref_provider);
TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF);
}
@@ -2415,16 +2376,10 @@ TEST_F(ExtensionsServiceTest, ExternalInstallPrefUpdateUrl) {
InitializeEmptyExtensionsService();
set_extensions_enabled(false);
- // TODO(skerner): The mock provider is not a good model of a provider
- // that works with update URLs, because it adds file and version info.
- // Extend the mock to work with update URLs. This test checks the
- // behavior that is common to all external extension visitors. The
- // browser test ExtensionManagementTest.ExternalUrlUpdate tests that
- // what the visitor does results in an extension being downloaded and
- // installed.
+ // Now add providers. Extension system takes ownership of the objects.
MockExtensionProvider* pref_provider =
new MockExtensionProvider(Extension::EXTERNAL_PREF_DOWNLOAD);
- AddMockExternalProvider(pref_provider);
+ SetMockExternalProvider(Extension::EXTERNAL_PREF_DOWNLOAD, pref_provider);
TestExternalProvider(pref_provider, Extension::EXTERNAL_PREF_DOWNLOAD);
}