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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/content_action_unittest.cc

Issue 344433003: Prepare declarativeContent API for new script injection feature. Added Javascript types and functio… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implement fixes from comments and add unit tests Created 6 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/extensions/api/declarative_content/content_action.h" 5 #include "chrome/browser/extensions/api/declarative_content/content_action.h"
6 6
7 #include "base/test/values_test_util.h" 7 #include "base/test/values_test_util.h"
8 #include "chrome/browser/extensions/extension_action.h" 8 #include "chrome/browser/extensions/extension_action.h"
9 #include "chrome/browser/extensions/extension_action_manager.h" 9 #include "chrome/browser/extensions/extension_action_manager.h"
10 #include "chrome/browser/extensions/extension_tab_util.h" 10 #include "chrome/browser/extensions/extension_tab_util.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 result->Apply(extension->id(), base::Time(), &apply_info); 102 result->Apply(extension->id(), base::Time(), &apply_info);
103 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); 103 EXPECT_TRUE(page_action->GetIsVisible(tab_id));
104 result->Apply(extension->id(), base::Time(), &apply_info); 104 result->Apply(extension->id(), base::Time(), &apply_info);
105 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); 105 EXPECT_TRUE(page_action->GetIsVisible(tab_id));
106 result->Revert(extension->id(), base::Time(), &apply_info); 106 result->Revert(extension->id(), base::Time(), &apply_info);
107 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); 107 EXPECT_TRUE(page_action->GetIsVisible(tab_id));
108 result->Revert(extension->id(), base::Time(), &apply_info); 108 result->Revert(extension->id(), base::Time(), &apply_info);
109 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 109 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
110 } 110 }
111 111
112 TEST(DeclarativeContentActionTest, RequestContentScriptMissingScripts) {
113 TestExtensionEnvironment env;
114
115 std::string error;
116 bool bad_message = false;
117 scoped_refptr<const ContentAction> result = ContentAction::Create(
118 NULL,
119 *ParseJson(
120 "{\n"
121 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
122 " \"allFrames\": true,\n"
123 " \"matchAboutBlank\": true\n"
124 "}"),
125 &error,
126 &bad_message);
127 EXPECT_THAT(error, testing::HasSubstr("Missing parameter is required"));
128 EXPECT_TRUE(bad_message);
129 ASSERT_FALSE(result.get());
130 }
131
132 TEST(DeclarativeContentActionTest, RequestContentScriptCSS) {
133 TestExtensionEnvironment env;
134
135 std::string error;
136 bool bad_message = false;
137 scoped_refptr<const ContentAction> result = ContentAction::Create(
138 NULL,
139 *ParseJson(
140 "{\n"
141 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
142 " \"css\": [\"style.css\"]\n"
143 "}"),
144 &error,
145 &bad_message);
146 EXPECT_EQ("", error);
147 EXPECT_FALSE(bad_message);
148 ASSERT_TRUE(result.get());
149 EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType());
150 }
151
152 TEST(DeclarativeContentActionTest, RequestContentScriptJS) {
153 TestExtensionEnvironment env;
154
155 std::string error;
156 bool bad_message = false;
157 scoped_refptr<const ContentAction> result = ContentAction::Create(
158 NULL,
159 *ParseJson(
160 "{\n"
161 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
162 " \"js\": [\"script.js\"]\n"
163 "}"),
164 &error,
165 &bad_message);
166 EXPECT_EQ("", error);
167 EXPECT_FALSE(bad_message);
168 ASSERT_TRUE(result.get());
169 EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType());
170 }
171
172 TEST(DeclarativeContentActionTest, RequestContentScriptCSSBadType) {
173 TestExtensionEnvironment env;
174
175 std::string error;
176 bool bad_message = false;
177 scoped_refptr<const ContentAction> result = ContentAction::Create(
178 NULL,
179 *ParseJson(
180 "{\n"
181 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
182 " \"css\": \"style.css\"\n"
183 "}"),
184 &error,
185 &bad_message);
186 EXPECT_THAT(error, testing::HasSubstr("has an invalid type"));
187 EXPECT_THAT(error, testing::HasSubstr("Expected type: Array of strings"));
188 EXPECT_TRUE(bad_message);
189 ASSERT_FALSE(result.get());
190 }
191
192 TEST(DeclarativeContentActionTest, RequestContentScriptJSBadType) {
193 TestExtensionEnvironment env;
194
195 std::string error;
196 bool bad_message = false;
197 scoped_refptr<const ContentAction> result = ContentAction::Create(
198 NULL,
199 *ParseJson(
200 "{\n"
201 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
202 " \"js\": \"script.js\"\n"
203 "}"),
204 &error,
205 &bad_message);
206 EXPECT_THAT(error, testing::HasSubstr("has an invalid type"));
207 EXPECT_THAT(error, testing::HasSubstr("Expected type: Array of strings"));
208 EXPECT_TRUE(bad_message);
209 ASSERT_FALSE(result.get());
210 }
211
212 TEST(DeclarativeContentActionTest, RequestContentScriptAllFrames) {
213 TestExtensionEnvironment env;
214
215 std::string error;
216 bool bad_message = false;
217 scoped_refptr<const ContentAction> result = ContentAction::Create(
218 NULL,
219 *ParseJson(
220 "{\n"
221 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
222 " \"js\": [\"script.js\"],\n"
223 " \"allFrames\": true\n"
224 "}"),
225 &error,
226 &bad_message);
227 EXPECT_EQ("", error);
228 EXPECT_FALSE(bad_message);
229 ASSERT_TRUE(result.get());
230 EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType());
231 }
232
233 TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlank) {
234 TestExtensionEnvironment env;
235
236 std::string error;
237 bool bad_message = false;
238 scoped_refptr<const ContentAction> result = ContentAction::Create(
239 NULL,
240 *ParseJson(
241 "{\n"
242 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
243 " \"js\": [\"script.js\"],\n"
244 " \"matchAboutBlank\": true\n"
245 "}"),
246 &error,
247 &bad_message);
248 EXPECT_EQ("", error);
249 EXPECT_FALSE(bad_message);
250 ASSERT_TRUE(result.get());
251 EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType());
252 }
253
254 TEST(DeclarativeContentActionTest, RequestContentScriptAllFramesBadType) {
255 TestExtensionEnvironment env;
256
257 std::string error;
258 bool bad_message = false;
259 scoped_refptr<const ContentAction> result = ContentAction::Create(
260 NULL,
261 *ParseJson(
262 "{\n"
263 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
264 " \"js\": [\"script.js\"],\n"
265 " \"allFrames\": null\n"
266 "}"),
267 &error,
268 &bad_message);
269 EXPECT_THAT(error, testing::HasSubstr("has an invalid type"));
270 EXPECT_THAT(error, testing::HasSubstr("Expected type: Boolean"));
271 EXPECT_TRUE(bad_message);
272 ASSERT_FALSE(result.get());
273 }
274
275 TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlankBadType) {
276 TestExtensionEnvironment env;
277
278 std::string error;
279 bool bad_message = false;
280 scoped_refptr<const ContentAction> result = ContentAction::Create(
281 NULL,
282 *ParseJson(
283 "{\n"
284 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n"
285 " \"js\": [\"script.js\"],\n"
286 " \"matchAboutBlank\": null\n"
287 "}"),
288 &error,
289 &bad_message);
290 EXPECT_THAT(error, testing::HasSubstr("has an invalid type"));
291 EXPECT_THAT(error, testing::HasSubstr("Expected type: Boolean"));
292 EXPECT_TRUE(bad_message);
293 ASSERT_FALSE(result.get());
294 }
295
112 } // namespace 296 } // namespace
113 } // namespace extensions 297 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698