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

Side by Side Diff: chrome/browser/extensions/api/declarative/url_matcher_unittest.cc

Issue 9844028: Implement rules removal for WebRequestRulesRegistry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 9 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/url_matcher.h" 5 #include "chrome/browser/extensions/api/declarative/url_matcher.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 EXPECT_EQ(c2.criterion(), c3.criterion()); 145 EXPECT_EQ(c2.criterion(), c3.criterion());
146 EXPECT_NE(c2.substring_pattern(), c3.substring_pattern()); 146 EXPECT_NE(c2.substring_pattern(), c3.substring_pattern());
147 EXPECT_NE(c2.substring_pattern()->id(), c3.substring_pattern()->id()); 147 EXPECT_NE(c2.substring_pattern()->id(), c3.substring_pattern()->id());
148 EXPECT_NE(c2.substring_pattern()->pattern(), 148 EXPECT_NE(c2.substring_pattern()->pattern(),
149 c3.substring_pattern()->pattern()); 149 c3.substring_pattern()->pattern());
150 150
151 // Check that all SubstringPattern singletons are freed if we call 151 // Check that all SubstringPattern singletons are freed if we call
152 // ForgetUnusedPatterns. 152 // ForgetUnusedPatterns.
153 SubstringPattern::ID old_id_1 = c1.substring_pattern()->id(); 153 SubstringPattern::ID old_id_1 = c1.substring_pattern()->id();
154 factory.ForgetUnusedPatterns(std::set<SubstringPattern::ID>()); 154 factory.ForgetUnusedPatterns(std::set<SubstringPattern::ID>());
155 EXPECT_TRUE(factory.IsEmpty());
155 URLMatcherCondition c4 = factory.CreateHostEqualsCondition("www.google.com"); 156 URLMatcherCondition c4 = factory.CreateHostEqualsCondition("www.google.com");
156 EXPECT_NE(old_id_1, c4.substring_pattern()->id()); 157 EXPECT_NE(old_id_1, c4.substring_pattern()->id());
157 } 158 }
158 159
159 TEST(URLMatcherConditionFactoryTest, TestComponentSearches) { 160 TEST(URLMatcherConditionFactoryTest, TestComponentSearches) {
160 GURL gurl("https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8" 161 GURL gurl("https://www.google.com/webhp?sourceid=chrome-instant&ie=UTF-8"
161 "&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome"); 162 "&ion=1#hl=en&output=search&sclient=psy-ab&q=chrome%20is%20awesome");
162 URLMatcherConditionFactory factory; 163 URLMatcherConditionFactory factory;
163 std::string url = factory.CanonicalizeURLForComponentSearches(gurl); 164 std::string url = factory.CanonicalizeURLForComponentSearches(gurl);
164 165
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 EXPECT_EQ(1u, matcher.MatchURL(url1).size()); 380 EXPECT_EQ(1u, matcher.MatchURL(url1).size());
380 EXPECT_EQ(0u, matcher.MatchURL(url2).size()); 381 EXPECT_EQ(0u, matcher.MatchURL(url2).size());
381 382
382 // Removal of first insert. 383 // Removal of first insert.
383 std::vector<URLMatcherConditionSet::ID> remove1; 384 std::vector<URLMatcherConditionSet::ID> remove1;
384 remove1.push_back(kConditionSetId1); 385 remove1.push_back(kConditionSetId1);
385 matcher.RemoveConditionSets(remove1); 386 matcher.RemoveConditionSets(remove1);
386 EXPECT_EQ(0u, matcher.MatchURL(url1).size()); 387 EXPECT_EQ(0u, matcher.MatchURL(url1).size());
387 EXPECT_EQ(0u, matcher.MatchURL(url2).size()); 388 EXPECT_EQ(0u, matcher.MatchURL(url2).size());
388 389
390 EXPECT_TRUE(matcher.IsEmpty());
391
389 // The cached singleton in matcher.condition_factory_ should be destroyed to 392 // The cached singleton in matcher.condition_factory_ should be destroyed to
390 // free memory. 393 // free memory.
391 int patternId2 = factory->CreateHostSuffixCondition( 394 int patternId2 = factory->CreateHostSuffixCondition(
392 "example.com").substring_pattern()->id(); 395 "example.com").substring_pattern()->id();
393 // If patternId1 and patternId2 are different that indicates that 396 // If patternId1 and patternId2 are different that indicates that
394 // matcher.condition_factory_ does not leak memory. 397 // matcher.condition_factory_ does not leak memory.
395 EXPECT_NE(patternId1, patternId2); 398 EXPECT_NE(patternId1, patternId2);
396 } 399 }
397 400
398 } // namespace extensions 401 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698