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

Side by Side Diff: test/FilterEngine.cpp

Issue 29335462: Issue 3337 - Update adblockplus reference in libadblockplus to revision hg:813682c7161e (Closed)
Patch Set: rebase Created April 19, 2016, 9:27 p.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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 ASSERT_TRUE(match1); 273 ASSERT_TRUE(match1);
274 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); 274 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
275 275
276 AdblockPlus::FilterPtr match2 = 276 AdblockPlus::FilterPtr match2 =
277 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 277 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
278 "http://example.org/"); 278 "http://example.org/");
279 ASSERT_TRUE(match2); 279 ASSERT_TRUE(match2);
280 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); 280 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
281 } 281 }
282 282
283 TEST_F(FilterEngineTest, MatchesWithContentTypeMask)
284 {
285 filterEngine->GetFilter("adbanner.gif.js$script,image")->AddToList();
286 filterEngine->GetFilter("@@notbanner.gif")->AddToList();
287 filterEngine->GetFilter("blockme")->AddToList();
288 filterEngine->GetFilter("@@||example.doc^$document")->AddToList();
289
290 EXPECT_FALSE(filterEngine->Matches("http://example.org/foobar.gif",
291 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""))
292 << "another url should not match";
293
294 EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js",
295 /*mask*/ 0, "")) << "zero mask should not match (filter with some options)";
296
297 EXPECT_FALSE(filterEngine->Matches("http://example.xxx/blockme",
298 /*mask*/ 0, "")) << "zero mask should not match (filter without any option)" ;
299
300 EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js",
301 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, ""))
302 << "one arbitrary flag in mask should not match";
303
304 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js",
305 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE |
306 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, ""))
307 << "one of flags in mask should match";
308
309 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js",
310 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE |
311 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT, ""))
312 << "both flags in mask should match";
313
314 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js",
315 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE |
316 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT |
317 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, ""))
318 << "both flags with another flag in mask should match";
319
320 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js",
321 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT |
322 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, ""))
323 << "one of flags in mask should match";
324
325 {
326 AdblockPlus::FilterPtr filter;
327 ASSERT_TRUE(filter = filterEngine->Matches("http://child.any/blockme",
328 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT |
329 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "http://example.doc"))
330 << "non-zero mask should match on whitelisted document";
331
332 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType());
333 }
334
335 {
336 AdblockPlus::FilterPtr filter;
337 ASSERT_TRUE(filter = filterEngine->Matches("http://example.doc/blockme",
338 /*mask*/0, "http://example.doc"))
339 << "zero mask should match when document is whitelisted";
340
341 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType());
342 }
343 }
344
283 TEST_F(FilterEngineTest, MatchesNestedFrameRequest) 345 TEST_F(FilterEngineTest, MatchesNestedFrameRequest)
284 { 346 {
285 filterEngine->GetFilter("adbanner.gif")->AddToList(); 347 filterEngine->GetFilter("adbanner.gif")->AddToList();
286 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList(); 348 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList();
287 349
288 std::vector<std::string> documentUrls1; 350 std::vector<std::string> documentUrls1;
289 documentUrls1.push_back("http://ads.com/frame/"); 351 documentUrls1.push_back("http://ads.com/frame/");
290 documentUrls1.push_back("http://example.com/"); 352 documentUrls1.push_back("http://example.com/");
291 AdblockPlus::FilterPtr match1 = 353 AdblockPlus::FilterPtr match1 =
292 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 354 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 documentUrls1.push_back("http://example.de"); 526 documentUrls1.push_back("http://example.de");
465 527
466 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted( 528 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted(
467 "http://example.com", 529 "http://example.com",
468 documentUrls1)); 530 documentUrls1));
469 531
470 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted( 532 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted(
471 "http://example.co.uk", 533 "http://example.co.uk",
472 documentUrls1)); 534 documentUrls1));
473 } 535 }
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