Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/Prefs.cpp

Issue 29508569: Issue 5450 - don't expose std::shared_ptr<JsEngine> (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Aug. 7, 2017, 8:39 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/Notification.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 result.exists = result.isFile = !prefsContents.empty(); 67 result.exists = result.isFile = !prefsContents.empty();
68 callback(result, ""); 68 callback(result, "");
69 return; 69 return;
70 } 70 }
71 71
72 LazyFileSystem::Stat(path, callback); 72 LazyFileSystem::Stat(path, callback);
73 }); 73 });
74 } 74 }
75 }; 75 };
76 76
77 class PrefsTest : public ::testing::Test 77 class PrefsTest : public BaseJsTest
78 { 78 {
79 protected: 79 protected:
80 std::unique_ptr<Platform> platform;
81 std::shared_ptr<TestFileSystem> fileSystem; 80 std::shared_ptr<TestFileSystem> fileSystem;
82 81
83 void SetUp() 82 void SetUp()
84 { 83 {
85 fileSystem = std::make_shared<TestFileSystem>(); 84 fileSystem = std::make_shared<TestFileSystem>();
86 ResetPlatform(); 85 ResetPlatform();
87 } 86 }
88 87
89 void ResetPlatform() 88 void ResetPlatform()
90 { 89 {
(...skipping 16 matching lines...) Expand all
107 } 106 }
108 107
109 TEST_F(PrefsTest, PrefsGetSet) 108 TEST_F(PrefsTest, PrefsGetSet)
110 { 109 {
111 auto filterEngine = CreateFilterEngine(); 110 auto filterEngine = CreateFilterEngine();
112 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile").AsString()); 111 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile").AsString());
113 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt()); 112 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt());
114 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate").AsBool()); 113 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
115 ASSERT_TRUE(filterEngine->GetPref("foobar").IsUndefined()); 114 ASSERT_TRUE(filterEngine->GetPref("foobar").IsUndefined());
116 115
117 ASSERT_ANY_THROW(filterEngine->SetPref("patternsfile", platform->GetJsEngine() ->NewValue(0))); 116 ASSERT_ANY_THROW(filterEngine->SetPref("patternsfile", GetJsEngine().NewValue( 0)));
118 ASSERT_ANY_THROW(filterEngine->SetPref("patternsbackupinterval", platform->Get JsEngine()->NewValue(true))); 117 ASSERT_ANY_THROW(filterEngine->SetPref("patternsbackupinterval", GetJsEngine() .NewValue(true)));
119 ASSERT_ANY_THROW(filterEngine->SetPref("subscriptions_autoupdate", platform->G etJsEngine()->NewValue("foo"))); 118 ASSERT_ANY_THROW(filterEngine->SetPref("subscriptions_autoupdate", GetJsEngine ().NewValue("foo")));
120 119
121 filterEngine->SetPref("patternsfile", platform->GetJsEngine()->NewValue("filte rs.ini")); 120 filterEngine->SetPref("patternsfile", GetJsEngine().NewValue("filters.ini"));
122 filterEngine->SetPref("patternsbackupinterval", platform->GetJsEngine()->NewVa lue(48)); 121 filterEngine->SetPref("patternsbackupinterval", GetJsEngine().NewValue(48));
123 filterEngine->SetPref("subscriptions_autoupdate", platform->GetJsEngine()->New Value(false)); 122 filterEngine->SetPref("subscriptions_autoupdate", GetJsEngine().NewValue(false ));
124 123
125 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile").AsString()); 124 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile").AsString());
126 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval").AsInt()); 125 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval").AsInt());
127 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate").AsBool()); 126 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
128 } 127 }
129 128
130 TEST_F(PrefsTest, PrefsPersist) 129 TEST_F(PrefsTest, PrefsPersist)
131 { 130 {
132 { 131 {
133 auto filterEngine = CreateFilterEngine(); 132 auto filterEngine = CreateFilterEngine();
134 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile").AsString()); 133 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile").AsString());
135 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt()); 134 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt());
136 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate").AsBool()); 135 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
137 136
138 filterEngine->SetPref("patternsfile", platform->GetJsEngine()->NewValue("fil ters.ini")); 137 filterEngine->SetPref("patternsfile", GetJsEngine().NewValue("filters.ini")) ;
139 filterEngine->SetPref("patternsbackupinterval", platform->GetJsEngine()->New Value(48)); 138 filterEngine->SetPref("patternsbackupinterval", GetJsEngine().NewValue(48));
140 filterEngine->SetPref("subscriptions_autoupdate", platform->GetJsEngine()->N ewValue(false)); 139 filterEngine->SetPref("subscriptions_autoupdate", GetJsEngine().NewValue(fal se));
141 } 140 }
142 ASSERT_FALSE(fileSystem->prefsContents.empty()); 141 ASSERT_FALSE(fileSystem->prefsContents.empty());
143 142
144 { 143 {
145 ResetPlatform(); 144 ResetPlatform();
146 auto filterEngine = CreateFilterEngine(); 145 auto filterEngine = CreateFilterEngine();
147 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile").AsString()); 146 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile").AsString());
148 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval").AsInt()); 147 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval").AsInt());
149 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate").AsBool()); 148 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
150 } 149 }
(...skipping 15 matching lines...) Expand all
166 std::string content = "{\"patternsbackupinterval\": 6, \"foo\"}"; 165 std::string content = "{\"patternsbackupinterval\": 6, \"foo\"}";
167 fileSystem->prefsContents = IOBuffer(content.cbegin(), content.cend()); 166 fileSystem->prefsContents = IOBuffer(content.cbegin(), content.cend());
168 auto filterEngine = CreateFilterEngine(); 167 auto filterEngine = CreateFilterEngine();
169 168
170 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt()); 169 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt());
171 } 170 }
172 171
173 TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured) 172 TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured)
174 { 173 {
175 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 174 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
176 preconfiguredPrefs.emplace("disable_auto_updates", platform->GetJsEngine()->Ne wValue(false)); 175 preconfiguredPrefs.emplace("disable_auto_updates", GetJsEngine().NewValue(fals e));
177 preconfiguredPrefs.emplace("suppress_first_run_page", platform->GetJsEngine()- >NewValue(true)); 176 preconfiguredPrefs.emplace("suppress_first_run_page", GetJsEngine().NewValue(t rue));
178 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 177 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
179 178
180 ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates").IsBool()); 179 ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates").IsBool());
181 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates").AsBool()); 180 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates").AsBool());
182 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool()); 181 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
183 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").AsBool()); 182 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").AsBool());
184 } 183 }
185 184
186 TEST_F(PrefsTest, PreconfiguredPrefsUnsupported) 185 TEST_F(PrefsTest, PreconfiguredPrefsUnsupported)
187 { 186 {
188 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 187 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
189 preconfiguredPrefs.emplace("unsupported_preconfig", platform->GetJsEngine()->N ewValue(true)); 188 preconfiguredPrefs.emplace("unsupported_preconfig", GetJsEngine().NewValue(tru e));
190 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 189 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
191 190
192 ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig").IsUndefined()); 191 ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig").IsUndefined());
193 } 192 }
194 193
195 TEST_F(PrefsTest, PreconfiguredPrefsOverride) 194 TEST_F(PrefsTest, PreconfiguredPrefsOverride)
196 { 195 {
197 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 196 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
198 preconfiguredPrefs.emplace("suppress_first_run_page", platform->GetJsEngine()- >NewValue(true)); 197 preconfiguredPrefs.emplace("suppress_first_run_page", GetJsEngine().NewValue(t rue));
199 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 198 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
200 199
201 filterEngine->SetPref("suppress_first_run_page", platform->GetJsEngine()->NewV alue(false)); 200 filterEngine->SetPref("suppress_first_run_page", GetJsEngine().NewValue(false) );
202 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool()); 201 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
203 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page").AsBool()); 202 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page").AsBool());
204 } 203 }
205 204
206 TEST_F(PrefsTest, PrefsPersistWhenPreconfigured) 205 TEST_F(PrefsTest, PrefsPersistWhenPreconfigured)
207 { 206 {
208 { 207 {
209 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 208 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
210 preconfiguredPrefs.emplace("suppress_first_run_page", platform->GetJsEngine( )->NewValue(true)); 209 preconfiguredPrefs.emplace("suppress_first_run_page", GetJsEngine().NewValue (true));
211 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 210 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
212 211
213 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool()); 212 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
214 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").AsBool()); 213 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").AsBool());
215 filterEngine->SetPref("suppress_first_run_page", platform->GetJsEngine()->Ne wValue(false)); 214 filterEngine->SetPref("suppress_first_run_page", GetJsEngine().NewValue(fals e));
216 } 215 }
217 ASSERT_FALSE(fileSystem->prefsContents.empty()); 216 ASSERT_FALSE(fileSystem->prefsContents.empty());
218 217
219 { 218 {
220 ResetPlatform(); 219 ResetPlatform();
221 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 220 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
222 preconfiguredPrefs.emplace("suppress_first_run_page", platform->GetJsEngine( )->NewValue(true)); 221 preconfiguredPrefs.emplace("suppress_first_run_page", GetJsEngine().NewValue (true));
223 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 222 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
224 223
225 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool()); 224 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
226 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page").AsBool()); 225 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page").AsBool());
227 } 226 }
228 } 227 }
OLDNEW
« no previous file with comments | « test/Notification.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld