Chromium Code Reviews| 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/simple_feature.h" | 5 #include "extensions/common/features/simple_feature.h" |
| 6 | 6 |
| 7 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h" | 7 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h" |
| 8 #include "chrome/common/extensions/features/feature_channel.h" | 8 #include "chrome/common/extensions/features/feature_channel.h" |
| 9 #include "extensions/common/value_builder.h" | 9 #include "extensions/common/value_builder.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 using chrome::VersionInfo; | 12 using chrome::VersionInfo; |
| 13 using extensions::DictionaryBuilder; | 13 using extensions::DictionaryBuilder; |
| 14 using extensions::Extension; | 14 using extensions::Extension; |
| 15 using extensions::Feature; | 15 using extensions::Feature; |
| 16 using extensions::ListBuilder; | 16 using extensions::ListBuilder; |
| 17 using extensions::Manifest; | 17 using extensions::Manifest; |
| 18 using extensions::ScopedCurrentChannel; | 18 using extensions::ScopedCurrentChannel; |
| 19 using extensions::SimpleFeature; | 19 using extensions::SimpleFeature; |
| 20 | 20 |
| 21 namespace extensions { | |
| 22 | |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 struct IsAvailableTestData { | 25 struct IsAvailableTestData { |
| 24 std::string extension_id; | 26 std::string extension_id; |
| 25 Manifest::Type extension_type; | 27 Manifest::Type extension_type; |
| 26 Feature::Location location; | 28 Manifest::Location location; |
| 27 Feature::Platform platform; | 29 Feature::Platform platform; |
| 28 int manifest_version; | 30 int manifest_version; |
| 29 Feature::AvailabilityResult expected_result; | 31 Feature::AvailabilityResult expected_result; |
| 30 }; | 32 }; |
| 31 | 33 |
| 34 } // namespace | |
| 35 | |
| 32 class ExtensionSimpleFeatureTest : public testing::Test { | 36 class ExtensionSimpleFeatureTest : public testing::Test { |
| 33 protected: | 37 protected: |
| 34 ExtensionSimpleFeatureTest() | 38 ExtensionSimpleFeatureTest() |
| 35 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} | 39 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {} |
| 36 virtual ~ExtensionSimpleFeatureTest() {} | 40 virtual ~ExtensionSimpleFeatureTest() {} |
| 37 | 41 |
| 38 private: | 42 private: |
| 39 ScopedCurrentChannel current_channel_; | 43 ScopedCurrentChannel current_channel_; |
| 40 }; | 44 }; |
| 41 | 45 |
| 42 TEST_F(ExtensionSimpleFeatureTest, IsAvailableNullCase) { | 46 TEST_F(ExtensionSimpleFeatureTest, IsAvailableNullCase) { |
| 43 const IsAvailableTestData tests[] = { | 47 const IsAvailableTestData tests[] = { |
| 44 { "", Manifest::TYPE_UNKNOWN, | 48 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 45 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, | 49 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 46 Feature::IS_AVAILABLE }, | 50 {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 47 { "random-extension", Manifest::TYPE_UNKNOWN, | 51 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 48 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, | 52 {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION, |
| 49 Feature::IS_AVAILABLE }, | 53 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 50 { "", Manifest::TYPE_LEGACY_PACKAGED_APP, | 54 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 51 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, | 55 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 52 Feature::IS_AVAILABLE }, | 56 {"", Manifest::TYPE_UNKNOWN, Manifest::COMPONENT, |
| 53 { "", Manifest::TYPE_UNKNOWN, | 57 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 54 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, | 58 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 55 Feature::IS_AVAILABLE }, | 59 Feature::CHROMEOS_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 56 { "", Manifest::TYPE_UNKNOWN, | 60 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 57 Feature::COMPONENT_LOCATION, Feature::UNSPECIFIED_PLATFORM, -1, | 61 Feature::UNSPECIFIED_PLATFORM, 25, Feature::IS_AVAILABLE}}; |
| 58 Feature::IS_AVAILABLE }, | |
| 59 { "", Manifest::TYPE_UNKNOWN, | |
| 60 Feature::UNSPECIFIED_LOCATION, Feature::CHROMEOS_PLATFORM, -1, | |
| 61 Feature::IS_AVAILABLE }, | |
| 62 { "", Manifest::TYPE_UNKNOWN, | |
| 63 Feature::UNSPECIFIED_LOCATION, Feature::UNSPECIFIED_PLATFORM, 25, | |
| 64 Feature::IS_AVAILABLE } | |
| 65 }; | |
| 66 | 62 |
| 67 SimpleFeature feature; | 63 SimpleFeature feature; |
| 68 for (size_t i = 0; i < arraysize(tests); ++i) { | 64 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 69 const IsAvailableTestData& test = tests[i]; | 65 const IsAvailableTestData& test = tests[i]; |
| 70 EXPECT_EQ(test.expected_result, | 66 EXPECT_EQ(test.expected_result, |
| 71 feature.IsAvailableToManifest(test.extension_id, | 67 feature.IsAvailableToManifest(test.extension_id, |
| 72 test.extension_type, | 68 test.extension_type, |
| 73 test.location, | 69 test.location, |
| 74 test.manifest_version, | 70 test.manifest_version, |
| 75 test.platform).result()); | 71 test.platform).result()); |
| 76 } | 72 } |
| 77 } | 73 } |
| 78 | 74 |
| 79 TEST_F(ExtensionSimpleFeatureTest, Whitelist) { | 75 TEST_F(ExtensionSimpleFeatureTest, Whitelist) { |
| 80 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); | 76 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); |
| 81 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); | 77 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); |
| 82 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); | 78 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); |
| 83 SimpleFeature feature; | 79 SimpleFeature feature; |
| 84 feature.whitelist()->insert(kIdFoo); | 80 feature.whitelist()->insert(kIdFoo); |
| 85 feature.whitelist()->insert(kIdBar); | 81 feature.whitelist()->insert(kIdBar); |
| 86 | 82 |
| 87 EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( | 83 EXPECT_EQ( |
| 88 kIdFoo, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1, | 84 Feature::IS_AVAILABLE, |
| 89 Feature::UNSPECIFIED_PLATFORM).result()); | 85 feature.IsAvailableToManifest(kIdFoo, |
| 90 EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( | 86 Manifest::TYPE_UNKNOWN, |
| 91 kIdBar, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1, | 87 Manifest::INVALID_LOCATION, |
| 92 Feature::UNSPECIFIED_PLATFORM).result()); | 88 -1, |
| 89 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 90 EXPECT_EQ( | |
| 91 Feature::IS_AVAILABLE, | |
| 92 feature.IsAvailableToManifest(kIdBar, | |
| 93 Manifest::TYPE_UNKNOWN, | |
| 94 Manifest::INVALID_LOCATION, | |
| 95 -1, | |
| 96 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 93 | 97 |
| 94 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest( | 98 EXPECT_EQ( |
| 95 kIdBaz, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1, | 99 Feature::NOT_FOUND_IN_WHITELIST, |
| 96 Feature::UNSPECIFIED_PLATFORM).result()); | 100 feature.IsAvailableToManifest(kIdBaz, |
| 101 Manifest::TYPE_UNKNOWN, | |
| 102 Manifest::INVALID_LOCATION, | |
| 103 -1, | |
| 104 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 97 EXPECT_EQ( | 105 EXPECT_EQ( |
| 98 Feature::NOT_FOUND_IN_WHITELIST, | 106 Feature::NOT_FOUND_IN_WHITELIST, |
| 99 feature.IsAvailableToManifest(std::string(), | 107 feature.IsAvailableToManifest(std::string(), |
| 100 Manifest::TYPE_UNKNOWN, | 108 Manifest::TYPE_UNKNOWN, |
| 101 Feature::UNSPECIFIED_LOCATION, | 109 Manifest::INVALID_LOCATION, |
| 102 -1, | 110 -1, |
| 103 Feature::UNSPECIFIED_PLATFORM).result()); | 111 Feature::UNSPECIFIED_PLATFORM).result()); |
| 104 | 112 |
| 105 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); | 113 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 106 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest( | 114 EXPECT_EQ( |
| 107 kIdBaz, Manifest::TYPE_LEGACY_PACKAGED_APP, | 115 Feature::NOT_FOUND_IN_WHITELIST, |
| 108 Feature::UNSPECIFIED_LOCATION, -1, | 116 feature.IsAvailableToManifest(kIdBaz, |
| 109 Feature::UNSPECIFIED_PLATFORM).result()); | 117 Manifest::TYPE_LEGACY_PACKAGED_APP, |
| 118 Manifest::INVALID_LOCATION, | |
| 119 -1, | |
| 120 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 110 } | 121 } |
| 111 | 122 |
| 112 TEST_F(ExtensionSimpleFeatureTest, HashedIdWhitelist) { | 123 TEST_F(ExtensionSimpleFeatureTest, HashedIdWhitelist) { |
| 113 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | | 124 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | |
| 114 // sha1sum | tr '[:lower:]' '[:upper:]' | 125 // sha1sum | tr '[:lower:]' '[:upper:]' |
| 115 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); | 126 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); |
| 116 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); | 127 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); |
| 117 SimpleFeature feature; | 128 SimpleFeature feature; |
| 118 | 129 |
| 119 feature.whitelist()->insert(kIdFooHashed); | 130 feature.whitelist()->insert(kIdFooHashed); |
| 120 | 131 |
| 121 EXPECT_EQ(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( | 132 EXPECT_EQ( |
| 122 kIdFoo, Manifest::TYPE_UNKNOWN, Feature::UNSPECIFIED_LOCATION, -1, | 133 Feature::IS_AVAILABLE, |
| 123 Feature::UNSPECIFIED_PLATFORM).result()); | 134 feature.IsAvailableToManifest(kIdFoo, |
| 124 EXPECT_NE(Feature::IS_AVAILABLE, feature.IsAvailableToManifest( | 135 Manifest::TYPE_UNKNOWN, |
| 125 kIdFooHashed, Manifest::TYPE_UNKNOWN, | 136 Manifest::INVALID_LOCATION, |
| 126 Feature::UNSPECIFIED_LOCATION, -1, | 137 -1, |
| 127 Feature::UNSPECIFIED_PLATFORM).result()); | 138 Feature::UNSPECIFIED_PLATFORM).result()); |
| 128 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest( | 139 EXPECT_NE( |
| 129 "slightlytoooolongforanextensionid", Manifest::TYPE_UNKNOWN, | 140 Feature::IS_AVAILABLE, |
| 130 Feature::UNSPECIFIED_LOCATION, -1, | 141 feature.IsAvailableToManifest(kIdFooHashed, |
| 131 Feature::UNSPECIFIED_PLATFORM).result()); | 142 Manifest::TYPE_UNKNOWN, |
| 132 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToManifest( | 143 Manifest::INVALID_LOCATION, |
| 133 "tooshortforanextensionid", Manifest::TYPE_UNKNOWN, | 144 -1, |
| 134 Feature::UNSPECIFIED_LOCATION, -1, | 145 Feature::UNSPECIFIED_PLATFORM).result()); |
| 135 Feature::UNSPECIFIED_PLATFORM).result()); | 146 EXPECT_EQ( |
| 147 Feature::NOT_FOUND_IN_WHITELIST, | |
| 148 feature.IsAvailableToManifest("slightlytoooolongforanextensionid", | |
| 149 Manifest::TYPE_UNKNOWN, | |
| 150 Manifest::INVALID_LOCATION, | |
| 151 -1, | |
| 152 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 153 EXPECT_EQ( | |
| 154 Feature::NOT_FOUND_IN_WHITELIST, | |
| 155 feature.IsAvailableToManifest("tooshortforanextensionid", | |
| 156 Manifest::TYPE_UNKNOWN, | |
| 157 Manifest::INVALID_LOCATION, | |
| 158 -1, | |
| 159 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 136 } | 160 } |
| 137 | 161 |
| 138 TEST_F(ExtensionSimpleFeatureTest, PackageType) { | 162 TEST_F(ExtensionSimpleFeatureTest, PackageType) { |
| 139 SimpleFeature feature; | 163 SimpleFeature feature; |
| 140 feature.extension_types()->insert(Manifest::TYPE_EXTENSION); | 164 feature.extension_types()->insert(Manifest::TYPE_EXTENSION); |
| 141 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); | 165 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 142 | 166 |
| 143 EXPECT_EQ( | 167 EXPECT_EQ( |
| 144 Feature::IS_AVAILABLE, | 168 Feature::IS_AVAILABLE, |
| 145 feature.IsAvailableToManifest(std::string(), | 169 feature.IsAvailableToManifest(std::string(), |
| 146 Manifest::TYPE_EXTENSION, | 170 Manifest::TYPE_EXTENSION, |
| 147 Feature::UNSPECIFIED_LOCATION, | 171 Manifest::INVALID_LOCATION, |
| 148 -1, | 172 -1, |
| 149 Feature::UNSPECIFIED_PLATFORM).result()); | 173 Feature::UNSPECIFIED_PLATFORM).result()); |
| 150 EXPECT_EQ( | 174 EXPECT_EQ( |
| 151 Feature::IS_AVAILABLE, | 175 Feature::IS_AVAILABLE, |
| 152 feature.IsAvailableToManifest(std::string(), | 176 feature.IsAvailableToManifest(std::string(), |
| 153 Manifest::TYPE_LEGACY_PACKAGED_APP, | 177 Manifest::TYPE_LEGACY_PACKAGED_APP, |
| 154 Feature::UNSPECIFIED_LOCATION, | 178 Manifest::INVALID_LOCATION, |
| 155 -1, | 179 -1, |
| 156 Feature::UNSPECIFIED_PLATFORM).result()); | 180 Feature::UNSPECIFIED_PLATFORM).result()); |
| 157 | 181 |
| 158 EXPECT_EQ( | 182 EXPECT_EQ( |
| 159 Feature::INVALID_TYPE, | 183 Feature::INVALID_TYPE, |
| 160 feature.IsAvailableToManifest(std::string(), | 184 feature.IsAvailableToManifest(std::string(), |
| 161 Manifest::TYPE_UNKNOWN, | 185 Manifest::TYPE_UNKNOWN, |
| 162 Feature::UNSPECIFIED_LOCATION, | 186 Manifest::INVALID_LOCATION, |
| 163 -1, | 187 -1, |
| 164 Feature::UNSPECIFIED_PLATFORM).result()); | 188 Feature::UNSPECIFIED_PLATFORM).result()); |
| 165 EXPECT_EQ( | 189 EXPECT_EQ( |
| 166 Feature::INVALID_TYPE, | 190 Feature::INVALID_TYPE, |
| 167 feature.IsAvailableToManifest(std::string(), | 191 feature.IsAvailableToManifest(std::string(), |
| 168 Manifest::TYPE_THEME, | 192 Manifest::TYPE_THEME, |
| 169 Feature::UNSPECIFIED_LOCATION, | 193 Manifest::INVALID_LOCATION, |
| 170 -1, | 194 -1, |
| 171 Feature::UNSPECIFIED_PLATFORM).result()); | 195 Feature::UNSPECIFIED_PLATFORM).result()); |
| 172 } | 196 } |
| 173 | 197 |
| 174 TEST_F(ExtensionSimpleFeatureTest, Context) { | 198 TEST_F(ExtensionSimpleFeatureTest, Context) { |
| 175 SimpleFeature feature; | 199 SimpleFeature feature; |
| 176 feature.set_name("somefeature"); | 200 feature.set_name("somefeature"); |
| 177 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); | 201 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); |
| 178 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); | 202 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 179 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); | 203 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 256 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 233 Feature::CHROMEOS_PLATFORM); | 257 Feature::CHROMEOS_PLATFORM); |
| 234 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); | 258 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); |
| 235 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes, " | 259 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes, " |
| 236 "content scripts, and web pages, but this is a privileged page", | 260 "content scripts, and web pages, but this is a privileged page", |
| 237 availability.message()); | 261 availability.message()); |
| 238 } | 262 } |
| 239 | 263 |
| 240 feature.GetContexts()->clear(); | 264 feature.GetContexts()->clear(); |
| 241 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); | 265 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); |
| 242 feature.set_location(Feature::COMPONENT_LOCATION); | 266 feature.set_location(SimpleFeature::COMPONENT_LOCATION); |
| 243 EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext( | 267 EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext( |
| 244 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 268 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 245 Feature::CHROMEOS_PLATFORM).result()); | 269 Feature::CHROMEOS_PLATFORM).result()); |
| 246 feature.set_location(Feature::UNSPECIFIED_LOCATION); | 270 feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION); |
| 247 | 271 |
| 248 EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext( | 272 EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext( |
| 249 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 273 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 250 Feature::UNSPECIFIED_PLATFORM).result()); | 274 Feature::UNSPECIFIED_PLATFORM).result()); |
| 251 | 275 |
| 252 feature.set_min_manifest_version(22); | 276 feature.set_min_manifest_version(22); |
| 253 EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION, feature.IsAvailableToContext( | 277 EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION, feature.IsAvailableToContext( |
| 254 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 278 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 255 Feature::CHROMEOS_PLATFORM).result()); | 279 Feature::CHROMEOS_PLATFORM).result()); |
| 256 feature.set_min_manifest_version(21); | 280 feature.set_min_manifest_version(21); |
| 257 | 281 |
| 258 feature.set_max_manifest_version(18); | 282 feature.set_max_manifest_version(18); |
| 259 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( | 283 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( |
| 260 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 284 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 261 Feature::CHROMEOS_PLATFORM).result()); | 285 Feature::CHROMEOS_PLATFORM).result()); |
| 262 feature.set_max_manifest_version(25); | 286 feature.set_max_manifest_version(25); |
| 263 } | 287 } |
| 264 | 288 |
| 265 TEST_F(ExtensionSimpleFeatureTest, Location) { | 289 TEST_F(ExtensionSimpleFeatureTest, Location) { |
|
Yoyo Zhou
2014/04/17 23:48:21
There should be a test in here for the new locatio
not at google - send to devlin
2014/04/18 01:57:46
Done.
| |
| 266 SimpleFeature feature; | 290 SimpleFeature feature; |
| 267 | 291 |
| 268 // If the feature specifies "component" as its location, then only component | 292 // If the feature specifies "component" as its location, then only component |
| 269 // extensions can access it. | 293 // extensions can access it. |
| 270 feature.set_location(Feature::COMPONENT_LOCATION); | 294 feature.set_location(SimpleFeature::COMPONENT_LOCATION); |
| 271 EXPECT_EQ( | 295 EXPECT_EQ( |
| 272 Feature::IS_AVAILABLE, | 296 Feature::IS_AVAILABLE, |
| 273 feature.IsAvailableToManifest(std::string(), | 297 feature.IsAvailableToManifest(std::string(), |
| 274 Manifest::TYPE_UNKNOWN, | 298 Manifest::TYPE_UNKNOWN, |
| 275 Feature::COMPONENT_LOCATION, | 299 Manifest::COMPONENT, |
| 276 -1, | 300 -1, |
| 277 Feature::UNSPECIFIED_PLATFORM).result()); | 301 Feature::UNSPECIFIED_PLATFORM).result()); |
| 278 EXPECT_EQ( | 302 EXPECT_EQ( |
| 279 Feature::INVALID_LOCATION, | 303 Feature::INVALID_LOCATION, |
| 280 feature.IsAvailableToManifest(std::string(), | 304 feature.IsAvailableToManifest(std::string(), |
| 281 Manifest::TYPE_UNKNOWN, | 305 Manifest::TYPE_UNKNOWN, |
| 282 Feature::UNSPECIFIED_LOCATION, | 306 Manifest::INVALID_LOCATION, |
| 283 -1, | 307 -1, |
| 284 Feature::UNSPECIFIED_PLATFORM).result()); | 308 Feature::UNSPECIFIED_PLATFORM).result()); |
| 285 | 309 |
| 286 // But component extensions can access anything else, whatever their location. | 310 // But component extensions can access anything else, whatever their location. |
| 287 feature.set_location(Feature::UNSPECIFIED_LOCATION); | 311 feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION); |
| 288 EXPECT_EQ( | 312 EXPECT_EQ( |
| 289 Feature::IS_AVAILABLE, | 313 Feature::IS_AVAILABLE, |
| 290 feature.IsAvailableToManifest(std::string(), | 314 feature.IsAvailableToManifest(std::string(), |
| 291 Manifest::TYPE_UNKNOWN, | 315 Manifest::TYPE_UNKNOWN, |
| 292 Feature::COMPONENT_LOCATION, | 316 Manifest::COMPONENT, |
| 293 -1, | 317 -1, |
| 294 Feature::UNSPECIFIED_PLATFORM).result()); | 318 Feature::UNSPECIFIED_PLATFORM).result()); |
| 295 } | 319 } |
| 296 | 320 |
| 297 TEST_F(ExtensionSimpleFeatureTest, Platform) { | 321 TEST_F(ExtensionSimpleFeatureTest, Platform) { |
| 298 SimpleFeature feature; | 322 SimpleFeature feature; |
| 299 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); | 323 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); |
| 300 EXPECT_EQ(Feature::IS_AVAILABLE, | 324 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 301 feature.IsAvailableToManifest(std::string(), | 325 feature.IsAvailableToManifest(std::string(), |
| 302 Manifest::TYPE_UNKNOWN, | 326 Manifest::TYPE_UNKNOWN, |
| 303 Feature::UNSPECIFIED_LOCATION, | 327 Manifest::INVALID_LOCATION, |
| 304 -1, | 328 -1, |
| 305 Feature::CHROMEOS_PLATFORM).result()); | 329 Feature::CHROMEOS_PLATFORM).result()); |
| 306 EXPECT_EQ( | 330 EXPECT_EQ( |
| 307 Feature::INVALID_PLATFORM, | 331 Feature::INVALID_PLATFORM, |
| 308 feature.IsAvailableToManifest(std::string(), | 332 feature.IsAvailableToManifest(std::string(), |
| 309 Manifest::TYPE_UNKNOWN, | 333 Manifest::TYPE_UNKNOWN, |
| 310 Feature::UNSPECIFIED_LOCATION, | 334 Manifest::INVALID_LOCATION, |
| 311 -1, | 335 -1, |
| 312 Feature::UNSPECIFIED_PLATFORM).result()); | 336 Feature::UNSPECIFIED_PLATFORM).result()); |
| 313 } | 337 } |
| 314 | 338 |
| 315 TEST_F(ExtensionSimpleFeatureTest, Version) { | 339 TEST_F(ExtensionSimpleFeatureTest, Version) { |
| 316 SimpleFeature feature; | 340 SimpleFeature feature; |
| 317 feature.set_min_manifest_version(5); | 341 feature.set_min_manifest_version(5); |
| 318 | 342 |
| 319 EXPECT_EQ( | 343 EXPECT_EQ( |
| 320 Feature::INVALID_MIN_MANIFEST_VERSION, | 344 Feature::INVALID_MIN_MANIFEST_VERSION, |
| 321 feature.IsAvailableToManifest(std::string(), | 345 feature.IsAvailableToManifest(std::string(), |
| 322 Manifest::TYPE_UNKNOWN, | 346 Manifest::TYPE_UNKNOWN, |
| 323 Feature::UNSPECIFIED_LOCATION, | 347 Manifest::INVALID_LOCATION, |
| 324 0, | 348 0, |
| 325 Feature::UNSPECIFIED_PLATFORM).result()); | 349 Feature::UNSPECIFIED_PLATFORM).result()); |
| 326 EXPECT_EQ( | 350 EXPECT_EQ( |
| 327 Feature::INVALID_MIN_MANIFEST_VERSION, | 351 Feature::INVALID_MIN_MANIFEST_VERSION, |
| 328 feature.IsAvailableToManifest(std::string(), | 352 feature.IsAvailableToManifest(std::string(), |
| 329 Manifest::TYPE_UNKNOWN, | 353 Manifest::TYPE_UNKNOWN, |
| 330 Feature::UNSPECIFIED_LOCATION, | 354 Manifest::INVALID_LOCATION, |
| 331 4, | 355 4, |
| 332 Feature::UNSPECIFIED_PLATFORM).result()); | 356 Feature::UNSPECIFIED_PLATFORM).result()); |
| 333 | 357 |
| 334 EXPECT_EQ( | 358 EXPECT_EQ( |
| 335 Feature::IS_AVAILABLE, | 359 Feature::IS_AVAILABLE, |
| 336 feature.IsAvailableToManifest(std::string(), | 360 feature.IsAvailableToManifest(std::string(), |
| 337 Manifest::TYPE_UNKNOWN, | 361 Manifest::TYPE_UNKNOWN, |
| 338 Feature::UNSPECIFIED_LOCATION, | 362 Manifest::INVALID_LOCATION, |
| 339 5, | 363 5, |
| 340 Feature::UNSPECIFIED_PLATFORM).result()); | 364 Feature::UNSPECIFIED_PLATFORM).result()); |
| 341 EXPECT_EQ( | 365 EXPECT_EQ( |
| 342 Feature::IS_AVAILABLE, | 366 Feature::IS_AVAILABLE, |
| 343 feature.IsAvailableToManifest(std::string(), | 367 feature.IsAvailableToManifest(std::string(), |
| 344 Manifest::TYPE_UNKNOWN, | 368 Manifest::TYPE_UNKNOWN, |
| 345 Feature::UNSPECIFIED_LOCATION, | 369 Manifest::INVALID_LOCATION, |
| 346 10, | 370 10, |
| 347 Feature::UNSPECIFIED_PLATFORM).result()); | 371 Feature::UNSPECIFIED_PLATFORM).result()); |
| 348 | 372 |
| 349 feature.set_max_manifest_version(8); | 373 feature.set_max_manifest_version(8); |
| 350 | 374 |
| 351 EXPECT_EQ( | 375 EXPECT_EQ( |
| 352 Feature::INVALID_MAX_MANIFEST_VERSION, | 376 Feature::INVALID_MAX_MANIFEST_VERSION, |
| 353 feature.IsAvailableToManifest(std::string(), | 377 feature.IsAvailableToManifest(std::string(), |
| 354 Manifest::TYPE_UNKNOWN, | 378 Manifest::TYPE_UNKNOWN, |
| 355 Feature::UNSPECIFIED_LOCATION, | 379 Manifest::INVALID_LOCATION, |
| 356 10, | 380 10, |
| 357 Feature::UNSPECIFIED_PLATFORM).result()); | 381 Feature::UNSPECIFIED_PLATFORM).result()); |
| 358 EXPECT_EQ( | 382 EXPECT_EQ( |
| 359 Feature::IS_AVAILABLE, | 383 Feature::IS_AVAILABLE, |
| 360 feature.IsAvailableToManifest(std::string(), | 384 feature.IsAvailableToManifest(std::string(), |
| 361 Manifest::TYPE_UNKNOWN, | 385 Manifest::TYPE_UNKNOWN, |
| 362 Feature::UNSPECIFIED_LOCATION, | 386 Manifest::INVALID_LOCATION, |
| 363 8, | 387 8, |
| 364 Feature::UNSPECIFIED_PLATFORM).result()); | 388 Feature::UNSPECIFIED_PLATFORM).result()); |
| 365 EXPECT_EQ( | 389 EXPECT_EQ( |
| 366 Feature::IS_AVAILABLE, | 390 Feature::IS_AVAILABLE, |
| 367 feature.IsAvailableToManifest(std::string(), | 391 feature.IsAvailableToManifest(std::string(), |
| 368 Manifest::TYPE_UNKNOWN, | 392 Manifest::TYPE_UNKNOWN, |
| 369 Feature::UNSPECIFIED_LOCATION, | 393 Manifest::INVALID_LOCATION, |
| 370 7, | 394 7, |
| 371 Feature::UNSPECIFIED_PLATFORM).result()); | 395 Feature::UNSPECIFIED_PLATFORM).result()); |
| 372 } | 396 } |
| 373 | 397 |
| 374 TEST_F(ExtensionSimpleFeatureTest, ParseNull) { | 398 TEST_F(ExtensionSimpleFeatureTest, ParseNull) { |
| 375 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 399 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 376 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 400 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 377 feature->Parse(value.get()); | 401 feature->Parse(value.get()); |
| 378 EXPECT_TRUE(feature->whitelist()->empty()); | 402 EXPECT_TRUE(feature->whitelist()->empty()); |
| 379 EXPECT_TRUE(feature->extension_types()->empty()); | 403 EXPECT_TRUE(feature->extension_types()->empty()); |
| 380 EXPECT_TRUE(feature->GetContexts()->empty()); | 404 EXPECT_TRUE(feature->GetContexts()->empty()); |
| 381 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); | 405 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); |
| 382 EXPECT_TRUE(feature->platforms()->empty()); | 406 EXPECT_TRUE(feature->platforms()->empty()); |
| 383 EXPECT_EQ(0, feature->min_manifest_version()); | 407 EXPECT_EQ(0, feature->min_manifest_version()); |
| 384 EXPECT_EQ(0, feature->max_manifest_version()); | 408 EXPECT_EQ(0, feature->max_manifest_version()); |
| 385 } | 409 } |
| 386 | 410 |
| 387 TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) { | 411 TEST_F(ExtensionSimpleFeatureTest, ParseWhitelist) { |
| 388 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 412 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 389 base::ListValue* whitelist = new base::ListValue(); | 413 base::ListValue* whitelist = new base::ListValue(); |
| 390 whitelist->Append(new base::StringValue("foo")); | 414 whitelist->Append(new base::StringValue("foo")); |
| 391 whitelist->Append(new base::StringValue("bar")); | 415 whitelist->Append(new base::StringValue("bar")); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); | 475 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); |
| 452 feature2->Parse(value.get()); | 476 feature2->Parse(value.get()); |
| 453 EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts())); | 477 EXPECT_EQ(*(feature->GetContexts()), *(feature2->GetContexts())); |
| 454 } | 478 } |
| 455 | 479 |
| 456 TEST_F(ExtensionSimpleFeatureTest, ParseLocation) { | 480 TEST_F(ExtensionSimpleFeatureTest, ParseLocation) { |
| 457 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 481 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 458 value->SetString("location", "component"); | 482 value->SetString("location", "component"); |
| 459 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 483 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 460 feature->Parse(value.get()); | 484 feature->Parse(value.get()); |
| 461 EXPECT_EQ(Feature::COMPONENT_LOCATION, feature->location()); | 485 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location()); |
| 462 } | 486 } |
| 463 | 487 |
| 464 TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) { | 488 TEST_F(ExtensionSimpleFeatureTest, ParsePlatforms) { |
| 465 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 489 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 466 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 490 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 467 base::ListValue* platforms = new base::ListValue(); | 491 base::ListValue* platforms = new base::ListValue(); |
| 468 value->Set("platforms", platforms); | 492 value->Set("platforms", platforms); |
| 469 feature->Parse(value.get()); | 493 feature->Parse(value.get()); |
| 470 EXPECT_TRUE(feature->platforms()->empty()); | 494 EXPECT_TRUE(feature->platforms()->empty()); |
| 471 | 495 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 500 feature->Parse(value.get()); | 524 feature->Parse(value.get()); |
| 501 EXPECT_EQ(1, feature->min_manifest_version()); | 525 EXPECT_EQ(1, feature->min_manifest_version()); |
| 502 EXPECT_EQ(5, feature->max_manifest_version()); | 526 EXPECT_EQ(5, feature->max_manifest_version()); |
| 503 } | 527 } |
| 504 | 528 |
| 505 TEST_F(ExtensionSimpleFeatureTest, Inheritance) { | 529 TEST_F(ExtensionSimpleFeatureTest, Inheritance) { |
| 506 SimpleFeature feature; | 530 SimpleFeature feature; |
| 507 feature.whitelist()->insert("foo"); | 531 feature.whitelist()->insert("foo"); |
| 508 feature.extension_types()->insert(Manifest::TYPE_THEME); | 532 feature.extension_types()->insert(Manifest::TYPE_THEME); |
| 509 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); | 533 feature.GetContexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); |
| 510 feature.set_location(Feature::COMPONENT_LOCATION); | 534 feature.set_location(SimpleFeature::COMPONENT_LOCATION); |
| 511 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); | 535 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); |
| 512 feature.set_min_manifest_version(1); | 536 feature.set_min_manifest_version(1); |
| 513 feature.set_max_manifest_version(2); | 537 feature.set_max_manifest_version(2); |
| 514 | 538 |
| 515 // Test additive parsing. Parsing an empty dictionary should result in no | 539 // Test additive parsing. Parsing an empty dictionary should result in no |
| 516 // changes to a SimpleFeature. | 540 // changes to a SimpleFeature. |
| 517 base::DictionaryValue definition; | 541 base::DictionaryValue definition; |
| 518 feature.Parse(&definition); | 542 feature.Parse(&definition); |
| 519 EXPECT_EQ(1u, feature.whitelist()->size()); | 543 EXPECT_EQ(1u, feature.whitelist()->size()); |
| 520 EXPECT_EQ(1u, feature.extension_types()->size()); | 544 EXPECT_EQ(1u, feature.extension_types()->size()); |
| 521 EXPECT_EQ(1u, feature.GetContexts()->size()); | 545 EXPECT_EQ(1u, feature.GetContexts()->size()); |
| 522 EXPECT_EQ(1u, feature.whitelist()->count("foo")); | 546 EXPECT_EQ(1u, feature.whitelist()->count("foo")); |
| 523 EXPECT_EQ(Feature::COMPONENT_LOCATION, feature.location()); | 547 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location()); |
| 524 EXPECT_EQ(1u, feature.platforms()->size()); | 548 EXPECT_EQ(1u, feature.platforms()->size()); |
| 525 EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM)); | 549 EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM)); |
| 526 EXPECT_EQ(1, feature.min_manifest_version()); | 550 EXPECT_EQ(1, feature.min_manifest_version()); |
| 527 EXPECT_EQ(2, feature.max_manifest_version()); | 551 EXPECT_EQ(2, feature.max_manifest_version()); |
| 528 | 552 |
| 529 base::ListValue* whitelist = new base::ListValue(); | 553 base::ListValue* whitelist = new base::ListValue(); |
| 530 base::ListValue* extension_types = new base::ListValue(); | 554 base::ListValue* extension_types = new base::ListValue(); |
| 531 base::ListValue* contexts = new base::ListValue(); | 555 base::ListValue* contexts = new base::ListValue(); |
| 532 whitelist->Append(new base::StringValue("bar")); | 556 whitelist->Append(new base::StringValue("bar")); |
| 533 extension_types->Append(new base::StringValue("extension")); | 557 extension_types->Append(new base::StringValue("extension")); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 557 | 581 |
| 558 SimpleFeature feature; | 582 SimpleFeature feature; |
| 559 feature.AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>( | 583 feature.AddFilter(scoped_ptr<extensions::SimpleFeatureFilter>( |
| 560 new extensions::ChromeChannelFeatureFilter(&feature))); | 584 new extensions::ChromeChannelFeatureFilter(&feature))); |
| 561 if (!channel.empty()) { | 585 if (!channel.empty()) { |
| 562 base::DictionaryValue feature_value; | 586 base::DictionaryValue feature_value; |
| 563 feature_value.SetString("channel", channel); | 587 feature_value.SetString("channel", channel); |
| 564 feature.Parse(&feature_value); | 588 feature.Parse(&feature_value); |
| 565 } | 589 } |
| 566 | 590 |
| 567 return feature.IsAvailableToManifest( | 591 return feature.IsAvailableToManifest("random-extension", |
| 568 "random-extension", | 592 Manifest::TYPE_UNKNOWN, |
| 569 Manifest::TYPE_UNKNOWN, | 593 Manifest::INVALID_LOCATION, |
| 570 Feature::UNSPECIFIED_LOCATION, | 594 -1, |
| 571 -1, | 595 Feature::GetCurrentPlatform()).result(); |
| 572 Feature::GetCurrentPlatform()).result(); | |
| 573 } | 596 } |
| 574 | 597 |
| 575 TEST_F(ExtensionSimpleFeatureTest, SupportedChannel) { | 598 TEST_F(ExtensionSimpleFeatureTest, SupportedChannel) { |
| 576 // stable supported. | 599 // stable supported. |
| 577 EXPECT_EQ(Feature::IS_AVAILABLE, | 600 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 578 IsAvailableInChannel("stable", VersionInfo::CHANNEL_UNKNOWN)); | 601 IsAvailableInChannel("stable", VersionInfo::CHANNEL_UNKNOWN)); |
| 579 EXPECT_EQ(Feature::IS_AVAILABLE, | 602 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 580 IsAvailableInChannel("stable", VersionInfo::CHANNEL_CANARY)); | 603 IsAvailableInChannel("stable", VersionInfo::CHANNEL_CANARY)); |
| 581 EXPECT_EQ(Feature::IS_AVAILABLE, | 604 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 582 IsAvailableInChannel("stable", VersionInfo::CHANNEL_DEV)); | 605 IsAvailableInChannel("stable", VersionInfo::CHANNEL_DEV)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 650 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 628 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_CANARY)); | 651 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_CANARY)); |
| 629 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 652 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 630 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_DEV)); | 653 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_DEV)); |
| 631 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 654 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 632 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_BETA)); | 655 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_BETA)); |
| 633 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 656 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 634 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_STABLE)); | 657 IsAvailableInChannel("trunk", VersionInfo::CHANNEL_STABLE)); |
| 635 } | 658 } |
| 636 | 659 |
| 637 } // namespace | 660 } // namespace extensions |
| OLD | NEW |