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

Side by Side Diff: test/Prefs.cpp

Issue 29409558: Issue 5125 - Fix prefs tests to comply with new v8 (Closed)
Patch Set: Created April 11, 2017, 8:11 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 | « no previous file | 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-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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return LazyFileSystem::Stat(path); 61 return LazyFileSystem::Stat(path);
62 } 62 }
63 }; 63 };
64 64
65 class PrefsTest : public ::testing::Test 65 class PrefsTest : public ::testing::Test
66 { 66 {
67 protected: 67 protected:
68 TestFileSystem* fileSystem; 68 TestFileSystem* fileSystem;
69 AdblockPlus::FileSystemPtr fileSystemPtr; 69 AdblockPlus::FileSystemPtr fileSystemPtr;
70 AdblockPlus::JsEnginePtr jsEngine; 70 AdblockPlus::JsEnginePtr jsEngine;
71 FilterEnginePtr filterEngine;
72 71
73 void SetUp() 72 void SetUp()
74 { 73 {
75 fileSystem = new TestFileSystem(); 74 fileSystem = new TestFileSystem();
76 fileSystemPtr.reset(fileSystem); 75 fileSystemPtr.reset(fileSystem);
77 jsEngine = CreateJsEngine();
78 76
79 Reset(); 77 ResetJsEngine();
80 } 78 }
81 79
82 void Reset(const AdblockPlus::FilterEngine::Prefs& preconfiguredPrefs = 80 void ResetJsEngine()
83 AdblockPlus::FilterEngine::Prefs())
84 { 81 {
85 if (!jsEngine) 82 jsEngine = CreateJsEngine();
86 jsEngine = CreateJsEngine();
87 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem)); 83 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem));
88 jsEngine->SetFileSystem(fileSystemPtr); 84 jsEngine->SetFileSystem(fileSystemPtr);
89 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); 85 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest));
86 }
87
88 FilterEnginePtr CreateFilterEngine(const AdblockPlus::FilterEngine::Prefs& p reconfiguredPrefs =
89 AdblockPlus::FilterEngine::Prefs())
90 {
90 AdblockPlus::FilterEngine::CreationParameters createParams; 91 AdblockPlus::FilterEngine::CreationParameters createParams;
91 createParams.preconfiguredPrefs = preconfiguredPrefs; 92 createParams.preconfiguredPrefs = preconfiguredPrefs;
92 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParams); 93 return AdblockPlus::FilterEngine::Create(jsEngine, createParams);
93 } 94 }
94 }; 95 };
95 } 96 }
96 97
97 TEST_F(PrefsTest, PrefsGetSet) 98 TEST_F(PrefsTest, PrefsGetSet)
98 { 99 {
100 auto filterEngine = CreateFilterEngine();
99 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString()); 101 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString());
100 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 102 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt());
101 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 103 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
102 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined()); 104 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined());
103 105
104 ASSERT_ANY_THROW(filterEngine->SetPref("patternsfile", jsEngine->NewValue(0))) ; 106 ASSERT_ANY_THROW(filterEngine->SetPref("patternsfile", jsEngine->NewValue(0))) ;
105 ASSERT_ANY_THROW(filterEngine->SetPref("patternsbackupinterval", jsEngine->New Value(true))); 107 ASSERT_ANY_THROW(filterEngine->SetPref("patternsbackupinterval", jsEngine->New Value(true)));
106 ASSERT_ANY_THROW(filterEngine->SetPref("subscriptions_autoupdate", jsEngine->N ewValue("foo"))); 108 ASSERT_ANY_THROW(filterEngine->SetPref("subscriptions_autoupdate", jsEngine->N ewValue("foo")));
107 109
108 filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini")); 110 filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini"));
109 filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48)); 111 filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48));
110 filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false)); 112 filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false));
111 113
112 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile")->AsString()); 114 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile")->AsString());
113 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 115 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval")->AsInt());
114 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 116 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
115 } 117 }
116 118
117 TEST_F(PrefsTest, PrefsPersist) 119 TEST_F(PrefsTest, PrefsPersist)
118 { 120 {
119 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString()); 121 {
120 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 122 auto filterEngine = CreateFilterEngine();
121 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 123 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString()) ;
124 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt());
125 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
122 126
123 filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini")); 127 filterEngine->SetPref("patternsfile", jsEngine->NewValue("filters.ini"));
124 filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48)); 128 filterEngine->SetPref("patternsbackupinterval", jsEngine->NewValue(48));
125 filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false)); 129 filterEngine->SetPref("subscriptions_autoupdate", jsEngine->NewValue(false)) ;
126 130
127 AdblockPlus::Sleep(100); 131 AdblockPlus::Sleep(100);
128 132 }
129 ASSERT_FALSE(fileSystem->prefsContents.empty()); 133 ASSERT_FALSE(fileSystem->prefsContents.empty());
130 134
131 Reset(); 135 {
132 136 ResetJsEngine();
133 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile")->AsString()); 137 auto filterEngine = CreateFilterEngine();
134 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 138 ASSERT_EQ("filters.ini", filterEngine->GetPref("patternsfile")->AsString());
135 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 139 ASSERT_EQ(48, filterEngine->GetPref("patternsbackupinterval")->AsInt());
140 ASSERT_FALSE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
141 }
136 } 142 }
137 143
138 TEST_F(PrefsTest, UnknownPrefs) 144 TEST_F(PrefsTest, UnknownPrefs)
139 { 145 {
140 fileSystem->prefsContents = "{\"foobar\":2, \"patternsbackupinterval\": 12}"; 146 fileSystem->prefsContents = "{\"foobar\":2, \"patternsbackupinterval\": 12}";
141 Reset(); 147 auto filterEngine = CreateFilterEngine();
142
143 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined()); 148 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined());
144 ASSERT_EQ(12, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 149 ASSERT_EQ(12, filterEngine->GetPref("patternsbackupinterval")->AsInt());
145 } 150 }
146 151
147 TEST_F(PrefsTest, SyntaxFailure) 152 TEST_F(PrefsTest, SyntaxFailure)
148 { 153 {
149 fileSystem->prefsContents = "{\"patternsbackupinterval\": 6, \"foo\"}"; 154 fileSystem->prefsContents = "{\"patternsbackupinterval\": 6, \"foo\"}";
150 Reset(); 155 auto filterEngine = CreateFilterEngine();
151 156
152 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 157 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt());
153 } 158 }
154 159
155 TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured) 160 TEST_F(PrefsTest, PreconfiguredPrefsPreconfigured)
156 { 161 {
157 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 162 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
158 preconfiguredPrefs["disable_auto_updates"] = jsEngine->NewValue(false); 163 preconfiguredPrefs["disable_auto_updates"] = jsEngine->NewValue(false);
159 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); 164 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
160 Reset(preconfiguredPrefs); 165 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
161 166
162 ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates")->IsBool()); 167 ASSERT_TRUE(filterEngine->GetPref("disable_auto_updates")->IsBool());
163 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates")->AsBool()); 168 ASSERT_FALSE(filterEngine->GetPref("disable_auto_updates")->AsBool());
164 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 169 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
165 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 170 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
166 } 171 }
167 172
168 TEST_F(PrefsTest, PreconfiguredPrefsUnsupported) 173 TEST_F(PrefsTest, PreconfiguredPrefsUnsupported)
169 { 174 {
170 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 175 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
171 preconfiguredPrefs["unsupported_preconfig"] = jsEngine->NewValue(true); 176 preconfiguredPrefs["unsupported_preconfig"] = jsEngine->NewValue(true);
172 Reset(preconfiguredPrefs); 177 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
173 178
174 ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig")->IsUndefined()); 179 ASSERT_TRUE(filterEngine->GetPref("unsupported_preconfig")->IsUndefined());
175 } 180 }
176 181
177 TEST_F(PrefsTest, PreconfiguredPrefsOverride) 182 TEST_F(PrefsTest, PreconfiguredPrefsOverride)
178 { 183 {
179 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 184 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
180 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); 185 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
181 Reset(preconfiguredPrefs); 186 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
182 187
183 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false)); 188 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
184 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 189 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
185 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 190 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
186 } 191 }
187 192
188 TEST_F(PrefsTest, PrefsPersistWhenPreconfigured) 193 TEST_F(PrefsTest, PrefsPersistWhenPreconfigured)
189 { 194 {
190 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 195 {
191 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true); 196 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
192 Reset(preconfiguredPrefs); 197 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
198 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
193 199
194 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 200 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
195 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 201 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
196 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false)); 202 filterEngine->SetPref("suppress_first_run_page", jsEngine->NewValue(false));
197 203
198 AdblockPlus::Sleep(100); 204 AdblockPlus::Sleep(100);
199 205 }
200 ASSERT_FALSE(fileSystem->prefsContents.empty()); 206 ASSERT_FALSE(fileSystem->prefsContents.empty());
201 207
202 jsEngine.reset(); 208 {
203 Reset(preconfiguredPrefs); 209 ResetJsEngine();
210 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
211 preconfiguredPrefs["suppress_first_run_page"] = jsEngine->NewValue(true);
212 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
204 213
205 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 214 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
206 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 215 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
216 }
207 } 217 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld