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

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

Issue 11316164: Implement ComplexFeature to support permission features with multiple rules. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new Created 8 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/features/complex_feature.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 using chrome::VersionInfo;
10 using extensions::ComplexFeature;
11 using extensions::Extension;
12 using extensions::Feature;
13 using extensions::PermissionFeature;
14
15 namespace {
16
17 class ExtensionComplexFeatureTest : public testing::Test {
18 protected:
19 ExtensionComplexFeatureTest()
20 : current_channel_(VersionInfo::CHANNEL_UNKNOWN) {}
21 virtual ~ExtensionComplexFeatureTest() {}
22
23 private:
24 Feature::ScopedCurrentChannel current_channel_;
25 };
26
27 TEST_F(ExtensionComplexFeatureTest, MultipleRulesWhitelist) {
28 scoped_ptr<ComplexFeature> feature(new ComplexFeature());
29
30 // Rule: "extension", whitelist "foo".
31 scoped_ptr<PermissionFeature> simple_feature(new PermissionFeature());
32 scoped_ptr<DictionaryValue> rule(new DictionaryValue());
33 ListValue* whitelist = new ListValue();
34 whitelist->Append(Value::CreateStringValue("foo"));
35 rule->Set("whitelist", whitelist);
36 ListValue* extension_types = new ListValue();
37 extension_types->Append(Value::CreateStringValue("extension"));
38 rule->Set("extension_types", extension_types);
39 simple_feature->Parse(rule.get());
40 feature->AddSimpleFeature(simple_feature.get());
41
not at google - send to devlin 2012/12/12 17:42:41 ditto
justinlin 2012/12/14 12:26:26 Done.
42 // Rule: "packaged_app", whitelist "bar".
43 simple_feature.reset(new PermissionFeature());
44 rule.reset(new DictionaryValue());
45 whitelist = new ListValue();
46 whitelist->Append(Value::CreateStringValue("bar"));
47 rule->Set("whitelist", whitelist);
48 extension_types = new ListValue();
49 extension_types->Append(Value::CreateStringValue("packaged_app"));
50 rule->Set("extension_types", extension_types);
51 simple_feature->Parse(rule.get());
52 feature->AddSimpleFeature(simple_feature.get());
53
54 // Test match 1st rule.
55 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
56 "foo",
57 Extension::TYPE_EXTENSION,
58 Feature::UNSPECIFIED_LOCATION,
59 Feature::UNSPECIFIED_PLATFORM,
60 Feature::GetCurrentPlatform()).result());
61
62 // Test match 2nd rule.
63 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
64 "bar",
65 Extension::TYPE_LEGACY_PACKAGED_APP,
66 Feature::UNSPECIFIED_LOCATION,
67 Feature::UNSPECIFIED_PLATFORM,
68 Feature::GetCurrentPlatform()).result());
69
70 // Test whitelist with wrong extension type.
71 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
72 "bar",
73 Extension::TYPE_EXTENSION,
74 Feature::UNSPECIFIED_LOCATION,
75 Feature::UNSPECIFIED_PLATFORM,
76 Feature::GetCurrentPlatform()).result());
77 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
78 "foo",
79 Extension::TYPE_LEGACY_PACKAGED_APP,
80 Feature::UNSPECIFIED_LOCATION,
81 Feature::UNSPECIFIED_PLATFORM,
82 Feature::GetCurrentPlatform()).result());
83 }
84
85 TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) {
86 scoped_ptr<ComplexFeature> feature(new ComplexFeature());
87
88 // Rule: "extension", channel trunk.
89 scoped_ptr<PermissionFeature> simple_feature(new PermissionFeature());
90 scoped_ptr<DictionaryValue> rule(new DictionaryValue());
91 ListValue* extension_types = new ListValue();
92 extension_types->Append(Value::CreateStringValue("extension"));
93 rule->Set("extension_types", extension_types);
94 rule->SetString("channel", "trunk");
95 simple_feature->Parse(rule.get());
96 feature->AddSimpleFeature(simple_feature.get());
97
98 // Rule: "packaged_app", channel stable.
99 simple_feature.reset(new PermissionFeature());
100 rule.reset(new DictionaryValue());
101 extension_types = new ListValue();
102 extension_types->Append(Value::CreateStringValue("packaged_app"));
103 rule->Set("extension_types", extension_types);
104 rule->SetString("channel", "stable");
105 simple_feature->Parse(rule.get());
106 feature->AddSimpleFeature(simple_feature.get());
107
108 // Test match 1st rule.
109 {
110 Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_UNKNOWN);
111 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
112 "1",
113 Extension::TYPE_EXTENSION,
114 Feature::UNSPECIFIED_LOCATION,
115 Feature::UNSPECIFIED_PLATFORM,
116 Feature::GetCurrentPlatform()).result());
117 }
118
119 // Test match 2nd rule.
120 {
121 Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
122 EXPECT_EQ(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
123 "2",
124 Extension::TYPE_LEGACY_PACKAGED_APP,
125 Feature::UNSPECIFIED_LOCATION,
126 Feature::UNSPECIFIED_PLATFORM,
127 Feature::GetCurrentPlatform()).result());
128 }
129
130 // Test feature not available to extensions above channel unknown.
131 {
132 Feature::ScopedCurrentChannel current_channel(VersionInfo::CHANNEL_BETA);
133 EXPECT_NE(Feature::IS_AVAILABLE, feature->IsAvailableToManifest(
134 "1",
135 Extension::TYPE_EXTENSION,
136 Feature::UNSPECIFIED_LOCATION,
137 Feature::UNSPECIFIED_PLATFORM,
138 Feature::GetCurrentPlatform()).result());
139 }
140 }
141
142 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698