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

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

Issue 2116293003: extensions: Generate hash of extension ID at a higher level Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/complex_feature.cc ('k') | extensions/common/features/feature.h » ('j') | 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/complex_feature.h" 5 #include "extensions/common/features/complex_feature.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "extensions/common/features/simple_feature.h" 10 #include "extensions/common/features/simple_feature.h"
(...skipping 26 matching lines...) Expand all
37 .Set("extension_types", 37 .Set("extension_types",
38 ListBuilder().Append("legacy_packaged_app").Build()) 38 ListBuilder().Append("legacy_packaged_app").Build())
39 .Build(); 39 .Build();
40 simple_feature->Parse(rule.get()); 40 simple_feature->Parse(rule.get());
41 features->push_back(std::move(simple_feature)); 41 features->push_back(std::move(simple_feature));
42 42
43 std::unique_ptr<ComplexFeature> feature( 43 std::unique_ptr<ComplexFeature> feature(
44 new ComplexFeature(std::move(features))); 44 new ComplexFeature(std::move(features)));
45 45
46 // Test match 1st rule. 46 // Test match 1st rule.
47 EXPECT_EQ( 47 EXPECT_EQ(Feature::IS_AVAILABLE,
48 Feature::IS_AVAILABLE, 48 feature
49 feature->IsAvailableToManifest(kIdFoo, 49 ->Feature::IsAvailableToManifest(
50 Manifest::TYPE_EXTENSION, 50 kIdFoo, Manifest::TYPE_EXTENSION,
51 Manifest::INVALID_LOCATION, 51 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM)
52 Feature::UNSPECIFIED_PLATFORM, 52 .result());
53 Feature::GetCurrentPlatform()).result());
54 53
55 // Test match 2nd rule. 54 // Test match 2nd rule.
56 EXPECT_EQ( 55 EXPECT_EQ(Feature::IS_AVAILABLE,
57 Feature::IS_AVAILABLE, 56 feature
58 feature->IsAvailableToManifest(kIdBar, 57 ->Feature::IsAvailableToManifest(
59 Manifest::TYPE_LEGACY_PACKAGED_APP, 58 kIdBar, Manifest::TYPE_LEGACY_PACKAGED_APP,
60 Manifest::INVALID_LOCATION, 59 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM)
61 Feature::UNSPECIFIED_PLATFORM, 60 .result());
62 Feature::GetCurrentPlatform()).result());
63 61
64 // Test whitelist with wrong extension type. 62 // Test whitelist with wrong extension type.
65 EXPECT_NE( 63 EXPECT_NE(Feature::IS_AVAILABLE,
66 Feature::IS_AVAILABLE, 64 feature
67 feature->IsAvailableToManifest(kIdBar, 65 ->Feature::IsAvailableToManifest(
68 Manifest::TYPE_EXTENSION, 66 kIdBar, Manifest::TYPE_EXTENSION,
69 Manifest::INVALID_LOCATION, 67 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM)
70 Feature::UNSPECIFIED_PLATFORM, 68 .result());
71 Feature::GetCurrentPlatform()).result()); 69 EXPECT_NE(Feature::IS_AVAILABLE,
72 EXPECT_NE( 70 feature
73 Feature::IS_AVAILABLE, 71 ->Feature::IsAvailableToManifest(
74 feature->IsAvailableToManifest(kIdFoo, 72 kIdFoo, Manifest::TYPE_LEGACY_PACKAGED_APP,
75 Manifest::TYPE_LEGACY_PACKAGED_APP, 73 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM)
76 Manifest::INVALID_LOCATION, 74 .result());
77 Feature::UNSPECIFIED_PLATFORM,
78 Feature::GetCurrentPlatform()).result());
79 } 75 }
80 76
81 // Tests that dependencies are correctly checked. 77 // Tests that dependencies are correctly checked.
82 TEST(ComplexFeatureTest, Dependencies) { 78 TEST(ComplexFeatureTest, Dependencies) {
83 std::unique_ptr<ComplexFeature::FeatureList> features( 79 std::unique_ptr<ComplexFeature::FeatureList> features(
84 new ComplexFeature::FeatureList()); 80 new ComplexFeature::FeatureList());
85 81
86 // Rule which depends on an extension-only feature (content_security_policy). 82 // Rule which depends on an extension-only feature (content_security_policy).
87 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature); 83 std::unique_ptr<SimpleFeature> simple_feature(new SimpleFeature);
88 std::unique_ptr<base::DictionaryValue> rule = 84 std::unique_ptr<base::DictionaryValue> rule =
(...skipping 10 matching lines...) Expand all
99 .Set("dependencies", 95 .Set("dependencies",
100 ListBuilder().Append("permission:serial").Build()) 96 ListBuilder().Append("permission:serial").Build())
101 .Build(); 97 .Build();
102 simple_feature->Parse(rule.get()); 98 simple_feature->Parse(rule.get());
103 features->push_back(std::move(simple_feature)); 99 features->push_back(std::move(simple_feature));
104 100
105 std::unique_ptr<ComplexFeature> feature( 101 std::unique_ptr<ComplexFeature> feature(
106 new ComplexFeature(std::move(features))); 102 new ComplexFeature(std::move(features)));
107 103
108 // Available to extensions because of the content_security_policy rule. 104 // Available to extensions because of the content_security_policy rule.
109 EXPECT_EQ( 105 EXPECT_EQ(Feature::IS_AVAILABLE,
110 Feature::IS_AVAILABLE, 106 feature
111 feature->IsAvailableToManifest("extensionid", 107 ->Feature::IsAvailableToManifest(
112 Manifest::TYPE_EXTENSION, 108 "extensionid", Manifest::TYPE_EXTENSION,
113 Manifest::INVALID_LOCATION, 109 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM)
114 Feature::UNSPECIFIED_PLATFORM, 110 .result());
115 Feature::GetCurrentPlatform()).result());
116 111
117 // Available to platform apps because of the serial rule. 112 // Available to platform apps because of the serial rule.
118 EXPECT_EQ( 113 EXPECT_EQ(Feature::IS_AVAILABLE,
119 Feature::IS_AVAILABLE, 114 feature
120 feature->IsAvailableToManifest("platformappid", 115 ->Feature::IsAvailableToManifest(
121 Manifest::TYPE_PLATFORM_APP, 116 "platformappid", Manifest::TYPE_PLATFORM_APP,
122 Manifest::INVALID_LOCATION, 117 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM)
123 Feature::UNSPECIFIED_PLATFORM, 118 .result());
124 Feature::GetCurrentPlatform()).result());
125 119
126 // Not available to hosted apps. 120 // Not available to hosted apps.
127 EXPECT_EQ( 121 EXPECT_EQ(Feature::INVALID_TYPE,
128 Feature::INVALID_TYPE, 122 feature
129 feature->IsAvailableToManifest("hostedappid", 123 ->Feature::IsAvailableToManifest(
130 Manifest::TYPE_HOSTED_APP, 124 "hostedappid", Manifest::TYPE_HOSTED_APP,
131 Manifest::INVALID_LOCATION, 125 Manifest::INVALID_LOCATION, Feature::UNSPECIFIED_PLATFORM)
132 Feature::UNSPECIFIED_PLATFORM, 126 .result());
133 Feature::GetCurrentPlatform()).result());
134 } 127 }
135 128
136 } // namespace extensions 129 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/complex_feature.cc ('k') | extensions/common/features/feature.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698