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 #include <vector> | 10 #include <vector> | 
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 | 
| 39 struct FeatureSessionTypeTestData { | 39 struct FeatureSessionTypeTestData { | 
| 40 std::string desc; | 40 std::string desc; | 
| 41 Feature::AvailabilityResult expected_availability; | 41 Feature::AvailabilityResult expected_availability; | 
| 42 FeatureSessionType current_session_type; | 42 FeatureSessionType current_session_type; | 
| 43 std::initializer_list<FeatureSessionType> feature_session_types; | 43 std::initializer_list<FeatureSessionType> feature_session_types; | 
| 44 }; | 44 }; | 
| 45 | 45 | 
| 46 Feature::AvailabilityResult IsAvailableInChannel(Channel channel_for_feature, | 46 Feature::AvailabilityResult IsAvailableInChannel(Channel channel_for_feature, | 
| 47 Channel channel_for_testing) { | 47 Channel channel_for_testing) { | 
| 48 ScopedCurrentChannel current_channel(channel_for_testing); | |
| 49 | |
| 50 SimpleFeature feature; | 48 SimpleFeature feature; | 
| 51 feature.set_channel(channel_for_feature); | 49 feature.set_channel(channel_for_feature); | 
| 52 return feature | 50 return feature.IsAvailableToChannel(channel_for_testing).result(); | 
| 53 .IsAvailableToManifest("random-extension", Manifest::TYPE_UNKNOWN, | |
| 54 Manifest::INVALID_LOCATION, -1, | |
| 55 Feature::GetCurrentPlatform()) | |
| 56 .result(); | |
| 57 } | 51 } | 
| 58 | 52 | 
| 59 } // namespace | 53 } // namespace | 
| 60 | 54 | 
| 61 class SimpleFeatureTest : public testing::Test { | 55 class SimpleFeatureTest : public testing::Test { | 
| 62 protected: | 56 protected: | 
| 63 SimpleFeatureTest() : current_channel_(Channel::UNKNOWN) {} | 57 SimpleFeatureTest() : current_channel_(Channel::UNKNOWN) {} | 
| 64 bool LocationIsAvailable(SimpleFeature::Location feature_location, | 58 bool LocationIsAvailable(SimpleFeature::Location feature_location, | 
| 65 Manifest::Location manifest_location) { | 59 Manifest::Location manifest_location) { | 
| 66 SimpleFeature feature; | 60 SimpleFeature feature; | 
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 749 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 
| 756 IsAvailableInChannel(Channel::UNKNOWN, Channel::CANARY)); | 750 IsAvailableInChannel(Channel::UNKNOWN, Channel::CANARY)); | 
| 757 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 751 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 
| 758 IsAvailableInChannel(Channel::UNKNOWN, Channel::DEV)); | 752 IsAvailableInChannel(Channel::UNKNOWN, Channel::DEV)); | 
| 759 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 753 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 
| 760 IsAvailableInChannel(Channel::UNKNOWN, Channel::BETA)); | 754 IsAvailableInChannel(Channel::UNKNOWN, Channel::BETA)); | 
| 761 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 755 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | 
| 762 IsAvailableInChannel(Channel::UNKNOWN, Channel::STABLE)); | 756 IsAvailableInChannel(Channel::UNKNOWN, Channel::STABLE)); | 
| 763 } | 757 } | 
| 764 | 758 | 
| 765 // Tests simple feature availability across channels. | |
| 766 TEST_F(SimpleFeatureTest, SimpleFeatureAvailability) { | |
| 
 
karandeepb
2017/02/18 02:00:29
Deleted this test (Diff isn't clear on that). It w
 
 | |
| 767 std::unique_ptr<ComplexFeature> complex_feature; | |
| 768 { | |
| 769 std::unique_ptr<SimpleFeature> feature1(new SimpleFeature()); | |
| 770 feature1->channel_.reset(new Channel(Channel::BETA)); | |
| 771 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION); | |
| 772 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); | |
| 773 feature2->channel_.reset(new Channel(Channel::BETA)); | |
| 774 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); | |
| 775 std::vector<Feature*> list; | |
| 776 list.push_back(feature1.release()); | |
| 777 list.push_back(feature2.release()); | |
| 778 complex_feature.reset(new ComplexFeature(&list)); | |
| 779 } | |
| 780 | |
| 781 Feature* feature = static_cast<Feature*>(complex_feature.get()); | |
| 782 // Make sure both rules are applied correctly. | |
| 783 { | |
| 784 ScopedCurrentChannel current_channel(Channel::BETA); | |
| 785 EXPECT_EQ( | |
| 786 Feature::IS_AVAILABLE, | |
| 787 feature->IsAvailableToManifest("1", | |
| 788 Manifest::TYPE_EXTENSION, | |
| 789 Manifest::INVALID_LOCATION, | |
| 790 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 791 EXPECT_EQ( | |
| 792 Feature::IS_AVAILABLE, | |
| 793 feature->IsAvailableToManifest("2", | |
| 794 Manifest::TYPE_LEGACY_PACKAGED_APP, | |
| 795 Manifest::INVALID_LOCATION, | |
| 796 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 797 } | |
| 798 { | |
| 799 ScopedCurrentChannel current_channel(Channel::STABLE); | |
| 800 EXPECT_NE( | |
| 801 Feature::IS_AVAILABLE, | |
| 802 feature->IsAvailableToManifest("1", | |
| 803 Manifest::TYPE_EXTENSION, | |
| 804 Manifest::INVALID_LOCATION, | |
| 805 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 806 EXPECT_NE( | |
| 807 Feature::IS_AVAILABLE, | |
| 808 feature->IsAvailableToManifest("2", | |
| 809 Manifest::TYPE_LEGACY_PACKAGED_APP, | |
| 810 Manifest::INVALID_LOCATION, | |
| 811 Feature::UNSPECIFIED_PLATFORM).result()); | |
| 812 } | |
| 813 } | |
| 814 | |
| 815 // Tests complex feature availability across channels. | 759 // Tests complex feature availability across channels. | 
| 816 TEST_F(SimpleFeatureTest, ComplexFeatureAvailability) { | 760 TEST_F(SimpleFeatureTest, ComplexFeatureAvailability) { | 
| 817 std::unique_ptr<ComplexFeature> complex_feature; | 761 std::unique_ptr<ComplexFeature> complex_feature; | 
| 818 { | 762 { | 
| 819 // Rule: "extension", channel trunk. | 763 // Rule: "extension", channel trunk. | 
| 820 std::unique_ptr<SimpleFeature> feature1(new SimpleFeature()); | 764 std::unique_ptr<SimpleFeature> feature1(new SimpleFeature()); | 
| 821 feature1->channel_.reset(new Channel(Channel::UNKNOWN)); | 765 feature1->channel_.reset(new Channel(Channel::UNKNOWN)); | 
| 822 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION); | 766 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION); | 
| 823 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); | 767 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); | 
| 824 // Rule: "legacy_packaged_app", channel stable. | 768 // Rule: "legacy_packaged_app", channel stable. | 
| 
 
Devlin
2017/02/18 07:50:07
nit: update this comment -> channel beta
 
karandeepb
2017/02/21 18:47:08
Done.
 
 | |
| 825 feature2->channel_.reset(new Channel(Channel::STABLE)); | 769 feature2->channel_.reset(new Channel(Channel::BETA)); | 
| 826 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); | 770 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); | 
| 827 std::vector<Feature*> list; | 771 std::vector<Feature*> list; | 
| 828 list.push_back(feature1.release()); | 772 list.push_back(feature1.release()); | 
| 829 list.push_back(feature2.release()); | 773 list.push_back(feature2.release()); | 
| 830 complex_feature.reset(new ComplexFeature(&list)); | 774 complex_feature.reset(new ComplexFeature(&list)); | 
| 831 } | 775 } | 
| 832 | 776 | 
| 833 Feature* feature = static_cast<Feature*>(complex_feature.get()); | 777 Feature* feature = complex_feature.get(); | 
| 778 EXPECT_EQ(Feature::IS_AVAILABLE, | |
| 779 feature->IsAvailableToChannel(Channel::UNKNOWN).result()); | |
| 780 EXPECT_EQ(Feature::IS_AVAILABLE, | |
| 781 feature->IsAvailableToChannel(Channel::CANARY).result()); | |
| 782 EXPECT_EQ(Feature::IS_AVAILABLE, | |
| 783 feature->IsAvailableToChannel(Channel::DEV).result()); | |
| 784 EXPECT_EQ(Feature::IS_AVAILABLE, | |
| 785 feature->IsAvailableToChannel(Channel::BETA).result()); | |
| 786 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, | |
| 787 feature->IsAvailableToChannel(Channel::STABLE).result()); | |
| 788 | |
| 834 { | 789 { | 
| 835 ScopedCurrentChannel current_channel(Channel::UNKNOWN); | 790 ScopedCurrentChannel current_channel(Channel::UNKNOWN); | 
| 836 EXPECT_EQ(Feature::IS_AVAILABLE, | 791 EXPECT_EQ(Feature::IS_AVAILABLE, | 
| 837 feature | 792 feature | 
| 838 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 793 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 
| 839 Manifest::INVALID_LOCATION, | 794 Manifest::INVALID_LOCATION, | 
| 840 Feature::UNSPECIFIED_PLATFORM) | 795 Feature::UNSPECIFIED_PLATFORM) | 
| 841 .result()); | 796 .result()); | 
| 797 EXPECT_EQ(Feature::IS_AVAILABLE, | |
| 798 feature | |
| 799 ->IsAvailableToManifest( | |
| 800 "1", Manifest::TYPE_LEGACY_PACKAGED_APP, | |
| 801 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM) | |
| 802 .result()); | |
| 842 } | 803 } | 
| 843 { | 804 { | 
| 844 ScopedCurrentChannel current_channel(Channel::BETA); | 805 ScopedCurrentChannel current_channel(Channel::BETA); | 
| 845 EXPECT_EQ(Feature::IS_AVAILABLE, | 806 EXPECT_EQ(Feature::IS_AVAILABLE, | 
| 846 feature | 807 feature | 
| 847 ->IsAvailableToManifest( | 808 ->IsAvailableToManifest( | 
| 848 "2", Manifest::TYPE_LEGACY_PACKAGED_APP, | 809 "2", Manifest::TYPE_LEGACY_PACKAGED_APP, | 
| 849 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM) | 810 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM) | 
| 850 .result()); | 811 .result()); | 
| 851 } | |
| 852 { | |
| 853 ScopedCurrentChannel current_channel(Channel::BETA); | |
| 854 EXPECT_NE(Feature::IS_AVAILABLE, | 812 EXPECT_NE(Feature::IS_AVAILABLE, | 
| 855 feature | 813 feature | 
| 856 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 814 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | 
| 815 Manifest::INVALID_LOCATION, | |
| 816 Feature::UNSPECIFIED_PLATFORM) | |
| 817 .result()); | |
| 818 } | |
| 819 { | |
| 820 ScopedCurrentChannel current_channel(Channel::STABLE); | |
| 821 EXPECT_NE(Feature::IS_AVAILABLE, | |
| 822 feature | |
| 823 ->IsAvailableToManifest( | |
| 824 "2", Manifest::TYPE_LEGACY_PACKAGED_APP, | |
| 825 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM) | |
| 826 .result()); | |
| 827 EXPECT_NE(Feature::IS_AVAILABLE, | |
| 828 feature | |
| 829 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, | |
| 857 Manifest::INVALID_LOCATION, | 830 Manifest::INVALID_LOCATION, | 
| 858 Feature::UNSPECIFIED_PLATFORM) | 831 Feature::UNSPECIFIED_PLATFORM) | 
| 859 .result()); | 832 .result()); | 
| 860 } | 833 } | 
| 861 } | 834 } | 
| 862 | 835 | 
| 863 } // namespace extensions | 836 } // namespace extensions | 
| OLD | NEW |