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

Side by Side Diff: test/FilterEngine.cpp

Issue 23127017: Consider the frame structure in Matches() (Closed)
Patch Set: Better test coverage Created Nov. 15, 2013, 8:15 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
« no previous file with comments | « src/FilterEngine.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-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 ASSERT_FALSE(match10); 195 ASSERT_FALSE(match10);
196 196
197 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org banner.gif", "IMAGE", "http://example.com/"); 197 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org banner.gif", "IMAGE", "http://example.com/");
198 ASSERT_FALSE(match11); 198 ASSERT_FALSE(match11);
199 199
200 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org banner.gif", "IMAGE", "http://example.org/"); 200 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org banner.gif", "IMAGE", "http://example.org/");
201 ASSERT_TRUE(match12); 201 ASSERT_TRUE(match12);
202 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType()); 202 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType());
203 } 203 }
204 204
205 TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain)
206 {
207 filterEngine->GetFilter("adbanner.gif")->AddToList();
208 filterEngine->GetFilter("@@||example.org^$document")->AddToList();
209
210 AdblockPlus::FilterPtr match1 =
211 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
212 "http://example.com/");
213 ASSERT_TRUE(match1);
214 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
215
216 AdblockPlus::FilterPtr match2 =
217 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
218 "http://example.org/");
219 ASSERT_TRUE(match2);
220 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
221 }
222
223 TEST_F(FilterEngineTest, MatchesNestedFrameRequest)
224 {
225 filterEngine->GetFilter("adbanner.gif")->AddToList();
226 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList();
227
228 std::vector<std::string> documentUrls1;
229 documentUrls1.push_back("http://ads.com/frame/");
230 documentUrls1.push_back("http://example.com/");
231 AdblockPlus::FilterPtr match1 =
232 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
233 documentUrls1);
234 ASSERT_TRUE(match1);
235 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
236
237 std::vector<std::string> documentUrls2;
238 documentUrls2.push_back("http://ads.com/frame/");
239 documentUrls2.push_back("http://example.org/");
240 AdblockPlus::FilterPtr match2 =
241 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
242 documentUrls2);
243 ASSERT_TRUE(match2);
244 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
245
246 std::vector<std::string> documentUrls3;
247 documentUrls3.push_back("http://example.org/");
248 documentUrls3.push_back("http://ads.com/frame/");
249 AdblockPlus::FilterPtr match3 =
250 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
251 documentUrls3);
252 ASSERT_TRUE(match3);
253 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType());
254 }
255
256 TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain)
257 {
258 filterEngine->GetFilter("adbanner.gif")->AddToList();
259 filterEngine->GetFilter("@@||example.org^$document,domain=ads.com")->AddToList ();
260
261 std::vector<std::string> documentUrls1;
262 documentUrls1.push_back("http://ads.com/frame/");
263 documentUrls1.push_back("http://example.com/");
264 AdblockPlus::FilterPtr match1 =
265 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
266 documentUrls1);
267 ASSERT_TRUE(match1);
268 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
269
270 std::vector<std::string> documentUrls2;
271 documentUrls2.push_back("http://ads.com/frame/");
272 documentUrls2.push_back("http://example.org/");
273 AdblockPlus::FilterPtr match2 =
274 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
275 documentUrls2);
276 ASSERT_TRUE(match2);
277 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
278
279 std::vector<std::string> documentUrls3;
280 documentUrls3.push_back("http://example.org/");
281 AdblockPlus::FilterPtr match3 =
282 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
283 documentUrls3);
284 ASSERT_TRUE(match3);
285 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType());
286
287 std::vector<std::string> documentUrls4;
288 documentUrls4.push_back("http://example.org/");
289 documentUrls4.push_back("http://ads.com/frame/");
290 AdblockPlus::FilterPtr match4 =
291 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
292 documentUrls4);
293 ASSERT_TRUE(match4);
294 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match4->GetType());
295
296 std::vector<std::string> documentUrls5;
297 documentUrls5.push_back("http://ads.com/frame/");
298 documentUrls5.push_back("http://example.org/");
299 documentUrls5.push_back("http://example.com/");
300 AdblockPlus::FilterPtr match5 =
301 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE",
302 documentUrls5);
303 ASSERT_TRUE(match5);
304 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType());
305 }
306
205 TEST_F(FilterEngineTest, FirstRunFlag) 307 TEST_F(FilterEngineTest, FirstRunFlag)
206 { 308 {
207 ASSERT_FALSE(filterEngine->IsFirstRun()); 309 ASSERT_FALSE(filterEngine->IsFirstRun());
208 } 310 }
209 311
210 TEST_F(FilterEngineTestNoData, FirstRunFlag) 312 TEST_F(FilterEngineTestNoData, FirstRunFlag)
211 { 313 {
212 ASSERT_FALSE(filterEngine->IsFirstRun()); 314 ASSERT_FALSE(filterEngine->IsFirstRun());
213 } 315 }
OLDNEW
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld