Index: test/ReferrerMapping.cpp |
=================================================================== |
--- a/test/ReferrerMapping.cpp |
+++ b/test/ReferrerMapping.cpp |
@@ -18,21 +18,32 @@ |
#include <AdblockPlus.h> |
#include <gtest/gtest.h> |
-TEST(ReferrerMappingTest, EmptyReferrerChain) |
+typedef AdblockPlus::FilterEngine::ContentType ContentType; |
+ |
+TEST(ReferrerMappingTest, BuildFrameStructureShouldIncludeUrlItselfWhenThereIsNoMappingEntryForIt) |
Wladimir Palant
2014/11/25 15:46:37
Now that you've earned the price for the longest c
|
{ |
AdblockPlus::ReferrerMapping referrerMapping; |
std::vector<std::string> referrerChain = |
- referrerMapping.BuildReferrerChain("first"); |
+ referrerMapping.BuildFrameStructure("first"); |
ASSERT_EQ(1, referrerChain.size()); |
ASSERT_EQ("first", referrerChain[0]); |
} |
-TEST(ReferrerMappingTest, TwoElementReferrerChain) |
+TEST(ReferrerMappingTest, BuildFrameStructureShouldNotIncludeUrlItselfWhenItsTypeIsNotSubdocument) |
{ |
AdblockPlus::ReferrerMapping referrerMapping; |
- referrerMapping.Add("second", "first"); |
+ referrerMapping.Add("first", "", ContentType::CONTENT_TYPE_IMAGE); |
std::vector<std::string> referrerChain = |
- referrerMapping.BuildReferrerChain("second"); |
+ referrerMapping.BuildFrameStructure("first"); |
+ ASSERT_EQ(0, referrerChain.size()); |
+} |
+ |
+TEST(ReferrerMappingTest, BuildFrameStructureShouldIncludeReferrerIfThereIsNoInfoAboutIt) |
+{ |
+ AdblockPlus::ReferrerMapping referrerMapping; |
+ referrerMapping.Add("second", "first", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ std::vector<std::string> referrerChain = |
+ referrerMapping.BuildFrameStructure("second"); |
ASSERT_EQ(2, referrerChain.size()); |
ASSERT_EQ("first", referrerChain[0]); |
ASSERT_EQ("second", referrerChain[1]); |
@@ -41,17 +52,17 @@ |
TEST(ReferrerMappingTest, TenElementReferrerChain) |
{ |
AdblockPlus::ReferrerMapping referrerMapping; |
- referrerMapping.Add("second", "first"); |
- referrerMapping.Add("third", "second"); |
- referrerMapping.Add("fourth", "third"); |
- referrerMapping.Add("fifth", "fourth"); |
- referrerMapping.Add("sixth", "fifth"); |
- referrerMapping.Add("seventh", "sixth"); |
- referrerMapping.Add("eighth", "seventh"); |
- referrerMapping.Add("ninth", "eighth"); |
- referrerMapping.Add("tenth", "ninth"); |
+ referrerMapping.Add("second", "first", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("third", "second", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("fourth", "third", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("fifth", "fourth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("sixth", "fifth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("seventh", "sixth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("eighth", "seventh", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("ninth", "eighth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("tenth", "ninth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
std::vector<std::string> referrerChain = |
- referrerMapping.BuildReferrerChain("tenth"); |
+ referrerMapping.BuildFrameStructure("tenth"); |
ASSERT_EQ(10, referrerChain.size()); |
ASSERT_EQ("first", referrerChain[0]); |
ASSERT_EQ("second", referrerChain[1]); |
@@ -68,14 +79,15 @@ |
TEST(ReferrerMappingTest, CacheOnlyFiveUrls) |
{ |
AdblockPlus::ReferrerMapping referrerMapping(5); |
- referrerMapping.Add("second", "first"); |
- referrerMapping.Add("third", "second"); |
- referrerMapping.Add("fourth", "third"); |
- referrerMapping.Add("fifth", "fourth"); |
- referrerMapping.Add("sixth", "fifth"); |
- referrerMapping.Add("seventh", "sixth"); |
+ std::string outOfCacheUrl = "first"; |
+ referrerMapping.Add("second", outOfCacheUrl, ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("third", "second", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("fourth", "third", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("fifth", "fourth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("sixth", "fifth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("seventh", "sixth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
std::vector<std::string> referrerChain = |
- referrerMapping.BuildReferrerChain("seventh"); |
+ referrerMapping.BuildFrameStructure("seventh"); |
ASSERT_EQ(6, referrerChain.size()); |
ASSERT_EQ("second", referrerChain[0]); |
ASSERT_EQ("third", referrerChain[1]); |
@@ -84,3 +96,34 @@ |
ASSERT_EQ("sixth", referrerChain[4]); |
ASSERT_EQ("seventh", referrerChain[5]); |
} |
+ |
+TEST(ReferrerMappingTest, BuildFrameStructureShouldIncludeOnlySubdocumentReferrers) |
+{ |
+ AdblockPlus::ReferrerMapping referrerMapping; |
+ referrerMapping.Add("iframe1", "root-page", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("other", "iframe1", ContentType::CONTENT_TYPE_OTHER); |
+ referrerMapping.Add("script", "other", ContentType::CONTENT_TYPE_SCRIPT); |
+ referrerMapping.Add("image", "script", ContentType::CONTENT_TYPE_IMAGE); |
+ referrerMapping.Add("stylesheet", "image", ContentType::CONTENT_TYPE_STYLESHEET); |
+ referrerMapping.Add("object", "stylesheet", ContentType::CONTENT_TYPE_OBJECT); |
+ referrerMapping.Add("iframe2", "object", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerMapping.Add("document", "iframe2", ContentType::CONTENT_TYPE_DOCUMENT); |
+ referrerMapping.Add("xmlhttprequest", "document", ContentType::CONTENT_TYPE_XMLHTTPREQUEST); |
+ referrerMapping.Add("object subrequest", "xmlhttprequest", ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST); |
+ referrerMapping.Add("font", "object subrequest", ContentType::CONTENT_TYPE_FONT); |
+ referrerMapping.Add("media", "font", ContentType::CONTENT_TYPE_MEDIA); |
+ |
+ std::vector<std::string> referrerChain = referrerMapping.BuildFrameStructure("media"); |
+ ASSERT_EQ(3, referrerChain.size()); |
+ EXPECT_EQ("root-page", referrerChain[0]); |
+ EXPECT_EQ("iframe1", referrerChain[1]); |
+ EXPECT_EQ("iframe2", referrerChain[2]); |
+ |
+ referrerMapping.Add("iframe3", "media", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
+ referrerChain = referrerMapping.BuildFrameStructure("iframe3"); |
+ ASSERT_EQ(4, referrerChain.size()); |
+ EXPECT_EQ("root-page", referrerChain[0]); |
+ EXPECT_EQ("iframe1", referrerChain[1]); |
+ EXPECT_EQ("iframe2", referrerChain[2]); |
+ EXPECT_EQ("iframe3", referrerChain[3]); |
+} |