Chromium Code Reviews| 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..6433f59487ee5ed799c3b21598d5d0c4b9a304f1 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 |
| @@ -42,6 +42,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 +230,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 +238,24 @@ 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(matches_ids.find(std::make_pair(kExtensionId, kRuleId1)) != |
|
Jeffrey Yasskin
2012/12/18 21:56:02
Use ContainsKey for this?
vabr (Chromium)
2012/12/19 08:38:19
Done.
|
| + matches_ids.end()); |
| + EXPECT_TRUE(matches_ids.find(std::make_pair(kExtensionId, kRuleId2)) != |
| + matches_ids.end()); |
| 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 +275,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 +288,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 +301,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()); |
| } |