Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: chrome/browser/extensions/extension_info_map_unittest.cc

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_file_value_serializer.h" 5 #include "base/json/json_file_value_serializer.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "chrome/browser/extensions/extension_info_map.h" 8 #include "chrome/browser/extensions/extension_info_map.h"
9 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #endif 47 #endif
48 48
49 DictionaryValue manifest; 49 DictionaryValue manifest;
50 manifest.SetString(keys::kVersion, "1.0.0.0"); 50 manifest.SetString(keys::kVersion, "1.0.0.0");
51 manifest.SetString(keys::kName, name); 51 manifest.SetString(keys::kName, name);
52 52
53 std::string error; 53 std::string error;
54 scoped_refptr<Extension> extension = Extension::Create( 54 scoped_refptr<Extension> extension = Extension::Create(
55 path.AppendASCII(name), Manifest::INVALID_LOCATION, manifest, 55 path.AppendASCII(name), Manifest::INVALID_LOCATION, manifest,
56 Extension::NO_FLAGS, &error); 56 Extension::NO_FLAGS, &error);
57 EXPECT_TRUE(extension) << error; 57 EXPECT_TRUE(extension.get()) << error;
58 58
59 return extension; 59 return extension;
60 } 60 }
61 61
62 static scoped_refptr<Extension> LoadManifest(const std::string& dir, 62 static scoped_refptr<Extension> LoadManifest(const std::string& dir,
63 const std::string& test_file) { 63 const std::string& test_file) {
64 base::FilePath path; 64 base::FilePath path;
65 PathService::Get(chrome::DIR_TEST_DATA, &path); 65 PathService::Get(chrome::DIR_TEST_DATA, &path);
66 path = path.AppendASCII("extensions") 66 path = path.AppendASCII("extensions")
67 .AppendASCII(dir) 67 .AppendASCII(dir)
68 .AppendASCII(test_file); 68 .AppendASCII(test_file);
69 69
70 JSONFileValueSerializer serializer(path); 70 JSONFileValueSerializer serializer(path);
71 scoped_ptr<Value> result(serializer.Deserialize(NULL, NULL)); 71 scoped_ptr<Value> result(serializer.Deserialize(NULL, NULL));
72 if (!result) 72 if (!result)
73 return NULL; 73 return NULL;
74 74
75 std::string error; 75 std::string error;
76 scoped_refptr<Extension> extension = Extension::Create( 76 scoped_refptr<Extension> extension = Extension::Create(
77 path, Manifest::INVALID_LOCATION, 77 path, Manifest::INVALID_LOCATION,
78 *static_cast<DictionaryValue*>(result.get()), 78 *static_cast<DictionaryValue*>(result.get()),
79 Extension::NO_FLAGS, &error); 79 Extension::NO_FLAGS, &error);
80 EXPECT_TRUE(extension) << error; 80 EXPECT_TRUE(extension.get()) << error;
81 81
82 return extension; 82 return extension;
83 } 83 }
84 84
85 // Test that the ExtensionInfoMap handles refcounting properly. 85 // Test that the ExtensionInfoMap handles refcounting properly.
86 TEST_F(ExtensionInfoMapTest, RefCounting) { 86 TEST_F(ExtensionInfoMapTest, RefCounting) {
87 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); 87 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
88 88
89 // New extensions should have a single reference holding onto them. 89 // New extensions should have a single reference holding onto them.
90 scoped_refptr<Extension> extension1(CreateExtension("extension1")); 90 scoped_refptr<Extension> extension1(CreateExtension("extension1"));
91 scoped_refptr<Extension> extension2(CreateExtension("extension2")); 91 scoped_refptr<Extension> extension2(CreateExtension("extension2"));
92 scoped_refptr<Extension> extension3(CreateExtension("extension3")); 92 scoped_refptr<Extension> extension3(CreateExtension("extension3"));
93 EXPECT_TRUE(extension1->HasOneRef()); 93 EXPECT_TRUE(extension1->HasOneRef());
94 EXPECT_TRUE(extension2->HasOneRef()); 94 EXPECT_TRUE(extension2->HasOneRef());
95 EXPECT_TRUE(extension3->HasOneRef()); 95 EXPECT_TRUE(extension3->HasOneRef());
96 96
97 // Add a ref to each extension and give it to the info map. 97 // Add a ref to each extension and give it to the info map.
98 info_map->AddExtension(extension1, base::Time(), false); 98 info_map->AddExtension(extension1.get(), base::Time(), false);
99 info_map->AddExtension(extension2, base::Time(), false); 99 info_map->AddExtension(extension2.get(), base::Time(), false);
100 info_map->AddExtension(extension3, base::Time(), false); 100 info_map->AddExtension(extension3.get(), base::Time(), false);
101 101
102 // Release extension1, and the info map should have the only ref. 102 // Release extension1, and the info map should have the only ref.
103 const Extension* weak_extension1 = extension1; 103 const Extension* weak_extension1 = extension1.get();
104 extension1 = NULL; 104 extension1 = NULL;
105 EXPECT_TRUE(weak_extension1->HasOneRef()); 105 EXPECT_TRUE(weak_extension1->HasOneRef());
106 106
107 // Remove extension2, and the extension2 object should have the only ref. 107 // Remove extension2, and the extension2 object should have the only ref.
108 info_map->RemoveExtension( 108 info_map->RemoveExtension(
109 extension2->id(), extension_misc::UNLOAD_REASON_UNINSTALL); 109 extension2->id(), extension_misc::UNLOAD_REASON_UNINSTALL);
110 EXPECT_TRUE(extension2->HasOneRef()); 110 EXPECT_TRUE(extension2->HasOneRef());
111 111
112 // Delete the info map, and the extension3 object should have the only ref. 112 // Delete the info map, and the extension3 object should have the only ref.
113 info_map = NULL; 113 info_map = NULL;
114 EXPECT_TRUE(extension3->HasOneRef()); 114 EXPECT_TRUE(extension3->HasOneRef());
115 } 115 }
116 116
117 // Tests that we can query a few extension properties from the ExtensionInfoMap. 117 // Tests that we can query a few extension properties from the ExtensionInfoMap.
118 TEST_F(ExtensionInfoMapTest, Properties) { 118 TEST_F(ExtensionInfoMapTest, Properties) {
119 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); 119 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
120 120
121 scoped_refptr<Extension> extension1(CreateExtension("extension1")); 121 scoped_refptr<Extension> extension1(CreateExtension("extension1"));
122 scoped_refptr<Extension> extension2(CreateExtension("extension2")); 122 scoped_refptr<Extension> extension2(CreateExtension("extension2"));
123 123
124 info_map->AddExtension(extension1, base::Time(), false); 124 info_map->AddExtension(extension1.get(), base::Time(), false);
125 info_map->AddExtension(extension2, base::Time(), false); 125 info_map->AddExtension(extension2.get(), base::Time(), false);
126 126
127 EXPECT_EQ(2u, info_map->extensions().size()); 127 EXPECT_EQ(2u, info_map->extensions().size());
128 EXPECT_EQ(extension1.get(), info_map->extensions().GetByID(extension1->id())); 128 EXPECT_EQ(extension1.get(), info_map->extensions().GetByID(extension1->id()));
129 EXPECT_EQ(extension2.get(), info_map->extensions().GetByID(extension2->id())); 129 EXPECT_EQ(extension2.get(), info_map->extensions().GetByID(extension2->id()));
130 } 130 }
131 131
132 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs. 132 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs.
133 TEST_F(ExtensionInfoMapTest, CheckPermissions) { 133 TEST_F(ExtensionInfoMapTest, CheckPermissions) {
134 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); 134 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
135 135
136 scoped_refptr<Extension> app(LoadManifest("manifest_tests", 136 scoped_refptr<Extension> app(LoadManifest("manifest_tests",
137 "valid_app.json")); 137 "valid_app.json"));
138 scoped_refptr<Extension> extension(LoadManifest("manifest_tests", 138 scoped_refptr<Extension> extension(LoadManifest("manifest_tests",
139 "tabs_extension.json")); 139 "tabs_extension.json"));
140 140
141 GURL app_url("http://www.google.com/mail/foo.html"); 141 GURL app_url("http://www.google.com/mail/foo.html");
142 WebSecurityOrigin app_origin = WebSecurityOrigin::create( 142 WebSecurityOrigin app_origin = WebSecurityOrigin::create(
143 GURL("http://www.google.com/mail/foo.html")); 143 GURL("http://www.google.com/mail/foo.html"));
144 ASSERT_TRUE(app->is_app()); 144 ASSERT_TRUE(app->is_app());
145 ASSERT_TRUE(app->web_extent().MatchesURL(app_url)); 145 ASSERT_TRUE(app->web_extent().MatchesURL(app_url));
146 146
147 info_map->AddExtension(app, base::Time(), false); 147 info_map->AddExtension(app.get(), base::Time(), false);
148 info_map->AddExtension(extension, base::Time(), false); 148 info_map->AddExtension(extension.get(), base::Time(), false);
149 149
150 // The app should have the notifications permission, either from a 150 // The app should have the notifications permission, either from a
151 // chrome-extension URL or from its web extent. 151 // chrome-extension URL or from its web extent.
152 const Extension* match = info_map->extensions().GetExtensionOrAppByURL( 152 const Extension* match = info_map->extensions().GetExtensionOrAppByURL(
153 ExtensionURLInfo(app_origin, app->GetResourceURL("a.html"))); 153 ExtensionURLInfo(app_origin, app->GetResourceURL("a.html")));
154 EXPECT_TRUE(match && 154 EXPECT_TRUE(match &&
155 match->HasAPIPermission(APIPermission::kNotification)); 155 match->HasAPIPermission(APIPermission::kNotification));
156 match = info_map->extensions().GetExtensionOrAppByURL( 156 match = info_map->extensions().GetExtensionOrAppByURL(
157 ExtensionURLInfo(app_origin, app_url)); 157 ExtensionURLInfo(app_origin, app_url));
158 EXPECT_TRUE(match && 158 EXPECT_TRUE(match &&
(...skipping 16 matching lines...) Expand all
175 EXPECT_FALSE(match); 175 EXPECT_FALSE(match);
176 176
177 // Sandboxed origins should not have any permissions. 177 // Sandboxed origins should not have any permissions.
178 match = info_map->extensions().GetExtensionOrAppByURL(ExtensionURLInfo( 178 match = info_map->extensions().GetExtensionOrAppByURL(ExtensionURLInfo(
179 WebSecurityOrigin::createFromString(WebString::fromUTF8("null")), 179 WebSecurityOrigin::createFromString(WebString::fromUTF8("null")),
180 app_url)); 180 app_url));
181 EXPECT_FALSE(match); 181 EXPECT_FALSE(match);
182 } 182 }
183 183
184 } // namespace 184 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_icon_image_unittest.cc ('k') | chrome/browser/extensions/extension_install_prompt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698