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

Side by Side Diff: chrome/common/pepper_permission_util_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, 9 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/common/pepper_permission_util.h" 5 #include "chrome/common/pepper_permission_util.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 13 matching lines...) Expand all
24 // Return an extension with |id| which imports a module with the given 24 // Return an extension with |id| which imports a module with the given
25 // |import_id|. 25 // |import_id|.
26 scoped_refptr<Extension> CreateExtensionImportingModule( 26 scoped_refptr<Extension> CreateExtensionImportingModule(
27 const std::string& import_id, 27 const std::string& import_id,
28 const std::string& id) { 28 const std::string& id) {
29 scoped_ptr<base::DictionaryValue> manifest = 29 scoped_ptr<base::DictionaryValue> manifest =
30 DictionaryBuilder() 30 DictionaryBuilder()
31 .Set("name", "Has Dependent Modules") 31 .Set("name", "Has Dependent Modules")
32 .Set("version", "1.0") 32 .Set("version", "1.0")
33 .Set("manifest_version", 2) 33 .Set("manifest_version", 2)
34 .Set("import", std::move(ListBuilder().Append(std::move( 34 .Set("import",
35 DictionaryBuilder().Set("id", import_id))))) 35 ListBuilder()
36 .Append(DictionaryBuilder().Set("id", import_id).Build())
37 .Build())
36 .Build(); 38 .Build();
37 39
38 return ExtensionBuilder() 40 return ExtensionBuilder()
39 .SetManifest(std::move(manifest)) 41 .SetManifest(std::move(manifest))
40 .AddFlags(Extension::FROM_WEBSTORE) 42 .AddFlags(Extension::FROM_WEBSTORE)
41 .SetID(id) 43 .SetID(id)
42 .Build(); 44 .Build();
43 } 45 }
44 46
45 } // namespace 47 } // namespace
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 ExtensionSet extensions; 87 ExtensionSet extensions;
86 std::string whitelisted_id = crx_file::id_util::GenerateId("extension_id"); 88 std::string whitelisted_id = crx_file::id_util::GenerateId("extension_id");
87 std::string bad_id = crx_file::id_util::GenerateId("bad_id"); 89 std::string bad_id = crx_file::id_util::GenerateId("bad_id");
88 90
89 scoped_ptr<base::DictionaryValue> shared_module_manifest = 91 scoped_ptr<base::DictionaryValue> shared_module_manifest =
90 DictionaryBuilder() 92 DictionaryBuilder()
91 .Set("name", "Whitelisted Shared Module") 93 .Set("name", "Whitelisted Shared Module")
92 .Set("version", "1.0") 94 .Set("version", "1.0")
93 .Set("manifest_version", 2) 95 .Set("manifest_version", 2)
94 .Set("export", 96 .Set("export",
95 std::move( 97 DictionaryBuilder()
96 DictionaryBuilder() 98 .Set("resources", ListBuilder().Append("*").Build())
97 .Set("resources", std::move(ListBuilder().Append("*"))) 99 // Add the extension to the whitelist. This
98 // Add the extension to the whitelist. This 100 // restricts import to |whitelisted_id| only.
99 // restricts import to |whitelisted_id| only. 101 .Set("whitelist",
100 .Set("whitelist", 102 ListBuilder().Append(whitelisted_id).Build())
101 std::move(ListBuilder().Append(whitelisted_id))))) 103 .Build())
102 .Build(); 104 .Build();
103 scoped_refptr<Extension> shared_module = 105 scoped_refptr<Extension> shared_module =
104 ExtensionBuilder().SetManifest(std::move(shared_module_manifest)).Build(); 106 ExtensionBuilder().SetManifest(std::move(shared_module_manifest)).Build();
105 107
106 scoped_refptr<Extension> ext = 108 scoped_refptr<Extension> ext =
107 CreateExtensionImportingModule(shared_module->id(), whitelisted_id); 109 CreateExtensionImportingModule(shared_module->id(), whitelisted_id);
108 std::string extension_url = 110 std::string extension_url =
109 std::string("chrome-extension://") + ext->id() + std::string("/foo.html"); 111 std::string("chrome-extension://") + ext->id() + std::string("/foo.html");
110 112
111 std::set<std::string> whitelist; 113 std::set<std::string> whitelist;
(...skipping 22 matching lines...) Expand all
134 GURL(not_in_sm_whitelist_url), &extensions, whitelist)); 136 GURL(not_in_sm_whitelist_url), &extensions, whitelist));
135 137
136 // Note that the whitelist should be empty after this call, so tests checking 138 // Note that the whitelist should be empty after this call, so tests checking
137 // for failure to import will fail because of this. 139 // for failure to import will fail because of this.
138 whitelist.erase(shared_module->id()); 140 whitelist.erase(shared_module->id());
139 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted( 141 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted(
140 GURL(extension_url), &extensions, whitelist)); 142 GURL(extension_url), &extensions, whitelist));
141 } 143 }
142 144
143 } // namespace extensions 145 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698