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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 | 654 |
655 scoped_refptr<WebRequestRulesRegistry> registry( | 655 scoped_refptr<WebRequestRulesRegistry> registry( |
656 new TestWebRequestRulesRegistry()); | 656 new TestWebRequestRulesRegistry()); |
657 | 657 |
658 URLMatcher matcher; | 658 URLMatcher matcher; |
659 std::string error = registry->AddRulesImpl(kExtensionId, rules); | 659 std::string error = registry->AddRulesImpl(kExtensionId, rules); |
660 EXPECT_THAT(error, HasSubstr("no time in the request life-cycle")); | 660 EXPECT_THAT(error, HasSubstr("no time in the request life-cycle")); |
661 EXPECT_TRUE(registry->IsEmpty()); | 661 EXPECT_TRUE(registry->IsEmpty()); |
662 } | 662 } |
663 | 663 |
| 664 TEST_F(WebRequestRulesRegistryTest, CheckOriginAndPathRegEx) { |
| 665 const char kRule[] = |
| 666 "{ \n" |
| 667 " \"id\": \"rule1\", \n" |
| 668 " \"conditions\": [ \n" |
| 669 " { \n" |
| 670 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n" |
| 671 " \"url\": {\"originAndPathMatches\": \"fo+.com\"} \n" |
| 672 " } \n" |
| 673 " ], \n" |
| 674 " \"actions\": [ \n" |
| 675 " { \n" |
| 676 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\",\n" |
| 677 " \"redirectUrl\": \"http://bar.com\" \n" |
| 678 " } \n" |
| 679 " ], \n" |
| 680 " \"priority\": 200 \n" |
| 681 "} "; |
| 682 |
| 683 scoped_ptr<Value> value(base::JSONReader::Read(kRule)); |
| 684 ASSERT_TRUE(value.get()); |
| 685 |
| 686 std::vector<linked_ptr<RulesRegistry::Rule> > rules; |
| 687 rules.push_back(make_linked_ptr(new RulesRegistry::Rule)); |
| 688 ASSERT_TRUE(RulesRegistry::Rule::Populate(*value, rules.back().get())); |
| 689 |
| 690 scoped_refptr<WebRequestRulesRegistry> registry( |
| 691 new TestWebRequestRulesRegistry()); |
| 692 |
| 693 URLMatcher matcher; |
| 694 std::string error = registry->AddRulesImpl(kExtensionId, rules); |
| 695 EXPECT_EQ("", error); |
| 696 |
| 697 net::TestURLRequestContext context; |
| 698 std::list<LinkedPtrEventResponseDelta> deltas; |
| 699 |
| 700 // No match because match is in the query parameter. |
| 701 GURL url1("http://bar.com/index.html?foo.com"); |
| 702 net::TestURLRequest request1(url1, NULL, &context, NULL); |
| 703 WebRequestData request_data1(&request1, ON_BEFORE_REQUEST); |
| 704 deltas = registry->CreateDeltas(NULL, request_data1, false); |
| 705 EXPECT_EQ(0u, deltas.size()); |
| 706 |
| 707 // This is a correct match. |
| 708 GURL url2("http://foo.com/index.html"); |
| 709 net::TestURLRequest request2(url2, NULL, &context, NULL); |
| 710 WebRequestData request_data2(&request2, ON_BEFORE_REQUEST); |
| 711 deltas = registry->CreateDeltas(NULL, request_data2, false); |
| 712 EXPECT_EQ(1u, deltas.size()); |
| 713 } |
664 | 714 |
665 } // namespace extensions | 715 } // namespace extensions |
OLD | NEW |