OLD | NEW |
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem)); | 55 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem)); |
56 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); | 56 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); |
57 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem)); | 57 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem)); |
58 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); | 58 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); |
59 } | 59 } |
60 }; | 60 }; |
61 | 61 |
62 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem>
FilterEngineTest; | 62 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem>
FilterEngineTest; |
63 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin
eTestNoData; | 63 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin
eTestNoData; |
64 | 64 |
65 struct MockFilterChangeCallback | |
66 { | |
67 MockFilterChangeCallback(int& timesCalled) : timesCalled(timesCalled) {} | |
68 | |
69 void operator()(const std::string&, const AdblockPlus::JsValue&) | |
70 { | |
71 timesCalled++; | |
72 } | |
73 | |
74 private: | |
75 int& timesCalled; | |
76 }; | |
77 | |
78 class UpdaterTest : public ::testing::Test | 65 class UpdaterTest : public ::testing::Test |
79 { | 66 { |
80 protected: | 67 protected: |
81 class MockWebRequest : public AdblockPlus::WebRequest | 68 class MockWebRequest : public AdblockPlus::WebRequest |
82 { | 69 { |
83 public: | 70 public: |
84 AdblockPlus::ServerResponse response; | 71 AdblockPlus::ServerResponse response; |
85 | 72 |
86 AdblockPlus::ServerResponse GET(const std::string& url, | 73 AdblockPlus::ServerResponse GET(const std::string& url, |
87 const AdblockPlus::HeaderList& requestHeaders) const | 74 const AdblockPlus::HeaderList& requestHeaders) const |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 exampleSubscriptionResponse.responseStatus = 200; | 214 exampleSubscriptionResponse.responseStatus = 200; |
228 exampleSubscriptionResponse.status = WebRequest::NS_OK; | 215 exampleSubscriptionResponse.status = WebRequest::NS_OK; |
229 exampleSubscriptionResponse.responseText = "[Adblock Plus 2.0]\n||example.
com"; | 216 exampleSubscriptionResponse.responseText = "[Adblock Plus 2.0]\n||example.
com"; |
230 webRequest->responses.emplace(subscriptionUrlPrefix, exampleSubscriptionRe
sponse); | 217 webRequest->responses.emplace(subscriptionUrlPrefix, exampleSubscriptionRe
sponse); |
231 createParams.preconfiguredPrefs.emplace("first_run_subscription_auto_selec
t", jsEngine->NewValue(false)); | 218 createParams.preconfiguredPrefs.emplace("first_run_subscription_auto_selec
t", jsEngine->NewValue(false)); |
232 isConnectionAllowed = true; | 219 isConnectionAllowed = true; |
233 createParams.isConnectionAllowedCallback = [this](const std::string* allow
edConnectionType)->bool{ | 220 createParams.isConnectionAllowedCallback = [this](const std::string* allow
edConnectionType)->bool{ |
234 capturedConnectionTypes.Add(allowedConnectionType); | 221 capturedConnectionTypes.Add(allowedConnectionType); |
235 return isConnectionAllowed; | 222 return isConnectionAllowed; |
236 }; | 223 }; |
237 jsEngine->SetEventCallback("filterChange", [this](const JsValueList& param
s/*action, item*/) | 224 jsEngine->SetEventCallback("filterChange", [this](JsValueList&& params/*ac
tion, item*/) |
238 { | 225 { |
239 ASSERT_EQ(2u, params.size()); | 226 ASSERT_EQ(2u, params.size()); |
240 if (params[0].AsString() == "subscription.downloadStatus") | 227 if (params[0].AsString() == "subscription.downloadStatus") |
241 { | 228 { |
242 { | 229 { |
243 std::lock_guard<std::mutex> lock(downloadStatusChanged.mutex); | 230 std::lock_guard<std::mutex> lock(downloadStatusChanged.mutex); |
244 downloadStatusChanged.url = params[1].GetProperty("url").AsString(); | 231 downloadStatusChanged.url = params[1].GetProperty("url").AsString(); |
245 } | 232 } |
246 downloadStatusChanged.cv.notify_one(); | 233 downloadStatusChanged.cv.notify_one(); |
247 } | 234 } |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 } | 582 } |
596 | 583 |
597 TEST_F(FilterEngineTestNoData, FirstRunFlag) | 584 TEST_F(FilterEngineTestNoData, FirstRunFlag) |
598 { | 585 { |
599 ASSERT_TRUE(filterEngine->IsFirstRun()); | 586 ASSERT_TRUE(filterEngine->IsFirstRun()); |
600 } | 587 } |
601 | 588 |
602 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback) | 589 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback) |
603 { | 590 { |
604 int timesCalled = 0; | 591 int timesCalled = 0; |
605 MockFilterChangeCallback mockFilterChangeCallback(timesCalled); | |
606 std::this_thread::sleep_for(std::chrono::milliseconds(200)); | 592 std::this_thread::sleep_for(std::chrono::milliseconds(200)); |
607 filterEngine->SetFilterChangeCallback(mockFilterChangeCallback); | 593 filterEngine->SetFilterChangeCallback([×Called](const std::string&, Adblo
ckPlus::JsValue&&) |
| 594 { |
| 595 timesCalled++; |
| 596 }); |
608 filterEngine->GetFilter("foo").AddToList(); | 597 filterEngine->GetFilter("foo").AddToList(); |
609 EXPECT_EQ(1, timesCalled); | 598 EXPECT_EQ(1, timesCalled); |
610 | 599 |
611 filterEngine->RemoveFilterChangeCallback(); | 600 filterEngine->RemoveFilterChangeCallback(); |
612 filterEngine->GetFilter("foo").RemoveFromList(); | 601 filterEngine->GetFilter("foo").RemoveFromList(); |
613 EXPECT_EQ(1, timesCalled); | 602 EXPECT_EQ(1, timesCalled); |
614 } | 603 } |
615 | 604 |
616 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback) | 605 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback) |
617 { | 606 { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 filterEngine->SetAllowedConnectionType(&testConnection); | 1077 filterEngine->SetAllowedConnectionType(&testConnection); |
1089 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); | 1078 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); |
1090 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
ing()); | 1079 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
ing()); |
1091 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 1080 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); |
1092 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); | 1081 auto capturedConnectionTypes = this->capturedConnectionTypes.GetStrings(); |
1093 ASSERT_EQ(1u, capturedConnectionTypes.size()); | 1082 ASSERT_EQ(1u, capturedConnectionTypes.size()); |
1094 EXPECT_TRUE(capturedConnectionTypes[0].first); | 1083 EXPECT_TRUE(capturedConnectionTypes[0].first); |
1095 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); | 1084 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); |
1096 } | 1085 } |
1097 } | 1086 } |
OLD | NEW |