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

Side by Side Diff: test/Prefs.cpp

Issue 29417605: Issue 5034 - Part 3: Create plain JsValue instead of JsValuePtr (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: FIxed JsContext bug and a few others. Created April 19, 2017, 9:55 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 AdblockPlus::FilterEngine::CreationParameters createParams; 91 AdblockPlus::FilterEngine::CreationParameters createParams;
92 createParams.preconfiguredPrefs = preconfiguredPrefs; 92 createParams.preconfiguredPrefs = preconfiguredPrefs;
93 return AdblockPlus::FilterEngine::Create(jsEngine, createParams); 93 return AdblockPlus::FilterEngine::Create(jsEngine, createParams);
94 } 94 }
95 }; 95 };
96 } 96 }
97 97
98 TEST_F(PrefsTest, PrefsGetSet) 98 TEST_F(PrefsTest, PrefsGetSet)
99 { 99 {
100 auto filterEngine = CreateFilterEngine(); 100 auto filterEngine = CreateFilterEngine();
101 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString()); 101 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile").AsString());
102 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 102 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt());
103 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 103 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
104 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined()); 104 ASSERT_TRUE(filterEngine->GetPref("foobar").IsUndefined());
105 105
106 ASSERT_ANY_THROW(filterEngine->SetPref("patternsfile", jsEngine->NewValue(0))) ; 106 ASSERT_ANY_THROW(filterEngine->SetPref("patternsfile", jsEngine->NewValue(0))) ;
107 ASSERT_ANY_THROW(filterEngine->SetPref("patternsbackupinterval", jsEngine->New Value(true))); 107 ASSERT_ANY_THROW(filterEngine->SetPref("patternsbackupinterval", jsEngine->New Value(true)));
108 ASSERT_ANY_THROW(filterEngine->SetPref("subscriptions_autoupdate", jsEngine->N ewValue("foo"))); 108 ASSERT_ANY_THROW(filterEngine->SetPref("subscriptions_autoupdate", jsEngine->N ewValue("foo")));
109 109
110 filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini")); 110 filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini"));
111 filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48)); 111 filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48));
112 filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false)); 112 filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false));
113 113
114 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile")->AsString()); 114 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile").AsString());
115 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 115 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval").AsInt());
116 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 116 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
117 } 117 }
118 118
119 TEST_F(PrefsTest, PrefsPersist) 119 TEST_F(PrefsTest, PrefsPersist)
120 { 120 {
121 { 121 {
122 auto filterEngine = CreateFilterEngine(); 122 auto filterEngine = CreateFilterEngine();
123 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString()) ; 123 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile").AsString());
124 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 124 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt());
125 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 125 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
126 126
127 filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini")); 127 filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini"));
128 filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48)); 128 filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48));
129 filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false)) ; 129 filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false)) ;
130 130
131 AdblockPlus::Sleep(100); 131 AdblockPlus::Sleep(100);
132 } 132 }
133 ASSERT_FALSE(fileSystem->prefsContents.empty()); 133 ASSERT_FALSE(fileSystem->prefsContents.empty());
134 134
135 { 135 {
136 ResetJsEngine(); 136 ResetJsEngine();
137 auto filterEngine = CreateFilterEngine(); 137 auto filterEngine = CreateFilterEngine();
138 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile")->AsString()); 138 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile").AsString());
139 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 139 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval").AsInt());
140 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 140 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate").AsBool());
141 } 141 }
142 } 142 }
143 143
144 TEST_F(PrefsTest, UnknownPrefs) 144 TEST_F(PrefsTest, UnknownPrefs)
145 { 145 {
146 fileSystem->prefsContents = "{\"foobar\":2, \"patternsbackupinterval\": 12}"; 146 fileSystem->prefsContents = "{\"foobar\":2, \"patternsbackupinterval\": 12}";
147 auto filterEngine = CreateFilterEngine(); 147 auto filterEngine = CreateFilterEngine();
148 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined()); 148 ASSERT_TRUE(filterEngine->GetPref("foobar").IsUndefined());
149 ASSERT_EQ(12, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 149 ASSERT_EQ(12, filterEngine->GetPref("patternsbackupinterval").AsInt());
150 } 150 }
151 151
152 TEST_F(PrefsTest, SyntaxFailure) 152 TEST_F(PrefsTest, SyntaxFailure)
153 { 153 {
154 fileSystem->prefsContents = "{\"patternsbackupinterval\": 6, \"foo\"}"; 154 fileSystem->prefsContents = "{\"patternsbackupinterval\": 6, \"foo\"}";
155 auto filterEngine = CreateFilterEngine(); 155 auto filterEngine = CreateFilterEngine();
156 156
157 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 157 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval").AsInt());
158 } 158 }
159 159
160 TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured) 160 TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured)
161 { 161 {
162 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 162 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
163 preconfiguredPrefs["disable_auto_updates"] = jsEngine->NewValue(false); 163 preconfiguredPrefs.emplace("disable_auto_updates", jsEngine->NewValue(false));
164 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); 164 preconfiguredPrefs.emplace("suppress_first_run_page", jsEngine->NewValue(true) );
165 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 165 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
166 166
167 ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates")->IsBool()); 167 ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates").IsBool());
168 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates")->AsBool()); 168 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates").AsBool());
169 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 169 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
170 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 170 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").AsBool());
171 } 171 }
172 172
173 TEST_F(PrefsTest, PreconfiguredPrefsUnsupported) 173 TEST_F(PrefsTest, PreconfiguredPrefsUnsupported)
174 { 174 {
175 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 175 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
176 preconfiguredPrefs["unsupported_preconfig"] = jsEngine->NewValue(true); 176 preconfiguredPrefs.emplace("unsupported_preconfig", jsEngine->NewValue(true));
177 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 177 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
178 178
179 ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig")->IsUndefined()); 179 ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig").IsUndefined());
180 } 180 }
181 181
182 TEST_F(PrefsTest, PreconfiguredPrefsOverride) 182 TEST_F(PrefsTest, PreconfiguredPrefsOverride)
183 { 183 {
184 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 184 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
185 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); 185 preconfiguredPrefs.emplace("suppress_first_run_page", jsEngine->NewValue(true) );
186 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 186 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
187 187
188 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false)); 188 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
189 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 189 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
190 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 190 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page").AsBool());
191 } 191 }
192 192
193 TEST_F(PrefsTest, PrefsPersistWhenPreconfigured) 193 TEST_F(PrefsTest, PrefsPersistWhenPreconfigured)
194 { 194 {
195 { 195 {
196 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 196 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
197 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); 197 preconfiguredPrefs.emplace("suppress_first_run_page", jsEngine->NewValue(tru e));
198 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 198 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
199 199
200 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 200 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
201 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 201 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").AsBool());
202 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false)); 202 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
203 203
204 AdblockPlus::Sleep(100); 204 AdblockPlus::Sleep(100);
205 } 205 }
206 ASSERT_FALSE(fileSystem->prefsContents.empty()); 206 ASSERT_FALSE(fileSystem->prefsContents.empty());
207 207
208 { 208 {
209 ResetJsEngine(); 209 ResetJsEngine();
210 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 210 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
211 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); 211 preconfiguredPrefs.emplace("suppress_first_run_page", jsEngine->NewValue(tru e));
212 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 212 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
213 213
214 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 214 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
215 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 215 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page").AsBool());
216 } 216 }
217 } 217 }
OLDNEW
« src/JsValue.cpp ('K') | « test/JsValue.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld