summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_info_map_unittest.cc
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 18:54:58 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 18:54:58 +0000
commit9118e93ad88c2809973d1b2f97299cfe1601f20c (patch)
tree1a74f9c7570f53c4c6e3619f35111f2e8e4bc6fd /chrome/browser/extensions/extension_info_map_unittest.cc
parentd603cd3c0923238c5f8fbd755a04df7e3923a2f4 (diff)
downloadchromium_src-9118e93ad88c2809973d1b2f97299cfe1601f20c.zip
chromium_src-9118e93ad88c2809973d1b2f97299cfe1601f20c.tar.gz
chromium_src-9118e93ad88c2809973d1b2f97299cfe1601f20c.tar.bz2
Part 2 of immutable Extension refactor.
I made Extension a refcounted object, and privitized the existing con/destructor and InitFromValue. The only way to get an Extension is to call a factory method. In the next CL, I plan to make the factory method return a const Extension, to guarantee that no one can modify the Extension object after creation. Note: There was a tricky part of this CL because of the difference in semantics between scoped_ptr and scoped_refptr. I had to be careful not to use ptr.release(), since that would result in leaks (an un-Released AddRef). BUG=56558 TEST=no functional change Review URL: http://codereview.chromium.org/3982001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_info_map_unittest.cc')
-rw-r--r--chrome/browser/extensions/extension_info_map_unittest.cc39
1 files changed, 20 insertions, 19 deletions
diff --git a/chrome/browser/extensions/extension_info_map_unittest.cc b/chrome/browser/extensions/extension_info_map_unittest.cc
index 559febb..e417d23 100644
--- a/chrome/browser/extensions/extension_info_map_unittest.cc
+++ b/chrome/browser/extensions/extension_info_map_unittest.cc
@@ -28,27 +28,27 @@ class ExtensionInfoMapTest : public testing::Test {
};
// Returns a barebones test Extension object with the given name.
-static Extension* CreateExtension(const std::string& name) {
+static scoped_refptr<Extension> CreateExtension(const std::string& name) {
#if defined(OS_WIN)
FilePath path(FILE_PATH_LITERAL("c:\\foo"));
#elif defined(OS_POSIX)
FilePath path(FILE_PATH_LITERAL("/foo"));
#endif
- scoped_ptr<Extension> extension(new Extension(path.AppendASCII(name)));
-
DictionaryValue manifest;
manifest.SetString(keys::kVersion, "1.0.0.0");
manifest.SetString(keys::kName, name);
std::string error;
- EXPECT_TRUE(extension->InitFromValue(manifest, false, &error)) << error;
+ scoped_refptr<Extension> extension = Extension::Create(
+ path.AppendASCII(name), Extension::INVALID, manifest, false, &error);
+ EXPECT_TRUE(extension) << error;
- return extension.release();
+ return extension;
}
-static Extension* LoadManifest(const std::string& dir,
- const std::string& test_file) {
+static scoped_refptr<Extension> LoadManifest(const std::string& dir,
+ const std::string& test_file) {
FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
path = path.AppendASCII("extensions")
@@ -61,11 +61,12 @@ static Extension* LoadManifest(const std::string& dir,
return NULL;
std::string error;
- scoped_ptr<Extension> extension(new Extension(path));
- EXPECT_TRUE(extension->InitFromValue(
- *static_cast<DictionaryValue*>(result.get()), false, &error)) << error;
+ scoped_refptr<Extension> extension = Extension::Create(
+ path, Extension::INVALID, *static_cast<DictionaryValue*>(result.get()),
+ false, &error);
+ EXPECT_TRUE(extension) << error;
- return extension.release();
+ return extension;
}
// Test that the ExtensionInfoMap handles refcounting properly.
@@ -74,9 +75,9 @@ TEST_F(ExtensionInfoMapTest, RefCounting) {
// New extensions should have a single reference holding onto their static
// data.
- scoped_ptr<Extension> extension1(CreateExtension("extension1"));
- scoped_ptr<Extension> extension2(CreateExtension("extension2"));
- scoped_ptr<Extension> extension3(CreateExtension("extension3"));
+ scoped_refptr<Extension> extension1(CreateExtension("extension1"));
+ scoped_refptr<Extension> extension2(CreateExtension("extension2"));
+ scoped_refptr<Extension> extension3(CreateExtension("extension3"));
EXPECT_TRUE(extension1->static_data()->HasOneRef());
EXPECT_TRUE(extension2->static_data()->HasOneRef());
EXPECT_TRUE(extension3->static_data()->HasOneRef());
@@ -93,7 +94,7 @@ TEST_F(ExtensionInfoMapTest, RefCounting) {
// Delete extension1, and the info map should have the only ref.
const Extension::StaticData* data1 = extension1->static_data();
- extension1.reset();
+ extension1 = NULL;
EXPECT_TRUE(data1->HasOneRef());
// Remove extension2, and the extension2 object should have the only ref.
@@ -109,8 +110,8 @@ TEST_F(ExtensionInfoMapTest, RefCounting) {
TEST_F(ExtensionInfoMapTest, Properties) {
scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
- scoped_ptr<Extension> extension1(CreateExtension("extension1"));
- scoped_ptr<Extension> extension2(CreateExtension("extension2"));
+ scoped_refptr<Extension> extension1(CreateExtension("extension1"));
+ scoped_refptr<Extension> extension2(CreateExtension("extension2"));
extension1->static_data()->AddRef();
info_map->AddExtension(extension1->static_data());
@@ -132,9 +133,9 @@ TEST_F(ExtensionInfoMapTest, Properties) {
TEST_F(ExtensionInfoMapTest, CheckPermissions) {
scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
- scoped_ptr<Extension> app(LoadManifest("manifest_tests",
+ scoped_refptr<Extension> app(LoadManifest("manifest_tests",
"valid_app.json"));
- scoped_ptr<Extension> extension(LoadManifest("manifest_tests",
+ scoped_refptr<Extension> extension(LoadManifest("manifest_tests",
"tabs_extension.json"));
GURL app_url("http://www.google.com/mail/foo.html");