OLD | NEW |
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 <memory> |
7 #include <set> | 8 #include <set> |
8 #include <string> | 9 #include <string> |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "chrome/common/extensions/features/feature_channel.h" | 12 #include "chrome/common/extensions/features/feature_channel.h" |
12 #include "components/crx_file/id_util.h" | 13 #include "components/crx_file/id_util.h" |
13 #include "components/version_info/version_info.h" | 14 #include "components/version_info/version_info.h" |
14 #include "extensions/common/extension_builder.h" | 15 #include "extensions/common/extension_builder.h" |
15 #include "extensions/common/extension_set.h" | 16 #include "extensions/common/extension_set.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using chrome::IsExtensionOrSharedModuleWhitelisted; | 19 using chrome::IsExtensionOrSharedModuleWhitelisted; |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Return an extension with |id| which imports a module with the given | 25 // Return an extension with |id| which imports a module with the given |
25 // |import_id|. | 26 // |import_id|. |
26 scoped_refptr<Extension> CreateExtensionImportingModule( | 27 scoped_refptr<Extension> CreateExtensionImportingModule( |
27 const std::string& import_id, | 28 const std::string& import_id, |
28 const std::string& id) { | 29 const std::string& id) { |
29 scoped_ptr<base::DictionaryValue> manifest = | 30 std::unique_ptr<base::DictionaryValue> manifest = |
30 DictionaryBuilder() | 31 DictionaryBuilder() |
31 .Set("name", "Has Dependent Modules") | 32 .Set("name", "Has Dependent Modules") |
32 .Set("version", "1.0") | 33 .Set("version", "1.0") |
33 .Set("manifest_version", 2) | 34 .Set("manifest_version", 2) |
34 .Set("import", | 35 .Set("import", |
35 ListBuilder() | 36 ListBuilder() |
36 .Append(DictionaryBuilder().Set("id", import_id).Build()) | 37 .Append(DictionaryBuilder().Set("id", import_id).Build()) |
37 .Build()) | 38 .Build()) |
38 .Build(); | 39 .Build(); |
39 | 40 |
40 return ExtensionBuilder() | 41 return ExtensionBuilder() |
41 .SetManifest(std::move(manifest)) | 42 .SetManifest(std::move(manifest)) |
42 .AddFlags(Extension::FROM_WEBSTORE) | 43 .AddFlags(Extension::FROM_WEBSTORE) |
43 .SetID(id) | 44 .SetID(id) |
44 .Build(); | 45 .Build(); |
45 } | 46 } |
46 | 47 |
47 } // namespace | 48 } // namespace |
48 | 49 |
49 TEST(PepperPermissionUtilTest, ExtensionWhitelisting) { | 50 TEST(PepperPermissionUtilTest, ExtensionWhitelisting) { |
50 ScopedCurrentChannel current_channel(version_info::Channel::UNKNOWN); | 51 ScopedCurrentChannel current_channel(version_info::Channel::UNKNOWN); |
51 ExtensionSet extensions; | 52 ExtensionSet extensions; |
52 std::string whitelisted_id = | 53 std::string whitelisted_id = |
53 crx_file::id_util::GenerateId("whitelisted_extension"); | 54 crx_file::id_util::GenerateId("whitelisted_extension"); |
54 scoped_ptr<base::DictionaryValue> manifest = | 55 std::unique_ptr<base::DictionaryValue> manifest = |
55 DictionaryBuilder() | 56 DictionaryBuilder() |
56 .Set("name", "Whitelisted Extension") | 57 .Set("name", "Whitelisted Extension") |
57 .Set("version", "1.0") | 58 .Set("version", "1.0") |
58 .Set("manifest_version", 2) | 59 .Set("manifest_version", 2) |
59 .Build(); | 60 .Build(); |
60 scoped_refptr<Extension> ext = ExtensionBuilder() | 61 scoped_refptr<Extension> ext = ExtensionBuilder() |
61 .SetManifest(std::move(manifest)) | 62 .SetManifest(std::move(manifest)) |
62 .SetID(whitelisted_id) | 63 .SetID(whitelisted_id) |
63 .Build(); | 64 .Build(); |
64 extensions.Insert(ext); | 65 extensions.Insert(ext); |
(...skipping 16 matching lines...) Expand all Loading... |
81 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted( | 82 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted( |
82 GURL(bad_host_url), &extensions, whitelist)); | 83 GURL(bad_host_url), &extensions, whitelist)); |
83 } | 84 } |
84 | 85 |
85 TEST(PepperPermissionUtilTest, SharedModuleWhitelisting) { | 86 TEST(PepperPermissionUtilTest, SharedModuleWhitelisting) { |
86 ScopedCurrentChannel current_channel(version_info::Channel::UNKNOWN); | 87 ScopedCurrentChannel current_channel(version_info::Channel::UNKNOWN); |
87 ExtensionSet extensions; | 88 ExtensionSet extensions; |
88 std::string whitelisted_id = crx_file::id_util::GenerateId("extension_id"); | 89 std::string whitelisted_id = crx_file::id_util::GenerateId("extension_id"); |
89 std::string bad_id = crx_file::id_util::GenerateId("bad_id"); | 90 std::string bad_id = crx_file::id_util::GenerateId("bad_id"); |
90 | 91 |
91 scoped_ptr<base::DictionaryValue> shared_module_manifest = | 92 std::unique_ptr<base::DictionaryValue> shared_module_manifest = |
92 DictionaryBuilder() | 93 DictionaryBuilder() |
93 .Set("name", "Whitelisted Shared Module") | 94 .Set("name", "Whitelisted Shared Module") |
94 .Set("version", "1.0") | 95 .Set("version", "1.0") |
95 .Set("manifest_version", 2) | 96 .Set("manifest_version", 2) |
96 .Set("export", | 97 .Set("export", |
97 DictionaryBuilder() | 98 DictionaryBuilder() |
98 .Set("resources", ListBuilder().Append("*").Build()) | 99 .Set("resources", ListBuilder().Append("*").Build()) |
99 // Add the extension to the whitelist. This | 100 // Add the extension to the whitelist. This |
100 // restricts import to |whitelisted_id| only. | 101 // restricts import to |whitelisted_id| only. |
101 .Set("whitelist", | 102 .Set("whitelist", |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 GURL(not_in_sm_whitelist_url), &extensions, whitelist)); | 137 GURL(not_in_sm_whitelist_url), &extensions, whitelist)); |
137 | 138 |
138 // Note that the whitelist should be empty after this call, so tests checking | 139 // Note that the whitelist should be empty after this call, so tests checking |
139 // for failure to import will fail because of this. | 140 // for failure to import will fail because of this. |
140 whitelist.erase(shared_module->id()); | 141 whitelist.erase(shared_module->id()); |
141 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted( | 142 EXPECT_FALSE(IsExtensionOrSharedModuleWhitelisted( |
142 GURL(extension_url), &extensions, whitelist)); | 143 GURL(extension_url), &extensions, whitelist)); |
143 } | 144 } |
144 | 145 |
145 } // namespace extensions | 146 } // namespace extensions |
OLD | NEW |