OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <AdblockPlus.h> | 18 #include <AdblockPlus.h> |
19 #include <gtest/gtest.h> | 19 #include <gtest/gtest.h> |
20 | 20 |
21 TEST(ReferrerMappingTest, EmptyReferrerChain) | 21 typedef AdblockPlus::FilterEngine::ContentType ContentType; |
| 22 |
| 23 TEST(ReferrerMappingTest, BuildFrameStructureShouldIncludeUrlItselfWhenThereIsNo
MappingEntryForIt) |
22 { | 24 { |
23 AdblockPlus::ReferrerMapping referrerMapping; | 25 AdblockPlus::ReferrerMapping referrerMapping; |
24 std::vector<std::string> referrerChain = | 26 std::vector<std::string> referrerChain = |
25 referrerMapping.BuildReferrerChain("first"); | 27 referrerMapping.BuildFrameStructure("first"); |
26 ASSERT_EQ(1, referrerChain.size()); | 28 ASSERT_EQ(1, referrerChain.size()); |
27 ASSERT_EQ("first", referrerChain[0]); | 29 ASSERT_EQ("first", referrerChain[0]); |
28 } | 30 } |
29 | 31 |
30 TEST(ReferrerMappingTest, TwoElementReferrerChain) | 32 TEST(ReferrerMappingTest, BuildFrameStructureShouldNotIncludeUrlItselfWhenItsTyp
eIsNotSubdocument) |
31 { | 33 { |
32 AdblockPlus::ReferrerMapping referrerMapping; | 34 AdblockPlus::ReferrerMapping referrerMapping; |
33 referrerMapping.Add("second", "first"); | 35 referrerMapping.Add("first", "", ContentType::CONTENT_TYPE_IMAGE); |
34 std::vector<std::string> referrerChain = | 36 std::vector<std::string> referrerChain = |
35 referrerMapping.BuildReferrerChain("second"); | 37 referrerMapping.BuildFrameStructure("first"); |
| 38 ASSERT_EQ(0, referrerChain.size()); |
| 39 } |
| 40 |
| 41 TEST(ReferrerMappingTest, BuildFrameStructureShouldIncludeReferrerIfThereIsNoInf
oAboutIt) |
| 42 { |
| 43 AdblockPlus::ReferrerMapping referrerMapping; |
| 44 referrerMapping.Add("second", "first", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
| 45 std::vector<std::string> referrerChain = |
| 46 referrerMapping.BuildFrameStructure("second"); |
36 ASSERT_EQ(2, referrerChain.size()); | 47 ASSERT_EQ(2, referrerChain.size()); |
37 ASSERT_EQ("first", referrerChain[0]); | 48 ASSERT_EQ("first", referrerChain[0]); |
38 ASSERT_EQ("second", referrerChain[1]); | 49 ASSERT_EQ("second", referrerChain[1]); |
39 } | 50 } |
40 | 51 |
41 TEST(ReferrerMappingTest, TenElementReferrerChain) | 52 TEST(ReferrerMappingTest, TenElementReferrerChain) |
42 { | 53 { |
43 AdblockPlus::ReferrerMapping referrerMapping; | 54 AdblockPlus::ReferrerMapping referrerMapping; |
44 referrerMapping.Add("second", "first"); | 55 referrerMapping.Add("second", "first", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
45 referrerMapping.Add("third", "second"); | 56 referrerMapping.Add("third", "second", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
46 referrerMapping.Add("fourth", "third"); | 57 referrerMapping.Add("fourth", "third", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
47 referrerMapping.Add("fifth", "fourth"); | 58 referrerMapping.Add("fifth", "fourth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
48 referrerMapping.Add("sixth", "fifth"); | 59 referrerMapping.Add("sixth", "fifth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
49 referrerMapping.Add("seventh", "sixth"); | 60 referrerMapping.Add("seventh", "sixth", ContentType::CONTENT_TYPE_SUBDOCUMENT)
; |
50 referrerMapping.Add("eighth", "seventh"); | 61 referrerMapping.Add("eighth", "seventh", ContentType::CONTENT_TYPE_SUBDOCUMENT
); |
51 referrerMapping.Add("ninth", "eighth"); | 62 referrerMapping.Add("ninth", "eighth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
52 referrerMapping.Add("tenth", "ninth"); | 63 referrerMapping.Add("tenth", "ninth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
53 std::vector<std::string> referrerChain = | 64 std::vector<std::string> referrerChain = |
54 referrerMapping.BuildReferrerChain("tenth"); | 65 referrerMapping.BuildFrameStructure("tenth"); |
55 ASSERT_EQ(10, referrerChain.size()); | 66 ASSERT_EQ(10, referrerChain.size()); |
56 ASSERT_EQ("first", referrerChain[0]); | 67 ASSERT_EQ("first", referrerChain[0]); |
57 ASSERT_EQ("second", referrerChain[1]); | 68 ASSERT_EQ("second", referrerChain[1]); |
58 ASSERT_EQ("third", referrerChain[2]); | 69 ASSERT_EQ("third", referrerChain[2]); |
59 ASSERT_EQ("fourth", referrerChain[3]); | 70 ASSERT_EQ("fourth", referrerChain[3]); |
60 ASSERT_EQ("fifth", referrerChain[4]); | 71 ASSERT_EQ("fifth", referrerChain[4]); |
61 ASSERT_EQ("sixth", referrerChain[5]); | 72 ASSERT_EQ("sixth", referrerChain[5]); |
62 ASSERT_EQ("seventh", referrerChain[6]); | 73 ASSERT_EQ("seventh", referrerChain[6]); |
63 ASSERT_EQ("eighth", referrerChain[7]); | 74 ASSERT_EQ("eighth", referrerChain[7]); |
64 ASSERT_EQ("ninth", referrerChain[8]); | 75 ASSERT_EQ("ninth", referrerChain[8]); |
65 ASSERT_EQ("tenth", referrerChain[9]); | 76 ASSERT_EQ("tenth", referrerChain[9]); |
66 } | 77 } |
67 | 78 |
68 TEST(ReferrerMappingTest, CacheOnlyFiveUrls) | 79 TEST(ReferrerMappingTest, CacheOnlyFiveUrls) |
69 { | 80 { |
70 AdblockPlus::ReferrerMapping referrerMapping(5); | 81 AdblockPlus::ReferrerMapping referrerMapping(5); |
71 referrerMapping.Add("second", "first"); | 82 std::string outOfCacheUrl = "first"; |
72 referrerMapping.Add("third", "second"); | 83 referrerMapping.Add("second", outOfCacheUrl, ContentType::CONTENT_TYPE_SUBDOCU
MENT); |
73 referrerMapping.Add("fourth", "third"); | 84 referrerMapping.Add("third", "second", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
74 referrerMapping.Add("fifth", "fourth"); | 85 referrerMapping.Add("fourth", "third", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
75 referrerMapping.Add("sixth", "fifth"); | 86 referrerMapping.Add("fifth", "fourth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
76 referrerMapping.Add("seventh", "sixth"); | 87 referrerMapping.Add("sixth", "fifth", ContentType::CONTENT_TYPE_SUBDOCUMENT); |
| 88 referrerMapping.Add("seventh", "sixth", ContentType::CONTENT_TYPE_SUBDOCUMENT)
; |
77 std::vector<std::string> referrerChain = | 89 std::vector<std::string> referrerChain = |
78 referrerMapping.BuildReferrerChain("seventh"); | 90 referrerMapping.BuildFrameStructure("seventh"); |
79 ASSERT_EQ(6, referrerChain.size()); | 91 ASSERT_EQ(6, referrerChain.size()); |
80 ASSERT_EQ("second", referrerChain[0]); | 92 ASSERT_EQ("second", referrerChain[0]); |
81 ASSERT_EQ("third", referrerChain[1]); | 93 ASSERT_EQ("third", referrerChain[1]); |
82 ASSERT_EQ("fourth", referrerChain[2]); | 94 ASSERT_EQ("fourth", referrerChain[2]); |
83 ASSERT_EQ("fifth", referrerChain[3]); | 95 ASSERT_EQ("fifth", referrerChain[3]); |
84 ASSERT_EQ("sixth", referrerChain[4]); | 96 ASSERT_EQ("sixth", referrerChain[4]); |
85 ASSERT_EQ("seventh", referrerChain[5]); | 97 ASSERT_EQ("seventh", referrerChain[5]); |
86 } | 98 } |
| 99 |
| 100 TEST(ReferrerMappingTest, BuildFrameStructureShouldIncludeOnlySubdocumentReferre
rs) |
| 101 { |
| 102 AdblockPlus::ReferrerMapping referrerMapping; |
| 103 referrerMapping.Add("iframe1", "root-page", ContentType::CONTENT_TYPE_SUBDOCUM
ENT); |
| 104 referrerMapping.Add("other", "iframe1", ContentType::CONTENT_TYPE_OTHER); |
| 105 referrerMapping.Add("script", "other", ContentType::CONTENT_TYPE_SCRIPT); |
| 106 referrerMapping.Add("image", "script", ContentType::CONTENT_TYPE_IMAGE); |
| 107 referrerMapping.Add("stylesheet", "image", ContentType::CONTENT_TYPE_STYLESHEE
T); |
| 108 referrerMapping.Add("object", "stylesheet", ContentType::CONTENT_TYPE_OBJECT); |
| 109 referrerMapping.Add("iframe2", "object", ContentType::CONTENT_TYPE_SUBDOCUMENT
); |
| 110 referrerMapping.Add("document", "iframe2", ContentType::CONTENT_TYPE_DOCUMENT)
; |
| 111 referrerMapping.Add("xmlhttprequest", "document", ContentType::CONTENT_TYPE_XM
LHTTPREQUEST); |
| 112 referrerMapping.Add("object subrequest", "xmlhttprequest", ContentType::CONTEN
T_TYPE_OBJECT_SUBREQUEST); |
| 113 referrerMapping.Add("font", "object subrequest", ContentType::CONTENT_TYPE_FON
T); |
| 114 referrerMapping.Add("media", "font", ContentType::CONTENT_TYPE_MEDIA); |
| 115 |
| 116 std::vector<std::string> referrerChain = referrerMapping.BuildFrameStructure("
media"); |
| 117 ASSERT_EQ(3, referrerChain.size()); |
| 118 EXPECT_EQ("root-page", referrerChain[0]); |
| 119 EXPECT_EQ("iframe1", referrerChain[1]); |
| 120 EXPECT_EQ("iframe2", referrerChain[2]); |
| 121 |
| 122 referrerMapping.Add("iframe3", "media", ContentType::CONTENT_TYPE_SUBDOCUMENT)
; |
| 123 referrerChain = referrerMapping.BuildFrameStructure("iframe3"); |
| 124 ASSERT_EQ(4, referrerChain.size()); |
| 125 EXPECT_EQ("root-page", referrerChain[0]); |
| 126 EXPECT_EQ("iframe1", referrerChain[1]); |
| 127 EXPECT_EQ("iframe2", referrerChain[2]); |
| 128 EXPECT_EQ("iframe3", referrerChain[3]); |
| 129 } |
OLD | NEW |