OLD | NEW |
---|---|
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 Loading... | |
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_FALSE(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()); | |
Jeffrey Yasskin
2014/07/17 20:39:14
In your next patch, you should extend these to mak
Mark Dittmer
2014/07/17 23:58:14
Will do this when Apply gets implemented.
| |
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_TRUE(bad_message); | |
187 ASSERT_FALSE(result.get()); | |
188 } | |
189 | |
190 TEST(DeclarativeContentActionTest, RequestContentScriptJSBadType) { | |
191 TestExtensionEnvironment env; | |
192 | |
193 std::string error; | |
194 bool bad_message = false; | |
195 scoped_refptr<const ContentAction> result = ContentAction::Create( | |
196 NULL, | |
197 *ParseJson( | |
198 "{\n" | |
199 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" | |
200 " \"js\": \"script.js\"\n" | |
201 "}"), | |
202 &error, | |
203 &bad_message); | |
204 EXPECT_TRUE(bad_message); | |
205 ASSERT_FALSE(result.get()); | |
206 } | |
207 | |
208 TEST(DeclarativeContentActionTest, RequestContentScriptAllFrames) { | |
209 TestExtensionEnvironment env; | |
210 | |
211 std::string error; | |
212 bool bad_message = false; | |
213 scoped_refptr<const ContentAction> result = ContentAction::Create( | |
214 NULL, | |
215 *ParseJson( | |
216 "{\n" | |
217 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" | |
218 " \"js\": [\"script.js\"],\n" | |
219 " \"allFrames\": true\n" | |
220 "}"), | |
221 &error, | |
222 &bad_message); | |
223 EXPECT_EQ("", error); | |
224 EXPECT_FALSE(bad_message); | |
225 ASSERT_TRUE(result.get()); | |
226 EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); | |
227 } | |
228 | |
229 TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlank) { | |
230 TestExtensionEnvironment env; | |
231 | |
232 std::string error; | |
233 bool bad_message = false; | |
234 scoped_refptr<const ContentAction> result = ContentAction::Create( | |
235 NULL, | |
236 *ParseJson( | |
237 "{\n" | |
238 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" | |
239 " \"js\": [\"script.js\"],\n" | |
240 " \"matchAboutBlank\": true\n" | |
241 "}"), | |
242 &error, | |
243 &bad_message); | |
244 EXPECT_EQ("", error); | |
245 EXPECT_FALSE(bad_message); | |
246 ASSERT_TRUE(result.get()); | |
247 EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); | |
248 } | |
249 | |
250 TEST(DeclarativeContentActionTest, RequestContentScriptAllFramesBadType) { | |
251 TestExtensionEnvironment env; | |
252 | |
253 std::string error; | |
254 bool bad_message = false; | |
255 scoped_refptr<const ContentAction> result = ContentAction::Create( | |
256 NULL, | |
257 *ParseJson( | |
258 "{\n" | |
259 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" | |
260 " \"js\": [\"script.js\"],\n" | |
261 " \"allFrames\": null\n" | |
262 "}"), | |
263 &error, | |
264 &bad_message); | |
265 EXPECT_TRUE(bad_message); | |
266 ASSERT_FALSE(result.get()); | |
267 } | |
268 | |
269 TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlankBadType) { | |
270 TestExtensionEnvironment env; | |
271 | |
272 std::string error; | |
273 bool bad_message = false; | |
274 scoped_refptr<const ContentAction> result = ContentAction::Create( | |
275 NULL, | |
276 *ParseJson( | |
277 "{\n" | |
278 " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" | |
279 " \"js\": [\"script.js\"],\n" | |
280 " \"matchAboutBlank\": null\n" | |
281 "}"), | |
282 &error, | |
283 &bad_message); | |
284 EXPECT_TRUE(bad_message); | |
285 ASSERT_FALSE(result.get()); | |
286 } | |
287 | |
112 } // namespace | 288 } // namespace |
113 } // namespace extensions | 289 } // namespace extensions |
OLD | NEW |