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

Unified Diff: test/FilterEngine.cpp

Issue 23127017: Consider the frame structure in Matches() (Closed)
Patch Set: Better test coverage Created Nov. 15, 2013, 8:15 a.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
@@ -202,6 +202,108 @@
ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType());
}
+TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain)
+{
+ filterEngine->GetFilter("adbanner.gif")->AddToList();
+ filterEngine->GetFilter("@@||example.org^$document")->AddToList();
+
+ AdblockPlus::FilterPtr match1 =
+ filterEngine->Matches("http://ads.com/adbanner.gif", "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", "IMAGE",
+ "http://example.org/");
+ ASSERT_TRUE(match2);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
+}
+
+TEST_F(FilterEngineTest, MatchesNestedFrameRequest)
+{
+ 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", "IMAGE",
+ documentUrls1);
+ ASSERT_TRUE(match1);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
+
+ std::vector<std::string> documentUrls2;
+ documentUrls2.push_back("http://ads.com/frame/");
+ documentUrls2.push_back("http://example.org/");
+ AdblockPlus::FilterPtr match2 =
+ filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
+ documentUrls2);
+ ASSERT_TRUE(match2);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
+
+ std::vector<std::string> documentUrls3;
+ documentUrls3.push_back("http://example.org/");
+ documentUrls3.push_back("http://ads.com/frame/");
+ AdblockPlus::FilterPtr match3 =
+ filterEngine->Matches("http://ads.com/adbanner.gif", "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();
+
+ 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", "IMAGE",
+ documentUrls1);
+ ASSERT_TRUE(match1);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
+
+ std::vector<std::string> documentUrls2;
+ documentUrls2.push_back("http://ads.com/frame/");
+ documentUrls2.push_back("http://example.org/");
+ AdblockPlus::FilterPtr match2 =
+ filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
+ documentUrls2);
+ ASSERT_TRUE(match2);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
+
+ std::vector<std::string> documentUrls3;
+ documentUrls3.push_back("http://example.org/");
+ AdblockPlus::FilterPtr match3 =
+ filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
+ documentUrls3);
+ ASSERT_TRUE(match3);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType());
+
+ std::vector<std::string> documentUrls4;
+ documentUrls4.push_back("http://example.org/");
+ documentUrls4.push_back("http://ads.com/frame/");
+ AdblockPlus::FilterPtr match4 =
+ filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
+ documentUrls4);
+ ASSERT_TRUE(match4);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match4->GetType());
+
+ std::vector<std::string> documentUrls5;
+ documentUrls5.push_back("http://ads.com/frame/");
+ documentUrls5.push_back("http://example.org/");
+ documentUrls5.push_back("http://example.com/");
+ AdblockPlus::FilterPtr match5 =
+ filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
+ documentUrls5);
+ ASSERT_TRUE(match5);
+ ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType());
+}
+
TEST_F(FilterEngineTest, FirstRunFlag)
{
ASSERT_FALSE(filterEngine->IsFirstRun());
« 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