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

Side by Side Diff: test/ReferrerMapping.cpp

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

Powered by Google App Engine
This is Rietveld