| Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc
|
| index 3d6895c559d3856079aab304eb38a3142c7e4d0d..56ca28a396bc1346b630afe6077549b4e737b62a 100644
|
| --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc
|
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc
|
| @@ -8,6 +8,7 @@
|
|
|
| #include "base/memory/linked_ptr.h"
|
| #include "base/message_loop.h"
|
| +#include "base/stl_util.h"
|
| #include "base/values.h"
|
| #include "chrome/common/extensions/matcher/url_matcher_constants.h"
|
| #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h"
|
| @@ -42,6 +43,12 @@ class TestWebRequestRulesRegistry : public WebRequestRulesRegistry {
|
| // to be cleared.
|
| int num_clear_cache_calls() const { return num_clear_cache_calls_; }
|
|
|
| + // How many rules are there which have some conditions not triggered by URL
|
| + // matches.
|
| + size_t RulesWithoutTriggers() const {
|
| + return rules_with_untriggered_conditions_for_test().size();
|
| + }
|
| +
|
| protected:
|
| virtual ~TestWebRequestRulesRegistry() {}
|
|
|
| @@ -224,7 +231,7 @@ TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
|
| EXPECT_EQ("", error);
|
| EXPECT_EQ(1, registry->num_clear_cache_calls());
|
|
|
| - std::set<WebRequestRule::GlobalRuleId> matches;
|
| + std::set<const WebRequestRule*> matches;
|
|
|
| GURL http_url("http://www.example.com");
|
| net::TestURLRequestContext context;
|
| @@ -232,18 +239,22 @@ TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
|
| matches = registry->GetMatches(
|
| WebRequestRule::RequestData(&http_request, ON_BEFORE_REQUEST));
|
| EXPECT_EQ(2u, matches.size());
|
| - EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId1)) !=
|
| - matches.end());
|
| - EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId2)) !=
|
| - matches.end());
|
| +
|
| + std::set<WebRequestRule::GlobalRuleId> matches_ids;
|
| + for (std::set<const WebRequestRule*>::const_iterator it = matches.begin();
|
| + it != matches.end(); ++it)
|
| + matches_ids.insert((*it)->id());
|
| + EXPECT_TRUE(ContainsKey(matches_ids, std::make_pair(kExtensionId, kRuleId1)));
|
| + EXPECT_TRUE(ContainsKey(matches_ids, std::make_pair(kExtensionId, kRuleId2)));
|
|
|
| GURL foobar_url("http://www.foobar.com");
|
| net::TestURLRequest foobar_request(foobar_url, NULL, &context);
|
| matches = registry->GetMatches(
|
| WebRequestRule::RequestData(&foobar_request, ON_BEFORE_REQUEST));
|
| EXPECT_EQ(1u, matches.size());
|
| - EXPECT_TRUE(matches.find(std::make_pair(kExtensionId, kRuleId2)) !=
|
| - matches.end());
|
| + WebRequestRule::GlobalRuleId expected_pair =
|
| + std::make_pair(kExtensionId, kRuleId2);
|
| + EXPECT_EQ(expected_pair, (*matches.begin())->id());
|
| }
|
|
|
| TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
|
| @@ -263,6 +274,7 @@ TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
|
| std::vector<linked_ptr<RulesRegistry::Rule> > registered_rules;
|
| registry->GetAllRules(kExtensionId, ®istered_rules);
|
| EXPECT_EQ(2u, registered_rules.size());
|
| + EXPECT_EQ(1u, registry->RulesWithoutTriggers());
|
|
|
| // Remove first rule.
|
| std::vector<std::string> rules_to_remove;
|
| @@ -275,6 +287,7 @@ TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
|
| registered_rules.clear();
|
| registry->GetAllRules(kExtensionId, ®istered_rules);
|
| EXPECT_EQ(1u, registered_rules.size());
|
| + EXPECT_EQ(1u, registry->RulesWithoutTriggers());
|
|
|
| // Now rules_to_remove contains both rules, i.e. one that does not exist in
|
| // the rules registry anymore. Effectively we only remove the second rule.
|
| @@ -287,6 +300,7 @@ TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
|
| registered_rules.clear();
|
| registry->GetAllRules(kExtensionId, ®istered_rules);
|
| EXPECT_EQ(0u, registered_rules.size());
|
| + EXPECT_EQ(0u, registry->RulesWithoutTriggers());
|
|
|
| EXPECT_TRUE(registry->IsEmpty());
|
| }
|
|
|