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

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

Issue 1739183003: Make extensions::DictionaryBuilder and extensions::ListValue unmovable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/extensions/shared_module_service.h" 5 #include "chrome/browser/extensions/shared_module_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 20 matching lines...) Expand all
31 // |import_id|. 31 // |import_id|.
32 scoped_refptr<Extension> CreateExtensionImportingModule( 32 scoped_refptr<Extension> CreateExtensionImportingModule(
33 const std::string& import_id, 33 const std::string& import_id,
34 const std::string& id, 34 const std::string& id,
35 const std::string& version) { 35 const std::string& version) {
36 DictionaryBuilder builder; 36 DictionaryBuilder builder;
37 builder.Set("name", "Has Dependent Modules") 37 builder.Set("name", "Has Dependent Modules")
38 .Set("version", version) 38 .Set("version", version)
39 .Set("manifest_version", 2); 39 .Set("manifest_version", 2);
40 if (!import_id.empty()) { 40 if (!import_id.empty()) {
41 builder.Set("import", std::move(ListBuilder().Append(std::move( 41 builder.Set("import",
42 DictionaryBuilder().Set("id", import_id))))); 42 ListBuilder()
43 .Append(DictionaryBuilder().Set("id", import_id).Build())
44 .Build());
43 } 45 }
44 scoped_ptr<base::DictionaryValue> manifest = builder.Build(); 46 scoped_ptr<base::DictionaryValue> manifest = builder.Build();
45 47
46 return ExtensionBuilder() 48 return ExtensionBuilder()
47 .SetManifest(std::move(manifest)) 49 .SetManifest(std::move(manifest))
48 .AddFlags(Extension::FROM_WEBSTORE) 50 .AddFlags(Extension::FROM_WEBSTORE)
49 .SetID(id) 51 .SetID(id)
50 .Build(); 52 .Build();
51 } 53 }
52 54
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 126 }
125 127
126 TEST_F(SharedModuleServiceUnitTest, PruneSharedModulesOnUninstall) { 128 TEST_F(SharedModuleServiceUnitTest, PruneSharedModulesOnUninstall) {
127 // Create a module which exports a resource, and install it. 129 // Create a module which exports a resource, and install it.
128 scoped_ptr<base::DictionaryValue> manifest = 130 scoped_ptr<base::DictionaryValue> manifest =
129 DictionaryBuilder() 131 DictionaryBuilder()
130 .Set("name", "Shared Module") 132 .Set("name", "Shared Module")
131 .Set("version", "1.0") 133 .Set("version", "1.0")
132 .Set("manifest_version", 2) 134 .Set("manifest_version", 2)
133 .Set("export", 135 .Set("export",
134 std::move(DictionaryBuilder().Set( 136 DictionaryBuilder()
135 "resources", std::move(ListBuilder().Append("foo.js"))))) 137 .Set("resources", ListBuilder().Append("foo.js").Build())
138 .Build())
136 .Build(); 139 .Build();
137 scoped_refptr<Extension> shared_module = 140 scoped_refptr<Extension> shared_module =
138 ExtensionBuilder() 141 ExtensionBuilder()
139 .SetManifest(std::move(manifest)) 142 .SetManifest(std::move(manifest))
140 .AddFlags(Extension::FROM_WEBSTORE) 143 .AddFlags(Extension::FROM_WEBSTORE)
141 .SetID(crx_file::id_util::GenerateId("shared_module")) 144 .SetID(crx_file::id_util::GenerateId("shared_module"))
142 .Build(); 145 .Build();
143 146
144 EXPECT_TRUE(InstallExtension(shared_module.get(), false)); 147 EXPECT_TRUE(InstallExtension(shared_module.get(), false));
145 148
(...skipping 19 matching lines...) Expand all
165 } 168 }
166 169
167 TEST_F(SharedModuleServiceUnitTest, PruneSharedModulesOnUpdate) { 170 TEST_F(SharedModuleServiceUnitTest, PruneSharedModulesOnUpdate) {
168 // Create two modules which export a resource, and install them. 171 // Create two modules which export a resource, and install them.
169 scoped_ptr<base::DictionaryValue> manifest_1 = 172 scoped_ptr<base::DictionaryValue> manifest_1 =
170 DictionaryBuilder() 173 DictionaryBuilder()
171 .Set("name", "Shared Module 1") 174 .Set("name", "Shared Module 1")
172 .Set("version", "1.0") 175 .Set("version", "1.0")
173 .Set("manifest_version", 2) 176 .Set("manifest_version", 2)
174 .Set("export", 177 .Set("export",
175 std::move(DictionaryBuilder().Set( 178 DictionaryBuilder()
176 "resources", std::move(ListBuilder().Append("foo.js"))))) 179 .Set("resources", ListBuilder().Append("foo.js").Build())
180 .Build())
177 .Build(); 181 .Build();
178 scoped_refptr<Extension> shared_module_1 = 182 scoped_refptr<Extension> shared_module_1 =
179 ExtensionBuilder() 183 ExtensionBuilder()
180 .SetManifest(std::move(manifest_1)) 184 .SetManifest(std::move(manifest_1))
181 .AddFlags(Extension::FROM_WEBSTORE) 185 .AddFlags(Extension::FROM_WEBSTORE)
182 .SetID(crx_file::id_util::GenerateId("shared_module_1")) 186 .SetID(crx_file::id_util::GenerateId("shared_module_1"))
183 .Build(); 187 .Build();
184 EXPECT_TRUE(InstallExtension(shared_module_1.get(), false)); 188 EXPECT_TRUE(InstallExtension(shared_module_1.get(), false));
185 189
186 scoped_ptr<base::DictionaryValue> manifest_2 = 190 scoped_ptr<base::DictionaryValue> manifest_2 =
187 DictionaryBuilder() 191 DictionaryBuilder()
188 .Set("name", "Shared Module 2") 192 .Set("name", "Shared Module 2")
189 .Set("version", "1.0") 193 .Set("version", "1.0")
190 .Set("manifest_version", 2) 194 .Set("manifest_version", 2)
191 .Set("export", 195 .Set("export",
192 std::move(DictionaryBuilder().Set( 196 DictionaryBuilder()
193 "resources", std::move(ListBuilder().Append("foo.js"))))) 197 .Set("resources", ListBuilder().Append("foo.js").Build())
198 .Build())
194 .Build(); 199 .Build();
195 scoped_refptr<Extension> shared_module_2 = 200 scoped_refptr<Extension> shared_module_2 =
196 ExtensionBuilder() 201 ExtensionBuilder()
197 .SetManifest(std::move(manifest_2)) 202 .SetManifest(std::move(manifest_2))
198 .AddFlags(Extension::FROM_WEBSTORE) 203 .AddFlags(Extension::FROM_WEBSTORE)
199 .SetID(crx_file::id_util::GenerateId("shared_module_2")) 204 .SetID(crx_file::id_util::GenerateId("shared_module_2"))
200 .Build(); 205 .Build();
201 EXPECT_TRUE(InstallExtension(shared_module_2.get(), false)); 206 EXPECT_TRUE(InstallExtension(shared_module_2.get(), false));
202 207
203 std::string extension_id = crx_file::id_util::GenerateId("extension_id"); 208 std::string extension_id = crx_file::id_util::GenerateId("extension_id");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 std::string whitelisted_id = crx_file::id_util::GenerateId("whitelisted"); 248 std::string whitelisted_id = crx_file::id_util::GenerateId("whitelisted");
244 std::string nonwhitelisted_id = 249 std::string nonwhitelisted_id =
245 crx_file::id_util::GenerateId("nonwhitelisted"); 250 crx_file::id_util::GenerateId("nonwhitelisted");
246 // Create a module which exports to a restricted whitelist. 251 // Create a module which exports to a restricted whitelist.
247 scoped_ptr<base::DictionaryValue> manifest = 252 scoped_ptr<base::DictionaryValue> manifest =
248 DictionaryBuilder() 253 DictionaryBuilder()
249 .Set("name", "Shared Module") 254 .Set("name", "Shared Module")
250 .Set("version", "1.0") 255 .Set("version", "1.0")
251 .Set("manifest_version", 2) 256 .Set("manifest_version", 2)
252 .Set("export", 257 .Set("export",
253 std::move( 258 DictionaryBuilder()
254 DictionaryBuilder() 259 .Set("whitelist",
255 .Set("whitelist", 260 ListBuilder().Append(whitelisted_id).Build())
256 std::move(ListBuilder().Append(whitelisted_id))) 261 .Set("resources", ListBuilder().Append("*").Build())
257 .Set("resources", std::move(ListBuilder().Append("*"))))) 262 .Build())
258 .Build(); 263 .Build();
259 scoped_refptr<Extension> shared_module = 264 scoped_refptr<Extension> shared_module =
260 ExtensionBuilder() 265 ExtensionBuilder()
261 .SetManifest(std::move(manifest)) 266 .SetManifest(std::move(manifest))
262 .AddFlags(Extension::FROM_WEBSTORE) 267 .AddFlags(Extension::FROM_WEBSTORE)
263 .SetID(crx_file::id_util::GenerateId("shared_module")) 268 .SetID(crx_file::id_util::GenerateId("shared_module"))
264 .Build(); 269 .Build();
265 270
266 EXPECT_TRUE(InstallExtension(shared_module.get(), false)); 271 EXPECT_TRUE(InstallExtension(shared_module.get(), false));
267 272
(...skipping 10 matching lines...) Expand all
278 nonwhitelisted_id, 283 nonwhitelisted_id,
279 "1.0"); 284 "1.0");
280 // This should succeed because only CRX installer (and by extension the 285 // This should succeed because only CRX installer (and by extension the
281 // WebStore Installer) checks the shared module whitelist. InstallExtension 286 // WebStore Installer) checks the shared module whitelist. InstallExtension
282 // bypasses the whitelist check because the SharedModuleService does not 287 // bypasses the whitelist check because the SharedModuleService does not
283 // care about whitelists. 288 // care about whitelists.
284 EXPECT_TRUE(InstallExtension(nonwhitelisted_extension.get(), false)); 289 EXPECT_TRUE(InstallExtension(nonwhitelisted_extension.get(), false));
285 } 290 }
286 291
287 } // namespace extensions 292 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698