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

Delta Between Two Patch Sets: test/ReferrerMapping.cpp

Issue 5768603836088320: Issue 1564-Fix FilterEngine::Matches for allowing request which is whitelisted in the ascendant node
Left Patch Set: revert and change referrer map Created Nov. 25, 2014, 12:22 p.m.
Right Patch Set: fix according to comments Created Dec. 12, 2014, 4:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/ReferrerMapping.cpp ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 typedef AdblockPlus::FilterEngine::ContentType ContentType; 21 typedef AdblockPlus::FilterEngine::ContentType ContentType;
22 typedef AdblockPlus::ReferrerMapping::FrameIndicator FrameIndicator;
22 23
23 TEST(ReferrerMappingTest, BuildReferrerChainShouldIncludeUrlItselfWhenThereIsNoM appingEntryForIt) 24 TEST(ReferrerMappingTest, EmptyReferrerChain)
24 { 25 {
25 AdblockPlus::ReferrerMapping referrerMapping; 26 AdblockPlus::ReferrerMapping referrerMapping;
26 std::vector<std::string> referrerChain = 27 std::vector<std::string> referrerChain =
27 referrerMapping.BuildReferrerChain("first"); 28 referrerMapping.BuildFrameStructure("first");
28 ASSERT_EQ(1, referrerChain.size()); 29 ASSERT_EQ(1, referrerChain.size());
29 ASSERT_EQ("first", referrerChain[0]); 30 EXPECT_EQ("first", referrerChain[0]);
30 } 31 }
31 32
32 TEST(ReferrerMappingTest, BuildReferrerChainShouldNotIncludeUrlItselfWhenItsType IsNotSubdocument) 33 TEST(ReferrerMappingTest, EmptyUrl)
33 { 34 {
34 AdblockPlus::ReferrerMapping referrerMapping; 35 AdblockPlus::ReferrerMapping referrerMapping;
35 referrerMapping.Add("first", "", ContentType::CONTENT_TYPE_IMAGE);
36 std::vector<std::string> referrerChain = 36 std::vector<std::string> referrerChain =
37 referrerMapping.BuildReferrerChain("first"); 37 referrerMapping.BuildFrameStructure("");
38 EXPECT_EQ(0, referrerChain.size());
39
40 referrerMapping.Add("", "referrer", FrameIndicator::FRAME_INDICATOR_FRAME);
41 referrerChain = referrerMapping.BuildFrameStructure("");
42 EXPECT_EQ(0, referrerChain.size());
43 }
44
45 TEST(ReferrerMappingTest, EmptyReferrer)
46 {
47 AdblockPlus::ReferrerMapping referrerMapping;
48 referrerMapping.Add("first", "", FrameIndicator::FRAME_INDICATOR_FRAME);
49 std::vector<std::string> referrerChain =
50 referrerMapping.BuildFrameStructure("first");
51 ASSERT_EQ(1, referrerChain.size());
52 EXPECT_EQ("first", referrerChain[0]);
53 }
54
55 TEST(ReferrerMappingTest, NotAFrame)
56 {
57 AdblockPlus::ReferrerMapping referrerMapping;
58 referrerMapping.Add("first", "", FrameIndicator::FRAME_INDICATOR_NOT_FRAME);
59 std::vector<std::string> referrerChain =
60 referrerMapping.BuildFrameStructure("first");
38 ASSERT_EQ(0, referrerChain.size()); 61 ASSERT_EQ(0, referrerChain.size());
39 } 62 }
40 63
41 TEST(ReferrerMappingTest, BuildReferrerChainShouldIncludeReferrerIfThereIsNoInfo AboutIt) 64 TEST(ReferrerMappingTest, TwoElementReferrerChain)
42 { 65 {
43 AdblockPlus::ReferrerMapping referrerMapping; 66 AdblockPlus::ReferrerMapping referrerMapping;
44 referrerMapping.Add("second", "first", ContentType::CONTENT_TYPE_SUBDOCUMENT); 67 referrerMapping.Add("second", "first", FrameIndicator::FRAME_INDICATOR_FRAME);
45 std::vector<std::string> referrerChain = 68 std::vector<std::string> referrerChain =
46 referrerMapping.BuildReferrerChain("second"); 69 referrerMapping.BuildFrameStructure("second");
47 ASSERT_EQ(2, referrerChain.size()); 70 ASSERT_EQ(2, referrerChain.size());
48 ASSERT_EQ("first", referrerChain[0]); 71 ASSERT_EQ("first", referrerChain[0]);
49 ASSERT_EQ("second", referrerChain[1]); 72 ASSERT_EQ("second", referrerChain[1]);
50 } 73 }
51 74
52 TEST(ReferrerMappingTest, TenElementReferrerChain) 75 TEST(ReferrerMappingTest, TenElementReferrerChain)
53 { 76 {
54 AdblockPlus::ReferrerMapping referrerMapping; 77 AdblockPlus::ReferrerMapping referrerMapping;
55 referrerMapping.Add("second", "first", ContentType::CONTENT_TYPE_SUBDOCUMENT); 78 referrerMapping.Add("second", "first", FrameIndicator::FRAME_INDICATOR_FRAME);
56 referrerMapping.Add("third", "second", ContentType::CONTENT_TYPE_SUBDOCUMENT); 79 referrerMapping.Add("third", "second", FrameIndicator::FRAME_INDICATOR_FRAME);
57 referrerMapping.Add("fourth", "third", ContentType::CONTENT_TYPE_SUBDOCUMENT); 80 referrerMapping.Add("fourth", "third", FrameIndicator::FRAME_INDICATOR_FRAME);
58 referrerMapping.Add("fifth", "fourth", ContentType::CONTENT_TYPE_SUBDOCUMENT); 81 referrerMapping.Add("fifth", "fourth", FrameIndicator::FRAME_INDICATOR_FRAME);
59 referrerMapping.Add("sixth", "fifth", ContentType::CONTENT_TYPE_SUBDOCUMENT); 82 referrerMapping.Add("sixth", "fifth", FrameIndicator::FRAME_INDICATOR_FRAME);
60 referrerMapping.Add("seventh", "sixth", ContentType::CONTENT_TYPE_SUBDOCUMENT) ; 83 referrerMapping.Add("seventh", "sixth", FrameIndicator::FRAME_INDICATOR_FRAME) ;
61 referrerMapping.Add("eighth", "seventh", ContentType::CONTENT_TYPE_SUBDOCUMENT ); 84 referrerMapping.Add("eighth", "seventh", FrameIndicator::FRAME_INDICATOR_FRAME );
62 referrerMapping.Add("ninth", "eighth", ContentType::CONTENT_TYPE_SUBDOCUMENT); 85 referrerMapping.Add("ninth", "eighth", FrameIndicator::FRAME_INDICATOR_FRAME);
63 referrerMapping.Add("tenth", "ninth", ContentType::CONTENT_TYPE_SUBDOCUMENT); 86 referrerMapping.Add("tenth", "ninth", FrameIndicator::FRAME_INDICATOR_FRAME);
64 std::vector<std::string> referrerChain = 87 std::vector<std::string> referrerChain =
65 referrerMapping.BuildReferrerChain("tenth"); 88 referrerMapping.BuildFrameStructure("tenth");
66 ASSERT_EQ(10, referrerChain.size()); 89 ASSERT_EQ(10, referrerChain.size());
67 ASSERT_EQ("first", referrerChain[0]); 90 ASSERT_EQ("first", referrerChain[0]);
68 ASSERT_EQ("second", referrerChain[1]); 91 ASSERT_EQ("second", referrerChain[1]);
69 ASSERT_EQ("third", referrerChain[2]); 92 ASSERT_EQ("third", referrerChain[2]);
70 ASSERT_EQ("fourth", referrerChain[3]); 93 ASSERT_EQ("fourth", referrerChain[3]);
71 ASSERT_EQ("fifth", referrerChain[4]); 94 ASSERT_EQ("fifth", referrerChain[4]);
72 ASSERT_EQ("sixth", referrerChain[5]); 95 ASSERT_EQ("sixth", referrerChain[5]);
73 ASSERT_EQ("seventh", referrerChain[6]); 96 ASSERT_EQ("seventh", referrerChain[6]);
74 ASSERT_EQ("eighth", referrerChain[7]); 97 ASSERT_EQ("eighth", referrerChain[7]);
75 ASSERT_EQ("ninth", referrerChain[8]); 98 ASSERT_EQ("ninth", referrerChain[8]);
76 ASSERT_EQ("tenth", referrerChain[9]); 99 ASSERT_EQ("tenth", referrerChain[9]);
77 } 100 }
78 101
79 TEST(ReferrerMappingTest, CacheOnlyFiveUrls) 102 TEST(ReferrerMappingTest, CacheOnlyFiveUrls)
80 { 103 {
81 AdblockPlus::ReferrerMapping referrerMapping(5); 104 AdblockPlus::ReferrerMapping referrerMapping(5);
82 std::string outOfCacheUrl = "first"; 105 std::string outOfCacheUrl = "first";
83 referrerMapping.Add("second", outOfCacheUrl, ContentType::CONTENT_TYPE_SUBDOCU MENT); 106 referrerMapping.Add("second", outOfCacheUrl, FrameIndicator::FRAME_INDICATOR_F RAME);
84 referrerMapping.Add("third", "second", ContentType::CONTENT_TYPE_SUBDOCUMENT); 107 referrerMapping.Add("third", "second", FrameIndicator::FRAME_INDICATOR_FRAME);
85 referrerMapping.Add("fourth", "third", ContentType::CONTENT_TYPE_SUBDOCUMENT); 108 referrerMapping.Add("fourth", "third", FrameIndicator::FRAME_INDICATOR_FRAME);
86 referrerMapping.Add("fifth", "fourth", ContentType::CONTENT_TYPE_SUBDOCUMENT); 109 referrerMapping.Add("fifth", "fourth", FrameIndicator::FRAME_INDICATOR_FRAME);
87 referrerMapping.Add("sixth", "fifth", ContentType::CONTENT_TYPE_SUBDOCUMENT); 110 referrerMapping.Add("sixth", "fifth", FrameIndicator::FRAME_INDICATOR_FRAME);
88 referrerMapping.Add("seventh", "sixth", ContentType::CONTENT_TYPE_SUBDOCUMENT) ; 111 referrerMapping.Add("seventh", "sixth", FrameIndicator::FRAME_INDICATOR_FRAME) ;
89 std::vector<std::string> referrerChain = 112 std::vector<std::string> referrerChain =
90 referrerMapping.BuildReferrerChain("seventh"); 113 referrerMapping.BuildFrameStructure("seventh");
91 ASSERT_EQ(6, referrerChain.size()); 114 ASSERT_EQ(6, referrerChain.size());
92 ASSERT_EQ("second", referrerChain[0]); 115 ASSERT_EQ("second", referrerChain[0]);
93 ASSERT_EQ("third", referrerChain[1]); 116 ASSERT_EQ("third", referrerChain[1]);
94 ASSERT_EQ("fourth", referrerChain[2]); 117 ASSERT_EQ("fourth", referrerChain[2]);
95 ASSERT_EQ("fifth", referrerChain[3]); 118 ASSERT_EQ("fifth", referrerChain[3]);
96 ASSERT_EQ("sixth", referrerChain[4]); 119 ASSERT_EQ("sixth", referrerChain[4]);
97 ASSERT_EQ("seventh", referrerChain[5]); 120 ASSERT_EQ("seventh", referrerChain[5]);
98 } 121 }
99 122
100 TEST(ReferrerMappingTest, BuildReferrerChainShouldIncludeOnlySubdocumentReferrer s) 123 TEST(ReferrerMappingTest, OnlyFrames)
101 { 124 {
102 AdblockPlus::ReferrerMapping referrerMapping; 125 AdblockPlus::ReferrerMapping referrerMapping;
103 referrerMapping.Add("iframe1", "root-page", ContentType::CONTENT_TYPE_SUBDOCUM ENT); 126 referrerMapping.Add("iframe1", "root-page", FrameIndicator::FRAME_INDICATOR_FR AME);
104 referrerMapping.Add("other", "iframe1", ContentType::CONTENT_TYPE_OTHER); 127 referrerMapping.Add("not a frame", "iframe1", FrameIndicator::FRAME_INDICATOR_ NOT_FRAME);
105 referrerMapping.Add("script", "other", ContentType::CONTENT_TYPE_SCRIPT); 128 referrerMapping.Add("iframe2", "not a frame", FrameIndicator::FRAME_INDICATOR_ FRAME);
106 referrerMapping.Add("image", "script", ContentType::CONTENT_TYPE_IMAGE); 129 referrerMapping.Add("media", "iframe2", FrameIndicator::FRAME_INDICATOR_NOT_FR AME);
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 130
116 std::vector<std::string> referrerChain = referrerMapping.BuildReferrerChain("m edia"); 131 std::vector<std::string> referrerChain = referrerMapping.BuildFrameStructure(" media");
117 ASSERT_EQ(3, referrerChain.size()); 132 ASSERT_EQ(3, referrerChain.size());
118 EXPECT_EQ("root-page", referrerChain[0]); 133 EXPECT_EQ("root-page", referrerChain[0]);
119 EXPECT_EQ("iframe1", referrerChain[1]); 134 EXPECT_EQ("iframe1", referrerChain[1]);
120 EXPECT_EQ("iframe2", referrerChain[2]); 135 EXPECT_EQ("iframe2", referrerChain[2]);
121 136
122 referrerMapping.Add("iframe3", "media", ContentType::CONTENT_TYPE_SUBDOCUMENT) ; 137 referrerMapping.Add("iframe3", "media", FrameIndicator::FRAME_INDICATOR_FRAME) ;
123 referrerChain = referrerMapping.BuildReferrerChain("iframe3"); 138 referrerChain = referrerMapping.BuildFrameStructure("iframe3");
124 ASSERT_EQ(4, referrerChain.size()); 139 ASSERT_EQ(4, referrerChain.size());
125 EXPECT_EQ("root-page", referrerChain[0]); 140 EXPECT_EQ("root-page", referrerChain[0]);
126 EXPECT_EQ("iframe1", referrerChain[1]); 141 EXPECT_EQ("iframe1", referrerChain[1]);
127 EXPECT_EQ("iframe2", referrerChain[2]); 142 EXPECT_EQ("iframe2", referrerChain[2]);
128 EXPECT_EQ("iframe3", referrerChain[3]); 143 EXPECT_EQ("iframe3", referrerChain[3]);
129 } 144 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld