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

Side by Side Diff: test/FilterEngine.cpp

Issue 29442622: Noissue - move (UpdaterTest, SetRemoveUpdateAvailableCallback) to UpdateCheck.cpp (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created May 19, 2017, 4:48 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 | « no previous file | test/UpdateCheck.cpp » ('j') | 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 void TearDown() override 62 void TearDown() override
63 { 63 {
64 // Workaround for issue 5198 64 // Workaround for issue 5198
65 std::this_thread::sleep_for(std::chrono::milliseconds(100)); 65 std::this_thread::sleep_for(std::chrono::milliseconds(100));
66 } 66 }
67 }; 67 };
68 68
69 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem> FilterEngineTest; 69 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem> FilterEngineTest;
70 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin eTestNoData; 70 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin eTestNoData;
71 71
72 class UpdaterTest : public ::testing::Test
73 {
74 protected:
75 class MockWebRequest : public AdblockPlus::WebRequest
76 {
77 public:
78 AdblockPlus::ServerResponse response;
79
80 AdblockPlus::ServerResponse GET(const std::string& url,
81 const AdblockPlus::HeaderList& requestHeaders) const
82 {
83 return response;
84 }
85 };
86
87 std::shared_ptr<MockWebRequest> mockWebRequest;
88 FilterEnginePtr filterEngine;
89
90 void SetUp()
91 {
92 JsEngineCreationParameters jsEngineParams;
93 jsEngineParams.appInfo.name = "test";
94 jsEngineParams.appInfo.version = "1.0.1";
95 jsEngineParams.timer = CreateDefaultTimer();
96 jsEngineParams.fileSystem.reset(new LazyFileSystem());
97 AdblockPlus::JsEnginePtr jsEngine = CreateJsEngine(std::move(jsEngineParam s));
98 jsEngine->SetWebRequest(mockWebRequest = std::make_shared<MockWebRequest>( ));
99 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine);
100 }
101 };
102
103 class FilterEngineWithFreshFolder : public ::testing::Test 72 class FilterEngineWithFreshFolder : public ::testing::Test
104 { 73 {
105 protected: 74 protected:
106 FileSystemPtr fileSystem; 75 FileSystemPtr fileSystem;
107 std::weak_ptr<JsEngine> weakJsEngine; 76 std::weak_ptr<JsEngine> weakJsEngine;
108 77
109 void SetUp() override 78 void SetUp() override
110 { 79 {
111 fileSystem.reset(new DefaultFileSystem()); 80 fileSystem.reset(new DefaultFileSystem());
112 // Since there is neither in memory FS nor functionality to work with 81 // Since there is neither in memory FS nor functionality to work with
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 timesCalled++; 583 timesCalled++;
615 }); 584 });
616 filterEngine->GetFilter("foo").AddToList(); 585 filterEngine->GetFilter("foo").AddToList();
617 EXPECT_EQ(1, timesCalled); 586 EXPECT_EQ(1, timesCalled);
618 587
619 filterEngine->RemoveFilterChangeCallback(); 588 filterEngine->RemoveFilterChangeCallback();
620 filterEngine->GetFilter("foo").RemoveFromList(); 589 filterEngine->GetFilter("foo").RemoveFromList();
621 EXPECT_EQ(1, timesCalled); 590 EXPECT_EQ(1, timesCalled);
622 } 591 }
623 592
624 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback)
625 {
626 mockWebRequest->response.status = 0;
627 mockWebRequest->response.responseStatus = 200;
628 mockWebRequest->response.responseText = "\
629 {\
630 \"test\": {\
631 \"version\": \"1.0.2\",\
632 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\
633 }\
634 }";
635
636 int timesCalled = 0;
637 filterEngine->SetUpdateAvailableCallback([&timesCalled](const std::string&)->v oid
638 {
639 ++timesCalled;
640 });
641 filterEngine->ForceUpdateCheck();
642 AdblockPlus::Sleep(100);
643 EXPECT_EQ(1, timesCalled);
644
645 filterEngine->RemoveUpdateAvailableCallback();
646 filterEngine->ForceUpdateCheck();
647 AdblockPlus::Sleep(100);
648 EXPECT_EQ(1, timesCalled);
649 }
650
651 TEST_F(UpdaterTest, ForceUpdateCheck)
652 {
653 mockWebRequest->response.status = 0;
654 mockWebRequest->response.responseStatus = 200;
655 mockWebRequest->response.responseText = "\
656 {\
657 \"test\": {\
658 \"version\": \"1.0.2\",\
659 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\
660 }\
661 }";
662
663 int called = 0; // 0 - not called; 1 - once, no error; 2 - error
664 filterEngine->ForceUpdateCheck([&called](const std::string& error)->void
665 {
666 called = error.empty() ? 1 : 2;
667 });
668 AdblockPlus::Sleep(100);
669 EXPECT_EQ(1, called);
670 }
671
672 TEST_F(FilterEngineTest, DocumentWhitelisting) 593 TEST_F(FilterEngineTest, DocumentWhitelisting)
673 { 594 {
674 filterEngine->GetFilter("@@||example.org^$document").AddToList(); 595 filterEngine->GetFilter("@@||example.org^$document").AddToList();
675 filterEngine->GetFilter("@@||example.com^$document,domain=example.de").AddToLi st(); 596 filterEngine->GetFilter("@@||example.com^$document,domain=example.de").AddToLi st();
676 597
677 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted( 598 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted(
678 "http://example.org", 599 "http://example.org",
679 std::vector<std::string>())); 600 std::vector<std::string>()));
680 601
681 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted( 602 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted(
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 std::string testConnection = "test connection"; 1010 std::string testConnection = "test connection";
1090 filterEngine->SetAllowedConnectionType(&testConnection); 1011 filterEngine->SetAllowedConnectionType(&testConnection);
1091 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); 1012 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB");
1092 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr ing()); 1013 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr ing());
1093 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); 1014 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size());
1094 ASSERT_EQ(1u, capturedConnectionTypes.size()); 1015 ASSERT_EQ(1u, capturedConnectionTypes.size());
1095 EXPECT_TRUE(capturedConnectionTypes[0].first); 1016 EXPECT_TRUE(capturedConnectionTypes[0].first);
1096 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); 1017 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second);
1097 } 1018 }
1098 } 1019 }
OLDNEW
« no previous file with comments | « no previous file | test/UpdateCheck.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld