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

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: add thread safety to extensionregistry notifications 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 and must be a string");
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(manifest, "expected dictionary, got boolean");
74 }
75
76 TEST_F(DeclarativeManifestTest, ActionMissingType) {
77 // Create extension
78 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
79 "{"
80 " \"name\": \"Test\","
81 " \"version\": \"1\","
82 " \"event_rules\": ["
83 " {"
84 " \"event\": \"declarativeContent.onPageChanged\","
85 " \"actions\": [{}],"
86 " \"conditions\" : [{"
87 " \"css\": [\"video\"],"
88 " \"type\" : \"declarativeContent.PageStateMatcher\""
89 " }]"
90 " }"
91 " ]"
92 "}");
93 ManifestData manifest(manifest_data.get(), "test");
94 LoadAndExpectError(manifest, "'type' is required and must be a string");
95 }
96
97 TEST_F(DeclarativeManifestTest, ActionNotDictionary) {
98 // Create extension
99 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
100 "{"
101 " \"name\": \"Test\","
102 " \"version\": \"1\","
103 " \"event_rules\": ["
104 " {"
105 " \"event\": \"declarativeContent.onPageChanged\","
106 " \"actions\": [[]],"
107 " \"conditions\" : [{"
108 " \"css\": [\"video\"],"
109 " \"type\" : \"declarativeContent.PageStateMatcher\""
110 " }]"
111 " }"
112 " ]"
113 "}");
114 ManifestData manifest(manifest_data.get(), "test");
115 LoadAndExpectError(manifest, "expected dictionary, got list");
116 }
117
118 TEST_F(DeclarativeManifestTest, EventRulesNotList) {
119 // Create extension
120 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
121 "{"
122 " \"name\": \"Test\","
123 " \"version\": \"1\","
124 " \"event_rules\": {}"
125 "}");
126 ManifestData manifest(manifest_data.get(), "test");
127 LoadAndExpectError(manifest, "'event_rules' expected list, got dictionary");
128 }
129
130 TEST_F(DeclarativeManifestTest, EventRuleNotDictionary) {
131 // Create extension
132 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
133 "{"
134 " \"name\": \"Test\","
135 " \"version\": \"1\","
136 " \"event_rules\": [0,1,2]"
137 "}");
138 ManifestData manifest(manifest_data.get(), "test");
139 LoadAndExpectError(manifest, "expected dictionary, got integer");
140 }
141
142 TEST_F(DeclarativeManifestTest, EventMissingFromRule) {
143 // Create extension
144 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
145 "{"
146 " \"name\": \"Test\","
147 " \"version\": \"1\","
148 " \"event_rules\": ["
149 " {"
150 " \"actions\": [{"
151 " \"type\": \"declarativeContent.ShowPageAction\""
152 " }],"
153 " \"conditions\" : [{"
154 " \"css\": [\"video\"],"
155 " \"type\" : \"declarativeContent.PageStateMatcher\""
156 " }]"
157 " }"
158 " ]"
159 "}");
160 ManifestData manifest(manifest_data.get(), "test");
161 LoadAndExpectError(manifest, "'event' is required");
162 }
163
164 TEST_F(DeclarativeManifestTest, RuleFailedToPopulate) {
165 // Create extension
166 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
167 "{"
168 " \"name\": \"Test\","
169 " \"version\": \"1\","
170 " \"event_rules\": ["
171 " {"
172 " \"event\": \"declarativeContent.onPageChanged\""
173 " }"
174 " ]"
175 "}");
176 ManifestData manifest(manifest_data.get(), "test");
177 LoadAndExpectError(manifest, "rule failed to populate");
178 }
179
180 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/api/declarative/declarative_manifest_handler.cc ('k') | extensions/common/common_manifest_handlers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698