 Issue 29363607:
  Issue 4612 - enable AA on first run and make automatic adding of any subscription optional  (Closed)
    
  
    Issue 29363607:
  Issue 4612 - enable AA on first run and make automatic adding of any subscription optional  (Closed) 
  | Left: | ||
| Right: | 
| 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 | 
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. | 
| 13 * | 13 * | 
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License | 
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 
| 16 */ | 16 */ | 
| 17 | 17 | 
| 18 #include "BaseJsTest.h" | 18 #include "BaseJsTest.h" | 
| 19 #include <thread> | |
| 19 | 20 | 
| 21 using namespace AdblockPlus; | |
| 
Felix Dahlke
2016/11/22 17:37:16
Nit: Empty line after this to be in line with the
 
sergei
2016/11/23 14:20:50
Done.
 | |
| 20 namespace | 22 namespace | 
| 21 { | 23 { | 
| 22 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; | 24 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; | 
| 23 | 25 | 
| 24 class VeryLazyFileSystem : public LazyFileSystem | 26 class VeryLazyFileSystem : public LazyFileSystem | 
| 25 { | 27 { | 
| 26 public: | 28 public: | 
| 27 StatResult Stat(const std::string& path) const | 29 StatResult Stat(const std::string& path) const | 
| 28 { | 30 { | 
| 29 return StatResult(); | 31 return StatResult(); | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 } | 105 } | 
| 104 | 106 | 
| 105 private: | 107 private: | 
| 106 // We currently cannot store timesCalled in the functor, see: | 108 // We currently cannot store timesCalled in the functor, see: | 
| 107 // https://issues.adblockplus.org/ticket/1378. | 109 // https://issues.adblockplus.org/ticket/1378. | 
| 108 int& timesCalled; | 110 int& timesCalled; | 
| 109 }; | 111 }; | 
| 110 | 112 | 
| 111 // Workaround for https://issues.adblockplus.org/ticket/1397. | 113 // Workaround for https://issues.adblockplus.org/ticket/1397. | 
| 112 void NoOpUpdaterCallback(const std::string&) {} | 114 void NoOpUpdaterCallback(const std::string&) {} | 
| 115 | |
| 116 class FilterEngineWithFreshFolder : public ::testing::Test | |
| 117 { | |
| 118 protected: | |
| 119 FileSystemPtr m_fileSystem; | |
| 
Felix Dahlke
2016/11/22 17:37:17
From https://adblockplus.org/coding-style: "No hun
 
sergei
2016/11/23 14:20:50
I thought we finally started to use #pragma once a
 
Felix Dahlke
2016/12/02 12:26:34
#pragma is not restricted by the code style and we
 | |
| 120 std::weak_ptr<JsEngine> m_jsEngine; | |
| 121 | |
| 122 void SetUp() override | |
| 123 { | |
| 124 m_fileSystem.reset(new DefaultFileSystem()); | |
| 125 // Since there are neither in memory FS nor functionality to work with | |
| 
Felix Dahlke
2016/11/22 17:37:16
Wording nit: "Since there 'is' neither 'in-memory'
 
sergei
2016/11/23 14:20:50
Done.
 | |
| 126 // directories use the hack: manually clean the directory. | |
| 
Felix Dahlke
2016/11/22 17:37:16
Do you mean "functionality to work with _a differe
 
sergei
2016/11/23 14:20:50
No, it's possible to configure working directory o
 
Felix Dahlke
2016/12/02 12:26:34
Acknowledged.
 | |
| 127 removeFileIfExists("patterns.ini"); | |
| 128 removeFileIfExists("prefs.json"); | |
| 129 } | |
| 130 JsEnginePtr createJsEngine(const AppInfo& appInfo = AppInfo()) | |
| 131 { | |
| 132 auto jsEngine = JsEngine::New(appInfo); | |
| 
Felix Dahlke
2016/11/22 17:37:16
I guess my C++ might be getting rusty, but why ass
 
sergei
2016/11/23 14:20:50
JsEngine::New returns std::shared_ptr but the type
 
Felix Dahlke
2016/12/02 12:26:34
Acknowledged.
 | |
| 133 m_jsEngine = jsEngine; | |
| 134 jsEngine->SetFileSystem(m_fileSystem); | |
| 135 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest())); | |
| 136 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem())); | |
| 137 return jsEngine; | |
| 138 } | |
| 139 void TearDown() override | |
| 140 { | |
| 141 removeFileIfExists("patterns.ini"); | |
| 142 removeFileIfExists("prefs.json"); | |
| 143 m_fileSystem.reset(); | |
| 144 } | |
| 145 void removeFileIfExists(const std::string& path) | |
| 146 { | |
| 147 { | |
| 148 // Hack: allow IO to finish currently running operations, in particular | |
| 149 // writing into files. Otherwise we get Permission denied. | |
| 
Felix Dahlke
2016/11/22 17:37:16
Wording nit: Maybe put "Permission denied" in quot
 
sergei
2016/11/23 14:20:50
Done.
 | |
| 150 int i = 100; | |
| 151 while (i-- > 0 && m_jsEngine.lock()) { | |
| 
Felix Dahlke
2016/11/22 17:37:16
Nit: Opening brace on its own line please (might a
 
sergei
2016/11/23 14:20:50
Done.
 | |
| 152 std::this_thread::sleep_for(std::chrono::seconds(2)); | |
| 153 } | |
| 154 } | |
| 155 if (m_fileSystem->Stat(path).exists) | |
| 156 m_fileSystem->Remove(path); | |
| 157 } | |
| 158 }; | |
| 113 } | 159 } | 
| 114 | 160 | 
| 115 TEST_F(FilterEngineTest, FilterCreation) | 161 TEST_F(FilterEngineTest, FilterCreation) | 
| 116 { | 162 { | 
| 117 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); | 163 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); | 
| 118 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); | 164 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); | 
| 119 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); | 165 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); | 
| 120 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); | 166 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); | 
| 121 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); | 167 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); | 
| 122 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); | 168 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); | 
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine; | 585 std::weak_ptr<AdblockPlus::JsEngine> weakJsEngine; | 
| 540 { | 586 { | 
| 541 auto jsEngine = AdblockPlus::JsEngine::New(); | 587 auto jsEngine = AdblockPlus::JsEngine::New(); | 
| 542 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem())); | 588 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem())); | 
| 543 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest())); | 589 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest())); | 
| 544 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem())); | 590 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem())); | 
| 545 auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)) ; | 591 auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)) ; | 
| 546 } | 592 } | 
| 547 EXPECT_FALSE(weakJsEngine.lock()); | 593 EXPECT_FALSE(weakJsEngine.lock()); | 
| 548 } | 594 } | 
| 595 | |
| 596 TEST_F(FilterEngineWithFreshFolder, LangAndAASubscriptionsAreChosenOnFirstRun) | |
| 597 { | |
| 598 AppInfo appInfo; | |
| 599 appInfo.locale = "zh"; | |
| 600 const std::string langSubscriptionUrl = "https://easylist-downloads.adblockplu s.org/easylistchina+easylist.txt"; | |
| 601 auto jsEngine = createJsEngine(appInfo); | |
| 602 auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); | |
| 603 const auto subscriptions = filterEngine->GetListedSubscriptions(); | |
| 604 ASSERT_EQ(2u, subscriptions.size()); | |
| 605 const auto aaUrl = filterEngine->GetPref("subscriptions_exceptionsurl")->AsStr ing(); | |
| 
Felix Dahlke
2016/11/22 17:37:16
Hm, maybe we should hard code the URL as well here
 
sergei
2016/11/23 14:20:50
I will remove aaUrl and use Subscription::IsAA ins
 
Felix Dahlke
2016/12/02 12:26:34
Acknowledged.
 | |
| 606 SubscriptionPtr aaSubscription; | |
| 607 SubscriptionPtr langSubscription; | |
| 608 if (subscriptions[0]->GetProperty("url")->AsString() == aaUrl) | |
| 609 { | |
| 610 aaSubscription = subscriptions[0]; | |
| 611 langSubscription = subscriptions[1]; | |
| 612 } else if (subscriptions[1]->GetProperty("url")->AsString() == aaUrl) | |
| 
Felix Dahlke
2016/11/22 17:37:16
Nit: Closing brace on its own line please.
 
sergei
2016/11/23 14:20:50
Done.
 | |
| 613 { | |
| 614 aaSubscription = subscriptions[1]; | |
| 615 langSubscription = subscriptions[0]; | |
| 616 } | |
| 617 ASSERT_NE(nullptr, aaSubscription); | |
| 618 ASSERT_NE(nullptr, langSubscription); | |
| 619 EXPECT_EQ(aaUrl, aaSubscription->GetProperty("url")->AsString()); | |
| 620 EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url")->AsString( )); | |
| 621 } | |
| 622 | |
| 623 TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun) | |
| 624 { | |
| 625 auto jsEngine = createJsEngine(); | |
| 626 FilterEngine::Prefs preSettings; | |
| 627 preSettings["first_run_subscription_auto_select"] = jsEngine->NewValue(false); | |
| 628 auto filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine, pr eSettings)); | |
| 629 const auto subscriptions = filterEngine->GetListedSubscriptions(); | |
| 630 EXPECT_EQ(0u, subscriptions.size()); | |
| 631 } | |
| OLD | NEW |