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

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

Issue 493633003: Browser changes for wiring up RequestContentScript API to shared memory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nit: Inline methods in unit tests Created 6 years, 3 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_rules_ registry.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 std::string error; 699 std::string error;
700 URLMatcher matcher; 700 URLMatcher matcher;
701 scoped_ptr<WebRequestConditionSet> conditions = 701 scoped_ptr<WebRequestConditionSet> conditions =
702 WebRequestConditionSet::Create( 702 WebRequestConditionSet::Create(
703 NULL, matcher.condition_factory(), rule.conditions, &error); 703 NULL, matcher.condition_factory(), rule.conditions, &error);
704 ASSERT_TRUE(error.empty()) << error; 704 ASSERT_TRUE(error.empty()) << error;
705 ASSERT_TRUE(conditions); 705 ASSERT_TRUE(conditions);
706 706
707 bool bad_message = false; 707 bool bad_message = false;
708 scoped_ptr<WebRequestActionSet> actions = 708 scoped_ptr<WebRequestActionSet> actions =
709 WebRequestActionSet::Create(NULL, rule.actions, &error, &bad_message); 709 WebRequestActionSet::Create(
710 NULL, NULL, rule.actions, &error, &bad_message);
710 ASSERT_TRUE(error.empty()) << error; 711 ASSERT_TRUE(error.empty()) << error;
711 ASSERT_FALSE(bad_message); 712 ASSERT_FALSE(bad_message);
712 ASSERT_TRUE(actions); 713 ASSERT_TRUE(actions);
713 714
714 EXPECT_FALSE(WebRequestRulesRegistry::StageChecker( 715 EXPECT_FALSE(WebRequestRulesRegistry::StageChecker(
715 conditions.get(), actions.get(), &error)); 716 conditions.get(), actions.get(), &error));
716 EXPECT_THAT(error, HasSubstr("no time in the request life-cycle")); 717 EXPECT_THAT(error, HasSubstr("no time in the request life-cycle"));
717 EXPECT_THAT(error, HasSubstr(actions->actions().back()->GetName())); 718 EXPECT_THAT(error, HasSubstr(actions->actions().back()->GetName()));
718 } 719 }
719 720
720 TEST(WebRequestRulesRegistrySimpleTest, HostPermissionsChecker) { 721 TEST(WebRequestRulesRegistrySimpleTest, HostPermissionsChecker) {
721 const char kAction[] = // This action requires all URLs host permission. 722 const char kAction[] = // This action requires all URLs host permission.
722 "{ \n" 723 "{ \n"
723 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\",\n" 724 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\",\n"
724 " \"redirectUrl\": \"http://bar.com\" \n" 725 " \"redirectUrl\": \"http://bar.com\" \n"
725 "} "; 726 "} ";
726 scoped_ptr<base::Value> action_value(base::JSONReader::Read(kAction)); 727 scoped_ptr<base::Value> action_value(base::JSONReader::Read(kAction));
727 ASSERT_TRUE(action_value); 728 ASSERT_TRUE(action_value);
728 729
729 WebRequestActionSet::AnyVector actions; 730 WebRequestActionSet::AnyVector actions;
730 actions.push_back(linked_ptr<base::Value>(action_value.release())); 731 actions.push_back(linked_ptr<base::Value>(action_value.release()));
731 ASSERT_TRUE(actions.back().get()); 732 ASSERT_TRUE(actions.back().get());
732 733
733 std::string error; 734 std::string error;
734 bool bad_message = false; 735 bool bad_message = false;
735 scoped_ptr<WebRequestActionSet> action_set( 736 scoped_ptr<WebRequestActionSet> action_set(
736 WebRequestActionSet::Create(NULL, actions, &error, &bad_message)); 737 WebRequestActionSet::Create(NULL, NULL, actions, &error, &bad_message));
737 ASSERT_TRUE(error.empty()) << error; 738 ASSERT_TRUE(error.empty()) << error;
738 ASSERT_FALSE(bad_message); 739 ASSERT_FALSE(bad_message);
739 ASSERT_TRUE(action_set); 740 ASSERT_TRUE(action_set);
740 741
741 scoped_refptr<Extension> extension_no_url( 742 scoped_refptr<Extension> extension_no_url(
742 LoadManifest("permissions", "web_request_no_host.json")); 743 LoadManifest("permissions", "web_request_no_host.json"));
743 scoped_refptr<Extension> extension_some_urls( 744 scoped_refptr<Extension> extension_some_urls(
744 LoadManifest("permissions", "web_request_com_host_permissions.json")); 745 LoadManifest("permissions", "web_request_com_host_permissions.json"));
745 scoped_refptr<Extension> extension_all_urls( 746 scoped_refptr<Extension> extension_all_urls(
746 LoadManifest("permissions", "web_request_all_host_permissions.json")); 747 LoadManifest("permissions", "web_request_all_host_permissions.json"));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 806
806 // This is a correct match. 807 // This is a correct match.
807 GURL url2("http://foo.com/index.html"); 808 GURL url2("http://foo.com/index.html");
808 net::TestURLRequest request2(url2, net::DEFAULT_PRIORITY, NULL, &context); 809 net::TestURLRequest request2(url2, net::DEFAULT_PRIORITY, NULL, &context);
809 WebRequestData request_data2(&request2, ON_BEFORE_REQUEST); 810 WebRequestData request_data2(&request2, ON_BEFORE_REQUEST);
810 deltas = registry->CreateDeltas(NULL, request_data2, false); 811 deltas = registry->CreateDeltas(NULL, request_data2, false);
811 EXPECT_EQ(1u, deltas.size()); 812 EXPECT_EQ(1u, deltas.size());
812 } 813 }
813 814
814 } // namespace extensions 815 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698