diff options
3 files changed, 35 insertions, 34 deletions
diff --git a/chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc index 35ec289..bc866fc 100644 --- a/chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc +++ b/chrome/browser/privacy_blacklist/blacklist_interceptor_unittest.cc @@ -56,17 +56,17 @@ TEST_F(BlacklistInterceptorTest, Basic) { TEST_F(BlacklistInterceptorTest, Intercepted) { EXPECT_FALSE(InterceptedTestRequest(kDataUrl, NULL)); - Blacklist blacklist; + scoped_refptr<Blacklist> blacklist; Blacklist::Provider* provider = new Blacklist::Provider(); - blacklist.AddProvider(provider); + blacklist->AddProvider(provider); Blacklist::Entry* entry = new Blacklist::Entry("@/annoying_ads/@", provider, false); entry->AddAttributes(Blacklist::kBlockAll); - blacklist.AddEntry(entry); + blacklist->AddEntry(entry); BlacklistRequestInfo* request_info = new BlacklistRequestInfo(GURL(kBlockedUrl), ResourceType::MAIN_FRAME, - &blacklist); + blacklist.get()); EXPECT_TRUE(InterceptedTestRequest(kBlockedUrl, request_info)); } diff --git a/chrome/browser/privacy_blacklist/blacklist_perftest.cc b/chrome/browser/privacy_blacklist/blacklist_perftest.cc index 7c259ed..1357ed4 100644 --- a/chrome/browser/privacy_blacklist/blacklist_perftest.cc +++ b/chrome/browser/privacy_blacklist/blacklist_perftest.cc @@ -117,20 +117,20 @@ class BlacklistPerfTest : public testing::Test { Blacklist::Provider* provider = new Blacklist::Provider("test", "http://test.com", L"test"); - blacklist_.AddProvider(provider); + blacklist_->AddProvider(provider); // Create host.tld/ patterns. for (size_t i = 0; i < kNumHostEntries; ++i) { std::string pattern = "@" + GetRandomString(8) + "." + GetRandomString(3) + "/@"; - blacklist_.AddEntry(new Blacklist::Entry(pattern, provider, false)); + blacklist_->AddEntry(new Blacklist::Entry(pattern, provider, false)); } // Create /some/path/ patterns. for (size_t i = 0; i < kNumPathEntries; ++i) { std::string pattern = "@/" + GetRandomString(6) + "/" + GetRandomString(6) + "/@"; - blacklist_.AddEntry(new Blacklist::Entry(pattern, provider, false)); + blacklist_->AddEntry(new Blacklist::Entry(pattern, provider, false)); } // Create /some/path/script? patterns. @@ -138,7 +138,7 @@ class BlacklistPerfTest : public testing::Test { std::string pattern = "@/" + GetRandomString(6) + "/" + GetRandomString(6) + "/" + GetRandomString(6) + "?@"; - blacklist_.AddEntry(new Blacklist::Entry(pattern, provider, false)); + blacklist_->AddEntry(new Blacklist::Entry(pattern, provider, false)); } // Create host.tld/some/path patterns. @@ -146,7 +146,7 @@ class BlacklistPerfTest : public testing::Test { std::string pattern = "@" + GetRandomString(8) + "." + GetRandomString(3) + "/" + GetRandomString(6) + "/" + GetRandomString(6) + "/@"; - blacklist_.AddEntry(new Blacklist::Entry(pattern, provider, false)); + blacklist_->AddEntry(new Blacklist::Entry(pattern, provider, false)); } // Create host.tld/some/path/script? patterns. @@ -154,15 +154,15 @@ class BlacklistPerfTest : public testing::Test { std::string pattern = "@" + GetRandomString(8) + "." + GetRandomString(3) + "/" + GetRandomString(6) + "/" + GetRandomString(6) + "?@"; - blacklist_.AddEntry(new Blacklist::Entry(pattern, provider, false)); + blacklist_->AddEntry(new Blacklist::Entry(pattern, provider, false)); } - DCHECK_EQ(std::distance(blacklist_.entries_begin(), - blacklist_.entries_end()), static_cast<ptrdiff_t>(kNumPattern)); + DCHECK_EQ(std::distance(blacklist_->entries_begin(), + blacklist_->entries_end()), static_cast<ptrdiff_t>(kNumPattern)); } // Randomly generated benchmark blacklist. - Blacklist blacklist_; + scoped_refptr<Blacklist> blacklist_; }; // Perf test for matching URLs which are contained in the blacklist. @@ -170,7 +170,7 @@ TEST_F(BlacklistPerfTest, Match) { // Pick random patterns and generate matching URLs std::vector<std::string> urls; for (size_t i = 0; i < kNumUrls; ++i) { - const Blacklist::Entry* entry = (blacklist_.entries_begin() + + const Blacklist::Entry* entry = (blacklist_->entries_begin() + RandomIndex(kNumPattern))->get(); urls.push_back(GetURL(entry->pattern(), false)); } @@ -179,7 +179,7 @@ TEST_F(BlacklistPerfTest, Match) { PerfTimeLogger timer("blacklist_match"); for (size_t i = 0; i < kNumUrls; ++i) { - scoped_ptr<Blacklist::Match> match(blacklist_.FindMatch(GURL(urls[i]))); + scoped_ptr<Blacklist::Match> match(blacklist_->FindMatch(GURL(urls[i]))); ASSERT_TRUE(match.get()); } @@ -192,7 +192,7 @@ TEST_F(BlacklistPerfTest, Mismatch) { // are made so that they do NOT match any generated pattern std::vector<std::string> urls; for (size_t i = 0; i < kNumUrls; ++i) { - const Blacklist::Entry* entry = (blacklist_.entries_begin() + + const Blacklist::Entry* entry = (blacklist_->entries_begin() + RandomIndex(kNumPattern))->get(); urls.push_back(GetURL(entry->pattern(), true)); } @@ -201,7 +201,7 @@ TEST_F(BlacklistPerfTest, Mismatch) { PerfTimeLogger timer("blacklist_mismatch"); for (size_t i = 0; i < kNumUrls; ++i) { - scoped_ptr<Blacklist::Match> match(blacklist_.FindMatch(GURL(urls[i]))); + scoped_ptr<Blacklist::Match> match(blacklist_->FindMatch(GURL(urls[i]))); ASSERT_FALSE(match.get()); } diff --git a/chrome/browser/privacy_blacklist/blacklist_unittest.cc b/chrome/browser/privacy_blacklist/blacklist_unittest.cc index d89cd81..760ad97 100644 --- a/chrome/browser/privacy_blacklist/blacklist_unittest.cc +++ b/chrome/browser/privacy_blacklist/blacklist_unittest.cc @@ -31,9 +31,9 @@ class BlacklistTest : public testing::Test { }; TEST_F(BlacklistTest, Generic) { - Blacklist blacklist(prefs_.get()); - Blacklist::EntryList entries(blacklist.entries_begin(), - blacklist.entries_end()); + scoped_refptr<Blacklist> blacklist = new Blacklist(prefs_.get()); + Blacklist::EntryList entries(blacklist->entries_begin(), + blacklist->entries_end()); ASSERT_EQ(7U, entries.size()); @@ -73,20 +73,21 @@ TEST_F(BlacklistTest, Generic) { EXPECT_TRUE(entries[6]->is_exception()); EXPECT_EQ("www.site.com/bad/url/good", entries[6]->pattern()); - Blacklist::ProviderList providers(blacklist.providers_begin(), - blacklist.providers_end()); + Blacklist::ProviderList providers(blacklist->providers_begin(), + blacklist->providers_end()); ASSERT_EQ(1U, providers.size()); EXPECT_EQ("Sample", providers[0]->name()); EXPECT_EQ("http://www.example.com", providers[0]->url()); // No match for chrome, about or empty URLs. - EXPECT_FALSE(blacklist.FindMatch(GURL())); - EXPECT_FALSE(blacklist.FindMatch(GURL("chrome://new-tab"))); - EXPECT_FALSE(blacklist.FindMatch(GURL("about:blank"))); + EXPECT_FALSE(blacklist->FindMatch(GURL())); + EXPECT_FALSE(blacklist->FindMatch(GURL("chrome://new-tab"))); + EXPECT_FALSE(blacklist->FindMatch(GURL("about:blank"))); // Expected rule matches. - Blacklist::Match* match = blacklist.FindMatch(GURL("http://www.site.com/bad/url")); + Blacklist::Match* match = + blacklist->FindMatch(GURL("http://www.site.com/bad/url")); EXPECT_TRUE(match); if (match) { EXPECT_EQ(Blacklist::kBlockAll|0, match->attributes()); @@ -94,17 +95,17 @@ TEST_F(BlacklistTest, Generic) { delete match; } - match = blacklist.FindMatch(GURL("http://www.site.com/anonymous")); + match = blacklist->FindMatch(GURL("http://www.site.com/anonymous")); EXPECT_FALSE(match); if (match) delete match; - match = blacklist.FindMatch(GURL("http://www.site.com/anonymous/folder")); + match = blacklist->FindMatch(GURL("http://www.site.com/anonymous/folder")); EXPECT_FALSE(match); if (match) delete match; - match = blacklist.FindMatch( + match = blacklist->FindMatch( GURL("http://www.site.com/anonymous/folder/subfolder")); EXPECT_TRUE(match); if (match) { @@ -115,18 +116,18 @@ TEST_F(BlacklistTest, Generic) { } // No matches for URLs without query string - match = blacklist.FindMatch(GURL("http://badparam.com/")); + match = blacklist->FindMatch(GURL("http://badparam.com/")); EXPECT_FALSE(match); if (match) delete match; - match = blacklist.FindMatch(GURL("http://script.bad.org/")); + match = blacklist->FindMatch(GURL("http://script.bad.org/")); EXPECT_FALSE(match); if (match) delete match; // Expected rule matches. - match = blacklist.FindMatch(GURL("http://host.com/script?q=x")); + match = blacklist->FindMatch(GURL("http://host.com/script?q=x")); EXPECT_TRUE(match); if (match) { EXPECT_EQ(Blacklist::kBlockAll, match->attributes()); @@ -134,7 +135,7 @@ TEST_F(BlacklistTest, Generic) { delete match; } - match = blacklist.FindMatch(GURL("http://host.com/img?badparam=x")); + match = blacklist->FindMatch(GURL("http://host.com/img?badparam=x")); EXPECT_TRUE(match); if (match) { EXPECT_EQ(Blacklist::kBlockAll, match->attributes()); @@ -143,7 +144,7 @@ TEST_F(BlacklistTest, Generic) { } // Whitelisting tests. - match = blacklist.FindMatch(GURL("http://www.site.com/bad/url/good")); + match = blacklist->FindMatch(GURL("http://www.site.com/bad/url/good")); EXPECT_TRUE(match); if (match) { EXPECT_EQ(0U, match->attributes()); |