 Issue 5653480979038208:
  Issue 2325 - Add a way to set settings in libadblockplus for FRP and automatic updates  (Closed)
    
  
    Issue 5653480979038208:
  Issue 2325 - Add a way to set settings in libadblockplus for FRP and automatic updates  (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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 FilterEnginePtr filterEngine; | 71 FilterEnginePtr filterEngine; | 
| 72 | 72 | 
| 73 void SetUp() | 73 void SetUp() | 
| 74 { | 74 { | 
| 75 fileSystem = new TestFileSystem(); | 75 fileSystem = new TestFileSystem(); | 
| 76 fileSystemPtr.reset(fileSystem); | 76 fileSystemPtr.reset(fileSystem); | 
| 77 | 77 | 
| 78 Reset(); | 78 Reset(); | 
| 79 } | 79 } | 
| 80 | 80 | 
| 81 void Reset() | 81 void Reset(std::map<std::string, AdblockPlus::JsValuePtr> preconfiguredPrefs = | 
| 
sergei
2015/06/19 10:07:15
Why not to use `const Prefs&` in this file and in
 
Oleksandr
2015/06/22 07:47:08
Done.
 | |
| 82 std::map<std::string, AdblockPlus::JsValuePtr>()) | |
| 82 { | 83 { | 
| 83 jsEngine = AdblockPlus::JsEngine::New(); | 84 jsEngine = AdblockPlus::JsEngine::New(); | 
| 84 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem)); | 85 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem)); | 
| 85 jsEngine->SetFileSystem(fileSystemPtr); | 86 jsEngine->SetFileSystem(fileSystemPtr); | 
| 86 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); | 87 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); | 
| 87 | 88 | 
| 88 filterEngine.reset(new AdblockPlus::FilterEngine(jsEngine)); | 89 filterEngine.reset( | 
| 90 new AdblockPlus::FilterEngine(jsEngine, preconfiguredPrefs)); | |
| 89 } | 91 } | 
| 90 }; | 92 }; | 
| 91 } | 93 } | 
| 92 | 94 | 
| 93 TEST_F(PrefsTest, PrefsGetSet) | 95 TEST_F(PrefsTest, PrefsGetSet) | 
| 94 { | 96 { | 
| 95 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString()); | 97 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString()); | 
| 96 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); | 98 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); | 
| 97 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); | 99 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); | 
| 98 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined()); | 100 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined()); | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 ASSERT_EQ(12, filterEngine->GetPref("patternsbackupinterval")->AsInt()); | 142 ASSERT_EQ(12, filterEngine->GetPref("patternsbackupinterval")->AsInt()); | 
| 141 } | 143 } | 
| 142 | 144 | 
| 143 TEST_F(PrefsTest, SyntaxFailure) | 145 TEST_F(PrefsTest, SyntaxFailure) | 
| 144 { | 146 { | 
| 145 fileSystem->prefsContents = "{\"patternsbackupinterval\": 6, \"foo\"}"; | 147 fileSystem->prefsContents = "{\"patternsbackupinterval\": 6, \"foo\"}"; | 
| 146 Reset(); | 148 Reset(); | 
| 147 | 149 | 
| 148 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); | 150 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); | 
| 149 } | 151 } | 
| 152 | |
| 153 TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured) | |
| 154 { | |
| 155 std::map<std::string, AdblockPlus::JsValuePtr> preconfiguredPrefs; | |
| 156 preconfiguredPrefs["disable_auto_updates"] = jsEngine->NewValue(false); | |
| 157 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); | |
| 158 Reset(preconfiguredPrefs); | |
| 159 | |
| 160 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates")->AsBool()); | |
| 161 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); | |
| 162 } | |
| 163 | |
| 164 TEST_F(PrefsTest, PreconfiguredPrefsUnsupported) | |
| 165 { | |
| 166 std::map<std::string, AdblockPlus::JsValuePtr> preconfiguredPrefs; | |
| 167 preconfiguredPrefs["unsupported_preconfig"] = jsEngine->NewValue(true); | |
| 168 Reset(preconfiguredPrefs); | |
| 169 | |
| 170 ASSERT_FALSE(filterEngine->GetPref("unsupported_preconfig")->AsBool()); | |
| 171 } | |
| 172 | |
| 173 TEST_F(PrefsTest, PreconfiguredPrefsPreconfiguredOverride) | |
| 
Felix Dahlke
2015/06/12 08:04:20
Micro nit: Seems redundant, "PreconfiguredPrefsOve
 
Oleksandr
2015/06/12 10:47:57
Done.
 | |
| 174 { | |
| 175 std::map<std::string, AdblockPlus::JsValuePtr> preconfiguredPrefs; | |
| 176 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); | |
| 177 Reset(preconfiguredPrefs); | |
| 178 | |
| 179 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false)); | |
| 180 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); | |
| 181 } | |
| OLD | NEW |