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-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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 appInfo.name = "test"; | 87 appInfo.name = "test"; |
88 appInfo.version = "1.0.1"; | 88 appInfo.version = "1.0.1"; |
89 AdblockPlus::JsEnginePtr jsEngine = CreateJsEngine(appInfo); | 89 AdblockPlus::JsEnginePtr jsEngine = CreateJsEngine(appInfo); |
90 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); | 90 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); |
91 mockWebRequest = new MockWebRequest; | 91 mockWebRequest = new MockWebRequest; |
92 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(mockWebRequest)); | 92 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(mockWebRequest)); |
93 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); | 93 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); |
94 } | 94 } |
95 }; | 95 }; |
96 | 96 |
97 struct MockUpdateAvailableCallback | |
98 { | |
99 MockUpdateAvailableCallback(int& timesCalled) : timesCalled(timesCalled) {} | |
100 | |
101 void operator()(const std::string&) | |
102 { | |
103 timesCalled++; | |
104 } | |
105 | |
106 private: | |
107 // We currently cannot store timesCalled in the functor, see: | |
108 // https://issues.adblockplus.org/ticket/1378. | |
109 int& timesCalled; | |
110 }; | |
111 | |
112 // Workaround for https://issues.adblockplus.org/ticket/1397. | |
113 void NoOpUpdaterCallback(const std::string&) {} | |
114 | |
115 class FilterEngineWithFreshFolder : public ::testing::Test | 97 class FilterEngineWithFreshFolder : public ::testing::Test |
116 { | 98 { |
117 protected: | 99 protected: |
118 FileSystemPtr fileSystem; | 100 FileSystemPtr fileSystem; |
119 std::weak_ptr<JsEngine> weakJsEngine; | 101 std::weak_ptr<JsEngine> weakJsEngine; |
120 | 102 |
121 void SetUp() override | 103 void SetUp() override |
122 { | 104 { |
123 fileSystem.reset(new DefaultFileSystem()); | 105 fileSystem.reset(new DefaultFileSystem()); |
124 // Since there is neither in memory FS nor functionality to work with | 106 // Since there is neither in memory FS nor functionality to work with |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 mockWebRequest->response.responseStatus = 200; | 491 mockWebRequest->response.responseStatus = 200; |
510 mockWebRequest->response.responseText = "\ | 492 mockWebRequest->response.responseText = "\ |
511 {\ | 493 {\ |
512 \"test\": {\ | 494 \"test\": {\ |
513 \"version\": \"1.0.2\",\ | 495 \"version\": \"1.0.2\",\ |
514 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\ | 496 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\ |
515 }\ | 497 }\ |
516 }"; | 498 }"; |
517 | 499 |
518 int timesCalled = 0; | 500 int timesCalled = 0; |
519 MockUpdateAvailableCallback mockUpdateAvailableCallback(timesCalled); | 501 filterEngine->SetUpdateAvailableCallback([×Called](const std::string&)->v
oid |
520 | 502 { |
521 filterEngine->SetUpdateAvailableCallback(mockUpdateAvailableCallback); | 503 ++timesCalled; |
522 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback); | 504 }); |
| 505 filterEngine->ForceUpdateCheck(); |
523 AdblockPlus::Sleep(100); | 506 AdblockPlus::Sleep(100); |
524 ASSERT_EQ(1, timesCalled); | 507 EXPECT_EQ(1, timesCalled); |
525 | 508 |
526 filterEngine->RemoveUpdateAvailableCallback(); | 509 filterEngine->RemoveUpdateAvailableCallback(); |
527 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback); | 510 filterEngine->ForceUpdateCheck(); |
528 AdblockPlus::Sleep(100); | 511 AdblockPlus::Sleep(100); |
529 ASSERT_EQ(1, timesCalled); | 512 EXPECT_EQ(1, timesCalled); |
| 513 } |
| 514 |
| 515 TEST_F(UpdaterTest, ForceUpdateCheck) |
| 516 { |
| 517 mockWebRequest->response.status = 0; |
| 518 mockWebRequest->response.responseStatus = 200; |
| 519 mockWebRequest->response.responseText = "\ |
| 520 {\ |
| 521 \"test\": {\ |
| 522 \"version\": \"1.0.2\",\ |
| 523 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\ |
| 524 }\ |
| 525 }"; |
| 526 |
| 527 int called = 0; // 0 - not called; 1 - once, no error; 2 - error |
| 528 filterEngine->ForceUpdateCheck([&called](const std::string& error)->void |
| 529 { |
| 530 called = error.empty() ? 1 : 2; |
| 531 }); |
| 532 AdblockPlus::Sleep(100); |
| 533 EXPECT_EQ(1, called); |
530 } | 534 } |
531 | 535 |
532 TEST_F(FilterEngineTest, DocumentWhitelisting) | 536 TEST_F(FilterEngineTest, DocumentWhitelisting) |
533 { | 537 { |
534 filterEngine->GetFilter("@@||example.org^$document")->AddToList(); | 538 filterEngine->GetFilter("@@||example.org^$document")->AddToList(); |
535 filterEngine->GetFilter("@@||example.com^$document,domain=example.de")->AddToL
ist(); | 539 filterEngine->GetFilter("@@||example.com^$document,domain=example.de")->AddToL
ist(); |
536 | 540 |
537 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted( | 541 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted( |
538 "http://example.org", | 542 "http://example.org", |
539 std::vector<std::string>())); | 543 std::vector<std::string>())); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 break; | 870 break; |
867 } | 871 } |
868 } | 872 } |
869 ASSERT_TRUE(aaSubscription); | 873 ASSERT_TRUE(aaSubscription); |
870 aaSubscription->RemoveFromList(); | 874 aaSubscription->RemoveFromList(); |
871 } | 875 } |
872 | 876 |
873 testSubscriptionState(parameter.expectedAAStatus, otherSubscriptionsNumber); | 877 testSubscriptionState(parameter.expectedAAStatus, otherSubscriptionsNumber); |
874 } | 878 } |
875 } | 879 } |
OLD | NEW |