Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/FilterEngine.cpp

Issue 29419607: Issue 5163 - Reduce the use of FilterPtr (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 21, 2017, 1:04 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/FilterEngine.cpp
===================================================================
--- a/test/FilterEngine.cpp
+++ b/test/FilterEngine.cpp
@@ -272,64 +272,64 @@
}
return subscription;
}
};
}
TEST_F(FilterEngineTest, FilterCreation)
{
- AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo");
- ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType());
- AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo");
- ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType());
- AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo");
- ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType());
- AdblockPlus::FilterPtr filter4 = filterEngine->GetFilter("example.com#@#foo");
- ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetType());
- AdblockPlus::FilterPtr filter5 = filterEngine->GetFilter(" foo ");
- ASSERT_EQ(*filter1, *filter5);
+ AdblockPlus::Filter filter1 = filterEngine->GetFilter("foo");
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1.GetType());
+ AdblockPlus::Filter filter2 = filterEngine->GetFilter("@@foo");
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2.GetType());
+ AdblockPlus::Filter filter3 = filterEngine->GetFilter("example.com##foo");
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3.GetType());
+ AdblockPlus::Filter filter4 = filterEngine->GetFilter("example.com#@#foo");
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4.GetType());
+ AdblockPlus::Filter filter5 = filterEngine->GetFilter(" foo ");
+ ASSERT_EQ(filter1, filter5);
}
TEST_F(FilterEngineTest, FilterProperties)
{
- AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo");
+ AdblockPlus::Filter filter = filterEngine->GetFilter("foo");
- ASSERT_TRUE(filter->GetProperty("stringFoo").IsUndefined());
- ASSERT_TRUE(filter->GetProperty("intFoo").IsUndefined());
- ASSERT_TRUE(filter->GetProperty("boolFoo").IsUndefined());
+ ASSERT_TRUE(filter.GetProperty("stringFoo").IsUndefined());
+ ASSERT_TRUE(filter.GetProperty("intFoo").IsUndefined());
+ ASSERT_TRUE(filter.GetProperty("boolFoo").IsUndefined());
- filter->SetProperty("stringFoo", "y");
- filter->SetProperty("intFoo", 24);
- filter->SetProperty("boolFoo", true);
- ASSERT_EQ("y", filter->GetProperty("stringFoo").AsString());
- ASSERT_EQ(24, filter->GetProperty("intFoo").AsInt());
- ASSERT_TRUE(filter->GetProperty("boolFoo").AsBool());
+ filter.SetProperty("stringFoo", "y");
+ filter.SetProperty("intFoo", 24);
+ filter.SetProperty("boolFoo", true);
+ ASSERT_EQ("y", filter.GetProperty("stringFoo").AsString());
+ ASSERT_EQ(24, filter.GetProperty("intFoo").AsInt());
+ ASSERT_TRUE(filter.GetProperty("boolFoo").AsBool());
}
TEST_F(FilterEngineTest, AddRemoveFilters)
{
ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
- AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo");
+ AdblockPlus::Filter filter = filterEngine->GetFilter("foo");
ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
- ASSERT_FALSE(filter->IsListed());
- filter->AddToList();
+ ASSERT_FALSE(filter.IsListed());
+ filter.AddToList();
ASSERT_EQ(1u, filterEngine->GetListedFilters().size());
- ASSERT_EQ(*filter, *filterEngine->GetListedFilters()[0]);
- ASSERT_TRUE(filter->IsListed());
- filter->AddToList();
+ ASSERT_EQ(filter, filterEngine->GetListedFilters()[0]);
+ ASSERT_TRUE(filter.IsListed());
+ filter.AddToList();
ASSERT_EQ(1u, filterEngine->GetListedFilters().size());
- ASSERT_EQ(*filter, *filterEngine->GetListedFilters()[0]);
- ASSERT_TRUE(filter->IsListed());
- filter->RemoveFromList();
+ ASSERT_EQ(filter, filterEngine->GetListedFilters()[0]);
+ ASSERT_TRUE(filter.IsListed());
+ filter.RemoveFromList();
ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
- ASSERT_FALSE(filter->IsListed());
- filter->RemoveFromList();
+ ASSERT_FALSE(filter.IsListed());
+ filter.RemoveFromList();
ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
- ASSERT_FALSE(filter->IsListed());
+ ASSERT_FALSE(filter.IsListed());
}
TEST_F(FilterEngineTest, SubscriptionProperties)
{
AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
ASSERT_TRUE(subscription->GetProperty("stringFoo").IsUndefined());
ASSERT_TRUE(subscription->GetProperty("intFoo").IsUndefined());
@@ -369,22 +369,22 @@
{
AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo");
ASSERT_FALSE(subscription->IsUpdating());
subscription->UpdateFilters();
}
TEST_F(FilterEngineTest, Matches)
{
- filterEngine->GetFilter("adbanner.gif")->AddToList();
- filterEngine->GetFilter("@@notbanner.gif")->AddToList();
- filterEngine->GetFilter("tpbanner.gif$third-party")->AddToList();
- filterEngine->GetFilter("fpbanner.gif$~third-party")->AddToList();
- filterEngine->GetFilter("combanner.gif$domain=example.com")->AddToList();
- filterEngine->GetFilter("orgbanner.gif$domain=~example.com")->AddToList();
+ filterEngine->GetFilter("adbanner.gif").AddToList();
+ filterEngine->GetFilter("@@notbanner.gif").AddToList();
+ filterEngine->GetFilter("tpbanner.gif$third-party").AddToList();
+ filterEngine->GetFilter("fpbanner.gif$~third-party").AddToList();
+ filterEngine->GetFilter("combanner.gif$domain=example.com").AddToList();
+ filterEngine->GetFilter("orgbanner.gif$domain=~example.com").AddToList();
AdblockPlus::FilterPtr match1 = filterEngine->Matches("http://example.org/foobar.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "");
ASSERT_FALSE(match1);
AdblockPlus::FilterPtr match2 = filterEngine->Matches("http://example.org/adbanner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "");
ASSERT_TRUE(match2);
ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetType());
@@ -422,38 +422,38 @@
AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/orgbanner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/");
ASSERT_TRUE(match12);
ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType());
}
TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain)
{
- filterEngine->GetFilter("adbanner.gif")->AddToList();
- filterEngine->GetFilter("@@||example.org^$document")->AddToList();
+ filterEngine->GetFilter("adbanner.gif").AddToList();
+ filterEngine->GetFilter("@@||example.org^$document").AddToList();
AdblockPlus::FilterPtr match1 =
filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE,
"http://example.com/");
ASSERT_TRUE(match1);
ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
AdblockPlus::FilterPtr match2 =
filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE,
"http://example.org/");
ASSERT_TRUE(match2);
ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
}
TEST_F(FilterEngineTest, MatchesWithContentTypeMask)
{
- filterEngine->GetFilter("adbanner.gif.js$script,image")->AddToList();
- filterEngine->GetFilter("@@notbanner.gif")->AddToList();
- filterEngine->GetFilter("blockme")->AddToList();
- filterEngine->GetFilter("@@||example.doc^$document")->AddToList();
+ filterEngine->GetFilter("adbanner.gif.js$script,image").AddToList();
+ filterEngine->GetFilter("@@notbanner.gif").AddToList();
+ filterEngine->GetFilter("blockme").AddToList();
+ filterEngine->GetFilter("@@||example.doc^$document").AddToList();
EXPECT_FALSE(filterEngine->Matches("http://example.org/foobar.gif",
AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""))
<< "another url should not match";
EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js",
/*mask*/ 0, "")) << "zero mask should not match (filter with some options)";
@@ -502,18 +502,18 @@
<< "zero mask should match when document is whitelisted";
EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType());
}
}
TEST_F(FilterEngineTest, MatchesNestedFrameRequest)
{
- filterEngine->GetFilter("adbanner.gif")->AddToList();
- filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList();
+ filterEngine->GetFilter("adbanner.gif").AddToList();
+ filterEngine->GetFilter("@@adbanner.gif$domain=example.org").AddToList();
std::vector<std::string> documentUrls1;
documentUrls1.push_back("http://ads.com/frame/");
documentUrls1.push_back("http://example.com/");
AdblockPlus::FilterPtr match1 =
filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE,
documentUrls1);
ASSERT_TRUE(match1);
@@ -535,18 +535,18 @@
filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE,
documentUrls3);
ASSERT_TRUE(match3);
ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType());
}
TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain)
{
- filterEngine->GetFilter("adbanner.gif")->AddToList();
- filterEngine->GetFilter("@@||example.org^$document,domain=ads.com")->AddToList();
+ filterEngine->GetFilter("adbanner.gif").AddToList();
+ filterEngine->GetFilter("@@||example.org^$document,domain=ads.com").AddToList();
std::vector<std::string> documentUrls1;
documentUrls1.push_back("http://ads.com/frame/");
documentUrls1.push_back("http://example.com/");
AdblockPlus::FilterPtr match1 =
filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE,
documentUrls1);
ASSERT_TRUE(match1);
@@ -600,21 +600,21 @@
}
TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback)
{
int timesCalled = 0;
MockFilterChangeCallback mockFilterChangeCallback(timesCalled);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
filterEngine->SetFilterChangeCallback(mockFilterChangeCallback);
- filterEngine->GetFilter("foo")->AddToList();
+ filterEngine->GetFilter("foo").AddToList();
EXPECT_EQ(1, timesCalled);
filterEngine->RemoveFilterChangeCallback();
- filterEngine->GetFilter("foo")->RemoveFromList();
+ filterEngine->GetFilter("foo").RemoveFromList();
EXPECT_EQ(1, timesCalled);
}
TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback)
{
mockWebRequest->response.status = 0;
mockWebRequest->response.responseStatus = 200;
mockWebRequest->response.responseText = "\
@@ -658,18 +658,18 @@
called = error.empty() ? 1 : 2;
});
AdblockPlus::Sleep(100);
EXPECT_EQ(1, called);
}
TEST_F(FilterEngineTest, DocumentWhitelisting)
{
- filterEngine->GetFilter("@@||example.org^$document")->AddToList();
- filterEngine->GetFilter("@@||example.com^$document,domain=example.de")->AddToList();
+ filterEngine->GetFilter("@@||example.org^$document").AddToList();
+ filterEngine->GetFilter("@@||example.com^$document,domain=example.de").AddToList();
ASSERT_TRUE(filterEngine->IsDocumentWhitelisted(
"http://example.org",
std::vector<std::string>()));
ASSERT_FALSE(filterEngine->IsDocumentWhitelisted(
"http://example.co.uk",
std::vector<std::string>()));
@@ -687,18 +687,18 @@
ASSERT_FALSE(filterEngine->IsDocumentWhitelisted(
"http://example.co.uk",
documentUrls1));
}
TEST_F(FilterEngineTest, ElemhideWhitelisting)
{
- filterEngine->GetFilter("@@||example.org^$elemhide")->AddToList();
- filterEngine->GetFilter("@@||example.com^$elemhide,domain=example.de")->AddToList();
+ filterEngine->GetFilter("@@||example.org^$elemhide").AddToList();
+ filterEngine->GetFilter("@@||example.com^$elemhide,domain=example.de").AddToList();
ASSERT_TRUE(filterEngine->IsElemhideWhitelisted(
"http://example.org",
std::vector<std::string>()));
ASSERT_FALSE(filterEngine->IsElemhideWhitelisted(
"http://example.co.uk",
std::vector<std::string>()));
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld