| 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_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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 // Make sure that the right rule succeeded. | 660 // Make sure that the right rule succeeded. |
| 661 EXPECT_EQ(1u, matches.size()); | 661 EXPECT_EQ(1u, matches.size()); |
| 662 EXPECT_EQ(WebRequestRule::GlobalRuleId(std::make_pair(kExtensionId, | 662 EXPECT_EQ(WebRequestRule::GlobalRuleId(std::make_pair(kExtensionId, |
| 663 matchingRuleIds[i])), | 663 matchingRuleIds[i])), |
| 664 (*matches.begin())->id()); | 664 (*matches.begin())->id()); |
| 665 } | 665 } |
| 666 } | 666 } |
| 667 | 667 |
| 668 TEST(WebRequestRulesRegistrySimpleTest, StageChecker) { | 668 TEST(WebRequestRulesRegistrySimpleTest, StageChecker) { |
| 669 // The contentType condition can only be evaluated during ON_HEADERS_RECEIVED | 669 // The contentType condition can only be evaluated during ON_HEADERS_RECEIVED |
| 670 // but the redirect action can only be executed during ON_BEFORE_REQUEST. | 670 // but the SetRequestHeader action can only be executed during |
| 671 // ON_BEFORE_SEND_HEADERS. |
| 671 // Therefore, this is an inconsistent rule that needs to be flagged. | 672 // Therefore, this is an inconsistent rule that needs to be flagged. |
| 672 const char kRule[] = | 673 const char kRule[] = |
| 673 "{ \n" | 674 "{ \n" |
| 674 " \"id\": \"rule1\", \n" | 675 " \"id\": \"rule1\", \n" |
| 675 " \"conditions\": [ \n" | 676 " \"conditions\": [ \n" |
| 676 " { \n" | 677 " { \n" |
| 677 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" | 678 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
| 678 " \"url\": {\"hostSuffix\": \"foo.com\"}, \n" | 679 " \"url\": {\"hostSuffix\": \"foo.com\"}, \n" |
| 679 " \"contentType\": [\"image/jpeg\"] \n" | 680 " \"contentType\": [\"image/jpeg\"] \n" |
| 680 " } \n" | 681 " } \n" |
| 681 " ], \n" | 682 " ], \n" |
| 682 " \"actions\": [ \n" | 683 " \"actions\": [ \n" |
| 683 " { \n" | 684 " { \n" |
| 684 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\",\n" | 685 " \"instanceType\": \"declarativeWebRequest.SetRequestHeader\",\n" |
| 685 " \"redirectUrl\": \"http://bar.com\" \n" | 686 " \"name\": \"Content-Type\", \n" |
| 686 " } \n" | 687 " \"value\": \"text/plain\" \n" |
| 687 " ], \n" | 688 " } \n" |
| 688 " \"priority\": 200 \n" | 689 " ], \n" |
| 689 "} "; | 690 " \"priority\": 200 \n" |
| 691 "} "; |
| 690 | 692 |
| 691 scoped_ptr<base::Value> value(base::JSONReader::Read(kRule)); | 693 scoped_ptr<base::Value> value(base::JSONReader::Read(kRule)); |
| 692 ASSERT_TRUE(value); | 694 ASSERT_TRUE(value); |
| 693 | 695 |
| 694 RulesRegistry::Rule rule; | 696 RulesRegistry::Rule rule; |
| 695 ASSERT_TRUE(RulesRegistry::Rule::Populate(*value, &rule)); | 697 ASSERT_TRUE(RulesRegistry::Rule::Populate(*value, &rule)); |
| 696 | 698 |
| 697 std::string error; | 699 std::string error; |
| 698 URLMatcher matcher; | 700 URLMatcher matcher; |
| 699 scoped_ptr<WebRequestConditionSet> conditions = | 701 scoped_ptr<WebRequestConditionSet> conditions = |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 | 805 |
| 804 // This is a correct match. | 806 // This is a correct match. |
| 805 GURL url2("http://foo.com/index.html"); | 807 GURL url2("http://foo.com/index.html"); |
| 806 net::TestURLRequest request2(url2, net::DEFAULT_PRIORITY, NULL, &context); | 808 net::TestURLRequest request2(url2, net::DEFAULT_PRIORITY, NULL, &context); |
| 807 WebRequestData request_data2(&request2, ON_BEFORE_REQUEST); | 809 WebRequestData request_data2(&request2, ON_BEFORE_REQUEST); |
| 808 deltas = registry->CreateDeltas(NULL, request_data2, false); | 810 deltas = registry->CreateDeltas(NULL, request_data2, false); |
| 809 EXPECT_EQ(1u, deltas.size()); | 811 EXPECT_EQ(1u, deltas.size()); |
| 810 } | 812 } |
| 811 | 813 |
| 812 } // namespace extensions | 814 } // namespace extensions |
| OLD | NEW |