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

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

Issue 13699007: Provide a mechanism to the decl. WebRequest API to match URLs without the query against a RegEx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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_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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 585
586 scoped_refptr<WebRequestRulesRegistry> registry( 586 scoped_refptr<WebRequestRulesRegistry> registry(
587 new TestWebRequestRulesRegistry()); 587 new TestWebRequestRulesRegistry());
588 588
589 URLMatcher matcher; 589 URLMatcher matcher;
590 std::string error = registry->AddRulesImpl(kExtensionId, rules); 590 std::string error = registry->AddRulesImpl(kExtensionId, rules);
591 EXPECT_THAT(error, HasSubstr("no time in the request life-cycle")); 591 EXPECT_THAT(error, HasSubstr("no time in the request life-cycle"));
592 EXPECT_TRUE(registry->IsEmpty()); 592 EXPECT_TRUE(registry->IsEmpty());
593 } 593 }
594 594
595 TEST_F(WebRequestRulesRegistryTest, CheckStrippedUrlRegEx) {
596 const char kRule[] =
597 "{ \n"
598 " \"id\": \"rule1\", \n"
599 " \"conditions\": [ \n"
600 " { \n"
601 " \"instanceType\": \"declarativeWebRequest.RequestMatcher\", \n"
602 " \"url\": {\"strippedUrlMatches\": \"fo+.com\"} \n"
603 " } \n"
604 " ], \n"
605 " \"actions\": [ \n"
606 " { \n"
607 " \"instanceType\": \"declarativeWebRequest.RedirectRequest\",\n"
608 " \"redirectUrl\": \"http://bar.com\" \n"
609 " } \n"
610 " ], \n"
611 " \"priority\": 200 \n"
612 "} ";
613
614 scoped_ptr<Value> value(base::JSONReader::Read(kRule));
615 ASSERT_TRUE(value.get());
616
617 std::vector<linked_ptr<RulesRegistry::Rule> > rules;
618 rules.push_back(make_linked_ptr(new RulesRegistry::Rule));
619 ASSERT_TRUE(RulesRegistry::Rule::Populate(*value, rules.back().get()));
620
621 scoped_refptr<WebRequestRulesRegistry> registry(
622 new TestWebRequestRulesRegistry());
623
624 URLMatcher matcher;
625 std::string error = registry->AddRulesImpl(kExtensionId, rules);
626 EXPECT_EQ("", error);
627
628 net::TestURLRequestContext context;
629 std::list<LinkedPtrEventResponseDelta> deltas;
630
631 // No match because match is in the query parameter.
632 GURL url1("http://bar.com/index.html?foo.com");
633 net::TestURLRequest request1(url1, NULL, &context, NULL);
634 WebRequestData request_data1(&request1, ON_BEFORE_REQUEST);
635 deltas = registry->CreateDeltas(NULL, request_data1, false);
636 EXPECT_EQ(0u, deltas.size());
637
638 // This is a correct match.
639 GURL url2("http://foo.com/index.html");
640 net::TestURLRequest request2(url2, NULL, &context, NULL);
641 WebRequestData request_data2(&request2, ON_BEFORE_REQUEST);
642 deltas = registry->CreateDeltas(NULL, request_data2, false);
643 EXPECT_EQ(1u, deltas.size());
644 }
595 645
596 } // namespace extensions 646 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/events.json » ('j') | chrome/common/extensions/api/events.json » ('J')

Powered by Google App Engine
This is Rietveld 408576698