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

Side by Side Diff: extensions/common/api/declarative/declarative_manifest_unittest.cc

Issue 1158693006: Create a mechanism define declarative rules via the extension manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "extensions/browser/api_test_utils.h"
6 #include "extensions/common/api/declarative/declarative_manifest_data.h"
7 #include "extensions/common/manifest_test.h"
8
9 namespace extensions {
10
11 using api_test_utils::ParseDictionary;
12 using DeclarativeManifestTest = ManifestTest;
13
14 TEST_F(DeclarativeManifestTest, Valid) {
15 scoped_refptr<Extension> extension = LoadAndExpectSuccess("event_rules.json");
16 DeclarativeManifestData* manifest_data =
17 DeclarativeManifestData::Get(extension.get());
18 ASSERT_TRUE(manifest_data);
19 std::vector<linked_ptr<DeclarativeManifestData::Rule>>& rules =
20 manifest_data->RulesForEvent("foo");
21 EXPECT_EQ(1u, rules.size());
22 scoped_ptr<base::DictionaryValue> expected_rule = ParseDictionary(
23 "{"
24 " \"actions\": [{"
25 " \"instanceType\": \"action_type\""
26 " }],"
27 " \"conditions\" : [{"
28 " \"instanceType\" : \"condition_type\""
29 " }]"
30 "}");
31 EXPECT_TRUE(expected_rule->Equals(rules[0]->ToValue().get()));
32 }
33
34 TEST_F(DeclarativeManifestTest, ConditionMissingType) {
35 // Create extension
36 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
37 "{"
38 " \"name\": \"Test\","
39 " \"version\": \"1\","
40 " \"event_rules\": ["
41 " {"
42 " \"event\": \"declarativeContent.onPageChanged\","
43 " \"actions\": [{"
44 " \"type\": \"declarativeContent.ShowPageAction\""
45 " }],"
46 " \"conditions\" : [{"
47 " \"css\": [\"video\"]"
48 " }]"
49 " }"
50 " ]"
51 "}");
52 ManifestData manifest(manifest_data.get(), "test");
53 LoadAndExpectError(manifest, "'type' is required; rule failed to populate");
54 }
55
56 TEST_F(DeclarativeManifestTest, ConditionNotDictionary) {
57 // Create extension
58 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
59 "{"
60 " \"name\": \"Test\","
61 " \"version\": \"1\","
62 " \"event_rules\": ["
63 " {"
64 " \"event\": \"declarativeContent.onPageChanged\","
65 " \"actions\": [{"
66 " \"type\": \"declarativeContent.ShowPageAction\""
67 " }],"
68 " \"conditions\" : [true]"
69 " }"
70 " ]"
71 "}");
72 ManifestData manifest(manifest_data.get(), "test");
73 LoadAndExpectError(
74 manifest, "expected dictionary, got boolean; rule failed to populate");
75 }
76
77 TEST_F(DeclarativeManifestTest, ActionMissingType) {
78 // Create extension
79 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
80 "{"
81 " \"name\": \"Test\","
82 " \"version\": \"1\","
83 " \"event_rules\": ["
84 " {"
85 " \"event\": \"declarativeContent.onPageChanged\","
86 " \"actions\": [{}],"
87 " \"conditions\" : [{"
88 " \"css\": [\"video\"],"
89 " \"type\" : \"declarativeContent.PageStateMatcher\""
90 " }]"
91 " }"
92 " ]"
93 "}");
94 ManifestData manifest(manifest_data.get(), "test");
95 LoadAndExpectError(manifest, "'type' is required; rule failed to populate");
96 }
97
98 TEST_F(DeclarativeManifestTest, ActionNotDictionary) {
99 // Create extension
100 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
101 "{"
102 " \"name\": \"Test\","
103 " \"version\": \"1\","
104 " \"event_rules\": ["
105 " {"
106 " \"event\": \"declarativeContent.onPageChanged\","
107 " \"actions\": [[]],"
108 " \"conditions\" : [{"
109 " \"css\": [\"video\"],"
110 " \"type\" : \"declarativeContent.PageStateMatcher\""
111 " }]"
112 " }"
113 " ]"
114 "}");
115 ManifestData manifest(manifest_data.get(), "test");
116 LoadAndExpectError(manifest,
117 "expected dictionary, got list; rule failed to populate");
118 }
119
120 TEST_F(DeclarativeManifestTest, EventRulesNotList) {
121 // Create extension
122 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
123 "{"
124 " \"name\": \"Test\","
125 " \"version\": \"1\","
126 " \"event_rules\": {}"
127 "}");
128 ManifestData manifest(manifest_data.get(), "test");
129 LoadAndExpectError(manifest, "'event_rules' expected list, got dictionary");
130 }
131
132 TEST_F(DeclarativeManifestTest, EventRuleNotDictionary) {
133 // Create extension
134 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
135 "{"
136 " \"name\": \"Test\","
137 " \"version\": \"1\","
138 " \"event_rules\": [0,1,2]"
139 "}");
140 ManifestData manifest(manifest_data.get(), "test");
141 LoadAndExpectError(manifest, "expected dictionary, got integer");
142 }
143
144 TEST_F(DeclarativeManifestTest, EventMissingFromRule) {
145 // Create extension
146 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
147 "{"
148 " \"name\": \"Test\","
149 " \"version\": \"1\","
150 " \"event_rules\": ["
151 " {"
152 " \"actions\": [{"
153 " \"type\": \"declarativeContent.ShowPageAction\""
154 " }],"
155 " \"conditions\" : [{"
156 " \"css\": [\"video\"],"
157 " \"type\" : \"declarativeContent.PageStateMatcher\""
158 " }]"
159 " }"
160 " ]"
161 "}");
162 ManifestData manifest(manifest_data.get(), "test");
163 LoadAndExpectError(manifest, "'event' is required");
164 }
165
166 TEST_F(DeclarativeManifestTest, RuleFailedToPopulate) {
167 // Create extension
168 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
169 "{"
170 " \"name\": \"Test\","
171 " \"version\": \"1\","
172 " \"event_rules\": ["
173 " {"
174 " \"event\": \"declarativeContent.onPageChanged\""
175 " }"
176 " ]"
177 "}");
178 ManifestData manifest(manifest_data.get(), "test");
179 LoadAndExpectError(manifest, "rule failed to populate");
180 }
181
182 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698