This source file includes following definitions.
- CreateExtensionImportingModule
- SetUp
- InstallExtension
- TEST_F
- TEST_F
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_unittest.h"
#include "chrome/browser/extensions/pending_extension_manager.h"
#include "chrome/browser/extensions/shared_module_service.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/id_util.h"
#include "extensions/common/value_builder.h"
#include "sync/api/string_ordinal.h"
namespace extensions {
namespace {
scoped_refptr<Extension> CreateExtensionImportingModule(
const std::string& import_id) {
scoped_ptr<base::DictionaryValue> manifest =
DictionaryBuilder()
.Set("name", "Has Dependent Modules")
.Set("version", "1.0")
.Set("manifest_version", 2)
.Set("import",
ListBuilder().Append(DictionaryBuilder().Set("id", import_id)))
.Build();
return ExtensionBuilder().SetManifest(manifest.Pass())
.AddFlags(Extension::FROM_WEBSTORE)
.Build();
}
}
class SharedModuleServiceUnitTest : public ExtensionServiceTestBase {
protected:
virtual void SetUp() OVERRIDE;
testing::AssertionResult InstallExtension(const Extension* extension);
};
void SharedModuleServiceUnitTest::SetUp() {
ExtensionServiceTestBase::SetUp();
InitializeGoodInstalledExtensionService();
service_->Init();
}
testing::AssertionResult SharedModuleServiceUnitTest::InstallExtension(
const Extension* extension) {
if (registry_->GetExtensionById(extension->id(),
ExtensionRegistry::ENABLED)) {
return testing::AssertionFailure() << "Extension already installed.";
}
service_->OnExtensionInstalled(extension,
syncer::StringOrdinal(),
false,
NOT_BLACKLISTED,
false);
if (!registry_->GetExtensionById(extension->id(),
ExtensionRegistry::ENABLED)) {
return testing::AssertionFailure() << "Could not install extension.";
}
return testing::AssertionSuccess();
}
TEST_F(SharedModuleServiceUnitTest, AddDependentSharedModules) {
std::string import_id = id_util::GenerateId("id");
scoped_refptr<Extension> extension =
CreateExtensionImportingModule(import_id);
PendingExtensionManager* pending_extension_manager =
service_->pending_extension_manager();
EXPECT_FALSE(pending_extension_manager->IsIdPending(import_id));
service_->shared_module_service()->SatisfyImports(extension);
EXPECT_TRUE(pending_extension_manager->IsIdPending(import_id));
}
TEST_F(SharedModuleServiceUnitTest, PruneSharedModulesOnUninstall) {
scoped_ptr<base::DictionaryValue> manifest =
DictionaryBuilder()
.Set("name", "Shared Module")
.Set("version", "1.0")
.Set("manifest_version", 2)
.Set("export",
DictionaryBuilder().Set("resources",
ListBuilder().Append("foo.js"))).Build();
scoped_refptr<Extension> shared_module =
ExtensionBuilder().SetManifest(manifest.Pass())
.AddFlags(Extension::FROM_WEBSTORE)
.SetID(id_util::GenerateId("shared_module"))
.Build();
EXPECT_TRUE(InstallExtension(shared_module));
scoped_refptr<Extension> importing_extension =
CreateExtensionImportingModule(shared_module->id());
EXPECT_TRUE(InstallExtension(importing_extension));
base::string16 error;
service_->UninstallExtension(importing_extension->id(),
false,
&error);
EXPECT_TRUE(error.empty());
EXPECT_FALSE(registry_->GetExtensionById(shared_module->id(),
ExtensionRegistry::EVERYTHING));
}
}