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

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

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

Powered by Google App Engine
This is Rietveld 408576698