Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / common / api / declarative / declarative_manifest_unittest.cc
blobebef0409650af1f34eb241b2b9423122269d581e
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.
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"
9 namespace extensions {
11 using api_test_utils::ParseDictionary;
12 using DeclarativeManifestTest = ManifestTest;
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()));
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");
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");
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");
97 TEST_F(DeclarativeManifestTest, ActionNotDictionary) {
98 // Create extension
99 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
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");
118 TEST_F(DeclarativeManifestTest, EventRulesNotList) {
119 // Create extension
120 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
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");
130 TEST_F(DeclarativeManifestTest, EventRuleNotDictionary) {
131 // Create extension
132 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
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");
142 TEST_F(DeclarativeManifestTest, EventMissingFromRule) {
143 // Create extension
144 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
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");
164 TEST_F(DeclarativeManifestTest, RuleFailedToPopulate) {
165 // Create extension
166 scoped_ptr<base::DictionaryValue> manifest_data = ParseDictionary(
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");
180 } // namespace extensions