Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: extensions/common/features/simple_feature_unittest.cc

Issue 2783543003: [Merge-m58] Revert of Extensions: Only create Web request rules registry if Declarative Web Request… (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
48 SimpleFeature feature; 50 SimpleFeature feature;
49 feature.set_channel(channel_for_feature); 51 feature.set_channel(channel_for_feature);
50 return feature.IsAvailableToChannel(channel_for_testing).result(); 52 return feature
53 .IsAvailableToManifest("random-extension", Manifest::TYPE_UNKNOWN,
54 Manifest::INVALID_LOCATION, -1,
55 Feature::GetCurrentPlatform())
56 .result();
51 } 57 }
52 58
53 } // namespace 59 } // namespace
54 60
55 class SimpleFeatureTest : public testing::Test { 61 class SimpleFeatureTest : public testing::Test {
56 protected: 62 protected:
57 SimpleFeatureTest() : current_channel_(Channel::UNKNOWN) {} 63 SimpleFeatureTest() : current_channel_(Channel::UNKNOWN) {}
58 bool LocationIsAvailable(SimpleFeature::Location feature_location, 64 bool LocationIsAvailable(SimpleFeature::Location feature_location,
59 Manifest::Location manifest_location) { 65 Manifest::Location manifest_location) {
60 SimpleFeature feature; 66 SimpleFeature feature;
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 755 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
750 IsAvailableInChannel(Channel::UNKNOWN, Channel::CANARY)); 756 IsAvailableInChannel(Channel::UNKNOWN, Channel::CANARY));
751 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 757 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
752 IsAvailableInChannel(Channel::UNKNOWN, Channel::DEV)); 758 IsAvailableInChannel(Channel::UNKNOWN, Channel::DEV));
753 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 759 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
754 IsAvailableInChannel(Channel::UNKNOWN, Channel::BETA)); 760 IsAvailableInChannel(Channel::UNKNOWN, Channel::BETA));
755 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL, 761 EXPECT_EQ(Feature::UNSUPPORTED_CHANNEL,
756 IsAvailableInChannel(Channel::UNKNOWN, Channel::STABLE)); 762 IsAvailableInChannel(Channel::UNKNOWN, Channel::STABLE));
757 } 763 }
758 764
765 // Tests simple feature availability across channels.
766 TEST_F(SimpleFeatureTest, SimpleFeatureAvailability) {
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
759 // Tests complex feature availability across channels. 815 // Tests complex feature availability across channels.
760 TEST_F(SimpleFeatureTest, ComplexFeatureAvailability) { 816 TEST_F(SimpleFeatureTest, ComplexFeatureAvailability) {
761 std::unique_ptr<ComplexFeature> complex_feature; 817 std::unique_ptr<ComplexFeature> complex_feature;
762 { 818 {
763 // Rule: "extension", channel trunk. 819 // Rule: "extension", channel trunk.
764 std::unique_ptr<SimpleFeature> feature1(new SimpleFeature()); 820 std::unique_ptr<SimpleFeature> feature1(new SimpleFeature());
765 feature1->channel_.reset(new Channel(Channel::UNKNOWN)); 821 feature1->channel_.reset(new Channel(Channel::UNKNOWN));
766 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION); 822 feature1->extension_types_.push_back(Manifest::TYPE_EXTENSION);
767 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); 823 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature());
768 // Rule: "legacy_packaged_app", channel beta. 824 // Rule: "legacy_packaged_app", channel stable.
769 feature2->channel_.reset(new Channel(Channel::BETA)); 825 feature2->channel_.reset(new Channel(Channel::STABLE));
770 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP); 826 feature2->extension_types_.push_back(Manifest::TYPE_LEGACY_PACKAGED_APP);
771 std::vector<Feature*> list; 827 std::vector<Feature*> list;
772 list.push_back(feature1.release()); 828 list.push_back(feature1.release());
773 list.push_back(feature2.release()); 829 list.push_back(feature2.release());
774 complex_feature.reset(new ComplexFeature(&list)); 830 complex_feature.reset(new ComplexFeature(&list));
775 } 831 }
776 832
777 Feature* feature = complex_feature.get(); 833 Feature* feature = static_cast<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
789 { 834 {
790 ScopedCurrentChannel current_channel(Channel::UNKNOWN); 835 ScopedCurrentChannel current_channel(Channel::UNKNOWN);
791 EXPECT_EQ(Feature::IS_AVAILABLE, 836 EXPECT_EQ(Feature::IS_AVAILABLE,
792 feature 837 feature
793 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, 838 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION,
794 Manifest::INVALID_LOCATION, 839 Manifest::INVALID_LOCATION,
795 Feature::UNSPECIFIED_PLATFORM) 840 Feature::UNSPECIFIED_PLATFORM)
796 .result()); 841 .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());
803 } 842 }
804 { 843 {
805 ScopedCurrentChannel current_channel(Channel::BETA); 844 ScopedCurrentChannel current_channel(Channel::BETA);
806 EXPECT_EQ(Feature::IS_AVAILABLE, 845 EXPECT_EQ(Feature::IS_AVAILABLE,
807 feature 846 feature
808 ->IsAvailableToManifest( 847 ->IsAvailableToManifest(
809 "2", Manifest::TYPE_LEGACY_PACKAGED_APP, 848 "2", Manifest::TYPE_LEGACY_PACKAGED_APP,
810 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM) 849 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM)
811 .result()); 850 .result());
851 }
852 {
853 ScopedCurrentChannel current_channel(Channel::BETA);
812 EXPECT_NE(Feature::IS_AVAILABLE, 854 EXPECT_NE(Feature::IS_AVAILABLE,
813 feature 855 feature
814 ->IsAvailableToManifest("1", Manifest::TYPE_EXTENSION, 856 ->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,
830 Manifest::INVALID_LOCATION, 857 Manifest::INVALID_LOCATION,
831 Feature::UNSPECIFIED_PLATFORM) 858 Feature::UNSPECIFIED_PLATFORM)
832 .result()); 859 .result());
833 } 860 }
834 } 861 }
835 862
836 } // namespace extensions 863 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698