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

Side by Side Diff: test/Prefs.cpp

Issue 5653480979038208: Issue 2325 - Add a way to set settings in libadblockplus for FRP and automatic updates (Closed)
Patch Set: Address more comments Created June 22, 2015, 7:45 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/JsEngine.cpp ('k') | no next file » | 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-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
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(const AdblockPlus::FilterEngine::Prefs& preconfiguredPrefs =
82 AdblockPlus::FilterEngine::Prefs())
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
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 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
156 preconfiguredPrefs["disable_auto_updates"] = jsEngine->NewValue(false);
157 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
158 Reset(preconfiguredPrefs);
159
160 ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates")->IsBool());
161 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates")->AsBool());
162 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
163 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
164 }
165
166 TEST_F(PrefsTest, PreconfiguredPrefsUnsupported)
167 {
168 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
169 preconfiguredPrefs["unsupported_preconfig"] = jsEngine->NewValue(true);
170 Reset(preconfiguredPrefs);
171
172 ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig")->IsUndefined());
173 }
174
175 TEST_F(PrefsTest, PreconfiguredPrefsOverride)
176 {
177 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
178 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
179 Reset(preconfiguredPrefs);
180
181 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
182 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
183 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
184 }
185
186 TEST_F(PrefsTest, PrefsPersistWhenPreconfigured)
187 {
188 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
189 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
190 Reset(preconfiguredPrefs);
191
192 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
193 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
194 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
195
196 AdblockPlus::Sleep(100);
197
198 ASSERT_FALSE(fileSystem->prefsContents.empty());
199
200 Reset(preconfiguredPrefs);
201
202 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
203 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
204 }
OLDNEW
« no previous file with comments | « test/JsEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld