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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/test/scoped_command_line.h" | 14 #include "base/test/scoped_command_line.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "extensions/common/features/api_feature.h" | 16 #include "extensions/common/features/api_feature.h" |
| 17 #include "extensions/common/features/complex_feature.h" | 17 #include "extensions/common/features/complex_feature.h" |
| 18 #include "extensions/common/features/feature_channel.h" | 18 #include "extensions/common/features/feature_channel.h" |
| 19 #include "extensions/common/features/json_feature_provider.h" | |
| 20 #include "extensions/common/features/permission_feature.h" | 19 #include "extensions/common/features/permission_feature.h" |
| 21 #include "extensions/common/manifest.h" | 20 #include "extensions/common/manifest.h" |
| 22 #include "extensions/common/value_builder.h" | 21 #include "extensions/common/value_builder.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 23 |
| 24 using version_info::Channel; | |
| 25 | |
| 25 namespace extensions { | 26 namespace extensions { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 struct IsAvailableTestData { | 30 struct IsAvailableTestData { |
| 30 std::string extension_id; | 31 std::string extension_id; |
| 31 Manifest::Type extension_type; | 32 Manifest::Type extension_type; |
| 32 Manifest::Location location; | 33 Manifest::Location location; |
| 33 Feature::Platform platform; | 34 Feature::Platform platform; |
| 34 int manifest_version; | 35 int manifest_version; |
| 35 Feature::AvailabilityResult expected_result; | 36 Feature::AvailabilityResult expected_result; |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 template <class FeatureClass> | 39 template <class FeatureClass> |
| 39 SimpleFeature* CreateFeature() { | 40 SimpleFeature* CreateFeature() { |
| 40 return new FeatureClass(); | 41 return new FeatureClass(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 Feature::AvailabilityResult IsAvailableInChannel( | 44 Feature::AvailabilityResult IsAvailableInChannel(Channel channel_for_feature, |
| 44 const std::string& channel, | 45 Channel channel_for_testing) { |
| 45 version_info::Channel channel_for_testing) { | |
| 46 ScopedCurrentChannel current_channel(channel_for_testing); | 46 ScopedCurrentChannel current_channel(channel_for_testing); |
| 47 | 47 |
| 48 SimpleFeature feature; | 48 SimpleFeature feature; |
| 49 | 49 feature.set_channel(channel_for_feature); |
| 50 base::DictionaryValue feature_value; | |
| 51 feature_value.SetString("channel", channel); | |
| 52 feature.Parse(&feature_value); | |
| 53 | |
| 54 return feature | 50 return feature |
| 55 .IsAvailableToManifest("random-extension", Manifest::TYPE_UNKNOWN, | 51 .IsAvailableToManifest("random-extension", Manifest::TYPE_UNKNOWN, |
| 56 Manifest::INVALID_LOCATION, -1, | 52 Manifest::INVALID_LOCATION, -1, |
| 57 Feature::GetCurrentPlatform()) | 53 Feature::GetCurrentPlatform()) |
| 58 .result(); | 54 .result(); |
| 59 } | 55 } |
| 60 | 56 |
| 61 } // namespace | 57 } // namespace |
| 62 | 58 |
| 63 class SimpleFeatureTest : public testing::Test { | 59 class SimpleFeatureTest : public testing::Test { |
| 64 protected: | 60 protected: |
| 65 SimpleFeatureTest() : current_channel_(version_info::Channel::UNKNOWN) {} | 61 SimpleFeatureTest() : current_channel_(Channel::UNKNOWN) {} |
| 66 bool LocationIsAvailable(SimpleFeature::Location feature_location, | 62 bool LocationIsAvailable(SimpleFeature::Location feature_location, |
| 67 Manifest::Location manifest_location) { | 63 Manifest::Location manifest_location) { |
| 68 SimpleFeature feature; | 64 SimpleFeature feature; |
| 69 feature.set_location(feature_location); | 65 feature.set_location(feature_location); |
| 70 Feature::AvailabilityResult availability_result = | 66 Feature::AvailabilityResult availability_result = |
| 71 feature.IsAvailableToManifest(std::string(), | 67 feature.IsAvailableToManifest(std::string(), |
| 72 Manifest::TYPE_UNKNOWN, | 68 Manifest::TYPE_UNKNOWN, |
| 73 manifest_location, | 69 manifest_location, |
| 74 -1, | 70 -1, |
| 75 Feature::UNSPECIFIED_PLATFORM).result(); | 71 Feature::UNSPECIFIED_PLATFORM).result(); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 Feature::UNSPECIFIED_PLATFORM).result()); | 515 Feature::UNSPECIFIED_PLATFORM).result()); |
| 520 EXPECT_EQ( | 516 EXPECT_EQ( |
| 521 Feature::IS_AVAILABLE, | 517 Feature::IS_AVAILABLE, |
| 522 feature.IsAvailableToManifest(std::string(), | 518 feature.IsAvailableToManifest(std::string(), |
| 523 Manifest::TYPE_UNKNOWN, | 519 Manifest::TYPE_UNKNOWN, |
| 524 Manifest::INVALID_LOCATION, | 520 Manifest::INVALID_LOCATION, |
| 525 7, | 521 7, |
| 526 Feature::UNSPECIFIED_PLATFORM).result()); | 522 Feature::UNSPECIFIED_PLATFORM).result()); |
| 527 } | 523 } |
| 528 | 524 |
| 529 TEST_F(SimpleFeatureTest, ParseNull) { | |
|
Devlin
2016/08/03 15:13:36
Failure to parse now results in a compile error.
lazyboy
2016/08/03 18:52:20
Acknowledged.
| |
| 530 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 531 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | |
| 532 feature->Parse(value.get()); | |
| 533 EXPECT_TRUE(feature->whitelist().empty()); | |
| 534 EXPECT_TRUE(feature->extension_types().empty()); | |
| 535 EXPECT_TRUE(feature->contexts().empty()); | |
| 536 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); | |
| 537 EXPECT_TRUE(feature->platforms().empty()); | |
| 538 EXPECT_EQ(0, feature->min_manifest_version()); | |
| 539 EXPECT_EQ(0, feature->max_manifest_version()); | |
| 540 } | |
| 541 | |
| 542 TEST_F(SimpleFeatureTest, ParseWhitelist) { | |
| 543 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 544 base::ListValue* whitelist = new base::ListValue(); | |
| 545 whitelist->AppendString("foo"); | |
| 546 whitelist->AppendString("bar"); | |
| 547 value->Set("whitelist", whitelist); | |
| 548 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | |
| 549 feature->Parse(value.get()); | |
| 550 EXPECT_EQ(2u, feature->whitelist().size()); | |
| 551 EXPECT_TRUE(STLCount(feature->whitelist(), "foo")); | |
| 552 EXPECT_TRUE(STLCount(feature->whitelist(), "bar")); | |
| 553 } | |
| 554 | |
| 555 TEST_F(SimpleFeatureTest, ParsePackageTypes) { | |
| 556 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 557 base::ListValue* extension_types = new base::ListValue(); | |
| 558 extension_types->AppendString("extension"); | |
| 559 extension_types->AppendString("theme"); | |
| 560 extension_types->AppendString("legacy_packaged_app"); | |
| 561 extension_types->AppendString("hosted_app"); | |
| 562 extension_types->AppendString("platform_app"); | |
| 563 extension_types->AppendString("shared_module"); | |
| 564 value->Set("extension_types", extension_types); | |
| 565 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | |
| 566 feature->Parse(value.get()); | |
| 567 EXPECT_EQ(6u, feature->extension_types().size()); | |
| 568 EXPECT_TRUE(STLCount(feature->extension_types(), Manifest::TYPE_EXTENSION)); | |
| 569 EXPECT_TRUE(STLCount(feature->extension_types(), Manifest::TYPE_THEME)); | |
| 570 EXPECT_TRUE( | |
| 571 STLCount(feature->extension_types(), Manifest::TYPE_LEGACY_PACKAGED_APP)); | |
| 572 EXPECT_TRUE(STLCount(feature->extension_types(), Manifest::TYPE_HOSTED_APP)); | |
| 573 EXPECT_TRUE( | |
| 574 STLCount(feature->extension_types(), Manifest::TYPE_PLATFORM_APP)); | |
| 575 EXPECT_TRUE( | |
| 576 STLCount(feature->extension_types(), Manifest::TYPE_SHARED_MODULE)); | |
| 577 | |
| 578 value->SetString("extension_types", "all"); | |
| 579 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); | |
| 580 feature2->Parse(value.get()); | |
| 581 EXPECT_EQ(feature->extension_types(), feature2->extension_types()); | |
| 582 } | |
| 583 | |
| 584 TEST_F(SimpleFeatureTest, ParseContexts) { | |
| 585 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 586 base::ListValue* contexts = new base::ListValue(); | |
| 587 contexts->AppendString("blessed_extension"); | |
| 588 contexts->AppendString("unblessed_extension"); | |
| 589 contexts->AppendString("content_script"); | |
| 590 contexts->AppendString("web_page"); | |
| 591 contexts->AppendString("blessed_web_page"); | |
| 592 contexts->AppendString("webui"); | |
| 593 contexts->AppendString("extension_service_worker"); | |
| 594 value->Set("contexts", contexts); | |
| 595 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | |
| 596 feature->Parse(value.get()); | |
| 597 EXPECT_EQ(7u, feature->contexts().size()); | |
| 598 EXPECT_TRUE( | |
| 599 STLCount(feature->contexts(), Feature::BLESSED_EXTENSION_CONTEXT)); | |
| 600 EXPECT_TRUE( | |
| 601 STLCount(feature->contexts(), Feature::UNBLESSED_EXTENSION_CONTEXT)); | |
| 602 EXPECT_TRUE(STLCount(feature->contexts(), Feature::CONTENT_SCRIPT_CONTEXT)); | |
| 603 EXPECT_TRUE(STLCount(feature->contexts(), Feature::WEB_PAGE_CONTEXT)); | |
| 604 EXPECT_TRUE(STLCount(feature->contexts(), Feature::BLESSED_WEB_PAGE_CONTEXT)); | |
| 605 | |
| 606 value->SetString("contexts", "all"); | |
| 607 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); | |
| 608 feature2->Parse(value.get()); | |
| 609 EXPECT_EQ(feature->contexts(), feature2->contexts()); | |
| 610 } | |
| 611 | |
| 612 TEST_F(SimpleFeatureTest, ParseLocation) { | |
| 613 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 614 value->SetString("location", "component"); | |
| 615 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | |
| 616 feature->Parse(value.get()); | |
| 617 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location()); | |
| 618 } | |
| 619 | |
| 620 TEST_F(SimpleFeatureTest, ParsePlatforms) { | |
| 621 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 622 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | |
| 623 base::ListValue* platforms = new base::ListValue(); | |
| 624 value->Set("platforms", platforms); | |
| 625 feature->Parse(value.get()); | |
| 626 EXPECT_TRUE(feature->platforms().empty()); | |
| 627 | |
| 628 platforms->AppendString("chromeos"); | |
| 629 feature->Parse(value.get()); | |
| 630 EXPECT_FALSE(feature->platforms().empty()); | |
| 631 EXPECT_EQ(Feature::CHROMEOS_PLATFORM, *feature->platforms().begin()); | |
| 632 | |
| 633 platforms->Clear(); | |
| 634 platforms->AppendString("win"); | |
| 635 feature->Parse(value.get()); | |
| 636 EXPECT_FALSE(feature->platforms().empty()); | |
| 637 EXPECT_EQ(Feature::WIN_PLATFORM, *feature->platforms().begin()); | |
| 638 | |
| 639 platforms->Clear(); | |
| 640 platforms->AppendString("win"); | |
| 641 platforms->AppendString("chromeos"); | |
| 642 feature->Parse(value.get()); | |
| 643 std::vector<Feature::Platform> expected_platforms; | |
| 644 expected_platforms.push_back(Feature::CHROMEOS_PLATFORM); | |
| 645 expected_platforms.push_back(Feature::WIN_PLATFORM); | |
| 646 | |
| 647 EXPECT_FALSE(feature->platforms().empty()); | |
| 648 EXPECT_EQ(expected_platforms, feature->platforms()); | |
| 649 } | |
| 650 | |
| 651 TEST_F(SimpleFeatureTest, ParseManifestVersion) { | |
| 652 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | |
| 653 value->SetInteger("min_manifest_version", 1); | |
| 654 value->SetInteger("max_manifest_version", 5); | |
| 655 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); | |
| 656 feature->Parse(value.get()); | |
| 657 EXPECT_EQ(1, feature->min_manifest_version()); | |
| 658 EXPECT_EQ(5, feature->max_manifest_version()); | |
| 659 } | |
| 660 | |
| 661 TEST_F(SimpleFeatureTest, Inheritance) { | |
| 662 SimpleFeature feature; | |
| 663 feature.whitelist_.push_back("foo"); | |
| 664 feature.extension_types_.push_back(Manifest::TYPE_THEME); | |
| 665 feature.contexts_.push_back(Feature::BLESSED_EXTENSION_CONTEXT); | |
| 666 feature.set_location(SimpleFeature::COMPONENT_LOCATION); | |
| 667 feature.platforms_.push_back(Feature::CHROMEOS_PLATFORM); | |
| 668 feature.set_min_manifest_version(1); | |
| 669 feature.set_max_manifest_version(2); | |
| 670 | |
| 671 // Test additive parsing. Parsing an empty dictionary should result in no | |
| 672 // changes to a SimpleFeature. | |
| 673 base::DictionaryValue definition; | |
| 674 feature.Parse(&definition); | |
| 675 EXPECT_EQ(1u, feature.whitelist().size()); | |
| 676 EXPECT_EQ(1u, feature.extension_types().size()); | |
| 677 EXPECT_EQ(1u, feature.contexts().size()); | |
| 678 EXPECT_EQ(1, STLCount(feature.whitelist(), "foo")); | |
| 679 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature.location()); | |
| 680 EXPECT_EQ(1u, feature.platforms().size()); | |
| 681 EXPECT_EQ(1, STLCount(feature.platforms(), Feature::CHROMEOS_PLATFORM)); | |
| 682 EXPECT_EQ(1, feature.min_manifest_version()); | |
| 683 EXPECT_EQ(2, feature.max_manifest_version()); | |
| 684 | |
| 685 base::ListValue* whitelist = new base::ListValue(); | |
| 686 base::ListValue* extension_types = new base::ListValue(); | |
| 687 base::ListValue* contexts = new base::ListValue(); | |
| 688 whitelist->AppendString("bar"); | |
| 689 extension_types->AppendString("extension"); | |
| 690 contexts->AppendString("unblessed_extension"); | |
| 691 definition.Set("whitelist", whitelist); | |
| 692 definition.Set("extension_types", extension_types); | |
| 693 definition.Set("contexts", contexts); | |
| 694 // Can't test location or platform because we only have one value so far. | |
| 695 definition.Set("min_manifest_version", new base::FundamentalValue(2)); | |
| 696 definition.Set("max_manifest_version", new base::FundamentalValue(3)); | |
| 697 | |
| 698 feature.Parse(&definition); | |
| 699 EXPECT_EQ(1u, feature.whitelist().size()); | |
| 700 EXPECT_EQ(1u, feature.extension_types().size()); | |
| 701 EXPECT_EQ(1u, feature.contexts().size()); | |
| 702 EXPECT_EQ(1, STLCount(feature.whitelist(), "bar")); | |
| 703 EXPECT_EQ(1, STLCount(feature.extension_types(), Manifest::TYPE_EXTENSION)); | |
| 704 EXPECT_EQ(1, | |
| 705 STLCount(feature.contexts(), Feature::UNBLESSED_EXTENSION_CONTEXT)); | |
| 706 EXPECT_EQ(2, feature.min_manifest_version()); | |
| 707 EXPECT_EQ(3, feature.max_manifest_version()); | |
| 708 } | |
| 709 | |
| 710 TEST_F(SimpleFeatureTest, CommandLineSwitch) { | 525 TEST_F(SimpleFeatureTest, CommandLineSwitch) { |
| 711 SimpleFeature feature; | 526 SimpleFeature feature; |
| 712 feature.set_command_line_switch("laser-beams"); | 527 feature.set_command_line_switch("laser-beams"); |
| 713 { | 528 { |
| 714 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 529 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 715 feature.IsAvailableToEnvironment().result()); | 530 feature.IsAvailableToEnvironment().result()); |
| 716 } | 531 } |
| 717 { | 532 { |
| 718 base::test::ScopedCommandLine scoped_command_line; | 533 base::test::ScopedCommandLine scoped_command_line; |
| 719 scoped_command_line.GetProcessCommandLine()->AppendSwitch("laser-beams"); | 534 scoped_command_line.GetProcessCommandLine()->AppendSwitch("laser-beams"); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); | 580 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); |
| 766 EXPECT_TRUE(SimpleFeature::IsIdInArray( | 581 EXPECT_TRUE(SimpleFeature::IsIdInArray( |
| 767 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); | 582 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); |
| 768 } | 583 } |
| 769 | 584 |
| 770 // Tests that all combinations of feature channel and Chrome channel correctly | 585 // Tests that all combinations of feature channel and Chrome channel correctly |
| 771 // compute feature availability. | 586 // compute feature availability. |
| 772 TEST_F(SimpleFeatureTest, SupportedChannel) { | 587 TEST_F(SimpleFeatureTest, SupportedChannel) { |
| 773 // stable supported. | 588 // stable supported. |
| 774 EXPECT_EQ(Feature::IS_AVAILABLE, | 589 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 775 IsAvailableInChannel("stable", version_info::Channel::UNKNOWN)); | 590 IsAvailableInChannel(Channel::STABLE, Channel::UNKNOWN)); |
| 776 EXPECT_EQ(Feature::IS_AVAILABLE, | 591 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 777 IsAvailableInChannel("stable", version_info::Channel::CANARY)); | 592 IsAvailableInChannel(Channel::STABLE, Channel::CANARY)); |
| 778 EXPECT_EQ(Feature::IS_AVAILABLE, | 593 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 779 IsAvailableInChannel("stable", version_info::Channel::DEV)); | 594 IsAvailableInChannel(Channel::STABLE, Channel::DEV)); |
| 780 EXPECT_EQ(Feature::IS_AVAILABLE, | 595 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 781 IsAvailableInChannel("stable", version_info::Channel::BETA)); | 596 IsAvailableInChannel(Channel::STABLE, Channel::BETA)); |
| 782 EXPECT_EQ(Feature::IS_AVAILABLE, | 597 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 783 IsAvailableInChannel("stable", version_info::Channel::STABLE)); | 598 IsAvailableInChannel(Channel::STABLE, Channel::STABLE)); |
| 784 | 599 |
| 785 // beta supported. | 600 // beta supported. |
| 786 EXPECT_EQ(Feature::IS_AVAILABLE, | 601 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 787 IsAvailableInChannel("beta", version_info::Channel::UNKNOWN)); | 602 IsAvailableInChannel(Channel::BETA, Channel::UNKNOWN)); |
| 788 EXPECT_EQ(Feature::IS_AVAILABLE, | 603 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 789 IsAvailableInChannel("beta", version_info::Channel::CANARY)); | 604 IsAvailableInChannel(Channel::BETA, Channel::CANARY)); |
| 790 EXPECT_EQ(Feature::IS_AVAILABLE, | 605 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 791 IsAvailableInChannel("beta", version_info::Channel::DEV)); | 606 IsAvailableInChannel(Channel::BETA, Channel::DEV)); |
| 792 EXPECT_EQ(Feature::IS_AVAILABLE, | 607 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 793 IsAvailableInChannel("beta", version_info::Channel::BETA)); | 608 IsAvailableInChannel(Channel::BETA, Channel::BETA)); |
| 794 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 609 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 795 IsAvailableInChannel("beta", version_info::Channel::STABLE)); | 610 IsAvailableInChannel(Channel::BETA, Channel::STABLE)); |
| 796 | 611 |
| 797 // dev supported. | 612 // dev supported. |
| 798 EXPECT_EQ(Feature::IS_AVAILABLE, | 613 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 799 IsAvailableInChannel("dev", version_info::Channel::UNKNOWN)); | 614 IsAvailableInChannel(Channel::DEV, Channel::UNKNOWN)); |
| 800 EXPECT_EQ(Feature::IS_AVAILABLE, | 615 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 801 IsAvailableInChannel("dev", version_info::Channel::CANARY)); | 616 IsAvailableInChannel(Channel::DEV, Channel::CANARY)); |
| 802 EXPECT_EQ(Feature::IS_AVAILABLE, | 617 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 803 IsAvailableInChannel("dev", version_info::Channel::DEV)); | 618 IsAvailableInChannel(Channel::DEV, Channel::DEV)); |
| 804 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 619 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 805 IsAvailableInChannel("dev", version_info::Channel::BETA)); | 620 IsAvailableInChannel(Channel::DEV, Channel::BETA)); |
| 806 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 621 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 807 IsAvailableInChannel("dev", version_info::Channel::STABLE)); | 622 IsAvailableInChannel(Channel::DEV, Channel::STABLE)); |
| 808 | 623 |
| 809 // canary supported. | 624 // canary supported. |
| 810 EXPECT_EQ(Feature::IS_AVAILABLE, | 625 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 811 IsAvailableInChannel("canary", version_info::Channel::UNKNOWN)); | 626 IsAvailableInChannel(Channel::CANARY, Channel::UNKNOWN)); |
| 812 EXPECT_EQ(Feature::IS_AVAILABLE, | 627 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 813 IsAvailableInChannel("canary", version_info::Channel::CANARY)); | 628 IsAvailableInChannel(Channel::CANARY, Channel::CANARY)); |
| 814 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 629 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 815 IsAvailableInChannel("canary", version_info::Channel::DEV)); | 630 IsAvailableInChannel(Channel::CANARY, Channel::DEV)); |
| 816 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 631 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 817 IsAvailableInChannel("canary", version_info::Channel::BETA)); | 632 IsAvailableInChannel(Channel::CANARY, Channel::BETA)); |
| 818 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 633 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 819 IsAvailableInChannel("canary", version_info::Channel::STABLE)); | 634 IsAvailableInChannel(Channel::CANARY, Channel::STABLE)); |
| 820 | 635 |
| 821 // trunk supported. | 636 // trunk supported. |
| 822 EXPECT_EQ(Feature::IS_AVAILABLE, | 637 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 823 IsAvailableInChannel("trunk", version_info::Channel::UNKNOWN)); | 638 IsAvailableInChannel(Channel::UNKNOWN, Channel::UNKNOWN)); |
| 824 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 639 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 825 IsAvailableInChannel("trunk", version_info::Channel::CANARY)); | 640 IsAvailableInChannel(Channel::UNKNOWN, Channel::CANARY)); |
| 826 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 641 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 827 IsAvailableInChannel("trunk", version_info::Channel::DEV)); | 642 IsAvailableInChannel(Channel::UNKNOWN, Channel::DEV)); |
| 828 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 643 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 829 IsAvailableInChannel("trunk", version_info::Channel::BETA)); | 644 IsAvailableInChannel(Channel::UNKNOWN, Channel::BETA)); |
| 830 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 645 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, |
| 831 IsAvailableInChannel("trunk", version_info::Channel::STABLE)); | 646 IsAvailableInChannel(Channel::UNKNOWN, Channel::STABLE)); |
| 832 } | |
| 833 | |
| 834 // Tests the validation of features with channel entries. | |
| 835 TEST_F(SimpleFeatureTest, FeatureValidation) { | |
| 836 std::string error; | |
| 837 { | |
| 838 PermissionFeature feature; | |
| 839 feature.channel_.reset( | |
| 840 new version_info::Channel(version_info::Channel::UNKNOWN)); | |
| 841 // The feature won't validate because it lacks an extension type. | |
| 842 EXPECT_FALSE(feature.Validate(&error)); | |
| 843 // If we add one, it works. | |
| 844 feature.extension_types_.push_back(Manifest::TYPE_EXTENSION); | |
| 845 EXPECT_TRUE(feature.Validate(&error)); | |
| 846 // Remove the channel, and feature1 won't validate. | |
| 847 feature.channel_.reset(); | |
| 848 EXPECT_FALSE(feature.Validate(&error)); | |
| 849 } | |
| 850 { | |
| 851 PermissionFeature feature; | |
| 852 feature.channel_.reset( | |
| 853 new version_info::Channel(version_info::Channel::UNKNOWN)); | |
| 854 feature.extension_types_.push_back(Manifest::TYPE_EXTENSION); | |
| 855 feature.contexts_.push_back(Feature::BLESSED_EXTENSION_CONTEXT); | |
| 856 // The feature won't validate because of the presence of "contexts". | |
| 857 EXPECT_FALSE(feature.Validate(&error)); | |
| 858 feature.contexts_.clear(); | |
| 859 EXPECT_TRUE(feature.Validate(&error)); | |
| 860 } | |
| 861 { | |
| 862 APIFeature feature; | |
| 863 feature.channel_.reset( | |
| 864 new version_info::Channel(version_info::Channel::STABLE)); | |
| 865 // API features require contexts. | |
| 866 EXPECT_FALSE(feature.Validate(&error)); | |
| 867 feature.contexts_.push_back(Feature::CONTENT_SCRIPT_CONTEXT); | |
| 868 EXPECT_TRUE(feature.Validate(&error)); | |
| 869 } | |
| 870 } | 647 } |
| 871 | 648 |
| 872 // Tests simple feature availability across channels. | 649 // Tests simple feature availability across channels. |
| 873 TEST_F(SimpleFeatureTest, SimpleFeatureAvailability) { | 650 TEST_F(SimpleFeatureTest, SimpleFeatureAvailability) { |
| 874 std::unique_ptr<ComplexFeature> complex_feature; | 651 std::unique_ptr<ComplexFeature> complex_feature; |
| 875 { | 652 { |
| 876 std::unique_ptr<SimpleFeature> feature1(CreateFeature<SimpleFeature>()); | 653 std::unique_ptr<SimpleFeature> feature1(CreateFeature<SimpleFeature>()); |
| 877 feature1->channel_.reset( | 654 feature1->channel_.reset(new Channel(Channel::BETA)); |
| 878 new version_info::Channel(version_info::Channel::BETA)); | |
| 879 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION); | 655 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION); |
| 880 std::unique_ptr<SimpleFeature> feature2(CreateFeature<SimpleFeature>()); | 656 std::unique_ptr<SimpleFeature> feature2(CreateFeature<SimpleFeature>()); |
| 881 feature2->channel_.reset( | 657 feature2->channel_.reset(new Channel(Channel::BETA)); |
| 882 new version_info::Channel(version_info::Channel::BETA)); | |
| 883 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); | 658 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 884 std::vector<Feature*> list; | 659 std::vector<Feature*> list; |
| 885 list.push_back(feature1.release()); | 660 list.push_back(feature1.release()); |
| 886 list.push_back(feature2.release()); | 661 list.push_back(feature2.release()); |
| 887 complex_feature.reset(new ComplexFeature(&list)); | 662 complex_feature.reset(new ComplexFeature(&list)); |
| 888 } | 663 } |
| 889 | 664 |
| 890 Feature* feature = static_cast<Feature*>(complex_feature.get()); | 665 Feature* feature = static_cast<Feature*>(complex_feature.get()); |
| 891 // Make sure both rules are applied correctly. | 666 // Make sure both rules are applied correctly. |
| 892 { | 667 { |
| 893 ScopedCurrentChannel current_channel(version_info::Channel::BETA); | 668 ScopedCurrentChannel current_channel(Channel::BETA); |
| 894 EXPECT_EQ( | 669 EXPECT_EQ( |
| 895 Feature::IS_AVAILABLE, | 670 Feature::IS_AVAILABLE, |
| 896 feature->IsAvailableToManifest("1", | 671 feature->IsAvailableToManifest("1", |
| 897 Manifest::TYPE_EXTENSION, | 672 Manifest::TYPE_EXTENSION, |
| 898 Manifest::INVALID_LOCATION, | 673 Manifest::INVALID_LOCATION, |
| 899 Feature::UNSPECIFIED_PLATFORM).result()); | 674 Feature::UNSPECIFIED_PLATFORM).result()); |
| 900 EXPECT_EQ( | 675 EXPECT_EQ( |
| 901 Feature::IS_AVAILABLE, | 676 Feature::IS_AVAILABLE, |
| 902 feature->IsAvailableToManifest("2", | 677 feature->IsAvailableToManifest("2", |
| 903 Manifest::TYPE_LEGACY_PACKAGED_APP, | 678 Manifest::TYPE_LEGACY_PACKAGED_APP, |
| 904 Manifest::INVALID_LOCATION, | 679 Manifest::INVALID_LOCATION, |
| 905 Feature::UNSPECIFIED_PLATFORM).result()); | 680 Feature::UNSPECIFIED_PLATFORM).result()); |
| 906 } | 681 } |
| 907 { | 682 { |
| 908 ScopedCurrentChannel current_channel(version_info::Channel::STABLE); | 683 ScopedCurrentChannel current_channel(Channel::STABLE); |
| 909 EXPECT_NE( | 684 EXPECT_NE( |
| 910 Feature::IS_AVAILABLE, | 685 Feature::IS_AVAILABLE, |
| 911 feature->IsAvailableToManifest("1", | 686 feature->IsAvailableToManifest("1", |
| 912 Manifest::TYPE_EXTENSION, | 687 Manifest::TYPE_EXTENSION, |
| 913 Manifest::INVALID_LOCATION, | 688 Manifest::INVALID_LOCATION, |
| 914 Feature::UNSPECIFIED_PLATFORM).result()); | 689 Feature::UNSPECIFIED_PLATFORM).result()); |
| 915 EXPECT_NE( | 690 EXPECT_NE( |
| 916 Feature::IS_AVAILABLE, | 691 Feature::IS_AVAILABLE, |
| 917 feature->IsAvailableToManifest("2", | 692 feature->IsAvailableToManifest("2", |
| 918 Manifest::TYPE_LEGACY_PACKAGED_APP, | 693 Manifest::TYPE_LEGACY_PACKAGED_APP, |
| 919 Manifest::INVALID_LOCATION, | 694 Manifest::INVALID_LOCATION, |
| 920 Feature::UNSPECIFIED_PLATFORM).result()); | 695 Feature::UNSPECIFIED_PLATFORM).result()); |
| 921 } | 696 } |
| 922 } | 697 } |
| 923 | 698 |
| 924 // Tests complex feature availability across channels. | 699 // Tests complex feature availability across channels. |
| 925 TEST_F(SimpleFeatureTest, ComplexFeatureAvailability) { | 700 TEST_F(SimpleFeatureTest, ComplexFeatureAvailability) { |
| 926 std::unique_ptr<ComplexFeature> complex_feature; | 701 std::unique_ptr<ComplexFeature> complex_feature; |
| 927 { | 702 { |
| 928 // Rule: "extension", channel trunk. | 703 // Rule: "extension", channel trunk. |
| 929 std::unique_ptr<SimpleFeature> feature1(CreateFeature<SimpleFeature>()); | 704 std::unique_ptr<SimpleFeature> feature1(CreateFeature<SimpleFeature>()); |
| 930 feature1->channel_.reset( | 705 feature1->channel_.reset(new Channel(Channel::UNKNOWN)); |
| 931 new version_info::Channel(version_info::Channel::UNKNOWN)); | |
| 932 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION); | 706 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION); |
| 933 std::unique_ptr<SimpleFeature> feature2(CreateFeature<SimpleFeature>()); | 707 std::unique_ptr<SimpleFeature> feature2(CreateFeature<SimpleFeature>()); |
| 934 // Rule: "legacy_packaged_app", channel stable. | 708 // Rule: "legacy_packaged_app", channel stable. |
| 935 feature2->channel_.reset( | 709 feature2->channel_.reset(new Channel(Channel::STABLE)); |
| 936 new version_info::Channel(version_info::Channel::STABLE)); | |
| 937 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); | 710 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); |
| 938 std::vector<Feature*> list; | 711 std::vector<Feature*> list; |
| 939 list.push_back(feature1.release()); | 712 list.push_back(feature1.release()); |
| 940 list.push_back(feature2.release()); | 713 list.push_back(feature2.release()); |
| 941 complex_feature.reset(new ComplexFeature(&list)); | 714 complex_feature.reset(new ComplexFeature(&list)); |
| 942 } | 715 } |
| 943 | 716 |
| 944 Feature* feature = static_cast<Feature*>(complex_feature.get()); | 717 Feature* feature = static_cast<Feature*>(complex_feature.get()); |
| 945 { | 718 { |
| 946 ScopedCurrentChannel current_channel(version_info::Channel::UNKNOWN); | 719 ScopedCurrentChannel current_channel(Channel::UNKNOWN); |
| 947 EXPECT_EQ(Feature::IS_AVAILABLE, | 720 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 948 feature | 721 feature |
| 949 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 722 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, |
| 950 Manifest::INVALID_LOCATION, | 723 Manifest::INVALID_LOCATION, |
| 951 Feature::UNSPECIFIED_PLATFORM) | 724 Feature::UNSPECIFIED_PLATFORM) |
| 952 .result()); | 725 .result()); |
| 953 } | 726 } |
| 954 { | 727 { |
| 955 ScopedCurrentChannel current_channel(version_info::Channel::BETA); | 728 ScopedCurrentChannel current_channel(Channel::BETA); |
| 956 EXPECT_EQ(Feature::IS_AVAILABLE, | 729 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 957 feature | 730 feature |
| 958 ->IsAvailableToManifest( | 731 ->IsAvailableToManifest( |
| 959 "2", Manifest::TYPE_LEGACY_PACKAGED_APP, | 732 "2", Manifest::TYPE_LEGACY_PACKAGED_APP, |
| 960 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM) | 733 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM) |
| 961 .result()); | 734 .result()); |
| 962 } | 735 } |
| 963 { | 736 { |
| 964 ScopedCurrentChannel current_channel(version_info::Channel::BETA); | 737 ScopedCurrentChannel current_channel(Channel::BETA); |
| 965 EXPECT_NE(Feature::IS_AVAILABLE, | 738 EXPECT_NE(Feature::IS_AVAILABLE, |
| 966 feature | 739 feature |
| 967 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 740 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, |
| 968 Manifest::INVALID_LOCATION, | 741 Manifest::INVALID_LOCATION, |
| 969 Feature::UNSPECIFIED_PLATFORM) | 742 Feature::UNSPECIFIED_PLATFORM) |
| 970 .result()); | 743 .result()); |
| 971 } | 744 } |
| 972 } | 745 } |
| 973 | 746 |
| 974 } // namespace extensions | 747 } // namespace extensions |
| OLD | NEW |