| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "extensions/common/manifest.h" | 12 #include "extensions/common/manifest.h" |
| 12 #include "extensions/common/value_builder.h" | 13 #include "extensions/common/value_builder.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace extensions { | 16 namespace extensions { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 struct IsAvailableTestData { | 20 struct IsAvailableTestData { |
| 20 std::string extension_id; | 21 std::string extension_id; |
| 21 Manifest::Type extension_type; | 22 Manifest::Type extension_type; |
| 22 Manifest::Location location; | 23 Manifest::Location location; |
| 23 Feature::Platform platform; | 24 Feature::Platform platform; |
| 24 int manifest_version; | 25 int manifest_version; |
| 25 Feature::AvailabilityResult expected_result; | 26 Feature::AvailabilityResult expected_result; |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 bool LocationIsAvailable(SimpleFeature::Location feature_location, | |
| 29 Manifest::Location manifest_location) { | |
| 30 SimpleFeature feature; | |
| 31 feature.set_location(feature_location); | |
| 32 Feature::AvailabilityResult availability_result = | |
| 33 feature.IsAvailableToManifest(std::string(), | |
| 34 Manifest::TYPE_UNKNOWN, | |
| 35 manifest_location, | |
| 36 -1, | |
| 37 Feature::UNSPECIFIED_PLATFORM).result(); | |
| 38 return availability_result == Feature::IS_AVAILABLE; | |
| 39 } | |
| 40 | |
| 41 class ScopedCommandLineSwitch { | 29 class ScopedCommandLineSwitch { |
| 42 public: | 30 public: |
| 43 explicit ScopedCommandLineSwitch(const std::string& arg) | 31 explicit ScopedCommandLineSwitch(const std::string& arg) |
| 44 : original_command_line_(*base::CommandLine::ForCurrentProcess()) { | 32 : original_command_line_(*base::CommandLine::ForCurrentProcess()) { |
| 45 base::CommandLine::ForCurrentProcess()->AppendSwitch(arg); | 33 base::CommandLine::ForCurrentProcess()->AppendSwitch(arg); |
| 46 } | 34 } |
| 47 | 35 |
| 48 ~ScopedCommandLineSwitch() { | 36 ~ScopedCommandLineSwitch() { |
| 49 *base::CommandLine::ForCurrentProcess() = original_command_line_; | 37 *base::CommandLine::ForCurrentProcess() = original_command_line_; |
| 50 } | 38 } |
| 51 | 39 |
| 52 private: | 40 private: |
| 53 base::CommandLine original_command_line_; | 41 base::CommandLine original_command_line_; |
| 54 }; | 42 }; |
| 55 | 43 |
| 56 } // namespace | 44 } // namespace |
| 57 | 45 |
| 58 TEST(SimpleFeatureTest, IsAvailableNullCase) { | 46 class SimpleFeatureTest : public testing::Test { |
| 47 protected: |
| 48 bool LocationIsAvailable(SimpleFeature::Location feature_location, |
| 49 Manifest::Location manifest_location) { |
| 50 SimpleFeature feature; |
| 51 feature.set_location(feature_location); |
| 52 Feature::AvailabilityResult availability_result = |
| 53 feature.IsAvailableToManifest(std::string(), |
| 54 Manifest::TYPE_UNKNOWN, |
| 55 manifest_location, |
| 56 -1, |
| 57 Feature::UNSPECIFIED_PLATFORM).result(); |
| 58 return availability_result == Feature::IS_AVAILABLE; |
| 59 } |
| 60 }; |
| 61 |
| 62 TEST_F(SimpleFeatureTest, IsAvailableNullCase) { |
| 59 const IsAvailableTestData tests[] = { | 63 const IsAvailableTestData tests[] = { |
| 60 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, | 64 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 61 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, | 65 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 62 {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, | 66 {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 63 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, | 67 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 64 {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION, | 68 {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION, |
| 65 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, | 69 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 66 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, | 70 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 67 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, | 71 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 68 {"", Manifest::TYPE_UNKNOWN, Manifest::COMPONENT, | 72 {"", Manifest::TYPE_UNKNOWN, Manifest::COMPONENT, |
| 69 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, | 73 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 70 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, | 74 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 71 Feature::CHROMEOS_PLATFORM, -1, Feature::IS_AVAILABLE}, | 75 Feature::CHROMEOS_PLATFORM, -1, Feature::IS_AVAILABLE}, |
| 72 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, | 76 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, |
| 73 Feature::UNSPECIFIED_PLATFORM, 25, Feature::IS_AVAILABLE}}; | 77 Feature::UNSPECIFIED_PLATFORM, 25, Feature::IS_AVAILABLE}}; |
| 74 | 78 |
| 75 SimpleFeature feature; | 79 SimpleFeature feature; |
| 76 for (size_t i = 0; i < arraysize(tests); ++i) { | 80 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 77 const IsAvailableTestData& test = tests[i]; | 81 const IsAvailableTestData& test = tests[i]; |
| 78 EXPECT_EQ(test.expected_result, | 82 EXPECT_EQ(test.expected_result, |
| 79 feature.IsAvailableToManifest(test.extension_id, | 83 feature.IsAvailableToManifest(test.extension_id, |
| 80 test.extension_type, | 84 test.extension_type, |
| 81 test.location, | 85 test.location, |
| 82 test.manifest_version, | 86 test.manifest_version, |
| 83 test.platform).result()); | 87 test.platform).result()); |
| 84 } | 88 } |
| 85 } | 89 } |
| 86 | 90 |
| 87 TEST(SimpleFeatureTest, Whitelist) { | 91 TEST_F(SimpleFeatureTest, Whitelist) { |
| 88 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); | 92 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); |
| 89 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); | 93 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); |
| 90 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); | 94 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); |
| 91 SimpleFeature feature; | 95 SimpleFeature feature; |
| 92 feature.whitelist()->insert(kIdFoo); | 96 feature.whitelist()->push_back(kIdFoo); |
| 93 feature.whitelist()->insert(kIdBar); | 97 feature.whitelist()->push_back(kIdBar); |
| 94 | 98 |
| 95 EXPECT_EQ( | 99 EXPECT_EQ( |
| 96 Feature::IS_AVAILABLE, | 100 Feature::IS_AVAILABLE, |
| 97 feature.IsAvailableToManifest(kIdFoo, | 101 feature.IsAvailableToManifest(kIdFoo, |
| 98 Manifest::TYPE_UNKNOWN, | 102 Manifest::TYPE_UNKNOWN, |
| 99 Manifest::INVALID_LOCATION, | 103 Manifest::INVALID_LOCATION, |
| 100 -1, | 104 -1, |
| 101 Feature::UNSPECIFIED_PLATFORM).result()); | 105 Feature::UNSPECIFIED_PLATFORM).result()); |
| 102 EXPECT_EQ( | 106 EXPECT_EQ( |
| 103 Feature::IS_AVAILABLE, | 107 Feature::IS_AVAILABLE, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 115 -1, | 119 -1, |
| 116 Feature::UNSPECIFIED_PLATFORM).result()); | 120 Feature::UNSPECIFIED_PLATFORM).result()); |
| 117 EXPECT_EQ( | 121 EXPECT_EQ( |
| 118 Feature::NOT_FOUND_IN_WHITELIST, | 122 Feature::NOT_FOUND_IN_WHITELIST, |
| 119 feature.IsAvailableToManifest(std::string(), | 123 feature.IsAvailableToManifest(std::string(), |
| 120 Manifest::TYPE_UNKNOWN, | 124 Manifest::TYPE_UNKNOWN, |
| 121 Manifest::INVALID_LOCATION, | 125 Manifest::INVALID_LOCATION, |
| 122 -1, | 126 -1, |
| 123 Feature::UNSPECIFIED_PLATFORM).result()); | 127 Feature::UNSPECIFIED_PLATFORM).result()); |
| 124 | 128 |
| 125 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); | 129 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 126 EXPECT_EQ( | 130 EXPECT_EQ( |
| 127 Feature::NOT_FOUND_IN_WHITELIST, | 131 Feature::NOT_FOUND_IN_WHITELIST, |
| 128 feature.IsAvailableToManifest(kIdBaz, | 132 feature.IsAvailableToManifest(kIdBaz, |
| 129 Manifest::TYPE_LEGACY_PACKAGED_APP, | 133 Manifest::TYPE_LEGACY_PACKAGED_APP, |
| 130 Manifest::INVALID_LOCATION, | 134 Manifest::INVALID_LOCATION, |
| 131 -1, | 135 -1, |
| 132 Feature::UNSPECIFIED_PLATFORM).result()); | 136 Feature::UNSPECIFIED_PLATFORM).result()); |
| 133 } | 137 } |
| 134 | 138 |
| 135 TEST(SimpleFeatureTest, HashedIdWhitelist) { | 139 TEST_F(SimpleFeatureTest, HashedIdWhitelist) { |
| 136 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | | 140 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | |
| 137 // sha1sum | tr '[:lower:]' '[:upper:]' | 141 // sha1sum | tr '[:lower:]' '[:upper:]' |
| 138 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); | 142 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); |
| 139 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); | 143 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); |
| 140 SimpleFeature feature; | 144 SimpleFeature feature; |
| 141 | 145 |
| 142 feature.whitelist()->insert(kIdFooHashed); | 146 feature.whitelist()->push_back(kIdFooHashed); |
| 143 | 147 |
| 144 EXPECT_EQ( | 148 EXPECT_EQ( |
| 145 Feature::IS_AVAILABLE, | 149 Feature::IS_AVAILABLE, |
| 146 feature.IsAvailableToManifest(kIdFoo, | 150 feature.IsAvailableToManifest(kIdFoo, |
| 147 Manifest::TYPE_UNKNOWN, | 151 Manifest::TYPE_UNKNOWN, |
| 148 Manifest::INVALID_LOCATION, | 152 Manifest::INVALID_LOCATION, |
| 149 -1, | 153 -1, |
| 150 Feature::UNSPECIFIED_PLATFORM).result()); | 154 Feature::UNSPECIFIED_PLATFORM).result()); |
| 151 EXPECT_NE( | 155 EXPECT_NE( |
| 152 Feature::IS_AVAILABLE, | 156 Feature::IS_AVAILABLE, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 164 Feature::UNSPECIFIED_PLATFORM).result()); | 168 Feature::UNSPECIFIED_PLATFORM).result()); |
| 165 EXPECT_EQ( | 169 EXPECT_EQ( |
| 166 Feature::NOT_FOUND_IN_WHITELIST, | 170 Feature::NOT_FOUND_IN_WHITELIST, |
| 167 feature.IsAvailableToManifest("tooshortforanextensionid", | 171 feature.IsAvailableToManifest("tooshortforanextensionid", |
| 168 Manifest::TYPE_UNKNOWN, | 172 Manifest::TYPE_UNKNOWN, |
| 169 Manifest::INVALID_LOCATION, | 173 Manifest::INVALID_LOCATION, |
| 170 -1, | 174 -1, |
| 171 Feature::UNSPECIFIED_PLATFORM).result()); | 175 Feature::UNSPECIFIED_PLATFORM).result()); |
| 172 } | 176 } |
| 173 | 177 |
| 174 TEST(SimpleFeatureTest, Blacklist) { | 178 TEST_F(SimpleFeatureTest, Blacklist) { |
| 175 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); | 179 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); |
| 176 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); | 180 const std::string kIdBar("barabbbbccccddddeeeeffffgggghhhh"); |
| 177 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); | 181 const std::string kIdBaz("bazabbbbccccddddeeeeffffgggghhhh"); |
| 178 SimpleFeature feature; | 182 SimpleFeature feature; |
| 179 feature.blacklist()->insert(kIdFoo); | 183 feature.blacklist()->push_back(kIdFoo); |
| 180 feature.blacklist()->insert(kIdBar); | 184 feature.blacklist()->push_back(kIdBar); |
| 181 | 185 |
| 182 EXPECT_EQ( | 186 EXPECT_EQ( |
| 183 Feature::FOUND_IN_BLACKLIST, | 187 Feature::FOUND_IN_BLACKLIST, |
| 184 feature.IsAvailableToManifest(kIdFoo, | 188 feature.IsAvailableToManifest(kIdFoo, |
| 185 Manifest::TYPE_UNKNOWN, | 189 Manifest::TYPE_UNKNOWN, |
| 186 Manifest::INVALID_LOCATION, | 190 Manifest::INVALID_LOCATION, |
| 187 -1, | 191 -1, |
| 188 Feature::UNSPECIFIED_PLATFORM).result()); | 192 Feature::UNSPECIFIED_PLATFORM).result()); |
| 189 EXPECT_EQ( | 193 EXPECT_EQ( |
| 190 Feature::FOUND_IN_BLACKLIST, | 194 Feature::FOUND_IN_BLACKLIST, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 203 Feature::UNSPECIFIED_PLATFORM).result()); | 207 Feature::UNSPECIFIED_PLATFORM).result()); |
| 204 EXPECT_EQ( | 208 EXPECT_EQ( |
| 205 Feature::IS_AVAILABLE, | 209 Feature::IS_AVAILABLE, |
| 206 feature.IsAvailableToManifest(std::string(), | 210 feature.IsAvailableToManifest(std::string(), |
| 207 Manifest::TYPE_UNKNOWN, | 211 Manifest::TYPE_UNKNOWN, |
| 208 Manifest::INVALID_LOCATION, | 212 Manifest::INVALID_LOCATION, |
| 209 -1, | 213 -1, |
| 210 Feature::UNSPECIFIED_PLATFORM).result()); | 214 Feature::UNSPECIFIED_PLATFORM).result()); |
| 211 } | 215 } |
| 212 | 216 |
| 213 TEST(SimpleFeatureTest, HashedIdBlacklist) { | 217 TEST_F(SimpleFeatureTest, HashedIdBlacklist) { |
| 214 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | | 218 // echo -n "fooabbbbccccddddeeeeffffgggghhhh" | |
| 215 // sha1sum | tr '[:lower:]' '[:upper:]' | 219 // sha1sum | tr '[:lower:]' '[:upper:]' |
| 216 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); | 220 const std::string kIdFoo("fooabbbbccccddddeeeeffffgggghhhh"); |
| 217 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); | 221 const std::string kIdFooHashed("55BC7228A0D502A2A48C9BB16B07062A01E62897"); |
| 218 SimpleFeature feature; | 222 SimpleFeature feature; |
| 219 | 223 |
| 220 feature.blacklist()->insert(kIdFooHashed); | 224 feature.blacklist()->push_back(kIdFooHashed); |
| 221 | 225 |
| 222 EXPECT_EQ( | 226 EXPECT_EQ( |
| 223 Feature::FOUND_IN_BLACKLIST, | 227 Feature::FOUND_IN_BLACKLIST, |
| 224 feature.IsAvailableToManifest(kIdFoo, | 228 feature.IsAvailableToManifest(kIdFoo, |
| 225 Manifest::TYPE_UNKNOWN, | 229 Manifest::TYPE_UNKNOWN, |
| 226 Manifest::INVALID_LOCATION, | 230 Manifest::INVALID_LOCATION, |
| 227 -1, | 231 -1, |
| 228 Feature::UNSPECIFIED_PLATFORM).result()); | 232 Feature::UNSPECIFIED_PLATFORM).result()); |
| 229 EXPECT_NE( | 233 EXPECT_NE( |
| 230 Feature::FOUND_IN_BLACKLIST, | 234 Feature::FOUND_IN_BLACKLIST, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 242 Feature::UNSPECIFIED_PLATFORM).result()); | 246 Feature::UNSPECIFIED_PLATFORM).result()); |
| 243 EXPECT_EQ( | 247 EXPECT_EQ( |
| 244 Feature::IS_AVAILABLE, | 248 Feature::IS_AVAILABLE, |
| 245 feature.IsAvailableToManifest("tooshortforanextensionid", | 249 feature.IsAvailableToManifest("tooshortforanextensionid", |
| 246 Manifest::TYPE_UNKNOWN, | 250 Manifest::TYPE_UNKNOWN, |
| 247 Manifest::INVALID_LOCATION, | 251 Manifest::INVALID_LOCATION, |
| 248 -1, | 252 -1, |
| 249 Feature::UNSPECIFIED_PLATFORM).result()); | 253 Feature::UNSPECIFIED_PLATFORM).result()); |
| 250 } | 254 } |
| 251 | 255 |
| 252 TEST(SimpleFeatureTest, PackageType) { | 256 TEST_F(SimpleFeatureTest, PackageType) { |
| 253 SimpleFeature feature; | 257 SimpleFeature feature; |
| 254 feature.extension_types()->insert(Manifest::TYPE_EXTENSION); | 258 feature.extension_types()->push_back(Manifest::TYPE_EXTENSION); |
| 255 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); | 259 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 256 | 260 |
| 257 EXPECT_EQ( | 261 EXPECT_EQ( |
| 258 Feature::IS_AVAILABLE, | 262 Feature::IS_AVAILABLE, |
| 259 feature.IsAvailableToManifest(std::string(), | 263 feature.IsAvailableToManifest(std::string(), |
| 260 Manifest::TYPE_EXTENSION, | 264 Manifest::TYPE_EXTENSION, |
| 261 Manifest::INVALID_LOCATION, | 265 Manifest::INVALID_LOCATION, |
| 262 -1, | 266 -1, |
| 263 Feature::UNSPECIFIED_PLATFORM).result()); | 267 Feature::UNSPECIFIED_PLATFORM).result()); |
| 264 EXPECT_EQ( | 268 EXPECT_EQ( |
| 265 Feature::IS_AVAILABLE, | 269 Feature::IS_AVAILABLE, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 278 Feature::UNSPECIFIED_PLATFORM).result()); | 282 Feature::UNSPECIFIED_PLATFORM).result()); |
| 279 EXPECT_EQ( | 283 EXPECT_EQ( |
| 280 Feature::INVALID_TYPE, | 284 Feature::INVALID_TYPE, |
| 281 feature.IsAvailableToManifest(std::string(), | 285 feature.IsAvailableToManifest(std::string(), |
| 282 Manifest::TYPE_THEME, | 286 Manifest::TYPE_THEME, |
| 283 Manifest::INVALID_LOCATION, | 287 Manifest::INVALID_LOCATION, |
| 284 -1, | 288 -1, |
| 285 Feature::UNSPECIFIED_PLATFORM).result()); | 289 Feature::UNSPECIFIED_PLATFORM).result()); |
| 286 } | 290 } |
| 287 | 291 |
| 288 TEST(SimpleFeatureTest, Context) { | 292 TEST_F(SimpleFeatureTest, Context) { |
| 289 SimpleFeature feature; | 293 SimpleFeature feature; |
| 290 feature.set_name("somefeature"); | 294 feature.set_name("somefeature"); |
| 291 feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); | 295 feature.contexts()->push_back(Feature::BLESSED_EXTENSION_CONTEXT); |
| 292 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); | 296 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 293 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); | 297 feature.platforms()->push_back(Feature::CHROMEOS_PLATFORM); |
| 294 feature.set_min_manifest_version(21); | 298 feature.set_min_manifest_version(21); |
| 295 feature.set_max_manifest_version(25); | 299 feature.set_max_manifest_version(25); |
| 296 | 300 |
| 297 base::DictionaryValue manifest; | 301 base::DictionaryValue manifest; |
| 298 manifest.SetString("name", "test"); | 302 manifest.SetString("name", "test"); |
| 299 manifest.SetString("version", "1"); | 303 manifest.SetString("version", "1"); |
| 300 manifest.SetInteger("manifest_version", 21); | 304 manifest.SetInteger("manifest_version", 21); |
| 301 manifest.SetString("app.launch.local_path", "foo.html"); | 305 manifest.SetString("app.launch.local_path", "foo.html"); |
| 302 | 306 |
| 303 std::string error; | 307 std::string error; |
| 304 scoped_refptr<const Extension> extension(Extension::Create( | 308 scoped_refptr<const Extension> extension(Extension::Create( |
| 305 base::FilePath(), Manifest::INTERNAL, manifest, Extension::NO_FLAGS, | 309 base::FilePath(), Manifest::INTERNAL, manifest, Extension::NO_FLAGS, |
| 306 &error)); | 310 &error)); |
| 307 EXPECT_EQ("", error); | 311 EXPECT_EQ("", error); |
| 308 ASSERT_TRUE(extension.get()); | 312 ASSERT_TRUE(extension.get()); |
| 309 | 313 |
| 310 feature.whitelist()->insert("monkey"); | 314 feature.whitelist()->push_back("monkey"); |
| 311 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToContext( | 315 EXPECT_EQ(Feature::NOT_FOUND_IN_WHITELIST, feature.IsAvailableToContext( |
| 312 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 316 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 313 Feature::CHROMEOS_PLATFORM).result()); | 317 Feature::CHROMEOS_PLATFORM).result()); |
| 314 feature.whitelist()->clear(); | 318 feature.whitelist()->clear(); |
| 315 | 319 |
| 316 feature.extension_types()->clear(); | 320 feature.extension_types()->clear(); |
| 317 feature.extension_types()->insert(Manifest::TYPE_THEME); | 321 feature.extension_types()->push_back(Manifest::TYPE_THEME); |
| 318 { | 322 { |
| 319 Feature::Availability availability = feature.IsAvailableToContext( | 323 Feature::Availability availability = feature.IsAvailableToContext( |
| 320 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 324 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 321 Feature::CHROMEOS_PLATFORM); | 325 Feature::CHROMEOS_PLATFORM); |
| 322 EXPECT_EQ(Feature::INVALID_TYPE, availability.result()); | 326 EXPECT_EQ(Feature::INVALID_TYPE, availability.result()); |
| 323 EXPECT_EQ("'somefeature' is only allowed for themes, " | 327 EXPECT_EQ("'somefeature' is only allowed for themes, " |
| 324 "but this is a legacy packaged app.", | 328 "but this is a legacy packaged app.", |
| 325 availability.message()); | 329 availability.message()); |
| 326 } | 330 } |
| 327 | 331 |
| 328 feature.extension_types()->clear(); | 332 feature.extension_types()->clear(); |
| 329 feature.extension_types()->insert(Manifest::TYPE_LEGACY_PACKAGED_APP); | 333 feature.extension_types()->push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 330 feature.contexts()->clear(); | 334 feature.contexts()->clear(); |
| 331 feature.contexts()->insert(Feature::UNBLESSED_EXTENSION_CONTEXT); | 335 feature.contexts()->push_back(Feature::UNBLESSED_EXTENSION_CONTEXT); |
| 332 feature.contexts()->insert(Feature::CONTENT_SCRIPT_CONTEXT); | 336 feature.contexts()->push_back(Feature::CONTENT_SCRIPT_CONTEXT); |
| 333 { | 337 { |
| 334 Feature::Availability availability = feature.IsAvailableToContext( | 338 Feature::Availability availability = feature.IsAvailableToContext( |
| 335 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 339 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 336 Feature::CHROMEOS_PLATFORM); | 340 Feature::CHROMEOS_PLATFORM); |
| 337 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); | 341 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); |
| 338 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes and " | 342 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes and " |
| 339 "content scripts, but this is a privileged page", | 343 "content scripts, but this is a privileged page", |
| 340 availability.message()); | 344 availability.message()); |
| 341 } | 345 } |
| 342 | 346 |
| 343 feature.contexts()->insert(Feature::WEB_PAGE_CONTEXT); | 347 feature.contexts()->push_back(Feature::WEB_PAGE_CONTEXT); |
| 344 { | 348 { |
| 345 Feature::Availability availability = feature.IsAvailableToContext( | 349 Feature::Availability availability = feature.IsAvailableToContext( |
| 346 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 350 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 347 Feature::CHROMEOS_PLATFORM); | 351 Feature::CHROMEOS_PLATFORM); |
| 348 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); | 352 EXPECT_EQ(Feature::INVALID_CONTEXT, availability.result()); |
| 349 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes, " | 353 EXPECT_EQ("'somefeature' is only allowed to run in extension iframes, " |
| 350 "content scripts, and web pages, but this is a privileged page", | 354 "content scripts, and web pages, but this is a privileged page", |
| 351 availability.message()); | 355 availability.message()); |
| 352 } | 356 } |
| 353 | 357 |
| 354 feature.contexts()->clear(); | 358 feature.contexts()->clear(); |
| 355 feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); | 359 feature.contexts()->push_back(Feature::BLESSED_EXTENSION_CONTEXT); |
| 356 feature.set_location(SimpleFeature::COMPONENT_LOCATION); | 360 feature.set_location(SimpleFeature::COMPONENT_LOCATION); |
| 357 EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext( | 361 EXPECT_EQ(Feature::INVALID_LOCATION, feature.IsAvailableToContext( |
| 358 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 362 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 359 Feature::CHROMEOS_PLATFORM).result()); | 363 Feature::CHROMEOS_PLATFORM).result()); |
| 360 feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION); | 364 feature.set_location(SimpleFeature::UNSPECIFIED_LOCATION); |
| 361 | 365 |
| 362 EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext( | 366 EXPECT_EQ(Feature::INVALID_PLATFORM, feature.IsAvailableToContext( |
| 363 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 367 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 364 Feature::UNSPECIFIED_PLATFORM).result()); | 368 Feature::UNSPECIFIED_PLATFORM).result()); |
| 365 | 369 |
| 366 feature.set_min_manifest_version(22); | 370 feature.set_min_manifest_version(22); |
| 367 EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION, feature.IsAvailableToContext( | 371 EXPECT_EQ(Feature::INVALID_MIN_MANIFEST_VERSION, feature.IsAvailableToContext( |
| 368 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 372 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 369 Feature::CHROMEOS_PLATFORM).result()); | 373 Feature::CHROMEOS_PLATFORM).result()); |
| 370 feature.set_min_manifest_version(21); | 374 feature.set_min_manifest_version(21); |
| 371 | 375 |
| 372 feature.set_max_manifest_version(18); | 376 feature.set_max_manifest_version(18); |
| 373 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( | 377 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( |
| 374 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 378 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 375 Feature::CHROMEOS_PLATFORM).result()); | 379 Feature::CHROMEOS_PLATFORM).result()); |
| 376 feature.set_max_manifest_version(25); | 380 feature.set_max_manifest_version(25); |
| 377 } | 381 } |
| 378 | 382 |
| 379 TEST(SimpleFeatureTest, Location) { | 383 TEST_F(SimpleFeatureTest, Location) { |
| 380 // Component extensions can access any location. | 384 // Component extensions can access any location. |
| 381 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, | 385 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, |
| 382 Manifest::COMPONENT)); | 386 Manifest::COMPONENT)); |
| 383 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, | 387 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, |
| 384 Manifest::COMPONENT)); | 388 Manifest::COMPONENT)); |
| 385 EXPECT_TRUE( | 389 EXPECT_TRUE( |
| 386 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT)); | 390 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT)); |
| 387 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION, | 391 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION, |
| 388 Manifest::COMPONENT)); | 392 Manifest::COMPONENT)); |
| 389 | 393 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 416 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::UNPACKED)); | 420 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::UNPACKED)); |
| 417 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION, | 421 EXPECT_FALSE(LocationIsAvailable(SimpleFeature::POLICY_LOCATION, |
| 418 Manifest::EXTERNAL_PREF_DOWNLOAD)); | 422 Manifest::EXTERNAL_PREF_DOWNLOAD)); |
| 419 | 423 |
| 420 // External component extensions can access the "external_component" | 424 // External component extensions can access the "external_component" |
| 421 // location. | 425 // location. |
| 422 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, | 426 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, |
| 423 Manifest::EXTERNAL_COMPONENT)); | 427 Manifest::EXTERNAL_COMPONENT)); |
| 424 } | 428 } |
| 425 | 429 |
| 426 TEST(SimpleFeatureTest, Platform) { | 430 TEST_F(SimpleFeatureTest, Platform) { |
| 427 SimpleFeature feature; | 431 SimpleFeature feature; |
| 428 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); | 432 feature.platforms()->push_back(Feature::CHROMEOS_PLATFORM); |
| 429 EXPECT_EQ(Feature::IS_AVAILABLE, | 433 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 430 feature.IsAvailableToManifest(std::string(), | 434 feature.IsAvailableToManifest(std::string(), |
| 431 Manifest::TYPE_UNKNOWN, | 435 Manifest::TYPE_UNKNOWN, |
| 432 Manifest::INVALID_LOCATION, | 436 Manifest::INVALID_LOCATION, |
| 433 -1, | 437 -1, |
| 434 Feature::CHROMEOS_PLATFORM).result()); | 438 Feature::CHROMEOS_PLATFORM).result()); |
| 435 EXPECT_EQ( | 439 EXPECT_EQ( |
| 436 Feature::INVALID_PLATFORM, | 440 Feature::INVALID_PLATFORM, |
| 437 feature.IsAvailableToManifest(std::string(), | 441 feature.IsAvailableToManifest(std::string(), |
| 438 Manifest::TYPE_UNKNOWN, | 442 Manifest::TYPE_UNKNOWN, |
| 439 Manifest::INVALID_LOCATION, | 443 Manifest::INVALID_LOCATION, |
| 440 -1, | 444 -1, |
| 441 Feature::UNSPECIFIED_PLATFORM).result()); | 445 Feature::UNSPECIFIED_PLATFORM).result()); |
| 442 } | 446 } |
| 443 | 447 |
| 444 TEST(SimpleFeatureTest, ManifestVersion) { | 448 TEST_F(SimpleFeatureTest, ManifestVersion) { |
| 445 SimpleFeature feature; | 449 SimpleFeature feature; |
| 446 feature.set_min_manifest_version(5); | 450 feature.set_min_manifest_version(5); |
| 447 | 451 |
| 448 EXPECT_EQ( | 452 EXPECT_EQ( |
| 449 Feature::INVALID_MIN_MANIFEST_VERSION, | 453 Feature::INVALID_MIN_MANIFEST_VERSION, |
| 450 feature.IsAvailableToManifest(std::string(), | 454 feature.IsAvailableToManifest(std::string(), |
| 451 Manifest::TYPE_UNKNOWN, | 455 Manifest::TYPE_UNKNOWN, |
| 452 Manifest::INVALID_LOCATION, | 456 Manifest::INVALID_LOCATION, |
| 453 0, | 457 0, |
| 454 Feature::UNSPECIFIED_PLATFORM).result()); | 458 Feature::UNSPECIFIED_PLATFORM).result()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 Feature::UNSPECIFIED_PLATFORM).result()); | 497 Feature::UNSPECIFIED_PLATFORM).result()); |
| 494 EXPECT_EQ( | 498 EXPECT_EQ( |
| 495 Feature::IS_AVAILABLE, | 499 Feature::IS_AVAILABLE, |
| 496 feature.IsAvailableToManifest(std::string(), | 500 feature.IsAvailableToManifest(std::string(), |
| 497 Manifest::TYPE_UNKNOWN, | 501 Manifest::TYPE_UNKNOWN, |
| 498 Manifest::INVALID_LOCATION, | 502 Manifest::INVALID_LOCATION, |
| 499 7, | 503 7, |
| 500 Feature::UNSPECIFIED_PLATFORM).result()); | 504 Feature::UNSPECIFIED_PLATFORM).result()); |
| 501 } | 505 } |
| 502 | 506 |
| 503 TEST(SimpleFeatureTest, ParseNull) { | 507 TEST_F(SimpleFeatureTest, ParseNull) { |
| 504 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 508 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 505 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 509 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 506 feature->Parse(value.get()); | 510 feature->Parse(value.get()); |
| 507 EXPECT_TRUE(feature->whitelist()->empty()); | 511 EXPECT_TRUE(feature->whitelist()->empty()); |
| 508 EXPECT_TRUE(feature->extension_types()->empty()); | 512 EXPECT_TRUE(feature->extension_types()->empty()); |
| 509 EXPECT_TRUE(feature->contexts()->empty()); | 513 EXPECT_TRUE(feature->contexts()->empty()); |
| 510 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); | 514 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); |
| 511 EXPECT_TRUE(feature->platforms()->empty()); | 515 EXPECT_TRUE(feature->platforms()->empty()); |
| 512 EXPECT_EQ(0, feature->min_manifest_version()); | 516 EXPECT_EQ(0, feature->min_manifest_version()); |
| 513 EXPECT_EQ(0, feature->max_manifest_version()); | 517 EXPECT_EQ(0, feature->max_manifest_version()); |
| 514 } | 518 } |
| 515 | 519 |
| 516 TEST(SimpleFeatureTest, ParseWhitelist) { | 520 TEST_F(SimpleFeatureTest, ParseWhitelist) { |
| 517 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 521 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 518 base::ListValue* whitelist = new base::ListValue(); | 522 base::ListValue* whitelist = new base::ListValue(); |
| 519 whitelist->Append(new base::StringValue("foo")); | 523 whitelist->Append(new base::StringValue("foo")); |
| 520 whitelist->Append(new base::StringValue("bar")); | 524 whitelist->Append(new base::StringValue("bar")); |
| 521 value->Set("whitelist", whitelist); | 525 value->Set("whitelist", whitelist); |
| 522 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 526 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 523 feature->Parse(value.get()); | 527 feature->Parse(value.get()); |
| 524 EXPECT_EQ(2u, feature->whitelist()->size()); | 528 EXPECT_EQ(2u, feature->whitelist()->size()); |
| 525 EXPECT_TRUE(feature->whitelist()->count("foo")); | 529 EXPECT_TRUE(STLCount(feature->whitelist(), "foo")); |
| 526 EXPECT_TRUE(feature->whitelist()->count("bar")); | 530 EXPECT_TRUE(STLCount(feature->whitelist(), "bar")); |
| 527 } | 531 } |
| 528 | 532 |
| 529 TEST(SimpleFeatureTest, ParsePackageTypes) { | 533 TEST_F(SimpleFeatureTest, ParsePackageTypes) { |
| 530 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 534 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 531 base::ListValue* extension_types = new base::ListValue(); | 535 base::ListValue* extension_types = new base::ListValue(); |
| 532 extension_types->Append(new base::StringValue("extension")); | 536 extension_types->Append(new base::StringValue("extension")); |
| 533 extension_types->Append(new base::StringValue("theme")); | 537 extension_types->Append(new base::StringValue("theme")); |
| 534 extension_types->Append(new base::StringValue("legacy_packaged_app")); | 538 extension_types->Append(new base::StringValue("legacy_packaged_app")); |
| 535 extension_types->Append(new base::StringValue("hosted_app")); | 539 extension_types->Append(new base::StringValue("hosted_app")); |
| 536 extension_types->Append(new base::StringValue("platform_app")); | 540 extension_types->Append(new base::StringValue("platform_app")); |
| 537 extension_types->Append(new base::StringValue("shared_module")); | 541 extension_types->Append(new base::StringValue("shared_module")); |
| 538 value->Set("extension_types", extension_types); | 542 value->Set("extension_types", extension_types); |
| 539 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 543 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 540 feature->Parse(value.get()); | 544 feature->Parse(value.get()); |
| 541 EXPECT_EQ(6u, feature->extension_types()->size()); | 545 EXPECT_EQ(6u, feature->extension_types()->size()); |
| 542 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_EXTENSION)); | 546 EXPECT_TRUE( |
| 543 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_THEME)); | 547 STLCount(feature->extension_types(), Manifest::TYPE_EXTENSION)); |
| 544 EXPECT_TRUE(feature->extension_types()->count( | 548 EXPECT_TRUE( |
| 545 Manifest::TYPE_LEGACY_PACKAGED_APP)); | 549 STLCount(feature->extension_types(), Manifest::TYPE_THEME)); |
| 546 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_HOSTED_APP)); | 550 EXPECT_TRUE( |
| 547 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_PLATFORM_APP)); | 551 STLCount(feature->extension_types(), Manifest::TYPE_LEGACY_PACKAGED_APP)); |
| 548 EXPECT_TRUE(feature->extension_types()->count(Manifest::TYPE_SHARED_MODULE)); | 552 EXPECT_TRUE( |
| 553 STLCount(feature->extension_types(), Manifest::TYPE_HOSTED_APP)); |
| 554 EXPECT_TRUE( |
| 555 STLCount(feature->extension_types(), Manifest::TYPE_PLATFORM_APP)); |
| 556 EXPECT_TRUE( |
| 557 STLCount(feature->extension_types(), Manifest::TYPE_SHARED_MODULE)); |
| 549 | 558 |
| 550 value->SetString("extension_types", "all"); | 559 value->SetString("extension_types", "all"); |
| 551 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); | 560 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); |
| 552 feature2->Parse(value.get()); | 561 feature2->Parse(value.get()); |
| 553 EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types())); | 562 EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types())); |
| 554 } | 563 } |
| 555 | 564 |
| 556 TEST(SimpleFeatureTest, ParseContexts) { | 565 TEST_F(SimpleFeatureTest, ParseContexts) { |
| 557 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 566 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 558 base::ListValue* contexts = new base::ListValue(); | 567 base::ListValue* contexts = new base::ListValue(); |
| 559 contexts->Append(new base::StringValue("blessed_extension")); | 568 contexts->Append(new base::StringValue("blessed_extension")); |
| 560 contexts->Append(new base::StringValue("unblessed_extension")); | 569 contexts->Append(new base::StringValue("unblessed_extension")); |
| 561 contexts->Append(new base::StringValue("content_script")); | 570 contexts->Append(new base::StringValue("content_script")); |
| 562 contexts->Append(new base::StringValue("web_page")); | 571 contexts->Append(new base::StringValue("web_page")); |
| 563 contexts->Append(new base::StringValue("blessed_web_page")); | 572 contexts->Append(new base::StringValue("blessed_web_page")); |
| 564 contexts->Append(new base::StringValue("webui")); | 573 contexts->Append(new base::StringValue("webui")); |
| 565 value->Set("contexts", contexts); | 574 value->Set("contexts", contexts); |
| 566 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 575 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 567 feature->Parse(value.get()); | 576 feature->Parse(value.get()); |
| 568 EXPECT_EQ(6u, feature->contexts()->size()); | 577 EXPECT_EQ(6u, feature->contexts()->size()); |
| 569 EXPECT_TRUE(feature->contexts()->count(Feature::BLESSED_EXTENSION_CONTEXT)); | 578 EXPECT_TRUE( |
| 570 EXPECT_TRUE(feature->contexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT)); | 579 STLCount(feature->contexts(), Feature::BLESSED_EXTENSION_CONTEXT)); |
| 571 EXPECT_TRUE(feature->contexts()->count(Feature::CONTENT_SCRIPT_CONTEXT)); | 580 EXPECT_TRUE( |
| 572 EXPECT_TRUE(feature->contexts()->count(Feature::WEB_PAGE_CONTEXT)); | 581 STLCount(feature->contexts(), Feature::UNBLESSED_EXTENSION_CONTEXT)); |
| 573 EXPECT_TRUE(feature->contexts()->count(Feature::BLESSED_WEB_PAGE_CONTEXT)); | 582 EXPECT_TRUE( |
| 583 STLCount(feature->contexts(), Feature::CONTENT_SCRIPT_CONTEXT)); |
| 584 EXPECT_TRUE( |
| 585 STLCount(feature->contexts(), Feature::WEB_PAGE_CONTEXT)); |
| 586 EXPECT_TRUE( |
| 587 STLCount(feature->contexts(), Feature::BLESSED_WEB_PAGE_CONTEXT)); |
| 574 | 588 |
| 575 value->SetString("contexts", "all"); | 589 value->SetString("contexts", "all"); |
| 576 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); | 590 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); |
| 577 feature2->Parse(value.get()); | 591 feature2->Parse(value.get()); |
| 578 EXPECT_EQ(*(feature->contexts()), *(feature2->contexts())); | 592 EXPECT_EQ(*(feature->contexts()), *(feature2->contexts())); |
| 579 } | 593 } |
| 580 | 594 |
| 581 TEST(SimpleFeatureTest, ParseLocation) { | 595 TEST_F(SimpleFeatureTest, ParseLocation) { |
| 582 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 596 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 583 value->SetString("location", "component"); | 597 value->SetString("location", "component"); |
| 584 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 598 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 585 feature->Parse(value.get()); | 599 feature->Parse(value.get()); |
| 586 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location()); | 600 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location()); |
| 587 } | 601 } |
| 588 | 602 |
| 589 TEST(SimpleFeatureTest, ParsePlatforms) { | 603 TEST_F(SimpleFeatureTest, ParsePlatforms) { |
| 590 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 604 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 591 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 605 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 592 base::ListValue* platforms = new base::ListValue(); | 606 base::ListValue* platforms = new base::ListValue(); |
| 593 value->Set("platforms", platforms); | 607 value->Set("platforms", platforms); |
| 594 feature->Parse(value.get()); | 608 feature->Parse(value.get()); |
| 595 EXPECT_TRUE(feature->platforms()->empty()); | 609 EXPECT_TRUE(feature->platforms()->empty()); |
| 596 | 610 |
| 597 platforms->AppendString("chromeos"); | 611 platforms->AppendString("chromeos"); |
| 598 feature->Parse(value.get()); | 612 feature->Parse(value.get()); |
| 599 EXPECT_FALSE(feature->platforms()->empty()); | 613 EXPECT_FALSE(feature->platforms()->empty()); |
| 600 EXPECT_EQ(Feature::CHROMEOS_PLATFORM, *feature->platforms()->begin()); | 614 EXPECT_EQ(Feature::CHROMEOS_PLATFORM, *feature->platforms()->begin()); |
| 601 | 615 |
| 602 platforms->Clear(); | 616 platforms->Clear(); |
| 603 platforms->AppendString("win"); | 617 platforms->AppendString("win"); |
| 604 feature->Parse(value.get()); | 618 feature->Parse(value.get()); |
| 605 EXPECT_FALSE(feature->platforms()->empty()); | 619 EXPECT_FALSE(feature->platforms()->empty()); |
| 606 EXPECT_EQ(Feature::WIN_PLATFORM, *feature->platforms()->begin()); | 620 EXPECT_EQ(Feature::WIN_PLATFORM, *feature->platforms()->begin()); |
| 607 | 621 |
| 608 platforms->Clear(); | 622 platforms->Clear(); |
| 609 platforms->AppendString("win"); | 623 platforms->AppendString("win"); |
| 610 platforms->AppendString("chromeos"); | 624 platforms->AppendString("chromeos"); |
| 611 feature->Parse(value.get()); | 625 feature->Parse(value.get()); |
| 612 std::set<Feature::Platform> expected_platforms; | 626 std::vector<Feature::Platform> expected_platforms; |
| 613 expected_platforms.insert(Feature::CHROMEOS_PLATFORM); | 627 expected_platforms.push_back(Feature::CHROMEOS_PLATFORM); |
| 614 expected_platforms.insert(Feature::WIN_PLATFORM); | 628 expected_platforms.push_back(Feature::WIN_PLATFORM); |
| 615 | 629 |
| 616 EXPECT_FALSE(feature->platforms()->empty()); | 630 EXPECT_FALSE(feature->platforms()->empty()); |
| 617 EXPECT_EQ(expected_platforms, *feature->platforms()); | 631 EXPECT_EQ(expected_platforms, *feature->platforms()); |
| 618 } | 632 } |
| 619 | 633 |
| 620 TEST(SimpleFeatureTest, ParseManifestVersion) { | 634 TEST_F(SimpleFeatureTest, ParseManifestVersion) { |
| 621 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 635 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 622 value->SetInteger("min_manifest_version", 1); | 636 value->SetInteger("min_manifest_version", 1); |
| 623 value->SetInteger("max_manifest_version", 5); | 637 value->SetInteger("max_manifest_version", 5); |
| 624 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 638 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 625 feature->Parse(value.get()); | 639 feature->Parse(value.get()); |
| 626 EXPECT_EQ(1, feature->min_manifest_version()); | 640 EXPECT_EQ(1, feature->min_manifest_version()); |
| 627 EXPECT_EQ(5, feature->max_manifest_version()); | 641 EXPECT_EQ(5, feature->max_manifest_version()); |
| 628 } | 642 } |
| 629 | 643 |
| 630 TEST(SimpleFeatureTest, Inheritance) { | 644 TEST_F(SimpleFeatureTest, Inheritance) { |
| 631 SimpleFeature feature; | 645 SimpleFeature feature; |
| 632 feature.whitelist()->insert("foo"); | 646 feature.whitelist()->push_back("foo"); |
| 633 feature.extension_types()->insert(Manifest::TYPE_THEME); | 647 feature.extension_types()->push_back(Manifest::TYPE_THEME); |
| 634 feature.contexts()->insert(Feature::BLESSED_EXTENSION_CONTEXT); | 648 feature.contexts()->push_back(Feature::BLESSED_EXTENSION_CONTEXT); |
| 635 feature.set_location(SimpleFeature::COMPONENT_LOCATION); | 649 feature.set_location(SimpleFeature::COMPONENT_LOCATION); |
| 636 feature.platforms()->insert(Feature::CHROMEOS_PLATFORM); | 650 feature.platforms()->push_back(Feature::CHROMEOS_PLATFORM); |
| 637 feature.set_min_manifest_version(1); | 651 feature.set_min_manifest_version(1); |
| 638 feature.set_max_manifest_version(2); | 652 feature.set_max_manifest_version(2); |
| 639 | 653 |
| 640 // Test additive parsing. Parsing an empty dictionary should result in no | 654 // Test additive parsing. Parsing an empty dictionary should result in no |
| 641 // changes to a SimpleFeature. | 655 // changes to a SimpleFeature. |
| 642 base::DictionaryValue definition; | 656 base::DictionaryValue definition; |
| 643 feature.Parse(&definition); | 657 feature.Parse(&definition); |
| 644 EXPECT_EQ(1u, feature.whitelist()->size()); | 658 EXPECT_EQ(1u, feature.whitelist()->size()); |
| 645 EXPECT_EQ(1u, feature.extension_types()->size()); | 659 EXPECT_EQ(1u, feature.extension_types()->size()); |
| 646 EXPECT_EQ(1u, feature.contexts()->size()); | 660 EXPECT_EQ(1u, feature.contexts()->size()); |
| 647 EXPECT_EQ(1u, feature.whitelist()->count("foo")); | 661 EXPECT_EQ(1u, STLCount(feature.whitelist(), "foo")); |
| 648 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location()); | 662 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location()); |
| 649 EXPECT_EQ(1u, feature.platforms()->size()); | 663 EXPECT_EQ(1u, feature.platforms()->size()); |
| 650 EXPECT_EQ(1u, feature.platforms()->count(Feature::CHROMEOS_PLATFORM)); | 664 EXPECT_EQ(1u, STLCount(feature.platforms(), Feature::CHROMEOS_PLATFORM)); |
| 651 EXPECT_EQ(1, feature.min_manifest_version()); | 665 EXPECT_EQ(1, feature.min_manifest_version()); |
| 652 EXPECT_EQ(2, feature.max_manifest_version()); | 666 EXPECT_EQ(2, feature.max_manifest_version()); |
| 653 | 667 |
| 654 base::ListValue* whitelist = new base::ListValue(); | 668 base::ListValue* whitelist = new base::ListValue(); |
| 655 base::ListValue* extension_types = new base::ListValue(); | 669 base::ListValue* extension_types = new base::ListValue(); |
| 656 base::ListValue* contexts = new base::ListValue(); | 670 base::ListValue* contexts = new base::ListValue(); |
| 657 whitelist->Append(new base::StringValue("bar")); | 671 whitelist->Append(new base::StringValue("bar")); |
| 658 extension_types->Append(new base::StringValue("extension")); | 672 extension_types->Append(new base::StringValue("extension")); |
| 659 contexts->Append(new base::StringValue("unblessed_extension")); | 673 contexts->Append(new base::StringValue("unblessed_extension")); |
| 660 definition.Set("whitelist", whitelist); | 674 definition.Set("whitelist", whitelist); |
| 661 definition.Set("extension_types", extension_types); | 675 definition.Set("extension_types", extension_types); |
| 662 definition.Set("contexts", contexts); | 676 definition.Set("contexts", contexts); |
| 663 // Can't test location or platform because we only have one value so far. | 677 // Can't test location or platform because we only have one value so far. |
| 664 definition.Set("min_manifest_version", new base::FundamentalValue(2)); | 678 definition.Set("min_manifest_version", new base::FundamentalValue(2)); |
| 665 definition.Set("max_manifest_version", new base::FundamentalValue(3)); | 679 definition.Set("max_manifest_version", new base::FundamentalValue(3)); |
| 666 | 680 |
| 667 feature.Parse(&definition); | 681 feature.Parse(&definition); |
| 668 EXPECT_EQ(1u, feature.whitelist()->size()); | 682 EXPECT_EQ(1u, feature.whitelist()->size()); |
| 669 EXPECT_EQ(1u, feature.extension_types()->size()); | 683 EXPECT_EQ(1u, feature.extension_types()->size()); |
| 670 EXPECT_EQ(1u, feature.contexts()->size()); | 684 EXPECT_EQ(1u, feature.contexts()->size()); |
| 671 EXPECT_EQ(1u, feature.whitelist()->count("bar")); | 685 EXPECT_EQ(1u, STLCount(feature.whitelist(), "bar")); |
| 672 EXPECT_EQ(1u, feature.extension_types()->count(Manifest::TYPE_EXTENSION)); | 686 EXPECT_EQ(1u, STLCount(feature.extension_types(), Manifest::TYPE_EXTENSION)); |
| 673 EXPECT_EQ(1u, | 687 EXPECT_EQ(1u, |
| 674 feature.contexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT)); | 688 STLCount(feature.contexts(), Feature::UNBLESSED_EXTENSION_CONTEXT)); |
| 675 EXPECT_EQ(2, feature.min_manifest_version()); | 689 EXPECT_EQ(2, feature.min_manifest_version()); |
| 676 EXPECT_EQ(3, feature.max_manifest_version()); | 690 EXPECT_EQ(3, feature.max_manifest_version()); |
| 677 } | 691 } |
| 678 | 692 |
| 679 TEST(SimpleFeatureTest, CommandLineSwitch) { | 693 TEST_F(SimpleFeatureTest, CommandLineSwitch) { |
| 680 SimpleFeature feature; | 694 SimpleFeature feature; |
| 681 feature.set_command_line_switch("laser-beams"); | 695 feature.set_command_line_switch("laser-beams"); |
| 682 { | 696 { |
| 683 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 697 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 684 feature.IsAvailableToEnvironment().result()); | 698 feature.IsAvailableToEnvironment().result()); |
| 685 } | 699 } |
| 686 { | 700 { |
| 687 ScopedCommandLineSwitch scoped_switch("laser-beams"); | 701 ScopedCommandLineSwitch scoped_switch("laser-beams"); |
| 688 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 702 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 689 feature.IsAvailableToEnvironment().result()); | 703 feature.IsAvailableToEnvironment().result()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 703 EXPECT_EQ(Feature::IS_AVAILABLE, | 717 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 704 feature.IsAvailableToEnvironment().result()); | 718 feature.IsAvailableToEnvironment().result()); |
| 705 } | 719 } |
| 706 { | 720 { |
| 707 ScopedCommandLineSwitch scoped_switch("laser-beams=0"); | 721 ScopedCommandLineSwitch scoped_switch("laser-beams=0"); |
| 708 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 722 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 709 feature.IsAvailableToEnvironment().result()); | 723 feature.IsAvailableToEnvironment().result()); |
| 710 } | 724 } |
| 711 } | 725 } |
| 712 | 726 |
| 727 TEST_F(SimpleFeatureTest, IsIdInArray) { |
| 728 EXPECT_FALSE(SimpleFeature::IsIdInArray("", {}, 0)); |
| 729 EXPECT_FALSE(SimpleFeature::IsIdInArray( |
| 730 "bbbbccccdddddddddeeeeeeffffgghhh", {}, 0)); |
| 731 |
| 732 const char* const kIdArray[] = { |
| 733 "bbbbccccdddddddddeeeeeeffffgghhh", |
| 734 // aaaabbbbccccddddeeeeffffgggghhhh |
| 735 "9A0417016F345C934A1A88F55CA17C05014EEEBA" |
| 736 }; |
| 737 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray))); |
| 738 EXPECT_FALSE(SimpleFeature::IsIdInArray( |
| 739 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray))); |
| 740 EXPECT_TRUE(SimpleFeature::IsIdInArray( |
| 741 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); |
| 742 EXPECT_TRUE(SimpleFeature::IsIdInArray( |
| 743 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); |
| 744 } |
| 745 |
| 713 } // namespace extensions | 746 } // namespace extensions |
| OLD | NEW |