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

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

Issue 11038031: Adding condition attributes for request headers to Declarative WebRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed 0-sized arrays. Created 8 years, 2 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_attribute.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion_attribute.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return dictionary.Pass(); 227 return dictionary.Pass();
228 } 228 }
229 229
230 // Returns whether the response headers from |url_request| satisfy the match 230 // Returns whether the response headers from |url_request| satisfy the match
231 // criteria given in |tests|. For at least one |i| all tests from |tests[i]| 231 // criteria given in |tests|. For at least one |i| all tests from |tests[i]|
232 // must pass. If |positive_test| is true, the dictionary is interpreted as the 232 // must pass. If |positive_test| is true, the dictionary is interpreted as the
233 // containsHeaders property of a RequestMatcher, otherwise as 233 // containsHeaders property of a RequestMatcher, otherwise as
234 // doesNotContainHeaders. 234 // doesNotContainHeaders.
235 void MatchAndCheck(const std::vector< std::vector<const std::string*> >& tests, 235 void MatchAndCheck(const std::vector< std::vector<const std::string*> >& tests,
236 const std::string& key, 236 const std::string& key,
237 RequestStage stage,
237 net::URLRequest* url_request, 238 net::URLRequest* url_request,
238 bool* result) { 239 bool* result) {
239 ListValue contains_headers; 240 ListValue contains_headers;
240 for (size_t i = 0; i < tests.size(); ++i) { 241 for (size_t i = 0; i < tests.size(); ++i) {
241 scoped_ptr<DictionaryValue> temp(GetDictionaryFromArray(tests[i])); 242 scoped_ptr<DictionaryValue> temp(GetDictionaryFromArray(tests[i]));
242 ASSERT_TRUE(temp.get() != NULL); 243 ASSERT_TRUE(temp.get() != NULL);
243 contains_headers.Append(temp.release()); 244 contains_headers.Append(temp.release());
244 } 245 }
245 246
246 std::string error; 247 std::string error;
247 scoped_ptr<WebRequestConditionAttribute> attribute = 248 scoped_ptr<WebRequestConditionAttribute> attribute =
248 WebRequestConditionAttribute::Create(key, &contains_headers, &error); 249 WebRequestConditionAttribute::Create(key, &contains_headers, &error);
249 ASSERT_EQ("", error); 250 ASSERT_EQ("", error);
250 ASSERT_TRUE(attribute.get() != NULL); 251 ASSERT_TRUE(attribute.get() != NULL);
251 252
252 *result = attribute->IsFulfilled(WebRequestRule::RequestData( 253 *result = attribute->IsFulfilled(WebRequestRule::RequestData(
253 url_request, ON_HEADERS_RECEIVED, url_request->response_headers())); 254 url_request, stage, url_request->response_headers()));
254 } 255 }
255 256
256 } // namespace 257 } // namespace
257 258
259 // Here we test WebRequestConditionAttributeRequestHeaders for matching
260 // correctly against request headers. This test is not as extensive as
261 // "ResponseHeaders" (below), because the header-matching code is shared
262 // by both types of condition attributes, so it is enough to test it once.
263 TEST(WebRequestConditionAttributeTest, RequestHeaders) {
264 // Necessary for TestURLRequest.
265 MessageLoop message_loop(MessageLoop::TYPE_IO);
266
267 TestURLRequestContext context;
268 TestDelegate delegate;
269 TestURLRequest url_request(GURL("http://example.com"), // Dummy URL.
270 &delegate, &context);
271 url_request.SetExtraRequestHeaderByName(
272 "Custom-header", "custom/value", true /* overwrite */);
273 url_request.Start();
274 MessageLoop::current()->Run();
275
276 std::vector< std::vector<const std::string*> > tests;
battre 2012/10/05 12:50:03 nit: the first space after std::vector< does not b
vabr (Chromium) 2012/10/05 15:56:53 Actually, the Google style guide allows it (search
277 bool result;
battre 2012/10/05 12:50:03 can you please initialize this to false by default
vabr (Chromium) 2012/10/05 15:56:53 Done.
278
279 #define MATCH_REQUEST_HEADERS(key) \
280 MatchAndCheck(tests, key, ON_BEFORE_SEND_HEADERS, &url_request, &result);
battre 2012/10/05 12:50:03 How about defining a variable stage and then repea
vabr (Chromium) 2012/10/05 15:56:53 Done. Sometimes it overflows, but I think the code
281
282 // First set of test data -- passing conjunction.
283 const std::string kPassingCondition[] = {
284 keys::kNameContainsKey, "CuStOm", // Header names are case insensitive.
285 keys::kNameEqualsKey, "custom-header",
286 keys::kValueSuffixKey, "alue",
287 keys::kValuePrefixKey, "custom/value"
288 };
289 const size_t kPassingConditionSizes[] = { arraysize(kPassingCondition) };
290 GetArrayAsVector(kPassingCondition, kPassingConditionSizes, 1u, &tests);
291 // Positive filter, passing (conjunction of tests).
292 MATCH_REQUEST_HEADERS(keys::kRequestHeadersKey);
293 EXPECT_TRUE(result);
294 // Negative filter, failing (conjunction of tests).
295 MATCH_REQUEST_HEADERS(keys::kExcludeRequestHeadersKey);
296 EXPECT_FALSE(result);
297
298 // Second set of test data -- failing disjunction.
299 const std::string kFailCondition[] = {
300 keys::kNameSuffixKey, "Custom", // Test 1.
301 keys::kNameEqualsKey, "ustom-valu", // Test 2.
302 keys::kValuePrefixKey, "custom ", // Test 3.
303 keys::kValueContainsKey, " value" // Test 4.
304 };
305 const size_t kFailConditionSizes[] = { 2u, 2u, 2u, 2u };
306 GetArrayAsVector(kFailCondition, kFailConditionSizes, 4u, &tests);
307 // Positive filter, failing (disjunction of tests).
308 MATCH_REQUEST_HEADERS(keys::kRequestHeadersKey);
309 EXPECT_FALSE(result);
310 // Negative filter, passing (disjunction of tests).
311 MATCH_REQUEST_HEADERS(keys::kExcludeRequestHeadersKey);
312 EXPECT_TRUE(result);
313
314 // Third set of test data, corner case -- empty disjunction.
315 GetArrayAsVector(NULL, NULL, 0u, &tests);
316 // Positive filter, failing (no test to pass).
317 MATCH_REQUEST_HEADERS(keys::kRequestHeadersKey);
318 EXPECT_FALSE(result);
319 // Negative filter, passing (no test to fail).
320 MATCH_REQUEST_HEADERS(keys::kExcludeRequestHeadersKey);
321 EXPECT_TRUE(result);
322
323 // Fourth set of test data, corner case -- empty conjunction.
324 const size_t kEmptyConjunctionSizes[] = { 0u };
325 GetArrayAsVector(NULL, kEmptyConjunctionSizes, 1u, &tests);
326 // Positive filter, passing (trivial test).
327 MATCH_REQUEST_HEADERS(keys::kRequestHeadersKey);
328 EXPECT_TRUE(result);
329 // Negative filter, failing.
battre 2012/10/05 12:50:03 Can you remind me again, why this is supposed to f
vabr (Chromium) 2012/10/05 15:56:53 It corresponds to constructing one RequestMatcher
330 MATCH_REQUEST_HEADERS(keys::kExcludeRequestHeadersKey);
331 EXPECT_FALSE(result);
332
333 #undef MATCH_REQUEST_HEADERS
334 }
335
258 // Here we test WebRequestConditionAttributeResponseHeaders for: 336 // Here we test WebRequestConditionAttributeResponseHeaders for:
259 // 1. Correct implementation of prefix/suffix/contains/equals matching. 337 // 1. Correct implementation of prefix/suffix/contains/equals matching.
260 // 2. Performing logical disjunction (||) between multiple specifications. 338 // 2. Performing logical disjunction (||) between multiple specifications.
261 // 3. Negating the match in case of 'doesNotContainHeaders'. 339 // 3. Negating the match in case of 'doesNotContainHeaders'.
262 TEST(WebRequestConditionAttributeTest, Headers) { 340 TEST(WebRequestConditionAttributeTest, ResponseHeaders) {
263 // Necessary for TestURLRequest. 341 // Necessary for TestURLRequest.
264 MessageLoop message_loop(MessageLoop::TYPE_IO); 342 MessageLoop message_loop(MessageLoop::TYPE_IO);
265 343
266 net::TestServer test_server( 344 net::TestServer test_server(
267 net::TestServer::TYPE_HTTP, 345 net::TestServer::TYPE_HTTP,
268 net::TestServer::kLocalhost, 346 net::TestServer::kLocalhost,
269 FilePath(FILE_PATH_LITERAL( 347 FilePath(FILE_PATH_LITERAL(
270 "chrome/test/data/extensions/api_test/webrequest/declarative"))); 348 "chrome/test/data/extensions/api_test/webrequest/declarative")));
271 ASSERT_TRUE(test_server.Start()); 349 ASSERT_TRUE(test_server.Start());
272 350
273 TestURLRequestContext context; 351 TestURLRequestContext context;
274 TestDelegate delegate; 352 TestDelegate delegate;
275 TestURLRequest url_request(test_server.GetURL("files/headers.html"), 353 TestURLRequest url_request(test_server.GetURL("files/headers.html"),
276 &delegate, &context); 354 &delegate, &context);
277 url_request.Start(); 355 url_request.Start();
278 MessageLoop::current()->Run(); 356 MessageLoop::current()->Run();
279 357
280 // In all the tests below we assume that the server includes the headers 358 // In all the tests below we assume that the server includes the headers
281 // Custom-Header: custom/value 359 // Custom-Header: custom/value
282 // Custom-Header-B: valueA 360 // Custom-Header-B: valueA
283 // Custom-Header-B: valueB 361 // Custom-Header-B: valueB
284 // Custom-Header-C: valueC, valueD 362 // Custom-Header-C: valueC, valueD
285 // Custom-Header-D: 363 // Custom-Header-D:
286 // in the response, but does not include "Non-existing: void". 364 // in the response, but does not include "Non-existing: void".
287 365
288 std::vector< std::vector<const std::string*> > tests; 366 std::vector< std::vector<const std::string*> > tests;
289 bool result; 367 bool result;
290 368
369 #define MATCH_RESPONSE_HEADERS(key) \
370 MatchAndCheck(tests, key, ON_HEADERS_RECEIVED, &url_request, &result);
371
291 // 1.a. -- All these tests should pass. 372 // 1.a. -- All these tests should pass.
292 const std::string kPassingCondition[] = { 373 const std::string kPassingCondition[] = {
293 keys::kNamePrefixKey, "Custom", 374 keys::kNamePrefixKey, "Custom",
294 keys::kNameSuffixKey, "m-header", // Header names are case insensitive. 375 keys::kNameSuffixKey, "m-header", // Header names are case insensitive.
295 keys::kValueContainsKey, "alu", 376 keys::kValueContainsKey, "alu",
296 keys::kValueEqualsKey, "custom/value" 377 keys::kValueEqualsKey, "custom/value"
297 }; 378 };
298 const size_t kPassingConditionSizes[] = { arraysize(kPassingCondition) }; 379 const size_t kPassingConditionSizes[] = { arraysize(kPassingCondition) };
299 GetArrayAsVector(kPassingCondition, kPassingConditionSizes, 1u, &tests); 380 GetArrayAsVector(kPassingCondition, kPassingConditionSizes, 1u, &tests);
300 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 381 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
301 EXPECT_TRUE(result); 382 EXPECT_TRUE(result);
302 383
303 // 1.b. -- None of the following tests in the discjunction should pass. 384 // 1.b. -- None of the following tests in the discjunction should pass.
304 const std::string kFailCondition[] = { 385 const std::string kFailCondition[] = {
305 keys::kNamePrefixKey, " Custom", // Test 1. 386 keys::kNamePrefixKey, " Custom", // Test 1.
306 keys::kNameContainsKey, " -", // Test 2. 387 keys::kNameContainsKey, " -", // Test 2.
307 keys::kValueSuffixKey, "alu", // Test 3. 388 keys::kValueSuffixKey, "alu", // Test 3.
308 keys::kValueEqualsKey, "custom" // Test 4. 389 keys::kValueEqualsKey, "custom" // Test 4.
309 }; 390 };
310 const size_t kFailConditionSizes[] = { 2u, 2u, 2u, 2u }; 391 const size_t kFailConditionSizes[] = { 2u, 2u, 2u, 2u };
311 GetArrayAsVector(kFailCondition, kFailConditionSizes, 4u, &tests); 392 GetArrayAsVector(kFailCondition, kFailConditionSizes, 4u, &tests);
312 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 393 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
313 EXPECT_FALSE(result); 394 EXPECT_FALSE(result);
314 395
315 // 1.c. -- This should fail (mixing name and value from different headers) 396 // 1.c. -- This should fail (mixing name and value from different headers)
316 const std::string kMixingCondition[] = { 397 const std::string kMixingCondition[] = {
317 keys::kNameSuffixKey, "Header-B", 398 keys::kNameSuffixKey, "Header-B",
318 keys::kValueEqualsKey, "custom/value" 399 keys::kValueEqualsKey, "custom/value"
319 }; 400 };
320 const size_t kMixingConditionSizes[] = { arraysize(kMixingCondition) }; 401 const size_t kMixingConditionSizes[] = { arraysize(kMixingCondition) };
321 GetArrayAsVector(kMixingCondition, kMixingConditionSizes, 1u, &tests); 402 GetArrayAsVector(kMixingCondition, kMixingConditionSizes, 1u, &tests);
322 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 403 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
323 EXPECT_FALSE(result); 404 EXPECT_FALSE(result);
324 405
325 // 1.d. -- Test handling multiple values for one header (both should pass). 406 // 1.d. -- Test handling multiple values for one header (both should pass).
326 const std::string kMoreValues1[] = { 407 const std::string kMoreValues1[] = {
327 keys::kNameEqualsKey, "Custom-header-b", 408 keys::kNameEqualsKey, "Custom-header-b",
328 keys::kValueEqualsKey, "valueA" 409 keys::kValueEqualsKey, "valueA"
329 }; 410 };
330 const size_t kMoreValues1Sizes[] = { arraysize(kMoreValues1) }; 411 const size_t kMoreValues1Sizes[] = { arraysize(kMoreValues1) };
331 GetArrayAsVector(kMoreValues1, kMoreValues1Sizes, 1u, &tests); 412 GetArrayAsVector(kMoreValues1, kMoreValues1Sizes, 1u, &tests);
332 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 413 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
333 EXPECT_TRUE(result); 414 EXPECT_TRUE(result);
334 const std::string kMoreValues2[] = { 415 const std::string kMoreValues2[] = {
335 keys::kNameEqualsKey, "Custom-header-b", 416 keys::kNameEqualsKey, "Custom-header-b",
336 keys::kValueEqualsKey, "valueB" 417 keys::kValueEqualsKey, "valueB"
337 }; 418 };
338 const size_t kMoreValues2Sizes[] = { arraysize(kMoreValues2) }; 419 const size_t kMoreValues2Sizes[] = { arraysize(kMoreValues2) };
339 GetArrayAsVector(kMoreValues2, kMoreValues2Sizes, 1u, &tests); 420 GetArrayAsVector(kMoreValues2, kMoreValues2Sizes, 1u, &tests);
340 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 421 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
341 EXPECT_TRUE(result); 422 EXPECT_TRUE(result);
342 423
343 // 1.e. -- This should fail as conjunction but pass as disjunction. 424 // 1.e. -- This should fail as conjunction but pass as disjunction.
344 const std::string kConflict[] = { 425 const std::string kConflict[] = {
345 keys::kNameSuffixKey, "Header", // True for some header. 426 keys::kNameSuffixKey, "Header", // True for some header.
346 keys::kNameContainsKey, "Header-B" // True for a different header. 427 keys::kNameContainsKey, "Header-B" // True for a different header.
347 }; 428 };
348 // First disjunction, no conflict. 429 // First disjunction, no conflict.
349 const size_t kNoConflictSizes[] = { 2u, 2u }; 430 const size_t kNoConflictSizes[] = { 2u, 2u };
350 GetArrayAsVector(kConflict, kNoConflictSizes, 2u, &tests); 431 GetArrayAsVector(kConflict, kNoConflictSizes, 2u, &tests);
351 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 432 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
352 EXPECT_TRUE(result); 433 EXPECT_TRUE(result);
353 // Then conjunction, conflict. 434 // Then conjunction, conflict.
354 const size_t kConflictSizes[] = { arraysize(kConflict) }; 435 const size_t kConflictSizes[] = { arraysize(kConflict) };
355 GetArrayAsVector(kConflict, kConflictSizes, 1u, &tests); 436 GetArrayAsVector(kConflict, kConflictSizes, 1u, &tests);
356 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 437 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
357 EXPECT_FALSE(result); 438 EXPECT_FALSE(result);
358 439
359 // 1.f. -- This should pass, checking for correct treatment of ',' in values. 440 // 1.f. -- This should pass, checking for correct treatment of ',' in values.
360 const std::string kComma[] = { 441 const std::string kComma[] = {
361 keys::kNameSuffixKey, "Header-C", 442 keys::kNameSuffixKey, "Header-C",
362 keys::kValueEqualsKey, "valueC, valueD" 443 keys::kValueEqualsKey, "valueC, valueD"
363 }; 444 };
364 const size_t kCommaSizes[] = { arraysize(kComma) }; 445 const size_t kCommaSizes[] = { arraysize(kComma) };
365 GetArrayAsVector(kComma, kCommaSizes, 1u, &tests); 446 GetArrayAsVector(kComma, kCommaSizes, 1u, &tests);
366 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 447 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
367 EXPECT_TRUE(result); 448 EXPECT_TRUE(result);
368 449
369 // 1.g. -- This should pass, empty values are values as well. 450 // 1.g. -- This should pass, empty values are values as well.
370 const std::string kEmpty[] = { 451 const std::string kEmpty[] = {
371 keys::kNameEqualsKey, "custom-header-d", 452 keys::kNameEqualsKey, "custom-header-d",
372 keys::kValueEqualsKey, "" 453 keys::kValueEqualsKey, ""
373 }; 454 };
374 const size_t kEmptySizes[] = { arraysize(kEmpty) }; 455 const size_t kEmptySizes[] = { arraysize(kEmpty) };
375 GetArrayAsVector(kEmpty, kEmptySizes, 1u, &tests); 456 GetArrayAsVector(kEmpty, kEmptySizes, 1u, &tests);
376 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 457 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
377 EXPECT_TRUE(result); 458 EXPECT_TRUE(result);
378 459
379 // 1.h. -- Values are case-sensitive, this should fail. 460 // 1.h. -- Values are case-sensitive, this should fail.
380 const std::string kLowercase[] = { 461 const std::string kLowercase[] = {
381 keys::kNameEqualsKey, "Custom-header-b", 462 keys::kNameEqualsKey, "Custom-header-b",
382 keys::kValuePrefixKey, "valueb", // valueb != valueB 463 keys::kValuePrefixKey, "valueb", // valueb != valueB
383 keys::kNameEqualsKey, "Custom-header-b", 464 keys::kNameEqualsKey, "Custom-header-b",
384 keys::kValueSuffixKey, "valueb", 465 keys::kValueSuffixKey, "valueb",
385 keys::kNameEqualsKey, "Custom-header-b", 466 keys::kNameEqualsKey, "Custom-header-b",
386 keys::kValueContainsKey, "valueb", 467 keys::kValueContainsKey, "valueb",
387 keys::kNameEqualsKey, "Custom-header-b", 468 keys::kNameEqualsKey, "Custom-header-b",
388 keys::kValueEqualsKey, "valueb" 469 keys::kValueEqualsKey, "valueb"
389 }; 470 };
390 const size_t kLowercaseSizes[] = { 4u, 4u, 4u, 4u }; // As disjunction. 471 const size_t kLowercaseSizes[] = { 4u, 4u, 4u, 4u }; // As disjunction.
391 GetArrayAsVector(kLowercase, kLowercaseSizes, 4u, &tests); 472 GetArrayAsVector(kLowercase, kLowercaseSizes, 4u, &tests);
392 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 473 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
393 EXPECT_FALSE(result); 474 EXPECT_FALSE(result);
394 475
395 // 1.i. -- Names are case-insensitive, this should pass. 476 // 1.i. -- Names are case-insensitive, this should pass.
396 const std::string kUppercase[] = { 477 const std::string kUppercase[] = {
397 keys::kNamePrefixKey, "CUSTOM-HEADER-B", 478 keys::kNamePrefixKey, "CUSTOM-HEADER-B",
398 keys::kNameSuffixKey, "CUSTOM-HEADER-B", 479 keys::kNameSuffixKey, "CUSTOM-HEADER-B",
399 keys::kNameEqualsKey, "CUSTOM-HEADER-B", 480 keys::kNameEqualsKey, "CUSTOM-HEADER-B",
400 keys::kNameContainsKey, "CUSTOM-HEADER-B" 481 keys::kNameContainsKey, "CUSTOM-HEADER-B"
401 }; 482 };
402 const size_t kUppercaseSizes[] = { arraysize(kUppercase) }; // Conjunction. 483 const size_t kUppercaseSizes[] = { arraysize(kUppercase) }; // Conjunction.
403 GetArrayAsVector(kUppercase, kUppercaseSizes, 1u, &tests); 484 GetArrayAsVector(kUppercase, kUppercaseSizes, 1u, &tests);
404 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 485 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
405 EXPECT_TRUE(result); 486 EXPECT_TRUE(result);
406 487
407 // 2.a. -- This should pass as disjunction, because one of the tests passes. 488 // 2.a. -- This should pass as disjunction, because one of the tests passes.
408 const std::string kDisjunction[] = { 489 const std::string kDisjunction[] = {
409 keys::kNamePrefixKey, "Non-existing", // This one fails. 490 keys::kNamePrefixKey, "Non-existing", // This one fails.
410 keys::kNameSuffixKey, "Non-existing", // This one fails. 491 keys::kNameSuffixKey, "Non-existing", // This one fails.
411 keys::kValueEqualsKey, "void", // This one fails. 492 keys::kValueEqualsKey, "void", // This one fails.
412 keys::kValueContainsKey, "alu" // This passes. 493 keys::kValueContainsKey, "alu" // This passes.
413 }; 494 };
414 const size_t kDisjunctionSizes[] = { 2u, 2u, 2u, 2u }; 495 const size_t kDisjunctionSizes[] = { 2u, 2u, 2u, 2u };
415 GetArrayAsVector(kDisjunction, kDisjunctionSizes, 4u, &tests); 496 GetArrayAsVector(kDisjunction, kDisjunctionSizes, 4u, &tests);
416 MatchAndCheck(tests, keys::kResponseHeadersKey, &url_request, &result); 497 MATCH_RESPONSE_HEADERS(keys::kResponseHeadersKey);
417 EXPECT_TRUE(result); 498 EXPECT_TRUE(result);
418 499
419 // 3.a. -- This should pass. 500 // 3.a. -- This should pass.
420 const std::string kNonExistent[] = { 501 const std::string kNonExistent[] = {
421 keys::kNameEqualsKey, "Non-existing", 502 keys::kNameEqualsKey, "Non-existing",
422 keys::kValueEqualsKey, "void" 503 keys::kValueEqualsKey, "void"
423 }; 504 };
424 const size_t kNonExistentSizes[] = { arraysize(kNonExistent) }; 505 const size_t kNonExistentSizes[] = { arraysize(kNonExistent) };
425 GetArrayAsVector(kNonExistent, kNonExistentSizes, 1u, &tests); 506 GetArrayAsVector(kNonExistent, kNonExistentSizes, 1u, &tests);
426 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, &url_request, &result); 507 MATCH_RESPONSE_HEADERS(keys::kExcludeResponseHeadersKey);
427 EXPECT_TRUE(result); 508 EXPECT_TRUE(result);
428 509
429 // 3.b. -- This should fail. 510 // 3.b. -- This should fail.
430 const std::string kExisting[] = { 511 const std::string kExisting[] = {
431 keys::kNameEqualsKey, "custom-header-b", 512 keys::kNameEqualsKey, "custom-header-b",
432 keys::kValueEqualsKey, "valueB" 513 keys::kValueEqualsKey, "valueB"
433 }; 514 };
434 const size_t kExistingSize[] = { arraysize(kExisting) }; 515 const size_t kExistingSize[] = { arraysize(kExisting) };
435 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); 516 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests);
436 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, &url_request, &result); 517 MATCH_RESPONSE_HEADERS(keys::kExcludeResponseHeadersKey);
437 EXPECT_FALSE(result); 518 EXPECT_FALSE(result);
519
520 #undef MATCH_RESPONSE_HEADERS
438 } 521 }
439 522
440 } // namespace extensions 523 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698