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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_unittest.cc

Issue 11827026: Overhaul JSON Schema Compiler to support a number of features required to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 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 | Annotate | Revision Log
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_webrequest/webrequest_condit ion.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/test/values_test_util.h" 10 #include "base/test/values_test_util.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 dummy_match_set, 171 dummy_match_set,
172 DeclarativeWebRequestData(&https_request, ON_BEFORE_REQUEST))); 172 DeclarativeWebRequestData(&https_request, ON_BEFORE_REQUEST)));
173 } 173 }
174 174
175 TEST(WebRequestConditionTest, CreateConditionSet) { 175 TEST(WebRequestConditionTest, CreateConditionSet) {
176 // Necessary for TestURLRequest. 176 // Necessary for TestURLRequest.
177 MessageLoop message_loop(MessageLoop::TYPE_IO); 177 MessageLoop message_loop(MessageLoop::TYPE_IO);
178 URLMatcher matcher; 178 URLMatcher matcher;
179 179
180 WebRequestConditionSet::AnyVector conditions; 180 WebRequestConditionSet::AnyVector conditions;
181 181 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson(
182 linked_ptr<json_schema_compiler::any::Any> condition1 = make_linked_ptr(
183 new json_schema_compiler::any::Any);
184 condition1->Init(*base::test::ParseJson(
185 "{ \n" 182 "{ \n"
186 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" 183 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
187 " \"url\": { \n" 184 " \"url\": { \n"
188 " \"hostSuffix\": \"example.com\", \n" 185 " \"hostSuffix\": \"example.com\", \n"
189 " \"schemes\": [\"http\"], \n" 186 " \"schemes\": [\"http\"], \n"
190 " }, \n" 187 " }, \n"
191 "}")); 188 "}").release()));
192 conditions.push_back(condition1); 189 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson(
193
194 linked_ptr<json_schema_compiler::any::Any> condition2 = make_linked_ptr(
195 new json_schema_compiler::any::Any);
196 condition2->Init(*base::test::ParseJson(
197 "{ \n" 190 "{ \n"
198 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" 191 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
199 " \"url\": { \n" 192 " \"url\": { \n"
200 " \"hostSuffix\": \"example.com\", \n" 193 " \"hostSuffix\": \"example.com\", \n"
201 " \"hostPrefix\": \"www\", \n" 194 " \"hostPrefix\": \"www\", \n"
202 " \"schemes\": [\"https\"], \n" 195 " \"schemes\": [\"https\"], \n"
203 " }, \n" 196 " }, \n"
204 "}")); 197 "}").release()));
205 conditions.push_back(condition2);
206 198
207 // Test insertion 199 // Test insertion
208 std::string error; 200 std::string error;
209 scoped_ptr<WebRequestConditionSet> result = 201 scoped_ptr<WebRequestConditionSet> result =
210 WebRequestConditionSet::Create(matcher.condition_factory(), 202 WebRequestConditionSet::Create(matcher.condition_factory(),
211 conditions, &error); 203 conditions, &error);
212 EXPECT_EQ("", error); 204 EXPECT_EQ("", error);
213 ASSERT_TRUE(result.get()); 205 ASSERT_TRUE(result.get());
214 EXPECT_EQ(2u, result->conditions().size()); 206 EXPECT_EQ(2u, result->conditions().size());
215 207
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 -1, 242 -1,
251 url_match_ids, 243 url_match_ids,
252 DeclarativeWebRequestData(&https_foo_request, ON_BEFORE_REQUEST))); 244 DeclarativeWebRequestData(&https_foo_request, ON_BEFORE_REQUEST)));
253 } 245 }
254 246
255 TEST(WebRequestConditionTest, TestPortFilter) { 247 TEST(WebRequestConditionTest, TestPortFilter) {
256 // Necessary for TestURLRequest. 248 // Necessary for TestURLRequest.
257 MessageLoop message_loop(MessageLoop::TYPE_IO); 249 MessageLoop message_loop(MessageLoop::TYPE_IO);
258 URLMatcher matcher; 250 URLMatcher matcher;
259 251
260 linked_ptr<json_schema_compiler::any::Any> any_condition = 252 WebRequestConditionSet::AnyVector conditions;
261 make_linked_ptr(new json_schema_compiler::any::Any); 253 conditions.push_back(linked_ptr<base::Value>(base::test::ParseJson(
262 any_condition->Init(*base::test::ParseJson(
263 "{ \n" 254 "{ \n"
264 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" 255 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
265 " \"url\": { \n" 256 " \"url\": { \n"
266 " \"ports\": [80, [1000, 1010]], \n" // Allow 80;1000-1010. 257 " \"ports\": [80, [1000, 1010]], \n" // Allow 80;1000-1010.
267 " \"hostSuffix\": \"example.com\", \n" 258 " \"hostSuffix\": \"example.com\", \n"
268 " }, \n" 259 " }, \n"
269 "}")); 260 "}").release()));
270 WebRequestConditionSet::AnyVector conditions;
271 conditions.push_back(any_condition);
272 261
273 // Test insertion 262 // Test insertion
274 std::string error; 263 std::string error;
275 scoped_ptr<WebRequestConditionSet> result = 264 scoped_ptr<WebRequestConditionSet> result =
276 WebRequestConditionSet::Create(matcher.condition_factory(), 265 WebRequestConditionSet::Create(matcher.condition_factory(),
277 conditions, &error); 266 conditions, &error);
278 EXPECT_EQ("", error); 267 EXPECT_EQ("", error);
279 ASSERT_TRUE(result.get()); 268 ASSERT_TRUE(result.get());
280 EXPECT_EQ(1u, result->conditions().size()); 269 EXPECT_EQ(1u, result->conditions().size());
281 270
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // filters. 324 // filters.
336 " \"requestHeaders\": [{}], \n" 325 " \"requestHeaders\": [{}], \n"
337 " \"responseHeaders\": [{}], \n" 326 " \"responseHeaders\": [{}], \n"
338 "}"), 327 "}"),
339 &error); 328 &error);
340 EXPECT_FALSE(error.empty()); 329 EXPECT_FALSE(error.empty());
341 EXPECT_FALSE(result.get()); 330 EXPECT_FALSE(result.get());
342 } 331 }
343 332
344 } // namespace extensions 333 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698