Index: test/ReferrerMapping.cpp |
=================================================================== |
--- a/test/ReferrerMapping.cpp |
+++ b/test/ReferrerMapping.cpp |
@@ -18,7 +18,9 @@ |
#include <AdblockPlus.h> |
#include <gtest/gtest.h> |
-TEST(ReferrerMappingTest, EmptyReferrerChain) |
+typedef AdblockPlus::FilterEngine::ContentType ContentType; |
+ |
+TEST(ReferrerMappingTest, BuildReferrerChainShouldIncludeUrlItselfWhenThereIsNoMappingEntryForIt) |
{ |
AdblockPlus::ReferrerMapping referrerMapping; |
std::vector<std::string> referrerChain = |
@@ -27,10 +29,19 @@ |
ASSERT_EQ("first", referrerChain[0]); |
} |
-TEST(ReferrerMappingTest, TwoElementReferrerChain) |
+TEST(ReferrerMappingTest, BuildReferrerChainShouldNotIncludeUrlItselfWhenItsTypeIsNotSubdocument) |
{ |
AdblockPlus::ReferrerMapping referrerMapping; |
- referrerMapping.Add("second", "first"); |
+ referrerMapping.Add("first", "", ContentType::CONTENT_TYPE_IMAGE); |
+ std::vector<std::string> referrerChain = |
+ referrerMapping.BuildReferrerChain("first"); |
+ ASSERT_EQ(0, referrerChain.size()); |
+} |
+ |
+TEST(ReferrerMappingTest, BuildReferrerChainShouldIncludeReferrerIfThereIsNoInfoAboutIt) |
+{ |
+ AdblockPlus::ReferrerMapping referrerMapping; |
+ referrerMapping.Add("second", "first", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
std::vector<std::string> referrerChain = |
referrerMapping.BuildReferrerChain("second"); |
ASSERT_EQ(2, referrerChain.size()); |
@@ -41,15 +52,15 @@ |
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"); |
ASSERT_EQ(10, referrerChain.size()); |
@@ -68,12 +79,13 @@ |
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"); |
ASSERT_EQ(6, referrerChain.size()); |
@@ -84,3 +96,34 @@ |
ASSERT_EQ("sixth", referrerChain[4]); |
ASSERT_EQ("seventh", referrerChain[5]); |
} |
+ |
+TEST(ReferrerMappingTest, BuildReferrerChainShouldIncludeOnlySubdocumentReferrers) |
+{ |
+ 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.BuildReferrerChain("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.BuildReferrerChain("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]); |
+} |