| 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 11 matching lines...) Expand all  Loading... | 
| 22 | 22 | 
| 23 using namespace AdblockPlus; | 23 using namespace AdblockPlus; | 
| 24 | 24 | 
| 25 namespace | 25 namespace | 
| 26 { | 26 { | 
| 27   class TestFileSystem : public LazyFileSystem | 27   class TestFileSystem : public LazyFileSystem | 
| 28   { | 28   { | 
| 29   public: | 29   public: | 
| 30     IOBuffer prefsContents; | 30     IOBuffer prefsContents; | 
| 31 | 31 | 
| 32     void Read(const std::string& path, const ReadCallback& callback) const overr
     ide | 32     void Read(const std::string& fileName, const ReadCallback& callback) const o
     verride | 
| 33     { | 33     { | 
| 34       scheduler([this, path, callback] | 34       scheduler([this, fileName, callback] | 
| 35       { | 35       { | 
| 36         if (path == "prefs.json" && !prefsContents.empty()) | 36         if (fileName == "prefs.json" && !prefsContents.empty()) | 
| 37         { | 37         { | 
| 38           callback(IOBuffer(prefsContents.cbegin(), prefsContents.cend()), ""); | 38           callback(IOBuffer(prefsContents.cbegin(), prefsContents.cend()), ""); | 
| 39           return; | 39           return; | 
| 40         } | 40         } | 
| 41 | 41 | 
| 42         LazyFileSystem::Read(path, callback); | 42         LazyFileSystem::Read(fileName, callback); | 
| 43       }); | 43       }); | 
| 44     } | 44     } | 
| 45 | 45 | 
| 46     void Write(const std::string& path, const IOBuffer& content, const Callback&
      callback) override | 46     void Write(const std::string& fileName, const IOBuffer& content, const Callb
     ack& callback) override | 
| 47     { | 47     { | 
| 48       scheduler([this, path, content, callback] | 48       scheduler([this, fileName, content, callback] | 
| 49       { | 49       { | 
| 50         if (path == "prefs.json") | 50         if (fileName == "prefs.json") | 
| 51         { | 51         { | 
| 52           prefsContents = content; | 52           prefsContents = content; | 
| 53           callback(""); | 53           callback(""); | 
| 54         } | 54         } | 
| 55       }); | 55       }); | 
| 56     } | 56     } | 
| 57 | 57 | 
| 58     void Stat(const std::string& path, const StatCallback& callback) const overr
     ide | 58     void Stat(const std::string& fileName, const StatCallback& callback) const o
     verride | 
| 59     { | 59     { | 
| 60       scheduler([this, path, callback] | 60       scheduler([this, fileName, callback] | 
| 61       { | 61       { | 
| 62         if (path == "prefs.json") | 62         if (fileName == "prefs.json") | 
| 63         { | 63         { | 
| 64           StatResult result; | 64           StatResult result; | 
| 65           result.exists = result.isFile = !prefsContents.empty(); | 65           result.exists = !prefsContents.empty(); | 
| 66           callback(result, ""); | 66           callback(result, ""); | 
| 67           return; | 67           return; | 
| 68         } | 68         } | 
| 69 | 69 | 
| 70         LazyFileSystem::Stat(path, callback); | 70         LazyFileSystem::Stat(fileName, callback); | 
| 71       }); | 71       }); | 
| 72     } | 72     } | 
| 73   }; | 73   }; | 
| 74 | 74 | 
| 75   class PrefsTest : public BaseJsTest | 75   class PrefsTest : public BaseJsTest | 
| 76   { | 76   { | 
| 77   protected: | 77   protected: | 
| 78     std::shared_ptr<TestFileSystem> fileSystem; | 78     std::shared_ptr<TestFileSystem> fileSystem; | 
| 79 | 79 | 
| 80     void SetUp() | 80     void SetUp() | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 99       AdblockPlus::FilterEngine::CreationParameters createParams; | 99       AdblockPlus::FilterEngine::CreationParameters createParams; | 
| 100       createParams.preconfiguredPrefs = preconfiguredPrefs; | 100       createParams.preconfiguredPrefs = preconfiguredPrefs; | 
| 101       return ::CreateFilterEngine(*fileSystem, *platform, createParams); | 101       return ::CreateFilterEngine(*fileSystem, *platform, createParams); | 
| 102     } | 102     } | 
| 103   }; | 103   }; | 
| 104 } | 104 } | 
| 105 | 105 | 
| 106 TEST_F(PrefsTest, PrefsGetSet) | 106 TEST_F(PrefsTest, PrefsGetSet) | 
| 107 { | 107 { | 
| 108   auto& filterEngine = CreateFilterEngine(); | 108   auto& filterEngine = CreateFilterEngine(); | 
| 109   ASSERT_EQ("patterns.ini", filterEngine.GetPref("patternsfile").AsString()); |  | 
| 110   ASSERT_EQ(24, filterEngine.GetPref("patternsbackupinterval").AsInt()); | 109   ASSERT_EQ(24, filterEngine.GetPref("patternsbackupinterval").AsInt()); | 
| 111   ASSERT_TRUE(filterEngine.GetPref("subscriptions_autoupdate").AsBool()); | 110   ASSERT_TRUE(filterEngine.GetPref("subscriptions_autoupdate").AsBool()); | 
| 112   ASSERT_TRUE(filterEngine.GetPref("foobar").IsUndefined()); | 111   ASSERT_TRUE(filterEngine.GetPref("foobar").IsUndefined()); | 
| 113 | 112 | 
| 114   ASSERT_ANY_THROW(filterEngine.SetPref("patternsfile", GetJsEngine().NewValue(0
     ))); |  | 
| 115   ASSERT_ANY_THROW(filterEngine.SetPref("patternsbackupinterval", GetJsEngine().
     NewValue(true))); | 113   ASSERT_ANY_THROW(filterEngine.SetPref("patternsbackupinterval", GetJsEngine().
     NewValue(true))); | 
| 116   ASSERT_ANY_THROW(filterEngine.SetPref("subscriptions_autoupdate", GetJsEngine(
     ).NewValue("foo"))); | 114   ASSERT_ANY_THROW(filterEngine.SetPref("subscriptions_autoupdate", GetJsEngine(
     ).NewValue("foo"))); | 
| 117 | 115 | 
| 118   filterEngine.SetPref("patternsfile", GetJsEngine().NewValue("filters.ini")); |  | 
| 119   filterEngine.SetPref("patternsbackupinterval", GetJsEngine().NewValue(48)); | 116   filterEngine.SetPref("patternsbackupinterval", GetJsEngine().NewValue(48)); | 
| 120   filterEngine.SetPref("subscriptions_autoupdate", GetJsEngine().NewValue(false)
     ); | 117   filterEngine.SetPref("subscriptions_autoupdate", GetJsEngine().NewValue(false)
     ); | 
| 121 | 118 | 
| 122   ASSERT_EQ("filters.ini", filterEngine.GetPref("patternsfile").AsString()); |  | 
| 123   ASSERT_EQ(48, filterEngine.GetPref("patternsbackupinterval").AsInt()); | 119   ASSERT_EQ(48, filterEngine.GetPref("patternsbackupinterval").AsInt()); | 
| 124   ASSERT_FALSE(filterEngine.GetPref("subscriptions_autoupdate").AsBool()); | 120   ASSERT_FALSE(filterEngine.GetPref("subscriptions_autoupdate").AsBool()); | 
| 125 } | 121 } | 
| 126 | 122 | 
| 127 TEST_F(PrefsTest, PrefsPersist) | 123 TEST_F(PrefsTest, PrefsPersist) | 
| 128 { | 124 { | 
| 129   { | 125   { | 
| 130     auto& filterEngine = CreateFilterEngine(); | 126     auto& filterEngine = CreateFilterEngine(); | 
| 131     ASSERT_EQ("patterns.ini", filterEngine.GetPref("patternsfile").AsString()); |  | 
| 132     ASSERT_EQ(24, filterEngine.GetPref("patternsbackupinterval").AsInt()); | 127     ASSERT_EQ(24, filterEngine.GetPref("patternsbackupinterval").AsInt()); | 
| 133     ASSERT_TRUE(filterEngine.GetPref("subscriptions_autoupdate").AsBool()); | 128     ASSERT_TRUE(filterEngine.GetPref("subscriptions_autoupdate").AsBool()); | 
| 134 | 129 | 
| 135     filterEngine.SetPref("patternsfile", GetJsEngine().NewValue("filters.ini")); |  | 
| 136     filterEngine.SetPref("patternsbackupinterval", GetJsEngine().NewValue(48)); | 130     filterEngine.SetPref("patternsbackupinterval", GetJsEngine().NewValue(48)); | 
| 137     filterEngine.SetPref("subscriptions_autoupdate", GetJsEngine().NewValue(fals
     e)); | 131     filterEngine.SetPref("subscriptions_autoupdate", GetJsEngine().NewValue(fals
     e)); | 
| 138   } | 132   } | 
| 139   ASSERT_FALSE(fileSystem->prefsContents.empty()); | 133   ASSERT_FALSE(fileSystem->prefsContents.empty()); | 
| 140 | 134 | 
| 141   { | 135   { | 
| 142     ResetPlatform(); | 136     ResetPlatform(); | 
| 143     auto& filterEngine = CreateFilterEngine(); | 137     auto& filterEngine = CreateFilterEngine(); | 
| 144     ASSERT_EQ("filters.ini", filterEngine.GetPref("patternsfile").AsString()); |  | 
| 145     ASSERT_EQ(48, filterEngine.GetPref("patternsbackupinterval").AsInt()); | 138     ASSERT_EQ(48, filterEngine.GetPref("patternsbackupinterval").AsInt()); | 
| 146     ASSERT_FALSE(filterEngine.GetPref("subscriptions_autoupdate").AsBool()); | 139     ASSERT_FALSE(filterEngine.GetPref("subscriptions_autoupdate").AsBool()); | 
| 147   } | 140   } | 
| 148 } | 141 } | 
| 149 | 142 | 
| 150 TEST_F(PrefsTest, UnknownPrefs) | 143 TEST_F(PrefsTest, UnknownPrefs) | 
| 151 { | 144 { | 
| 152   using IOBuffer = AdblockPlus::IFileSystem::IOBuffer; | 145   using IOBuffer = AdblockPlus::IFileSystem::IOBuffer; | 
| 153   std::string content = "{\"foobar\":2, \"patternsbackupinterval\": 12}"; | 146   std::string content = "{\"foobar\":2, \"patternsbackupinterval\": 12}"; | 
| 154   fileSystem->prefsContents = IOBuffer(content.cbegin(), content.cend()); | 147   fileSystem->prefsContents = IOBuffer(content.cbegin(), content.cend()); | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 214   { | 207   { | 
| 215     ResetPlatform(); | 208     ResetPlatform(); | 
| 216     AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; | 209     AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; | 
| 217     preconfiguredPrefs.emplace("suppress_first_run_page", GetJsEngine().NewValue
     (true)); | 210     preconfiguredPrefs.emplace("suppress_first_run_page", GetJsEngine().NewValue
     (true)); | 
| 218     auto& filterEngine = CreateFilterEngine(preconfiguredPrefs); | 211     auto& filterEngine = CreateFilterEngine(preconfiguredPrefs); | 
| 219 | 212 | 
| 220     ASSERT_TRUE(filterEngine.GetPref("suppress_first_run_page").IsBool()); | 213     ASSERT_TRUE(filterEngine.GetPref("suppress_first_run_page").IsBool()); | 
| 221     ASSERT_FALSE(filterEngine.GetPref("suppress_first_run_page").AsBool()); | 214     ASSERT_FALSE(filterEngine.GetPref("suppress_first_run_page").AsBool()); | 
| 222   } | 215   } | 
| 223 } | 216 } | 
| OLD | NEW | 
|---|