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

Delta Between Two Patch Sets: test/Prefs.cpp

Issue 5163715573841920: Issue 768 - Switch from TR1 to C++11 (Closed)
Left Patch Set: Created July 11, 2014, 2:24 p.m.
Right Patch Set: fix including of <memory> Created Aug. 7, 2015, 6:07 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/Notification.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2014 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 57 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 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld