| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/test/scoped_command_line.h" | 15 #include "base/test/scoped_command_line.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "extensions/common/features/api_feature.h" | 17 #include "extensions/common/features/api_feature.h" |
| 17 #include "extensions/common/features/complex_feature.h" | 18 #include "extensions/common/features/complex_feature.h" |
| 18 #include "extensions/common/features/feature_channel.h" | 19 #include "extensions/common/features/feature_channel.h" |
| 20 #include "extensions/common/features/feature_session_type.h" |
| 19 #include "extensions/common/features/permission_feature.h" | 21 #include "extensions/common/features/permission_feature.h" |
| 20 #include "extensions/common/manifest.h" | 22 #include "extensions/common/manifest.h" |
| 21 #include "extensions/common/value_builder.h" | 23 #include "extensions/common/value_builder.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 25 |
| 24 using version_info::Channel; | 26 using version_info::Channel; |
| 25 | 27 |
| 26 namespace extensions { | 28 namespace extensions { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 struct IsAvailableTestData { | 32 struct IsAvailableTestData { |
| 31 std::string extension_id; | 33 std::string extension_id; |
| 32 Manifest::Type extension_type; | 34 Manifest::Type extension_type; |
| 33 Manifest::Location location; | 35 Manifest::Location location; |
| 34 Feature::Platform platform; | 36 Feature::Platform platform; |
| 35 int manifest_version; | 37 int manifest_version; |
| 36 Feature::AvailabilityResult expected_result; | 38 Feature::AvailabilityResult expected_result; |
| 37 }; | 39 }; |
| 38 | 40 |
| 41 struct FeatureSessionTypeTestData { |
| 42 std::string desc; |
| 43 Feature::AvailabilityResult expected_availability; |
| 44 FeatureSessionType current_session_type; |
| 45 std::initializer_list<FeatureSessionType> feature_session_types; |
| 46 }; |
| 47 |
| 39 template <class FeatureClass> | 48 template <class FeatureClass> |
| 40 SimpleFeature* CreateFeature() { | 49 SimpleFeature* CreateFeature() { |
| 41 return new FeatureClass(); | 50 return new FeatureClass(); |
| 42 } | 51 } |
| 43 | 52 |
| 44 Feature::AvailabilityResult IsAvailableInChannel(Channel channel_for_feature, | 53 Feature::AvailabilityResult IsAvailableInChannel(Channel channel_for_feature, |
| 45 Channel channel_for_testing) { | 54 Channel channel_for_testing) { |
| 46 ScopedCurrentChannel current_channel(channel_for_testing); | 55 ScopedCurrentChannel current_channel(channel_for_testing); |
| 47 | 56 |
| 48 SimpleFeature feature; | 57 SimpleFeature feature; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 Feature::CHROMEOS_PLATFORM).result()); | 400 Feature::CHROMEOS_PLATFORM).result()); |
| 392 feature.set_min_manifest_version(21); | 401 feature.set_min_manifest_version(21); |
| 393 | 402 |
| 394 feature.set_max_manifest_version(18); | 403 feature.set_max_manifest_version(18); |
| 395 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( | 404 EXPECT_EQ(Feature::INVALID_MAX_MANIFEST_VERSION, feature.IsAvailableToContext( |
| 396 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, | 405 extension.get(), Feature::BLESSED_EXTENSION_CONTEXT, |
| 397 Feature::CHROMEOS_PLATFORM).result()); | 406 Feature::CHROMEOS_PLATFORM).result()); |
| 398 feature.set_max_manifest_version(25); | 407 feature.set_max_manifest_version(25); |
| 399 } | 408 } |
| 400 | 409 |
| 410 TEST_F(SimpleFeatureTest, SessionType) { |
| 411 base::DictionaryValue manifest; |
| 412 manifest.SetString("name", "test"); |
| 413 manifest.SetString("version", "1"); |
| 414 manifest.SetInteger("manifest_version", 2); |
| 415 manifest.SetString("app.launch.local_path", "foo.html"); |
| 416 |
| 417 std::string error; |
| 418 scoped_refptr<const Extension> extension( |
| 419 Extension::Create(base::FilePath(), Manifest::INTERNAL, manifest, |
| 420 Extension::NO_FLAGS, &error)); |
| 421 EXPECT_EQ("", error); |
| 422 ASSERT_TRUE(extension.get()); |
| 423 |
| 424 const FeatureSessionTypeTestData kTestData[] = { |
| 425 {"kiosk_feature in kiosk session", |
| 426 Feature::IS_AVAILABLE, |
| 427 FeatureSessionType::KIOSK, |
| 428 {FeatureSessionType::KIOSK}}, |
| 429 {"kiosk feature in regular session", |
| 430 Feature::INVALID_SESSION_TYPE, |
| 431 FeatureSessionType::REGULAR, |
| 432 {FeatureSessionType::KIOSK}}, |
| 433 {"kiosk feature in unknown session", |
| 434 Feature::INVALID_SESSION_TYPE, |
| 435 FeatureSessionType::UNKNOWN, |
| 436 {FeatureSessionType::KIOSK}}, |
| 437 {"kiosk feature in initial session", |
| 438 Feature::INVALID_SESSION_TYPE, |
| 439 FeatureSessionType::INITIAL, |
| 440 {FeatureSessionType::KIOSK}}, |
| 441 {"non kiosk feature in kiosk session", |
| 442 Feature::INVALID_SESSION_TYPE, |
| 443 FeatureSessionType::KIOSK, |
| 444 {FeatureSessionType::REGULAR}}, |
| 445 {"non kiosk feature in regular session", |
| 446 Feature::IS_AVAILABLE, |
| 447 FeatureSessionType::REGULAR, |
| 448 {FeatureSessionType::REGULAR}}, |
| 449 {"non kiosk feature in unknown session", |
| 450 Feature::INVALID_SESSION_TYPE, |
| 451 FeatureSessionType::UNKNOWN, |
| 452 {FeatureSessionType::REGULAR}}, |
| 453 {"non kiosk feature in initial session", |
| 454 Feature::INVALID_SESSION_TYPE, |
| 455 FeatureSessionType::INITIAL, |
| 456 {FeatureSessionType::REGULAR}}, |
| 457 {"session agnostic feature in kiosk session", |
| 458 Feature::IS_AVAILABLE, |
| 459 FeatureSessionType::KIOSK, |
| 460 {}}, |
| 461 {"session agnostic feature in regular session", |
| 462 Feature::IS_AVAILABLE, |
| 463 FeatureSessionType::REGULAR, |
| 464 {}}, |
| 465 {"session agnostic feature in unknown session", |
| 466 Feature::IS_AVAILABLE, |
| 467 FeatureSessionType::UNKNOWN, |
| 468 {}}, |
| 469 {"feature with multiple session types", |
| 470 Feature::IS_AVAILABLE, |
| 471 FeatureSessionType::REGULAR, |
| 472 {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK}}, |
| 473 {"feature with multiple session types in unknown session", |
| 474 Feature::INVALID_SESSION_TYPE, |
| 475 FeatureSessionType::UNKNOWN, |
| 476 {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK}}, |
| 477 {"feature with multiple session types in initial session", |
| 478 Feature::INVALID_SESSION_TYPE, |
| 479 FeatureSessionType::INITIAL, |
| 480 {FeatureSessionType::REGULAR, FeatureSessionType::KIOSK}}}; |
| 481 |
| 482 for (size_t i = 0; i < arraysize(kTestData); ++i) { |
| 483 std::unique_ptr<base::AutoReset<FeatureSessionType>> current_session( |
| 484 ScopedCurrentFeatureSessionType(kTestData[i].current_session_type)); |
| 485 |
| 486 SimpleFeature feature; |
| 487 feature.set_session_types(kTestData[i].feature_session_types); |
| 488 |
| 489 EXPECT_EQ(kTestData[i].expected_availability, |
| 490 feature |
| 491 .IsAvailableToContext(extension.get(), |
| 492 Feature::BLESSED_EXTENSION_CONTEXT, |
| 493 Feature::CHROMEOS_PLATFORM) |
| 494 .result()) |
| 495 << "Failed test '" << kTestData[i].desc << "'."; |
| 496 |
| 497 EXPECT_EQ( |
| 498 kTestData[i].expected_availability, |
| 499 feature |
| 500 .IsAvailableToManifest(extension->id(), Manifest::TYPE_UNKNOWN, |
| 501 Manifest::INVALID_LOCATION, -1, |
| 502 Feature::CHROMEOS_PLATFORM) |
| 503 .result()) |
| 504 << "Failed test '" << kTestData[i].desc << "'."; |
| 505 } |
| 506 } |
| 507 |
| 401 TEST_F(SimpleFeatureTest, Location) { | 508 TEST_F(SimpleFeatureTest, Location) { |
| 402 // Component extensions can access any location. | 509 // Component extensions can access any location. |
| 403 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, | 510 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::COMPONENT_LOCATION, |
| 404 Manifest::COMPONENT)); | 511 Manifest::COMPONENT)); |
| 405 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, | 512 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::EXTERNAL_COMPONENT_LOCATION, |
| 406 Manifest::COMPONENT)); | 513 Manifest::COMPONENT)); |
| 407 EXPECT_TRUE( | 514 EXPECT_TRUE( |
| 408 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT)); | 515 LocationIsAvailable(SimpleFeature::POLICY_LOCATION, Manifest::COMPONENT)); |
| 409 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION, | 516 EXPECT_TRUE(LocationIsAvailable(SimpleFeature::UNSPECIFIED_LOCATION, |
| 410 Manifest::COMPONENT)); | 517 Manifest::COMPONENT)); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 EXPECT_NE(Feature::IS_AVAILABLE, | 845 EXPECT_NE(Feature::IS_AVAILABLE, |
| 739 feature | 846 feature |
| 740 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 847 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, |
| 741 Manifest::INVALID_LOCATION, | 848 Manifest::INVALID_LOCATION, |
| 742 Feature::UNSPECIFIED_PLATFORM) | 849 Feature::UNSPECIFIED_PLATFORM) |
| 743 .result()); | 850 .result()); |
| 744 } | 851 } |
| 745 } | 852 } |
| 746 | 853 |
| 747 } // namespace extensions | 854 } // namespace extensions |
| OLD | NEW |