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

Side by Side Diff: test/FilterEngine.cpp

Issue 29419607: Issue 5163 - Reduce the use of FilterPtr (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 21, 2017, 1:04 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // with subscription object will result in execution of JS, which will 270 // with subscription object will result in execution of JS, which will
271 // be blocked until finishing of currently running code. 271 // be blocked until finishing of currently running code.
272 } 272 }
273 return subscription; 273 return subscription;
274 } 274 }
275 }; 275 };
276 } 276 }
277 277
278 TEST_F(FilterEngineTest, FilterCreation) 278 TEST_F(FilterEngineTest, FilterCreation)
279 { 279 {
280 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); 280 AdblockPlus::Filter filter1 = filterEngine->GetFilter("foo");
281 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); 281 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1.GetType());
282 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); 282 AdblockPlus::Filter filter2 = filterEngine->GetFilter("@@foo");
283 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); 283 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2.GetType());
284 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); 284 AdblockPlus::Filter filter3 = filterEngine->GetFilter("example.com##foo");
285 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); 285 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3.GetType());
286 AdblockPlus::FilterPtr filter4 = filterEngine->GetFilter("example.com#@#foo"); 286 AdblockPlus::Filter filter4 = filterEngine->GetFilter("example.com#@#foo");
287 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetType()); 287 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4.GetType());
288 AdblockPlus::FilterPtr filter5 = filterEngine->GetFilter(" foo "); 288 AdblockPlus::Filter filter5 = filterEngine->GetFilter(" foo ");
289 ASSERT_EQ(*filter1, *filter5); 289 ASSERT_EQ(filter1, filter5);
290 } 290 }
291 291
292 TEST_F(FilterEngineTest, FilterProperties) 292 TEST_F(FilterEngineTest, FilterProperties)
293 { 293 {
294 AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo"); 294 AdblockPlus::Filter filter = filterEngine->GetFilter("foo");
295 295
296 ASSERT_TRUE(filter->GetProperty("stringFoo").IsUndefined()); 296 ASSERT_TRUE(filter.GetProperty("stringFoo").IsUndefined());
297 ASSERT_TRUE(filter->GetProperty("intFoo").IsUndefined()); 297 ASSERT_TRUE(filter.GetProperty("intFoo").IsUndefined());
298 ASSERT_TRUE(filter->GetProperty("boolFoo").IsUndefined()); 298 ASSERT_TRUE(filter.GetProperty("boolFoo").IsUndefined());
299 299
300 filter->SetProperty("stringFoo", "y"); 300 filter.SetProperty("stringFoo", "y");
301 filter->SetProperty("intFoo", 24); 301 filter.SetProperty("intFoo", 24);
302 filter->SetProperty("boolFoo", true); 302 filter.SetProperty("boolFoo", true);
303 ASSERT_EQ("y", filter->GetProperty("stringFoo").AsString()); 303 ASSERT_EQ("y", filter.GetProperty("stringFoo").AsString());
304 ASSERT_EQ(24, filter->GetProperty("intFoo").AsInt()); 304 ASSERT_EQ(24, filter.GetProperty("intFoo").AsInt());
305 ASSERT_TRUE(filter->GetProperty("boolFoo").AsBool()); 305 ASSERT_TRUE(filter.GetProperty("boolFoo").AsBool());
306 } 306 }
307 307
308 TEST_F(FilterEngineTest, AddRemoveFilters) 308 TEST_F(FilterEngineTest, AddRemoveFilters)
309 { 309 {
310 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); 310 ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
311 AdblockPlus::FilterPtr filter = filterEngine->GetFilter("foo"); 311 AdblockPlus::Filter filter = filterEngine->GetFilter("foo");
312 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); 312 ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
313 ASSERT_FALSE(filter->IsListed()); 313 ASSERT_FALSE(filter.IsListed());
314 filter->AddToList(); 314 filter.AddToList();
315 ASSERT_EQ(1u, filterEngine->GetListedFilters().size()); 315 ASSERT_EQ(1u, filterEngine->GetListedFilters().size());
316 ASSERT_EQ(*filter, *filterEngine->GetListedFilters()[0]); 316 ASSERT_EQ(filter, filterEngine->GetListedFilters()[0]);
317 ASSERT_TRUE(filter->IsListed()); 317 ASSERT_TRUE(filter.IsListed());
318 filter->AddToList(); 318 filter.AddToList();
319 ASSERT_EQ(1u, filterEngine->GetListedFilters().size()); 319 ASSERT_EQ(1u, filterEngine->GetListedFilters().size());
320 ASSERT_EQ(*filter, *filterEngine->GetListedFilters()[0]); 320 ASSERT_EQ(filter, filterEngine->GetListedFilters()[0]);
321 ASSERT_TRUE(filter->IsListed()); 321 ASSERT_TRUE(filter.IsListed());
322 filter->RemoveFromList(); 322 filter.RemoveFromList();
323 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); 323 ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
324 ASSERT_FALSE(filter->IsListed()); 324 ASSERT_FALSE(filter.IsListed());
325 filter->RemoveFromList(); 325 filter.RemoveFromList();
326 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); 326 ASSERT_EQ(0u, filterEngine->GetListedFilters().size());
327 ASSERT_FALSE(filter->IsListed()); 327 ASSERT_FALSE(filter.IsListed());
328 } 328 }
329 329
330 TEST_F(FilterEngineTest, SubscriptionProperties) 330 TEST_F(FilterEngineTest, SubscriptionProperties)
331 { 331 {
332 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo "); 332 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo ");
333 333
334 ASSERT_TRUE(subscription->GetProperty("stringFoo").IsUndefined()); 334 ASSERT_TRUE(subscription->GetProperty("stringFoo").IsUndefined());
335 ASSERT_TRUE(subscription->GetProperty("intFoo").IsUndefined()); 335 ASSERT_TRUE(subscription->GetProperty("intFoo").IsUndefined());
336 ASSERT_TRUE(subscription->GetProperty("boolFoo").IsUndefined()); 336 ASSERT_TRUE(subscription->GetProperty("boolFoo").IsUndefined());
337 337
(...skipping 29 matching lines...) Expand all
367 367
368 TEST_F(FilterEngineTest, SubscriptionUpdates) 368 TEST_F(FilterEngineTest, SubscriptionUpdates)
369 { 369 {
370 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo "); 370 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo ");
371 ASSERT_FALSE(subscription->IsUpdating()); 371 ASSERT_FALSE(subscription->IsUpdating());
372 subscription->UpdateFilters(); 372 subscription->UpdateFilters();
373 } 373 }
374 374
375 TEST_F(FilterEngineTest, Matches) 375 TEST_F(FilterEngineTest, Matches)
376 { 376 {
377 filterEngine->GetFilter("adbanner.gif")->AddToList(); 377 filterEngine->GetFilter("adbanner.gif").AddToList();
378 filterEngine->GetFilter("@@notbanner.gif")->AddToList(); 378 filterEngine->GetFilter("@@notbanner.gif").AddToList();
379 filterEngine->GetFilter("tpbanner.gif$third-party")->AddToList(); 379 filterEngine->GetFilter("tpbanner.gif$third-party").AddToList();
380 filterEngine->GetFilter("fpbanner.gif$~third-party")->AddToList(); 380 filterEngine->GetFilter("fpbanner.gif$~third-party").AddToList();
381 filterEngine->GetFilter("combanner.gif$domain=example.com")->AddToList(); 381 filterEngine->GetFilter("combanner.gif$domain=example.com").AddToList();
382 filterEngine->GetFilter("orgbanner.gif$domain=~example.com")->AddToList(); 382 filterEngine->GetFilter("orgbanner.gif$domain=~example.com").AddToList();
383 383
384 AdblockPlus::FilterPtr match1 = filterEngine->Matches("http://example.org/foob ar.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); 384 AdblockPlus::FilterPtr match1 = filterEngine->Matches("http://example.org/foob ar.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "");
385 ASSERT_FALSE(match1); 385 ASSERT_FALSE(match1);
386 386
387 AdblockPlus::FilterPtr match2 = filterEngine->Matches("http://example.org/adba nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); 387 AdblockPlus::FilterPtr match2 = filterEngine->Matches("http://example.org/adba nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "");
388 ASSERT_TRUE(match2); 388 ASSERT_TRUE(match2);
389 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetType()); 389 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetType());
390 390
391 AdblockPlus::FilterPtr match3 = filterEngine->Matches("http://example.org/notb anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); 391 AdblockPlus::FilterPtr match3 = filterEngine->Matches("http://example.org/notb anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "");
392 ASSERT_TRUE(match3); 392 ASSERT_TRUE(match3);
(...skipping 27 matching lines...) Expand all
420 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/ "); 420 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/ ");
421 ASSERT_FALSE(match11); 421 ASSERT_FALSE(match11);
422 422
423 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/ "); 423 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/ ");
424 ASSERT_TRUE(match12); 424 ASSERT_TRUE(match12);
425 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType()); 425 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType());
426 } 426 }
427 427
428 TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain) 428 TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain)
429 { 429 {
430 filterEngine->GetFilter("adbanner.gif")->AddToList(); 430 filterEngine->GetFilter("adbanner.gif").AddToList();
431 filterEngine->GetFilter("@@||example.org^$document")->AddToList(); 431 filterEngine->GetFilter("@@||example.org^$document").AddToList();
432 432
433 AdblockPlus::FilterPtr match1 = 433 AdblockPlus::FilterPtr match1 =
434 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 434 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
435 "http://example.com/"); 435 "http://example.com/");
436 ASSERT_TRUE(match1); 436 ASSERT_TRUE(match1);
437 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); 437 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
438 438
439 AdblockPlus::FilterPtr match2 = 439 AdblockPlus::FilterPtr match2 =
440 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 440 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
441 "http://example.org/"); 441 "http://example.org/");
442 ASSERT_TRUE(match2); 442 ASSERT_TRUE(match2);
443 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); 443 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
444 } 444 }
445 445
446 TEST_F(FilterEngineTest, MatchesWithContentTypeMask) 446 TEST_F(FilterEngineTest, MatchesWithContentTypeMask)
447 { 447 {
448 filterEngine->GetFilter("adbanner.gif.js$script,image")->AddToList(); 448 filterEngine->GetFilter("adbanner.gif.js$script,image").AddToList();
449 filterEngine->GetFilter("@@notbanner.gif")->AddToList(); 449 filterEngine->GetFilter("@@notbanner.gif").AddToList();
450 filterEngine->GetFilter("blockme")->AddToList(); 450 filterEngine->GetFilter("blockme").AddToList();
451 filterEngine->GetFilter("@@||example.doc^$document")->AddToList(); 451 filterEngine->GetFilter("@@||example.doc^$document").AddToList();
452 452
453 EXPECT_FALSE(filterEngine->Matches("http://example.org/foobar.gif", 453 EXPECT_FALSE(filterEngine->Matches("http://example.org/foobar.gif",
454 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "")) 454 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""))
455 << "another url should not match"; 455 << "another url should not match";
456 456
457 EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js", 457 EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js",
458 /*mask*/ 0, "")) << "zero mask should not match (filter with some options)"; 458 /*mask*/ 0, "")) << "zero mask should not match (filter with some options)";
459 459
460 EXPECT_FALSE(filterEngine->Matches("http://example.xxx/blockme", 460 EXPECT_FALSE(filterEngine->Matches("http://example.xxx/blockme",
461 /*mask*/ 0, "")) << "zero mask should not match (filter without any option)" ; 461 /*mask*/ 0, "")) << "zero mask should not match (filter without any option)" ;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 ASSERT_TRUE(filter = filterEngine->Matches("http://example.doc/blockme", 500 ASSERT_TRUE(filter = filterEngine->Matches("http://example.doc/blockme",
501 /*mask*/0, "http://example.doc")) 501 /*mask*/0, "http://example.doc"))
502 << "zero mask should match when document is whitelisted"; 502 << "zero mask should match when document is whitelisted";
503 503
504 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType()); 504 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType());
505 } 505 }
506 } 506 }
507 507
508 TEST_F(FilterEngineTest, MatchesNestedFrameRequest) 508 TEST_F(FilterEngineTest, MatchesNestedFrameRequest)
509 { 509 {
510 filterEngine->GetFilter("adbanner.gif")->AddToList(); 510 filterEngine->GetFilter("adbanner.gif").AddToList();
511 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList(); 511 filterEngine->GetFilter("@@adbanner.gif$domain=example.org").AddToList();
512 512
513 std::vector<std::string> documentUrls1; 513 std::vector<std::string> documentUrls1;
514 documentUrls1.push_back("http://ads.com/frame/"); 514 documentUrls1.push_back("http://ads.com/frame/");
515 documentUrls1.push_back("http://example.com/"); 515 documentUrls1.push_back("http://example.com/");
516 AdblockPlus::FilterPtr match1 = 516 AdblockPlus::FilterPtr match1 =
517 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 517 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
518 documentUrls1); 518 documentUrls1);
519 ASSERT_TRUE(match1); 519 ASSERT_TRUE(match1);
520 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); 520 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
521 521
(...skipping 11 matching lines...) Expand all
533 documentUrls3.push_back("http://ads.com/frame/"); 533 documentUrls3.push_back("http://ads.com/frame/");
534 AdblockPlus::FilterPtr match3 = 534 AdblockPlus::FilterPtr match3 =
535 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 535 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
536 documentUrls3); 536 documentUrls3);
537 ASSERT_TRUE(match3); 537 ASSERT_TRUE(match3);
538 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); 538 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType());
539 } 539 }
540 540
541 TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain) 541 TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain)
542 { 542 {
543 filterEngine->GetFilter("adbanner.gif")->AddToList(); 543 filterEngine->GetFilter("adbanner.gif").AddToList();
544 filterEngine->GetFilter("@@||example.org^$document,domain=ads.com")->AddToList (); 544 filterEngine->GetFilter("@@||example.org^$document,domain=ads.com").AddToList( );
545 545
546 std::vector<std::string> documentUrls1; 546 std::vector<std::string> documentUrls1;
547 documentUrls1.push_back("http://ads.com/frame/"); 547 documentUrls1.push_back("http://ads.com/frame/");
548 documentUrls1.push_back("http://example.com/"); 548 documentUrls1.push_back("http://example.com/");
549 AdblockPlus::FilterPtr match1 = 549 AdblockPlus::FilterPtr match1 =
550 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 550 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
551 documentUrls1); 551 documentUrls1);
552 ASSERT_TRUE(match1); 552 ASSERT_TRUE(match1);
553 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); 553 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
554 554
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 { 598 {
599 ASSERT_TRUE(filterEngine->IsFirstRun()); 599 ASSERT_TRUE(filterEngine->IsFirstRun());
600 } 600 }
601 601
602 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback) 602 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback)
603 { 603 {
604 int timesCalled = 0; 604 int timesCalled = 0;
605 MockFilterChangeCallback mockFilterChangeCallback(timesCalled); 605 MockFilterChangeCallback mockFilterChangeCallback(timesCalled);
606 std::this_thread::sleep_for(std::chrono::milliseconds(200)); 606 std::this_thread::sleep_for(std::chrono::milliseconds(200));
607 filterEngine->SetFilterChangeCallback(mockFilterChangeCallback); 607 filterEngine->SetFilterChangeCallback(mockFilterChangeCallback);
608 filterEngine->GetFilter("foo")->AddToList(); 608 filterEngine->GetFilter("foo").AddToList();
609 EXPECT_EQ(1, timesCalled); 609 EXPECT_EQ(1, timesCalled);
610 610
611 filterEngine->RemoveFilterChangeCallback(); 611 filterEngine->RemoveFilterChangeCallback();
612 filterEngine->GetFilter("foo")->RemoveFromList(); 612 filterEngine->GetFilter("foo").RemoveFromList();
613 EXPECT_EQ(1, timesCalled); 613 EXPECT_EQ(1, timesCalled);
614 } 614 }
615 615
616 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback) 616 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback)
617 { 617 {
618 mockWebRequest->response.status = 0; 618 mockWebRequest->response.status = 0;
619 mockWebRequest->response.responseStatus = 200; 619 mockWebRequest->response.responseStatus = 200;
620 mockWebRequest->response.responseText = "\ 620 mockWebRequest->response.responseText = "\
621 {\ 621 {\
622 \"test\": {\ 622 \"test\": {\
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 filterEngine->ForceUpdateCheck([&called](const std::string& error)->void 656 filterEngine->ForceUpdateCheck([&called](const std::string& error)->void
657 { 657 {
658 called = error.empty() ? 1 : 2; 658 called = error.empty() ? 1 : 2;
659 }); 659 });
660 AdblockPlus::Sleep(100); 660 AdblockPlus::Sleep(100);
661 EXPECT_EQ(1, called); 661 EXPECT_EQ(1, called);
662 } 662 }
663 663
664 TEST_F(FilterEngineTest, DocumentWhitelisting) 664 TEST_F(FilterEngineTest, DocumentWhitelisting)
665 { 665 {
666 filterEngine->GetFilter("@@||example.org^$document")->AddToList(); 666 filterEngine->GetFilter("@@||example.org^$document").AddToList();
667 filterEngine->GetFilter("@@||example.com^$document,domain=example.de")->AddToL ist(); 667 filterEngine->GetFilter("@@||example.com^$document,domain=example.de").AddToLi st();
668 668
669 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted( 669 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted(
670 "http://example.org", 670 "http://example.org",
671 std::vector<std::string>())); 671 std::vector<std::string>()));
672 672
673 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted( 673 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted(
674 "http://example.co.uk", 674 "http://example.co.uk",
675 std::vector<std::string>())); 675 std::vector<std::string>()));
676 676
677 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted( 677 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted(
678 "http://example.com", 678 "http://example.com",
679 std::vector<std::string>())); 679 std::vector<std::string>()));
680 680
681 std::vector<std::string> documentUrls1; 681 std::vector<std::string> documentUrls1;
682 documentUrls1.push_back("http://example.de"); 682 documentUrls1.push_back("http://example.de");
683 683
684 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted( 684 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted(
685 "http://example.com", 685 "http://example.com",
686 documentUrls1)); 686 documentUrls1));
687 687
688 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted( 688 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted(
689 "http://example.co.uk", 689 "http://example.co.uk",
690 documentUrls1)); 690 documentUrls1));
691 } 691 }
692 692
693 TEST_F(FilterEngineTest, ElemhideWhitelisting) 693 TEST_F(FilterEngineTest, ElemhideWhitelisting)
694 { 694 {
695 filterEngine->GetFilter("@@||example.org^$elemhide")->AddToList(); 695 filterEngine->GetFilter("@@||example.org^$elemhide").AddToList();
696 filterEngine->GetFilter("@@||example.com^$elemhide,domain=example.de")->AddToL ist(); 696 filterEngine->GetFilter("@@||example.com^$elemhide,domain=example.de").AddToLi st();
697 697
698 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted( 698 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted(
699 "http://example.org", 699 "http://example.org",
700 std::vector<std::string>())); 700 std::vector<std::string>()));
701 701
702 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted( 702 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted(
703 "http://example.co.uk", 703 "http://example.co.uk",
704 std::vector<std::string>())); 704 std::vector<std::string>()));
705 705
706 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted( 706 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted(
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 filterEngine->SetAllowedConnectionType(&testConnection); 1088 filterEngine->SetAllowedConnectionType(&testConnection);
1089 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); 1089 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB");
1090 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring()); 1090 EXPECT_EQ("synchronize_ok", subscription->GetProperty("downloadStatus").AsSt ring());
1091 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size()); 1091 EXPECT_EQ(1u, subscription->GetProperty("filters").AsList().size());
1092 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); 1092 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings();
1093 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1093 ASSERT_EQ(1u, capturedConnectionTypes.size());
1094 EXPECT_TRUE(capturedConnectionTypes[0].first); 1094 EXPECT_TRUE(capturedConnectionTypes[0].first);
1095 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); 1095 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second);
1096 } 1096 }
1097 } 1097 }
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