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

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc

Issue 10905040: Clear in-memory caches of renderers when rules change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
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 2f8bcf6fd805abd1b6aad7f54ca156d7f7845f6b..b6c3e2fcd449e3a618df15c462789bcc5026952c 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
@@ -34,7 +34,13 @@ namespace keys2 = url_matcher_constants;
class TestWebRequestRulesRegistry : public WebRequestRulesRegistry {
public:
- TestWebRequestRulesRegistry() : WebRequestRulesRegistry(NULL, NULL) {}
+ TestWebRequestRulesRegistry()
+ : WebRequestRulesRegistry(NULL, NULL),
+ num_clear_cache_calls_(0) {}
+
+ // Returns how often the in-memory caches of the renderers were instructed
+ // to be cleared.
+ int num_clear_cache_calls() const { return num_clear_cache_calls_; }
protected:
virtual ~TestWebRequestRulesRegistry() {}
@@ -48,6 +54,13 @@ class TestWebRequestRulesRegistry : public WebRequestRulesRegistry {
else
return base::Time();
}
+
+ virtual void ClearCacheOnNavigation() {
+ ++num_clear_cache_calls_;
+ }
+
+ private:
+ int num_clear_cache_calls_;
};
class WebRequestRulesRegistryTest : public testing::Test {
@@ -199,7 +212,7 @@ class WebRequestRulesRegistryTest : public testing::Test {
};
TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
- scoped_refptr<WebRequestRulesRegistry> registry(
+ scoped_refptr<TestWebRequestRulesRegistry> registry(
new TestWebRequestRulesRegistry());
std::string error;
@@ -209,6 +222,7 @@ TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
error = registry->AddRules(kExtensionId, rules);
EXPECT_EQ("", error);
+ EXPECT_EQ(1, registry->num_clear_cache_calls());
std::set<WebRequestRule::GlobalRuleId> matches;
@@ -233,7 +247,7 @@ TEST_F(WebRequestRulesRegistryTest, AddRulesImpl) {
}
TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
- scoped_refptr<WebRequestRulesRegistry> registry(
+ scoped_refptr<TestWebRequestRulesRegistry> registry(
new TestWebRequestRulesRegistry());
std::string error;
@@ -243,6 +257,7 @@ TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
rules_to_add.push_back(CreateRule2());
error = registry->AddRules(kExtensionId, rules_to_add);
EXPECT_EQ("", error);
+ EXPECT_EQ(1, registry->num_clear_cache_calls());
// Verify initial state.
std::vector<linked_ptr<RulesRegistry::Rule> > registered_rules;
@@ -254,6 +269,7 @@ TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
rules_to_remove.push_back(kRuleId1);
error = registry->RemoveRules(kExtensionId, rules_to_remove);
EXPECT_EQ("", error);
+ EXPECT_EQ(2, registry->num_clear_cache_calls());
// Verify that only one rule is left.
registered_rules.clear();
@@ -265,6 +281,7 @@ TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
rules_to_remove.push_back(kRuleId2);
error = registry->RemoveRules(kExtensionId, rules_to_remove);
EXPECT_EQ("", error);
+ EXPECT_EQ(3, registry->num_clear_cache_calls());
// Verify that everything is gone.
registered_rules.clear();
@@ -275,7 +292,7 @@ TEST_F(WebRequestRulesRegistryTest, RemoveRulesImpl) {
}
TEST_F(WebRequestRulesRegistryTest, RemoveAllRulesImpl) {
- scoped_refptr<WebRequestRulesRegistry> registry(
+ scoped_refptr<TestWebRequestRulesRegistry> registry(
new TestWebRequestRulesRegistry());
std::string error;
@@ -284,10 +301,12 @@ TEST_F(WebRequestRulesRegistryTest, RemoveAllRulesImpl) {
rules_to_add[0] = CreateRule1();
error = registry->AddRules(kExtensionId, rules_to_add);
EXPECT_EQ("", error);
+ EXPECT_EQ(1, registry->num_clear_cache_calls());
rules_to_add[0] = CreateRule2();
error = registry->AddRules(kExtensionId2, rules_to_add);
EXPECT_EQ("", error);
+ EXPECT_EQ(2, registry->num_clear_cache_calls());
// Verify initial state.
std::vector<linked_ptr<RulesRegistry::Rule> > registered_rules;
@@ -300,6 +319,7 @@ TEST_F(WebRequestRulesRegistryTest, RemoveAllRulesImpl) {
// Remove rule of first extension.
error = registry->RemoveAllRules(kExtensionId);
EXPECT_EQ("", error);
+ EXPECT_EQ(3, registry->num_clear_cache_calls());
// Verify that only the first rule is deleted.
registered_rules.clear();
@@ -312,10 +332,12 @@ TEST_F(WebRequestRulesRegistryTest, RemoveAllRulesImpl) {
// Test removing rules if none exist.
error = registry->RemoveAllRules(kExtensionId);
EXPECT_EQ("", error);
+ EXPECT_EQ(4, registry->num_clear_cache_calls());
// Remove rule from second extension.
error = registry->RemoveAllRules(kExtensionId2);
EXPECT_EQ("", error);
+ EXPECT_EQ(5, registry->num_clear_cache_calls());
EXPECT_TRUE(registry->IsEmpty());
}

Powered by Google App Engine
This is Rietveld 408576698