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

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

Issue 11569007: Refactoring how conditions without URL attributes are handled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Polished 1st version Created 8 years 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 <vector> 7 #include <vector>
8 8
9 #include "base/memory/linked_ptr.h" 9 #include "base/memory/linked_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 24 matching lines...) Expand all
35 class TestWebRequestRulesRegistry : public WebRequestRulesRegistry { 35 class TestWebRequestRulesRegistry : public WebRequestRulesRegistry {
36 public: 36 public:
37 TestWebRequestRulesRegistry() 37 TestWebRequestRulesRegistry()
38 : WebRequestRulesRegistry(NULL, NULL), 38 : WebRequestRulesRegistry(NULL, NULL),
39 num_clear_cache_calls_(0) {} 39 num_clear_cache_calls_(0) {}
40 40
41 // Returns how often the in-memory caches of the renderers were instructed 41 // Returns how often the in-memory caches of the renderers were instructed
42 // to be cleared. 42 // to be cleared.
43 int num_clear_cache_calls() const { return num_clear_cache_calls_; } 43 int num_clear_cache_calls() const { return num_clear_cache_calls_; }
44 44
45 // How many rules are there which have some conditions not triggered by URL
46 // matches.
47 size_t RulesWithoutTriggers() const {
48 return rules_with_untriggered_conditions_for_test().size();
49 }
50
45 protected: 51 protected:
46 virtual ~TestWebRequestRulesRegistry() {} 52 virtual ~TestWebRequestRulesRegistry() {}
47 53
48 virtual base::Time GetExtensionInstallationTime( 54 virtual base::Time GetExtensionInstallationTime(
49 const std::string& extension_id) const { 55 const std::string& extension_id) const {
50 if (extension_id == kExtensionId) 56 if (extension_id == kExtensionId)
51 return base::Time() + base::TimeDelta::FromDays(1); 57 return base::Time() + base::TimeDelta::FromDays(1);
52 else if (extension_id == kExtensionId2) 58 else if (extension_id == kExtensionId2)
53 return base::Time() + base::TimeDelta::FromDays(2); 59 return base::Time() + base::TimeDelta::FromDays(2);
54 else 60 else
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 rules_to_add.push_back(CreateRule1()); 262 rules_to_add.push_back(CreateRule1());
257 rules_to_add.push_back(CreateRule2()); 263 rules_to_add.push_back(CreateRule2());
258 error = registry->AddRules(kExtensionId, rules_to_add); 264 error = registry->AddRules(kExtensionId, rules_to_add);
259 EXPECT_EQ("", error); 265 EXPECT_EQ("", error);
260 EXPECT_EQ(1, registry->num_clear_cache_calls()); 266 EXPECT_EQ(1, registry->num_clear_cache_calls());
261 267
262 // Verify initial state. 268 // Verify initial state.
263 std::vector<linked_ptr<RulesRegistry::Rule> > registered_rules; 269 std::vector<linked_ptr<RulesRegistry::Rule> > registered_rules;
264 registry->GetAllRules(kExtensionId, &registered_rules); 270 registry->GetAllRules(kExtensionId, &registered_rules);
265 EXPECT_EQ(2u, registered_rules.size()); 271 EXPECT_EQ(2u, registered_rules.size());
272 EXPECT_EQ(1u, registry->RulesWithoutTriggers());
266 273
267 // Remove first rule. 274 // Remove first rule.
268 std::vector<std::string> rules_to_remove; 275 std::vector<std::string> rules_to_remove;
269 rules_to_remove.push_back(kRuleId1); 276 rules_to_remove.push_back(kRuleId1);
270 error = registry->RemoveRules(kExtensionId, rules_to_remove); 277 error = registry->RemoveRules(kExtensionId, rules_to_remove);
271 EXPECT_EQ("", error); 278 EXPECT_EQ("", error);
272 EXPECT_EQ(2, registry->num_clear_cache_calls()); 279 EXPECT_EQ(2, registry->num_clear_cache_calls());
273 280
274 // Verify that only one rule is left. 281 // Verify that only one rule is left.
275 registered_rules.clear(); 282 registered_rules.clear();
276 registry->GetAllRules(kExtensionId, &registered_rules); 283 registry->GetAllRules(kExtensionId, &registered_rules);
277 EXPECT_EQ(1u, registered_rules.size()); 284 EXPECT_EQ(1u, registered_rules.size());
285 EXPECT_EQ(1u, registry->RulesWithoutTriggers());
278 286
279 // Now rules_to_remove contains both rules, i.e. one that does not exist in 287 // Now rules_to_remove contains both rules, i.e. one that does not exist in
280 // the rules registry anymore. Effectively we only remove the second rule. 288 // the rules registry anymore. Effectively we only remove the second rule.
281 rules_to_remove.push_back(kRuleId2); 289 rules_to_remove.push_back(kRuleId2);
282 error = registry->RemoveRules(kExtensionId, rules_to_remove); 290 error = registry->RemoveRules(kExtensionId, rules_to_remove);
283 EXPECT_EQ("", error); 291 EXPECT_EQ("", error);
284 EXPECT_EQ(3, registry->num_clear_cache_calls()); 292 EXPECT_EQ(3, registry->num_clear_cache_calls());
285 293
286 // Verify that everything is gone. 294 // Verify that everything is gone.
287 registered_rules.clear(); 295 registered_rules.clear();
288 registry->GetAllRules(kExtensionId, &registered_rules); 296 registry->GetAllRules(kExtensionId, &registered_rules);
289 EXPECT_EQ(0u, registered_rules.size()); 297 EXPECT_EQ(0u, registered_rules.size());
298 EXPECT_EQ(0u, registry->RulesWithoutTriggers());
290 299
291 EXPECT_TRUE(registry->IsEmpty()); 300 EXPECT_TRUE(registry->IsEmpty());
292 } 301 }
293 302
294 TEST_F(WebRequestRulesRegistryTest, RemoveAllRulesImpl) { 303 TEST_F(WebRequestRulesRegistryTest, RemoveAllRulesImpl) {
295 scoped_refptr<TestWebRequestRulesRegistry> registry( 304 scoped_refptr<TestWebRequestRulesRegistry> registry(
296 new TestWebRequestRulesRegistry()); 305 new TestWebRequestRulesRegistry());
297 std::string error; 306 std::string error;
298 307
299 // Setup RulesRegistry to contain two rules, one for each extension. 308 // Setup RulesRegistry to contain two rules, one for each extension.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // The redirect by the first extension is ignored due to the ignore rule. 429 // The redirect by the first extension is ignored due to the ignore rule.
421 ASSERT_EQ(1u, deltas.size()); 430 ASSERT_EQ(1u, deltas.size());
422 LinkedPtrEventResponseDelta effective_rule = *(deltas.begin()); 431 LinkedPtrEventResponseDelta effective_rule = *(deltas.begin());
423 432
424 EXPECT_EQ(kExtensionId2, effective_rule->extension_id); 433 EXPECT_EQ(kExtensionId2, effective_rule->extension_id);
425 EXPECT_EQ(base::Time() + base::TimeDelta::FromDays(2), 434 EXPECT_EQ(base::Time() + base::TimeDelta::FromDays(2),
426 effective_rule->extension_install_time); 435 effective_rule->extension_install_time);
427 EXPECT_EQ(GURL("http://www.bar.com"), effective_rule->new_url); 436 EXPECT_EQ(GURL("http://www.bar.com"), effective_rule->new_url);
428 } 437 }
429 } // namespace extensions 438 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698