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

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

Issue 154473002: Support redirectUrl at onHeadersReceived in WebRequest / DWR API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix WebRequestRulesRegistrySimpleTest.StageChecker test Created 6 years, 9 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_webrequest/webrequest_action .h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action .h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 #undef CallPerlToRe2Style 272 #undef CallPerlToRe2Style
273 } 273 }
274 274
275 TEST_F(WebRequestActionWithThreadsTest, PermissionsToRedirect) { 275 TEST_F(WebRequestActionWithThreadsTest, PermissionsToRedirect) {
276 const char kAction[] = 276 const char kAction[] =
277 "[{" 277 "[{"
278 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\"," 278 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\","
279 " \"redirectUrl\": \"http://www.foobar.com\"" 279 " \"redirectUrl\": \"http://www.foobar.com\""
280 "}]"; 280 "}]";
281 CheckActionNeedsAllUrls(kAction, ON_BEFORE_REQUEST); 281 CheckActionNeedsAllUrls(kAction, ON_BEFORE_REQUEST);
282 CheckActionNeedsAllUrls(kAction, ON_HEADERS_RECEIVED);
282 } 283 }
283 284
284 TEST_F(WebRequestActionWithThreadsTest, PermissionsToRedirectByRegEx) { 285 TEST_F(WebRequestActionWithThreadsTest, PermissionsToRedirectByRegEx) {
285 const char kAction[] = 286 const char kAction[] =
286 "[{" 287 "[{"
287 " \"instanceType\": \"declarativeWebRequest.RedirectByRegEx\"," 288 " \"instanceType\": \"declarativeWebRequest.RedirectByRegEx\","
288 " \"from\": \".*\"," 289 " \"from\": \".*\","
289 " \"to\": \"http://www.foobar.com\"" 290 " \"to\": \"http://www.foobar.com\""
290 "}]"; 291 "}]";
291 CheckActionNeedsAllUrls(kAction, ON_BEFORE_REQUEST); 292 CheckActionNeedsAllUrls(kAction, ON_BEFORE_REQUEST);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 "[{" 436 "[{"
436 " \"instanceType\": \"declarativeWebRequest.RedirectToTransparentImage\"" 437 " \"instanceType\": \"declarativeWebRequest.RedirectToTransparentImage\""
437 "}]"; 438 "}]";
438 scoped_ptr<WebRequestActionSet> action_set(CreateSetOfActions(kAction)); 439 scoped_ptr<WebRequestActionSet> action_set(CreateSetOfActions(kAction));
439 440
440 // Redirecting to transparent images works without full host permissions. 441 // Redirecting to transparent images works without full host permissions.
441 EXPECT_TRUE(ActionWorksOnRequest("http://test.org", 442 EXPECT_TRUE(ActionWorksOnRequest("http://test.org",
442 extension_->id(), 443 extension_->id(),
443 action_set.get(), 444 action_set.get(),
444 ON_BEFORE_REQUEST)); 445 ON_BEFORE_REQUEST));
446 EXPECT_TRUE(ActionWorksOnRequest("http://test.org",
447 extension_->id(),
448 action_set.get(),
449 ON_HEADERS_RECEIVED));
445 } 450 }
446 451
447 TEST_F(WebRequestActionWithThreadsTest, PermissionsToRedirectToEmptyDocument) { 452 TEST_F(WebRequestActionWithThreadsTest, PermissionsToRedirectToEmptyDocument) {
448 const char kAction[] = 453 const char kAction[] =
449 "[{" 454 "[{"
450 " \"instanceType\": \"declarativeWebRequest.RedirectToEmptyDocument\"" 455 " \"instanceType\": \"declarativeWebRequest.RedirectToEmptyDocument\""
451 "}]"; 456 "}]";
452 scoped_ptr<WebRequestActionSet> action_set(CreateSetOfActions(kAction)); 457 scoped_ptr<WebRequestActionSet> action_set(CreateSetOfActions(kAction));
453 458
454 // Redirecting to the empty document works without full host permissions. 459 // Redirecting to the empty document works without full host permissions.
455 EXPECT_TRUE(ActionWorksOnRequest("http://test.org", 460 EXPECT_TRUE(ActionWorksOnRequest("http://test.org",
456 extension_->id(), 461 extension_->id(),
457 action_set.get(), 462 action_set.get(),
458 ON_BEFORE_REQUEST)); 463 ON_BEFORE_REQUEST));
464 EXPECT_TRUE(ActionWorksOnRequest("http://test.org",
465 extension_->id(),
466 action_set.get(),
467 ON_HEADERS_RECEIVED));
459 } 468 }
460 469
461 TEST_F(WebRequestActionWithThreadsTest, PermissionsToIgnore) { 470 TEST_F(WebRequestActionWithThreadsTest, PermissionsToIgnore) {
462 const char kAction[] = 471 const char kAction[] =
463 "[{" 472 "[{"
464 " \"instanceType\": \"declarativeWebRequest.IgnoreRules\"," 473 " \"instanceType\": \"declarativeWebRequest.IgnoreRules\","
465 " \"lowerPriorityThan\": 123," 474 " \"lowerPriorityThan\": 123,"
466 " \"hasTag\": \"some_tag\"" 475 " \"hasTag\": \"some_tag\""
467 "}]"; 476 "}]";
468 scoped_ptr<WebRequestActionSet> action_set(CreateSetOfActions(kAction)); 477 scoped_ptr<WebRequestActionSet> action_set(CreateSetOfActions(kAction));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 for (WebRequestActionSet::Actions::const_iterator it = 581 for (WebRequestActionSet::Actions::const_iterator it =
573 action_set->actions().begin(); 582 action_set->actions().begin();
574 it != action_set->actions().end(); 583 it != action_set->actions().end();
575 ++it) { 584 ++it) {
576 EXPECT_EQ(kExpectedNames[index], (*it)->GetName()); 585 EXPECT_EQ(kExpectedNames[index], (*it)->GetName());
577 ++index; 586 ++index;
578 } 587 }
579 } 588 }
580 589
581 } // namespace extensions 590 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698