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: Added a unit test. Changed the global object injection routine. Created June 10, 2015, 8:42 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
« src/JsEngine.cpp ('K') | « src/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(std::map<std::string, AdblockPlus::JsValuePtr> preconfiguredPrefs =
82 std::map<std::string, AdblockPlus::JsValuePtr>())
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, PreconfiguredPrefs)
154 {
155 std::map<std::string, AdblockPlus::JsValuePtr> preconfiguredPrefs;
156 preconfiguredPrefs["disable_auto_updates"] = jsEngine->NewValue(false);
157 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
158 preconfiguredPrefs["unsupported_preconfig"] = jsEngine->NewValue(true);
159 Reset(preconfiguredPrefs);
160
161 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates")->AsBool());
162 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
163 ASSERT_FALSE(filterEngine->GetPref("unsupported_preconfig")->AsBool());
Eric 2015/06/10 17:48:16 This assertion should really be in a separate test
Oleksandr 2015/06/12 10:47:57 Done.
164 }
Eric 2015/06/10 17:48:16 With preconfigurable preferences, we now have thre
Oleksandr 2015/06/12 07:36:14 I think (a) and (a) and (c) are tested quite well
Felix Dahlke 2015/06/12 07:55:03 Most of that is covered here, but I think we shoul
Oleksandr 2015/06/12 10:47:57 Done. That's a great test, actually. Revealed one
OLDNEW
« src/JsEngine.cpp ('K') | « src/JsEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld