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 "extensions/common/features/base_feature_provider.h" | 5 #include "extensions/common/features/base_feature_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 ExtensionBuilder() | 48 ExtensionBuilder() |
49 .SetManifest(DictionaryBuilder() | 49 .SetManifest(DictionaryBuilder() |
50 .Set("name", "test extension") | 50 .Set("name", "test extension") |
51 .Set("version", "1") | 51 .Set("version", "1") |
52 .Set("description", "hello there") | 52 .Set("description", "hello there") |
53 .Build()) | 53 .Build()) |
54 .Build(); | 54 .Build(); |
55 ASSERT_TRUE(extension.get()); | 55 ASSERT_TRUE(extension.get()); |
56 | 56 |
57 Feature* feature = provider->GetFeature("description"); | 57 Feature* feature = provider->GetFeature("description"); |
58 EXPECT_EQ(Feature::IS_AVAILABLE, | 58 EXPECT_EQ( |
59 feature->IsAvailableToContext(extension.get(), | 59 Feature::IS_AVAILABLE, |
60 Feature::UNSPECIFIED_CONTEXT, | 60 feature |
61 GURL()).result()); | 61 ->IsAvailableToContext(extension.get(), Feature::UNSPECIFIED_CONTEXT, |
| 62 Feature::SESSION_TYPE_UNSPECIFIED, GURL()) |
| 63 .result()); |
62 | 64 |
63 // This is a generic extension, so an app-only feature isn't allowed. | 65 // This is a generic extension, so an app-only feature isn't allowed. |
64 feature = provider->GetFeature("app.background"); | 66 feature = provider->GetFeature("app.background"); |
65 ASSERT_TRUE(feature); | 67 ASSERT_TRUE(feature); |
66 EXPECT_EQ(Feature::INVALID_TYPE, | 68 EXPECT_EQ( |
67 feature->IsAvailableToContext(extension.get(), | 69 Feature::INVALID_TYPE, |
68 Feature::UNSPECIFIED_CONTEXT, | 70 feature |
69 GURL()).result()); | 71 ->IsAvailableToContext(extension.get(), Feature::UNSPECIFIED_CONTEXT, |
| 72 Feature::SESSION_TYPE_UNSPECIFIED, GURL()) |
| 73 .result()); |
70 | 74 |
71 // A feature not listed in the manifest isn't allowed. | 75 // A feature not listed in the manifest isn't allowed. |
72 feature = provider->GetFeature("background"); | 76 feature = provider->GetFeature("background"); |
73 ASSERT_TRUE(feature); | 77 ASSERT_TRUE(feature); |
74 EXPECT_EQ(Feature::NOT_PRESENT, | 78 EXPECT_EQ( |
75 feature->IsAvailableToContext(extension.get(), | 79 Feature::NOT_PRESENT, |
76 Feature::UNSPECIFIED_CONTEXT, | 80 feature |
77 GURL()).result()); | 81 ->IsAvailableToContext(extension.get(), Feature::UNSPECIFIED_CONTEXT, |
| 82 Feature::SESSION_TYPE_UNSPECIFIED, GURL()) |
| 83 .result()); |
78 } | 84 } |
79 | 85 |
80 // Tests that a real permission feature is available for the correct types of | 86 // Tests that a real permission feature is available for the correct types of |
81 // extensions and apps. | 87 // extensions and apps. |
82 TEST(BaseFeatureProviderTest, PermissionFeatureTypes) { | 88 TEST(BaseFeatureProviderTest, PermissionFeatureTypes) { |
83 // NOTE: This feature cannot have multiple rules, otherwise it is not a | 89 // NOTE: This feature cannot have multiple rules, otherwise it is not a |
84 // SimpleFeature. | 90 // SimpleFeature. |
85 const SimpleFeature* feature = static_cast<const SimpleFeature*>( | 91 const SimpleFeature* feature = static_cast<const SimpleFeature*>( |
86 BaseFeatureProvider::GetPermissionFeature("power")); | 92 BaseFeatureProvider::GetPermissionFeature("power")); |
87 ASSERT_TRUE(feature); | 93 ASSERT_TRUE(feature); |
(...skipping 29 matching lines...) Expand all Loading... |
117 .Set("permissions", ListBuilder().Append("power").Build()) | 123 .Set("permissions", ListBuilder().Append("power").Build()) |
118 .Build()) | 124 .Build()) |
119 .Build(); | 125 .Build(); |
120 ASSERT_TRUE(app.get()); | 126 ASSERT_TRUE(app.get()); |
121 ASSERT_TRUE(app->is_platform_app()); | 127 ASSERT_TRUE(app->is_platform_app()); |
122 | 128 |
123 // A permission requested in the manifest is available. | 129 // A permission requested in the manifest is available. |
124 Feature* feature = provider->GetFeature("power"); | 130 Feature* feature = provider->GetFeature("power"); |
125 EXPECT_EQ( | 131 EXPECT_EQ( |
126 Feature::IS_AVAILABLE, | 132 Feature::IS_AVAILABLE, |
127 feature->IsAvailableToContext( | 133 feature |
128 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); | 134 ->IsAvailableToContext(app.get(), Feature::UNSPECIFIED_CONTEXT, |
| 135 Feature::SESSION_TYPE_UNSPECIFIED, GURL()) |
| 136 .result()); |
129 | 137 |
130 // A permission only available to whitelisted extensions returns availability | 138 // A permission only available to whitelisted extensions returns availability |
131 // NOT_FOUND_IN_WHITELIST. | 139 // NOT_FOUND_IN_WHITELIST. |
132 feature = provider->GetFeature("bluetoothPrivate"); | 140 feature = provider->GetFeature("bluetoothPrivate"); |
133 ASSERT_TRUE(feature); | 141 ASSERT_TRUE(feature); |
134 EXPECT_EQ( | 142 EXPECT_EQ( |
135 Feature::NOT_FOUND_IN_WHITELIST, | 143 Feature::NOT_FOUND_IN_WHITELIST, |
136 feature->IsAvailableToContext( | 144 feature |
137 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); | 145 ->IsAvailableToContext(app.get(), Feature::UNSPECIFIED_CONTEXT, |
| 146 Feature::SESSION_TYPE_UNSPECIFIED, GURL()) |
| 147 .result()); |
138 | 148 |
139 // A permission that isn't part of the manifest returns NOT_PRESENT. | 149 // A permission that isn't part of the manifest returns NOT_PRESENT. |
140 feature = provider->GetFeature("serial"); | 150 feature = provider->GetFeature("serial"); |
141 ASSERT_TRUE(feature); | 151 ASSERT_TRUE(feature); |
142 EXPECT_EQ( | 152 EXPECT_EQ( |
143 Feature::NOT_PRESENT, | 153 Feature::NOT_PRESENT, |
144 feature->IsAvailableToContext( | 154 feature |
145 app.get(), Feature::UNSPECIFIED_CONTEXT, GURL()).result()); | 155 ->IsAvailableToContext(app.get(), Feature::UNSPECIFIED_CONTEXT, |
| 156 Feature::SESSION_TYPE_UNSPECIFIED, GURL()) |
| 157 .result()); |
146 } | 158 } |
147 | 159 |
148 } // namespace extensions | 160 } // namespace extensions |
OLD | NEW |