OLD | NEW |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 { | 44 { |
45 callback(StatResult(), ""); | 45 callback(StatResult(), ""); |
46 }); | 46 }); |
47 } | 47 } |
48 }; | 48 }; |
49 | 49 |
50 template<class LazyFileSystemT, class LogSystem> | 50 template<class LazyFileSystemT, class LogSystem> |
51 class FilterEngineTestGeneric : public BaseJsTest | 51 class FilterEngineTestGeneric : public BaseJsTest |
52 { | 52 { |
53 protected: | 53 protected: |
54 FilterEnginePtr filterEngine; | |
55 | |
56 void SetUp() override | 54 void SetUp() override |
57 { | 55 { |
58 LazyFileSystemT* fileSystem; | 56 LazyFileSystemT* fileSystem; |
59 ThrowingPlatformCreationParameters platformParams; | 57 ThrowingPlatformCreationParameters platformParams; |
60 platformParams.logSystem.reset(new LogSystem()); | 58 platformParams.logSystem.reset(new LogSystem()); |
61 platformParams.timer.reset(new NoopTimer()); | 59 platformParams.timer.reset(new NoopTimer()); |
62 platformParams.fileSystem.reset(fileSystem = new LazyFileSystemT()); | 60 platformParams.fileSystem.reset(fileSystem = new LazyFileSystemT()); |
63 platformParams.webRequest.reset(new NoopWebRequest()); | 61 platformParams.webRequest.reset(new NoopWebRequest()); |
64 platform.reset(new Platform(std::move(platformParams))); | 62 platform.reset(new Platform(std::move(platformParams))); |
65 filterEngine = CreateFilterEngine(*fileSystem, *platform); | 63 ::CreateFilterEngine(*fileSystem, *platform); |
| 64 } |
| 65 |
| 66 FilterEngine& GetFilterEngine() |
| 67 { |
| 68 return platform->GetFilterEngine(); |
66 } | 69 } |
67 }; | 70 }; |
68 | 71 |
69 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem>
FilterEngineTest; | 72 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem>
FilterEngineTest; |
70 typedef FilterEngineTestGeneric<NoFilesFileSystem, LazyLogSystem> FilterEngine
TestNoData; | 73 typedef FilterEngineTestGeneric<NoFilesFileSystem, LazyLogSystem> FilterEngine
TestNoData; |
71 | 74 |
72 class FilterEngineWithFreshFolder : public BaseJsTest | 75 class FilterEngineWithFreshFolder : public BaseJsTest |
73 { | 76 { |
74 protected: | 77 protected: |
75 FileSystemPtr fileSystem; | 78 FileSystemPtr fileSystem; |
(...skipping 14 matching lines...) Expand all Loading... |
90 { | 93 { |
91 ThrowingPlatformCreationParameters platformParams; | 94 ThrowingPlatformCreationParameters platformParams; |
92 platformParams.logSystem.reset(new LazyLogSystem()); | 95 platformParams.logSystem.reset(new LazyLogSystem()); |
93 platformParams.timer.reset(new NoopTimer()); | 96 platformParams.timer.reset(new NoopTimer()); |
94 platformParams.fileSystem = fileSystem; | 97 platformParams.fileSystem = fileSystem; |
95 platformParams.webRequest.reset(new NoopWebRequest()); | 98 platformParams.webRequest.reset(new NoopWebRequest()); |
96 platform.reset(new Platform(std::move(platformParams))); | 99 platform.reset(new Platform(std::move(platformParams))); |
97 platform->SetUpJsEngine(appInfo); | 100 platform->SetUpJsEngine(appInfo); |
98 } | 101 } |
99 | 102 |
100 FilterEnginePtr CreateFilterEngine(const FilterEngine::CreationParameters& c
reationParams = FilterEngine::CreationParameters()) | 103 FilterEngine& CreateFilterEngine(const FilterEngine::CreationParameters& cre
ationParams = FilterEngine::CreationParameters()) |
101 { | 104 { |
102 FilterEnginePtr retValue; | 105 bool isFilterEngineReady = false; |
103 platform->CreateFilterEngineAsync(creationParams, [&retValue](const Filter
EnginePtr& filterEngine) | 106 platform->CreateFilterEngineAsync(creationParams, [&isFilterEngineReady](c
onst FilterEngine& filterEngine) |
104 { | 107 { |
105 retValue = filterEngine; | 108 isFilterEngineReady = true; |
106 }); | 109 }); |
107 while (!retValue && !fileSystemTasks.empty()) | 110 while (!isFilterEngineReady && !fileSystemTasks.empty()) |
108 { | 111 { |
109 (*fileSystemTasks.begin())(); | 112 (*fileSystemTasks.begin())(); |
110 fileSystemTasks.pop_front(); | 113 fileSystemTasks.pop_front(); |
111 } | 114 } |
112 return retValue; | 115 return platform->GetFilterEngine(); |
113 } | 116 } |
114 | 117 |
115 void TearDown() override | 118 void TearDown() override |
116 { | 119 { |
117 removeFileIfExists("patterns.ini"); | 120 removeFileIfExists("patterns.ini"); |
118 removeFileIfExists("prefs.json"); | 121 removeFileIfExists("prefs.json"); |
119 fileSystem.reset(); | 122 fileSystem.reset(); |
120 BaseJsTest::TearDown(); | 123 BaseJsTest::TearDown(); |
121 } | 124 } |
122 void removeFileIfExists(const std::string& path) | 125 void removeFileIfExists(const std::string& path) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 class FilterEngineIsSubscriptionDownloadAllowedTest : public BaseJsTest | 158 class FilterEngineIsSubscriptionDownloadAllowedTest : public BaseJsTest |
156 { | 159 { |
157 protected: | 160 protected: |
158 typedef std::vector<std::pair<bool, std::string>> ConnectionTypes; | 161 typedef std::vector<std::pair<bool, std::string>> ConnectionTypes; |
159 DelayedWebRequest::SharedTasks webRequestTasks; | 162 DelayedWebRequest::SharedTasks webRequestTasks; |
160 DelayedTimer::SharedTasks timerTasks; | 163 DelayedTimer::SharedTasks timerTasks; |
161 FilterEngine::CreationParameters createParams; | 164 FilterEngine::CreationParameters createParams; |
162 ConnectionTypes capturedConnectionTypes; | 165 ConnectionTypes capturedConnectionTypes; |
163 bool isConnectionAllowed; | 166 bool isConnectionAllowed; |
164 std::vector<std::function<void(bool)>> isSubscriptionDownloadAllowedCallback
s; | 167 std::vector<std::function<void(bool)>> isSubscriptionDownloadAllowedCallback
s; |
165 FilterEnginePtr filterEngine; | |
166 LazyFileSystem* fileSystem; | 168 LazyFileSystem* fileSystem; |
| 169 bool isFilterEngineCreated; |
167 | 170 |
168 void SetUp() | 171 void SetUp() |
169 { | 172 { |
170 isConnectionAllowed = true; | 173 isConnectionAllowed = true; |
| 174 isFilterEngineCreated = false; |
171 | 175 |
172 ThrowingPlatformCreationParameters platformParams; | 176 ThrowingPlatformCreationParameters platformParams; |
173 platformParams.logSystem.reset(new LazyLogSystem()); | 177 platformParams.logSystem.reset(new LazyLogSystem()); |
174 platformParams.timer = DelayedTimer::New(timerTasks); | 178 platformParams.timer = DelayedTimer::New(timerTasks); |
175 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem()); | 179 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem()); |
176 platformParams.webRequest = DelayedWebRequest::New(webRequestTasks); | 180 platformParams.webRequest = DelayedWebRequest::New(webRequestTasks); |
177 platform.reset(new Platform(std::move(platformParams))); | 181 platform.reset(new Platform(std::move(platformParams))); |
178 | 182 |
179 createParams.preconfiguredPrefs.emplace("first_run_subscription_auto_selec
t", GetJsEngine().NewValue(false)); | 183 createParams.preconfiguredPrefs.emplace("first_run_subscription_auto_selec
t", GetJsEngine().NewValue(false)); |
180 | 184 |
181 createParams.isSubscriptionDownloadAllowedCallback = [this](const std::str
ing* allowedConnectionType, | 185 createParams.isSubscriptionDownloadAllowedCallback = [this](const std::str
ing* allowedConnectionType, |
182 const std::function<void(bool)>& isSubscriptionDownloadAllowedCallback){ | 186 const std::function<void(bool)>& isSubscriptionDownloadAllowedCallback){ |
183 capturedConnectionTypes.emplace_back(!!allowedConnectionType, allowedCon
nectionType ? *allowedConnectionType : std::string()); | 187 capturedConnectionTypes.emplace_back(!!allowedConnectionType, allowedCon
nectionType ? *allowedConnectionType : std::string()); |
184 isSubscriptionDownloadAllowedCallbacks.emplace_back(isSubscriptionDownlo
adAllowedCallback); | 188 isSubscriptionDownloadAllowedCallbacks.emplace_back(isSubscriptionDownlo
adAllowedCallback); |
185 }; | 189 }; |
186 } | 190 } |
187 | 191 |
| 192 FilterEngine& GetFilterEngine() |
| 193 { |
| 194 if (!isFilterEngineCreated) |
| 195 throw std::logic_error("Check that FilterEngine is properly initialized"
); |
| 196 return platform->GetFilterEngine(); |
| 197 } |
| 198 |
188 Subscription EnsureExampleSubscriptionAndForceUpdate(const std::string& appp
endToUrl = std::string()) | 199 Subscription EnsureExampleSubscriptionAndForceUpdate(const std::string& appp
endToUrl = std::string()) |
189 { | 200 { |
190 auto subscriptionUrl = "http://example" + apppendToUrl; | 201 auto subscriptionUrl = "http://example" + apppendToUrl; |
191 bool isSubscriptionDownloadStatusReceived = false; | 202 bool isSubscriptionDownloadStatusReceived = false; |
192 if (!filterEngine) | 203 if (!isFilterEngineCreated) |
193 { | 204 { |
194 filterEngine = CreateFilterEngine(*fileSystem, *platform, createParams); | 205 ::CreateFilterEngine(*fileSystem, *platform, createParams); |
195 filterEngine->SetFilterChangeCallback([&isSubscriptionDownloadStatusRece
ived, &subscriptionUrl](const std::string& action, JsValue&& item) | 206 isFilterEngineCreated = true; |
| 207 platform->GetFilterEngine().SetFilterChangeCallback([&isSubscriptionDown
loadStatusReceived, &subscriptionUrl](const std::string& action, JsValue&& item) |
196 { | 208 { |
197 if (action == "subscription.downloadStatus" && item.GetProperty("url")
.AsString() == subscriptionUrl) | 209 if (action == "subscription.downloadStatus" && item.GetProperty("url")
.AsString() == subscriptionUrl) |
198 isSubscriptionDownloadStatusReceived = true; | 210 isSubscriptionDownloadStatusReceived = true; |
199 }); | 211 }); |
200 } | 212 } |
201 auto subscription = filterEngine->GetSubscription(subscriptionUrl); | 213 auto subscription = platform->GetFilterEngine().GetSubscription(subscripti
onUrl); |
202 EXPECT_EQ(0u, subscription.GetProperty("filters").AsList().size()) << subs
criptionUrl; | 214 EXPECT_EQ(0u, subscription.GetProperty("filters").AsList().size()) << subs
criptionUrl; |
203 EXPECT_TRUE(subscription.GetProperty("downloadStatus").IsNull()) << subscr
iptionUrl; | 215 EXPECT_TRUE(subscription.GetProperty("downloadStatus").IsNull()) << subscr
iptionUrl; |
204 subscription.UpdateFilters(); | 216 subscription.UpdateFilters(); |
205 | 217 |
206 // Since currently the check is called from implemenation of web request | 218 // Since currently the check is called from implemenation of web request |
207 // they have to been firstly scheduled, namely before processing of | 219 // they have to been firstly scheduled, namely before processing of |
208 // 'is subscription download allowed' callbacks; | 220 // 'is subscription download allowed' callbacks; |
209 DelayedTimer::ProcessImmediateTimers(timerTasks); | 221 DelayedTimer::ProcessImmediateTimers(timerTasks); |
210 | 222 |
211 for (const auto& isSubscriptionDownloadAllowedCallback : isSubscriptionDow
nloadAllowedCallbacks) | 223 for (const auto& isSubscriptionDownloadAllowedCallback : isSubscriptionDow
nloadAllowedCallbacks) |
(...skipping 20 matching lines...) Expand all Loading... |
232 } | 244 } |
233 } | 245 } |
234 EXPECT_TRUE(isSubscriptionDownloadStatusReceived); | 246 EXPECT_TRUE(isSubscriptionDownloadStatusReceived); |
235 return subscription; | 247 return subscription; |
236 } | 248 } |
237 }; | 249 }; |
238 } | 250 } |
239 | 251 |
240 TEST_F(FilterEngineTest, FilterCreation) | 252 TEST_F(FilterEngineTest, FilterCreation) |
241 { | 253 { |
242 AdblockPlus::Filter filter1 = filterEngine->GetFilter("foo"); | 254 auto& filterEngine = GetFilterEngine(); |
| 255 AdblockPlus::Filter filter1 = filterEngine.GetFilter("foo"); |
243 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1.GetType()); | 256 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1.GetType()); |
244 AdblockPlus::Filter filter2 = filterEngine->GetFilter("@@foo"); | 257 AdblockPlus::Filter filter2 = filterEngine.GetFilter("@@foo"); |
245 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2.GetType()); | 258 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2.GetType()); |
246 AdblockPlus::Filter filter3 = filterEngine->GetFilter("example.com##foo"); | 259 AdblockPlus::Filter filter3 = filterEngine.GetFilter("example.com##foo"); |
247 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3.GetType()); | 260 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3.GetType()); |
248 AdblockPlus::Filter filter4 = filterEngine->GetFilter("example.com#@#foo"); | 261 AdblockPlus::Filter filter4 = filterEngine.GetFilter("example.com#@#foo"); |
249 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4.GetType()); | 262 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4.GetType()); |
250 AdblockPlus::Filter filter5 = filterEngine->GetFilter(" foo "); | 263 AdblockPlus::Filter filter5 = filterEngine.GetFilter(" foo "); |
251 ASSERT_EQ(filter1, filter5); | 264 ASSERT_EQ(filter1, filter5); |
252 } | 265 } |
253 | 266 |
254 TEST_F(FilterEngineTest, FilterProperties) | 267 TEST_F(FilterEngineTest, FilterProperties) |
255 { | 268 { |
256 AdblockPlus::Filter filter = filterEngine->GetFilter("foo"); | 269 AdblockPlus::Filter filter = GetFilterEngine().GetFilter("foo"); |
257 | 270 |
258 ASSERT_TRUE(filter.GetProperty("stringFoo").IsUndefined()); | 271 ASSERT_TRUE(filter.GetProperty("stringFoo").IsUndefined()); |
259 ASSERT_TRUE(filter.GetProperty("intFoo").IsUndefined()); | 272 ASSERT_TRUE(filter.GetProperty("intFoo").IsUndefined()); |
260 ASSERT_TRUE(filter.GetProperty("boolFoo").IsUndefined()); | 273 ASSERT_TRUE(filter.GetProperty("boolFoo").IsUndefined()); |
261 | 274 |
262 filter.SetProperty("stringFoo", "y"); | 275 filter.SetProperty("stringFoo", "y"); |
263 filter.SetProperty("intFoo", 24); | 276 filter.SetProperty("intFoo", 24); |
264 filter.SetProperty("boolFoo", true); | 277 filter.SetProperty("boolFoo", true); |
265 ASSERT_EQ("y", filter.GetProperty("stringFoo").AsString()); | 278 ASSERT_EQ("y", filter.GetProperty("stringFoo").AsString()); |
266 ASSERT_EQ(24, filter.GetProperty("intFoo").AsInt()); | 279 ASSERT_EQ(24, filter.GetProperty("intFoo").AsInt()); |
267 ASSERT_TRUE(filter.GetProperty("boolFoo").AsBool()); | 280 ASSERT_TRUE(filter.GetProperty("boolFoo").AsBool()); |
268 } | 281 } |
269 | 282 |
270 TEST_F(FilterEngineTest, AddRemoveFilters) | 283 TEST_F(FilterEngineTest, AddRemoveFilters) |
271 { | 284 { |
272 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); | 285 auto& filterEngine = GetFilterEngine(); |
273 AdblockPlus::Filter filter = filterEngine->GetFilter("foo"); | 286 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); |
274 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); | 287 AdblockPlus::Filter filter = filterEngine.GetFilter("foo"); |
| 288 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); |
275 ASSERT_FALSE(filter.IsListed()); | 289 ASSERT_FALSE(filter.IsListed()); |
276 filter.AddToList(); | 290 filter.AddToList(); |
277 ASSERT_EQ(1u, filterEngine->GetListedFilters().size()); | 291 ASSERT_EQ(1u, filterEngine.GetListedFilters().size()); |
278 ASSERT_EQ(filter, filterEngine->GetListedFilters()[0]); | 292 ASSERT_EQ(filter, filterEngine.GetListedFilters()[0]); |
279 ASSERT_TRUE(filter.IsListed()); | 293 ASSERT_TRUE(filter.IsListed()); |
280 filter.AddToList(); | 294 filter.AddToList(); |
281 ASSERT_EQ(1u, filterEngine->GetListedFilters().size()); | 295 ASSERT_EQ(1u, filterEngine.GetListedFilters().size()); |
282 ASSERT_EQ(filter, filterEngine->GetListedFilters()[0]); | 296 ASSERT_EQ(filter, filterEngine.GetListedFilters()[0]); |
283 ASSERT_TRUE(filter.IsListed()); | 297 ASSERT_TRUE(filter.IsListed()); |
284 filter.RemoveFromList(); | 298 filter.RemoveFromList(); |
285 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); | 299 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); |
286 ASSERT_FALSE(filter.IsListed()); | 300 ASSERT_FALSE(filter.IsListed()); |
287 filter.RemoveFromList(); | 301 filter.RemoveFromList(); |
288 ASSERT_EQ(0u, filterEngine->GetListedFilters().size()); | 302 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); |
289 ASSERT_FALSE(filter.IsListed()); | 303 ASSERT_FALSE(filter.IsListed()); |
290 } | 304 } |
291 | 305 |
292 TEST_F(FilterEngineTest, SubscriptionProperties) | 306 TEST_F(FilterEngineTest, SubscriptionProperties) |
293 { | 307 { |
294 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 308 AdblockPlus::Subscription subscription = GetFilterEngine().GetSubscription("fo
o"); |
295 | 309 |
296 ASSERT_TRUE(subscription.GetProperty("stringFoo").IsUndefined()); | 310 ASSERT_TRUE(subscription.GetProperty("stringFoo").IsUndefined()); |
297 ASSERT_TRUE(subscription.GetProperty("intFoo").IsUndefined()); | 311 ASSERT_TRUE(subscription.GetProperty("intFoo").IsUndefined()); |
298 ASSERT_TRUE(subscription.GetProperty("boolFoo").IsUndefined()); | 312 ASSERT_TRUE(subscription.GetProperty("boolFoo").IsUndefined()); |
299 | 313 |
300 subscription.SetProperty("stringFoo", "y"); | 314 subscription.SetProperty("stringFoo", "y"); |
301 subscription.SetProperty("intFoo", 24); | 315 subscription.SetProperty("intFoo", 24); |
302 subscription.SetProperty("boolFoo", true); | 316 subscription.SetProperty("boolFoo", true); |
303 ASSERT_EQ("y", subscription.GetProperty("stringFoo").AsString()); | 317 ASSERT_EQ("y", subscription.GetProperty("stringFoo").AsString()); |
304 ASSERT_EQ(24, subscription.GetProperty("intFoo").AsInt()); | 318 ASSERT_EQ(24, subscription.GetProperty("intFoo").AsInt()); |
305 ASSERT_TRUE(subscription.GetProperty("boolFoo").AsBool()); | 319 ASSERT_TRUE(subscription.GetProperty("boolFoo").AsBool()); |
306 } | 320 } |
307 | 321 |
308 TEST_F(FilterEngineTest, AddedSubscriptionIsEnabled) | 322 TEST_F(FilterEngineTest, AddedSubscriptionIsEnabled) |
309 { | 323 { |
310 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 324 AdblockPlus::Subscription subscription = GetFilterEngine().GetSubscription("fo
o"); |
311 EXPECT_FALSE(subscription.IsDisabled()); | 325 EXPECT_FALSE(subscription.IsDisabled()); |
312 } | 326 } |
313 | 327 |
314 TEST_F(FilterEngineTest, DisablingSubscriptionDisablesItAndFiresEvent) | 328 TEST_F(FilterEngineTest, DisablingSubscriptionDisablesItAndFiresEvent) |
315 { | 329 { |
316 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 330 AdblockPlus::Subscription subscription = GetFilterEngine().GetSubscription("fo
o"); |
317 int eventFiredCounter = 0; | 331 int eventFiredCounter = 0; |
318 filterEngine->SetFilterChangeCallback([&eventFiredCounter](const std::string&
eventName, JsValue&& subscriptionObject) | 332 GetFilterEngine().SetFilterChangeCallback([&eventFiredCounter](const std::stri
ng& eventName, JsValue&& subscriptionObject) |
319 { | 333 { |
320 if (eventName != "subscription.disabled" || subscriptionObject.GetProperty("
url").AsString() != "foo") | 334 if (eventName != "subscription.disabled" || subscriptionObject.GetProperty("
url").AsString() != "foo") |
321 return; | 335 return; |
322 ++eventFiredCounter; | 336 ++eventFiredCounter; |
323 }); | 337 }); |
324 EXPECT_FALSE(subscription.IsDisabled()); | 338 EXPECT_FALSE(subscription.IsDisabled()); |
325 subscription.SetDisabled(true); | 339 subscription.SetDisabled(true); |
326 EXPECT_EQ(1, eventFiredCounter); | 340 EXPECT_EQ(1, eventFiredCounter); |
327 EXPECT_TRUE(subscription.IsDisabled()); | 341 EXPECT_TRUE(subscription.IsDisabled()); |
328 } | 342 } |
329 | 343 |
330 TEST_F(FilterEngineTest, EnablingSubscriptionEnablesItAndFiresEvent) | 344 TEST_F(FilterEngineTest, EnablingSubscriptionEnablesItAndFiresEvent) |
331 { | 345 { |
332 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 346 AdblockPlus::Subscription subscription = GetFilterEngine().GetSubscription("fo
o"); |
333 EXPECT_FALSE(subscription.IsDisabled()); | 347 EXPECT_FALSE(subscription.IsDisabled()); |
334 subscription.SetDisabled(true); | 348 subscription.SetDisabled(true); |
335 EXPECT_TRUE(subscription.IsDisabled()); | 349 EXPECT_TRUE(subscription.IsDisabled()); |
336 | 350 |
337 int eventFiredCounter = 0; | 351 int eventFiredCounter = 0; |
338 filterEngine->SetFilterChangeCallback([&eventFiredCounter](const std::string&
eventName, JsValue&& subscriptionObject) | 352 GetFilterEngine().SetFilterChangeCallback([&eventFiredCounter](const std::stri
ng& eventName, JsValue&& subscriptionObject) |
339 { | 353 { |
340 if (eventName != "subscription.disabled" || subscriptionObject.GetProperty("
url").AsString() != "foo") | 354 if (eventName != "subscription.disabled" || subscriptionObject.GetProperty("
url").AsString() != "foo") |
341 return; | 355 return; |
342 ++eventFiredCounter; | 356 ++eventFiredCounter; |
343 }); | 357 }); |
344 subscription.SetDisabled(false); | 358 subscription.SetDisabled(false); |
345 EXPECT_EQ(1, eventFiredCounter); | 359 EXPECT_EQ(1, eventFiredCounter); |
346 EXPECT_FALSE(subscription.IsDisabled()); | 360 EXPECT_FALSE(subscription.IsDisabled()); |
347 } | 361 } |
348 | 362 |
349 TEST_F(FilterEngineTest, AddRemoveSubscriptions) | 363 TEST_F(FilterEngineTest, AddRemoveSubscriptions) |
350 { | 364 { |
351 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); | 365 auto& filterEngine = GetFilterEngine(); |
352 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 366 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); |
353 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); | 367 AdblockPlus::Subscription subscription = filterEngine.GetSubscription("foo"); |
| 368 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); |
354 ASSERT_FALSE(subscription.IsListed()); | 369 ASSERT_FALSE(subscription.IsListed()); |
355 subscription.AddToList(); | 370 subscription.AddToList(); |
356 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); | 371 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size()); |
357 ASSERT_EQ(subscription, filterEngine->GetListedSubscriptions()[0]); | 372 ASSERT_EQ(subscription, filterEngine.GetListedSubscriptions()[0]); |
358 ASSERT_TRUE(subscription.IsListed()); | 373 ASSERT_TRUE(subscription.IsListed()); |
359 subscription.AddToList(); | 374 subscription.AddToList(); |
360 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); | 375 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size()); |
361 ASSERT_EQ(subscription, filterEngine->GetListedSubscriptions()[0]); | 376 ASSERT_EQ(subscription, filterEngine.GetListedSubscriptions()[0]); |
362 ASSERT_TRUE(subscription.IsListed()); | 377 ASSERT_TRUE(subscription.IsListed()); |
363 subscription.RemoveFromList(); | 378 subscription.RemoveFromList(); |
364 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); | 379 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); |
365 ASSERT_FALSE(subscription.IsListed()); | 380 ASSERT_FALSE(subscription.IsListed()); |
366 subscription.RemoveFromList(); | 381 subscription.RemoveFromList(); |
367 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); | 382 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); |
368 ASSERT_FALSE(subscription.IsListed()); | 383 ASSERT_FALSE(subscription.IsListed()); |
369 } | 384 } |
370 | 385 |
371 TEST_F(FilterEngineTest, SubscriptionUpdates) | 386 TEST_F(FilterEngineTest, SubscriptionUpdates) |
372 { | 387 { |
373 AdblockPlus::Subscription subscription = filterEngine->GetSubscription("foo"); | 388 AdblockPlus::Subscription subscription = GetFilterEngine().GetSubscription("fo
o"); |
374 ASSERT_FALSE(subscription.IsUpdating()); | 389 ASSERT_FALSE(subscription.IsUpdating()); |
375 subscription.UpdateFilters(); | 390 subscription.UpdateFilters(); |
376 } | 391 } |
377 | 392 |
378 TEST_F(FilterEngineTest, Matches) | 393 TEST_F(FilterEngineTest, Matches) |
379 { | 394 { |
380 filterEngine->GetFilter("adbanner.gif").AddToList(); | 395 auto& filterEngine = GetFilterEngine(); |
381 filterEngine->GetFilter("@@notbanner.gif").AddToList(); | 396 filterEngine.GetFilter("adbanner.gif").AddToList(); |
382 filterEngine->GetFilter("tpbanner.gif$third-party").AddToList(); | 397 filterEngine.GetFilter("@@notbanner.gif").AddToList(); |
383 filterEngine->GetFilter("fpbanner.gif$~third-party").AddToList(); | 398 filterEngine.GetFilter("tpbanner.gif$third-party").AddToList(); |
384 filterEngine->GetFilter("combanner.gif$domain=example.com").AddToList(); | 399 filterEngine.GetFilter("fpbanner.gif$~third-party").AddToList(); |
385 filterEngine->GetFilter("orgbanner.gif$domain=~example.com").AddToList(); | 400 filterEngine.GetFilter("combanner.gif$domain=example.com").AddToList(); |
| 401 filterEngine.GetFilter("orgbanner.gif$domain=~example.com").AddToList(); |
386 | 402 |
387 AdblockPlus::FilterPtr match1 = filterEngine->Matches("http://example.org/foob
ar.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); | 403 AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org/fooba
r.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); |
388 ASSERT_FALSE(match1); | 404 ASSERT_FALSE(match1); |
389 | 405 |
390 AdblockPlus::FilterPtr match2 = filterEngine->Matches("http://example.org/adba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); | 406 AdblockPlus::FilterPtr match2 = filterEngine.Matches("http://example.org/adban
ner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); |
391 ASSERT_TRUE(match2); | 407 ASSERT_TRUE(match2); |
392 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetType()); | 408 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetType()); |
393 | 409 |
394 AdblockPlus::FilterPtr match3 = filterEngine->Matches("http://example.org/notb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); | 410 AdblockPlus::FilterPtr match3 = filterEngine.Matches("http://example.org/notba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); |
395 ASSERT_TRUE(match3); | 411 ASSERT_TRUE(match3); |
396 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetType()); | 412 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetType()); |
397 | 413 |
398 AdblockPlus::FilterPtr match4 = filterEngine->Matches("http://example.org/notb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); | 414 AdblockPlus::FilterPtr match4 = filterEngine.Matches("http://example.org/notba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); |
399 ASSERT_TRUE(match4); | 415 ASSERT_TRUE(match4); |
400 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetType()); | 416 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetType()); |
401 | 417 |
402 AdblockPlus::FilterPtr match5 = filterEngine->Matches("http://example.org/tpba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/")
; | 418 AdblockPlus::FilterPtr match5 = filterEngine.Matches("http://example.org/tpban
ner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/"); |
403 ASSERT_FALSE(match5); | 419 ASSERT_FALSE(match5); |
404 | 420 |
405 AdblockPlus::FilterPtr match6 = filterEngine->Matches("http://example.org/fpba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/")
; | 421 AdblockPlus::FilterPtr match6 = filterEngine.Matches("http://example.org/fpban
ner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/"); |
406 ASSERT_TRUE(match6); | 422 ASSERT_TRUE(match6); |
407 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); | 423 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); |
408 | 424 |
409 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/")
; | 425 AdblockPlus::FilterPtr match7 = filterEngine.Matches("http://example.org/tpban
ner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/"); |
410 ASSERT_TRUE(match7); | 426 ASSERT_TRUE(match7); |
411 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match7->GetType()); | 427 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match7->GetType()); |
412 | 428 |
413 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/")
; | 429 AdblockPlus::FilterPtr match8 = filterEngine.Matches("http://example.org/fpban
ner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/"); |
414 ASSERT_FALSE(match8); | 430 ASSERT_FALSE(match8); |
415 | 431 |
416 AdblockPlus::FilterPtr match9 = filterEngine->Matches("http://example.org/comb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/"
); | 432 AdblockPlus::FilterPtr match9 = filterEngine.Matches("http://example.org/comba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/")
; |
417 ASSERT_TRUE(match9); | 433 ASSERT_TRUE(match9); |
418 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match9->GetType()); | 434 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match9->GetType()); |
419 | 435 |
420 AdblockPlus::FilterPtr match10 = filterEngine->Matches("http://example.org/com
banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/
"); | 436 AdblockPlus::FilterPtr match10 = filterEngine.Matches("http://example.org/comb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/"
); |
421 ASSERT_FALSE(match10); | 437 ASSERT_FALSE(match10); |
422 | 438 |
423 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org
banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/
"); | 439 AdblockPlus::FilterPtr match11 = filterEngine.Matches("http://example.org/orgb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/"
); |
424 ASSERT_FALSE(match11); | 440 ASSERT_FALSE(match11); |
425 | 441 |
426 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org
banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/
"); | 442 AdblockPlus::FilterPtr match12 = filterEngine.Matches("http://example.org/orgb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/"
); |
427 ASSERT_TRUE(match12); | 443 ASSERT_TRUE(match12); |
428 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType()); | 444 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType()); |
429 } | 445 } |
430 | 446 |
431 TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain) | 447 TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain) |
432 { | 448 { |
433 filterEngine->GetFilter("adbanner.gif").AddToList(); | 449 auto& filterEngine = GetFilterEngine(); |
434 filterEngine->GetFilter("@@||example.org^$document").AddToList(); | 450 filterEngine.GetFilter("adbanner.gif").AddToList(); |
| 451 filterEngine.GetFilter("@@||example.org^$document").AddToList(); |
435 | 452 |
436 AdblockPlus::FilterPtr match1 = | 453 AdblockPlus::FilterPtr match1 = |
437 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 454 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
438 "http://example.com/"); | 455 "http://example.com/"); |
439 ASSERT_TRUE(match1); | 456 ASSERT_TRUE(match1); |
440 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); | 457 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); |
441 | 458 |
442 AdblockPlus::FilterPtr match2 = | 459 AdblockPlus::FilterPtr match2 = |
443 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 460 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
444 "http://example.org/"); | 461 "http://example.org/"); |
445 ASSERT_TRUE(match2); | 462 ASSERT_TRUE(match2); |
446 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); | 463 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); |
447 } | 464 } |
448 | 465 |
449 TEST_F(FilterEngineTest, MatchesWithContentTypeMask) | 466 TEST_F(FilterEngineTest, MatchesWithContentTypeMask) |
450 { | 467 { |
451 filterEngine->GetFilter("adbanner.gif.js$script,image").AddToList(); | 468 auto& filterEngine = GetFilterEngine(); |
452 filterEngine->GetFilter("@@notbanner.gif").AddToList(); | 469 filterEngine.GetFilter("adbanner.gif.js$script,image").AddToList(); |
453 filterEngine->GetFilter("blockme").AddToList(); | 470 filterEngine.GetFilter("@@notbanner.gif").AddToList(); |
454 filterEngine->GetFilter("@@||example.doc^$document").AddToList(); | 471 filterEngine.GetFilter("blockme").AddToList(); |
| 472 filterEngine.GetFilter("@@||example.doc^$document").AddToList(); |
455 | 473 |
456 EXPECT_FALSE(filterEngine->Matches("http://example.org/foobar.gif", | 474 EXPECT_FALSE(filterEngine.Matches("http://example.org/foobar.gif", |
457 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "")) | 475 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "")) |
458 << "another url should not match"; | 476 << "another url should not match"; |
459 | 477 |
460 EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js", | 478 EXPECT_FALSE(filterEngine.Matches("http://example.org/adbanner.gif.js", |
461 /*mask*/ 0, "")) << "zero mask should not match (filter with some options)"; | 479 /*mask*/ 0, "")) << "zero mask should not match (filter with some options)"; |
462 | 480 |
463 EXPECT_FALSE(filterEngine->Matches("http://example.xxx/blockme", | 481 EXPECT_FALSE(filterEngine.Matches("http://example.xxx/blockme", |
464 /*mask*/ 0, "")) << "zero mask should not match (filter without any option)"
; | 482 /*mask*/ 0, "")) << "zero mask should not match (filter without any option)"
; |
465 | 483 |
466 EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js", | 484 EXPECT_FALSE(filterEngine.Matches("http://example.org/adbanner.gif.js", |
467 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "")) | 485 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "")) |
468 << "one arbitrary flag in mask should not match"; | 486 << "one arbitrary flag in mask should not match"; |
469 | 487 |
470 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js", | 488 EXPECT_TRUE(filterEngine.Matches("http://example.org/adbanner.gif.js", |
471 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE | | 489 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE | |
472 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "")) | 490 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "")) |
473 << "one of flags in mask should match"; | 491 << "one of flags in mask should match"; |
474 | 492 |
475 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js", | 493 EXPECT_TRUE(filterEngine.Matches("http://example.org/adbanner.gif.js", |
476 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE | | 494 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE | |
477 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT, "")) | 495 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT, "")) |
478 << "both flags in mask should match"; | 496 << "both flags in mask should match"; |
479 | 497 |
480 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js", | 498 EXPECT_TRUE(filterEngine.Matches("http://example.org/adbanner.gif.js", |
481 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE | | 499 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE | |
482 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT | | 500 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT | |
483 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "")) | 501 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "")) |
484 << "both flags with another flag in mask should match"; | 502 << "both flags with another flag in mask should match"; |
485 | 503 |
486 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js", | 504 EXPECT_TRUE(filterEngine.Matches("http://example.org/adbanner.gif.js", |
487 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT | | 505 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT | |
488 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "")) | 506 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "")) |
489 << "one of flags in mask should match"; | 507 << "one of flags in mask should match"; |
490 | 508 |
491 { | 509 { |
492 AdblockPlus::FilterPtr filter; | 510 AdblockPlus::FilterPtr filter; |
493 ASSERT_TRUE(filter = filterEngine->Matches("http://child.any/blockme", | 511 ASSERT_TRUE(filter = filterEngine.Matches("http://child.any/blockme", |
494 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT | | 512 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT | |
495 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "http://example.doc")) | 513 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "http://example.doc")) |
496 << "non-zero mask should match on whitelisted document"; | 514 << "non-zero mask should match on whitelisted document"; |
497 | 515 |
498 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType()); | 516 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType()); |
499 } | 517 } |
500 | 518 |
501 { | 519 { |
502 AdblockPlus::FilterPtr filter; | 520 AdblockPlus::FilterPtr filter; |
503 ASSERT_TRUE(filter = filterEngine->Matches("http://example.doc/blockme", | 521 ASSERT_TRUE(filter = filterEngine.Matches("http://example.doc/blockme", |
504 /*mask*/0, "http://example.doc")) | 522 /*mask*/0, "http://example.doc")) |
505 << "zero mask should match when document is whitelisted"; | 523 << "zero mask should match when document is whitelisted"; |
506 | 524 |
507 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType()); | 525 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType()); |
508 } | 526 } |
509 } | 527 } |
510 | 528 |
511 TEST_F(FilterEngineTest, MatchesNestedFrameRequest) | 529 TEST_F(FilterEngineTest, MatchesNestedFrameRequest) |
512 { | 530 { |
513 filterEngine->GetFilter("adbanner.gif").AddToList(); | 531 auto& filterEngine = GetFilterEngine(); |
514 filterEngine->GetFilter("@@adbanner.gif$domain=example.org").AddToList(); | 532 filterEngine.GetFilter("adbanner.gif").AddToList(); |
| 533 filterEngine.GetFilter("@@adbanner.gif$domain=example.org").AddToList(); |
515 | 534 |
516 std::vector<std::string> documentUrls1; | 535 std::vector<std::string> documentUrls1; |
517 documentUrls1.push_back("http://ads.com/frame/"); | 536 documentUrls1.push_back("http://ads.com/frame/"); |
518 documentUrls1.push_back("http://example.com/"); | 537 documentUrls1.push_back("http://example.com/"); |
519 AdblockPlus::FilterPtr match1 = | 538 AdblockPlus::FilterPtr match1 = |
520 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 539 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
521 documentUrls1); | 540 documentUrls1); |
522 ASSERT_TRUE(match1); | 541 ASSERT_TRUE(match1); |
523 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); | 542 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); |
524 | 543 |
525 std::vector<std::string> documentUrls2; | 544 std::vector<std::string> documentUrls2; |
526 documentUrls2.push_back("http://ads.com/frame/"); | 545 documentUrls2.push_back("http://ads.com/frame/"); |
527 documentUrls2.push_back("http://example.org/"); | 546 documentUrls2.push_back("http://example.org/"); |
528 AdblockPlus::FilterPtr match2 = | 547 AdblockPlus::FilterPtr match2 = |
529 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 548 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
530 documentUrls2); | 549 documentUrls2); |
531 ASSERT_TRUE(match2); | 550 ASSERT_TRUE(match2); |
532 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); | 551 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); |
533 | 552 |
534 std::vector<std::string> documentUrls3; | 553 std::vector<std::string> documentUrls3; |
535 documentUrls3.push_back("http://example.org/"); | 554 documentUrls3.push_back("http://example.org/"); |
536 documentUrls3.push_back("http://ads.com/frame/"); | 555 documentUrls3.push_back("http://ads.com/frame/"); |
537 AdblockPlus::FilterPtr match3 = | 556 AdblockPlus::FilterPtr match3 = |
538 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 557 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
539 documentUrls3); | 558 documentUrls3); |
540 ASSERT_TRUE(match3); | 559 ASSERT_TRUE(match3); |
541 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); | 560 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); |
542 } | 561 } |
543 | 562 |
544 TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain) | 563 TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain) |
545 { | 564 { |
546 filterEngine->GetFilter("adbanner.gif").AddToList(); | 565 auto& filterEngine = GetFilterEngine(); |
547 filterEngine->GetFilter("@@||example.org^$document,domain=ads.com").AddToList(
); | 566 filterEngine.GetFilter("adbanner.gif").AddToList(); |
| 567 filterEngine.GetFilter("@@||example.org^$document,domain=ads.com").AddToList()
; |
548 | 568 |
549 std::vector<std::string> documentUrls1; | 569 std::vector<std::string> documentUrls1; |
550 documentUrls1.push_back("http://ads.com/frame/"); | 570 documentUrls1.push_back("http://ads.com/frame/"); |
551 documentUrls1.push_back("http://example.com/"); | 571 documentUrls1.push_back("http://example.com/"); |
552 AdblockPlus::FilterPtr match1 = | 572 AdblockPlus::FilterPtr match1 = |
553 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 573 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
554 documentUrls1); | 574 documentUrls1); |
555 ASSERT_TRUE(match1); | 575 ASSERT_TRUE(match1); |
556 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); | 576 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); |
557 | 577 |
558 std::vector<std::string> documentUrls2; | 578 std::vector<std::string> documentUrls2; |
559 documentUrls2.push_back("http://ads.com/frame/"); | 579 documentUrls2.push_back("http://ads.com/frame/"); |
560 documentUrls2.push_back("http://example.org/"); | 580 documentUrls2.push_back("http://example.org/"); |
561 AdblockPlus::FilterPtr match2 = | 581 AdblockPlus::FilterPtr match2 = |
562 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 582 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
563 documentUrls2); | 583 documentUrls2); |
564 ASSERT_TRUE(match2); | 584 ASSERT_TRUE(match2); |
565 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); | 585 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); |
566 | 586 |
567 std::vector<std::string> documentUrls3; | 587 std::vector<std::string> documentUrls3; |
568 documentUrls3.push_back("http://example.org/"); | 588 documentUrls3.push_back("http://example.org/"); |
569 AdblockPlus::FilterPtr match3 = | 589 AdblockPlus::FilterPtr match3 = |
570 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 590 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
571 documentUrls3); | 591 documentUrls3); |
572 ASSERT_TRUE(match3); | 592 ASSERT_TRUE(match3); |
573 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); | 593 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); |
574 | 594 |
575 std::vector<std::string> documentUrls4; | 595 std::vector<std::string> documentUrls4; |
576 documentUrls4.push_back("http://example.org/"); | 596 documentUrls4.push_back("http://example.org/"); |
577 documentUrls4.push_back("http://ads.com/frame/"); | 597 documentUrls4.push_back("http://ads.com/frame/"); |
578 AdblockPlus::FilterPtr match4 = | 598 AdblockPlus::FilterPtr match4 = |
579 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 599 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
580 documentUrls4); | 600 documentUrls4); |
581 ASSERT_TRUE(match4); | 601 ASSERT_TRUE(match4); |
582 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match4->GetType()); | 602 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match4->GetType()); |
583 | 603 |
584 std::vector<std::string> documentUrls5; | 604 std::vector<std::string> documentUrls5; |
585 documentUrls5.push_back("http://ads.com/frame/"); | 605 documentUrls5.push_back("http://ads.com/frame/"); |
586 documentUrls5.push_back("http://example.org/"); | 606 documentUrls5.push_back("http://example.org/"); |
587 documentUrls5.push_back("http://example.com/"); | 607 documentUrls5.push_back("http://example.com/"); |
588 AdblockPlus::FilterPtr match5 = | 608 AdblockPlus::FilterPtr match5 = |
589 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, | 609 filterEngine.Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngin
e::CONTENT_TYPE_IMAGE, |
590 documentUrls5); | 610 documentUrls5); |
591 ASSERT_TRUE(match5); | 611 ASSERT_TRUE(match5); |
592 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType()); | 612 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType()); |
593 } | 613 } |
594 | 614 |
595 TEST_F(FilterEngineTest, FirstRunFlag) | 615 TEST_F(FilterEngineTest, FirstRunFlag) |
596 { | 616 { |
597 ASSERT_FALSE(filterEngine->IsFirstRun()); | 617 ASSERT_FALSE(GetFilterEngine().IsFirstRun()); |
598 } | 618 } |
599 | 619 |
600 TEST_F(FilterEngineTestNoData, FirstRunFlag) | 620 TEST_F(FilterEngineTestNoData, FirstRunFlag) |
601 { | 621 { |
602 ASSERT_TRUE(filterEngine->IsFirstRun()); | 622 ASSERT_TRUE(GetFilterEngine().IsFirstRun()); |
603 } | 623 } |
604 | 624 |
605 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback) | 625 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback) |
606 { | 626 { |
| 627 auto& filterEngine = GetFilterEngine(); |
607 int timesCalled = 0; | 628 int timesCalled = 0; |
608 filterEngine->SetFilterChangeCallback([×Called](const std::string&, Adblo
ckPlus::JsValue&&) | 629 filterEngine.SetFilterChangeCallback([×Called](const std::string&, Adbloc
kPlus::JsValue&&) |
609 { | 630 { |
610 timesCalled++; | 631 timesCalled++; |
611 }); | 632 }); |
612 filterEngine->GetFilter("foo").AddToList(); | 633 filterEngine.GetFilter("foo").AddToList(); |
613 EXPECT_EQ(1, timesCalled); | 634 EXPECT_EQ(1, timesCalled); |
614 | 635 |
615 // we want to actually check the call count didn't change. | 636 // we want to actually check the call count didn't change. |
616 filterEngine->RemoveFilterChangeCallback(); | 637 filterEngine.RemoveFilterChangeCallback(); |
617 filterEngine->GetFilter("foo").RemoveFromList(); | 638 filterEngine.GetFilter("foo").RemoveFromList(); |
618 EXPECT_EQ(1, timesCalled); | 639 EXPECT_EQ(1, timesCalled); |
619 } | 640 } |
620 | 641 |
621 TEST_F(FilterEngineTest, DocumentWhitelisting) | 642 TEST_F(FilterEngineTest, DocumentWhitelisting) |
622 { | 643 { |
623 filterEngine->GetFilter("@@||example.org^$document").AddToList(); | 644 auto& filterEngine = GetFilterEngine(); |
624 filterEngine->GetFilter("@@||example.com^$document,domain=example.de").AddToLi
st(); | 645 filterEngine.GetFilter("@@||example.org^$document").AddToList(); |
| 646 filterEngine.GetFilter("@@||example.com^$document,domain=example.de").AddToLis
t(); |
625 | 647 |
626 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted( | 648 ASSERT_TRUE(filterEngine.IsDocumentWhitelisted( |
627 "http://example.org", | 649 "http://example.org", |
628 std::vector<std::string>())); | 650 std::vector<std::string>())); |
629 | 651 |
630 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted( | 652 ASSERT_FALSE(filterEngine.IsDocumentWhitelisted( |
631 "http://example.co.uk", | 653 "http://example.co.uk", |
632 std::vector<std::string>())); | 654 std::vector<std::string>())); |
633 | 655 |
634 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted( | 656 ASSERT_FALSE(filterEngine.IsDocumentWhitelisted( |
635 "http://example.com", | 657 "http://example.com", |
636 std::vector<std::string>())); | 658 std::vector<std::string>())); |
637 | 659 |
638 std::vector<std::string> documentUrls1; | 660 std::vector<std::string> documentUrls1; |
639 documentUrls1.push_back("http://example.de"); | 661 documentUrls1.push_back("http://example.de"); |
640 | 662 |
641 ASSERT_TRUE(filterEngine->IsDocumentWhitelisted( | 663 ASSERT_TRUE(filterEngine.IsDocumentWhitelisted( |
642 "http://example.com", | 664 "http://example.com", |
643 documentUrls1)); | 665 documentUrls1)); |
644 | 666 |
645 ASSERT_FALSE(filterEngine->IsDocumentWhitelisted( | 667 ASSERT_FALSE(filterEngine.IsDocumentWhitelisted( |
646 "http://example.co.uk", | 668 "http://example.co.uk", |
647 documentUrls1)); | 669 documentUrls1)); |
648 } | 670 } |
649 | 671 |
650 TEST_F(FilterEngineTest, ElemhideWhitelisting) | 672 TEST_F(FilterEngineTest, ElemhideWhitelisting) |
651 { | 673 { |
652 filterEngine->GetFilter("@@||example.org^$elemhide").AddToList(); | 674 auto& filterEngine = GetFilterEngine(); |
653 filterEngine->GetFilter("@@||example.com^$elemhide,domain=example.de").AddToLi
st(); | 675 filterEngine.GetFilter("@@||example.org^$elemhide").AddToList(); |
| 676 filterEngine.GetFilter("@@||example.com^$elemhide,domain=example.de").AddToLis
t(); |
654 | 677 |
655 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted( | 678 ASSERT_TRUE(filterEngine.IsElemhideWhitelisted( |
656 "http://example.org", | 679 "http://example.org", |
657 std::vector<std::string>())); | 680 std::vector<std::string>())); |
658 | 681 |
659 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted( | 682 ASSERT_FALSE(filterEngine.IsElemhideWhitelisted( |
660 "http://example.co.uk", | 683 "http://example.co.uk", |
661 std::vector<std::string>())); | 684 std::vector<std::string>())); |
662 | 685 |
663 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted( | 686 ASSERT_FALSE(filterEngine.IsElemhideWhitelisted( |
664 "http://example.com", | 687 "http://example.com", |
665 std::vector<std::string>())); | 688 std::vector<std::string>())); |
666 | 689 |
667 std::vector<std::string> documentUrls1; | 690 std::vector<std::string> documentUrls1; |
668 documentUrls1.push_back("http://example.de"); | 691 documentUrls1.push_back("http://example.de"); |
669 | 692 |
670 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted( | 693 ASSERT_TRUE(filterEngine.IsElemhideWhitelisted( |
671 "http://example.com", | 694 "http://example.com", |
672 documentUrls1)); | 695 documentUrls1)); |
673 | 696 |
674 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted( | 697 ASSERT_FALSE(filterEngine.IsElemhideWhitelisted( |
675 "http://example.co.uk", | 698 "http://example.co.uk", |
676 documentUrls1)); | 699 documentUrls1)); |
677 } | 700 } |
678 | 701 |
679 TEST_F(FilterEngineWithFreshFolder, LangAndAASubscriptionsAreChosenOnFirstRun) | 702 TEST_F(FilterEngineWithFreshFolder, LangAndAASubscriptionsAreChosenOnFirstRun) |
680 { | 703 { |
681 AppInfo appInfo; | 704 AppInfo appInfo; |
682 appInfo.locale = "zh"; | 705 appInfo.locale = "zh"; |
683 const std::string langSubscriptionUrl = "https://easylist-downloads.adblockplu
s.org/easylistchina+easylist.txt"; | 706 const std::string langSubscriptionUrl = "https://easylist-downloads.adblockplu
s.org/easylistchina+easylist.txt"; |
684 InitPlatformAndAppInfo(appInfo); | 707 InitPlatformAndAppInfo(appInfo); |
685 auto filterEngine = CreateFilterEngine(); | 708 auto& filterEngine = CreateFilterEngine(); |
686 const auto subscriptions = filterEngine->GetListedSubscriptions(); | 709 const auto subscriptions = filterEngine.GetListedSubscriptions(); |
687 ASSERT_EQ(2u, subscriptions.size()); | 710 ASSERT_EQ(2u, subscriptions.size()); |
688 std::unique_ptr<Subscription> aaSubscription; | 711 std::unique_ptr<Subscription> aaSubscription; |
689 std::unique_ptr<Subscription> langSubscription; | 712 std::unique_ptr<Subscription> langSubscription; |
690 if (subscriptions[0].IsAA()) | 713 if (subscriptions[0].IsAA()) |
691 { | 714 { |
692 aaSubscription.reset(new Subscription(subscriptions[0])); | 715 aaSubscription.reset(new Subscription(subscriptions[0])); |
693 langSubscription.reset(new Subscription(subscriptions[1])); | 716 langSubscription.reset(new Subscription(subscriptions[1])); |
694 } | 717 } |
695 else if (subscriptions[1].IsAA()) | 718 else if (subscriptions[1].IsAA()) |
696 { | 719 { |
697 aaSubscription.reset(new Subscription(subscriptions[1])); | 720 aaSubscription.reset(new Subscription(subscriptions[1])); |
698 langSubscription.reset(new Subscription(subscriptions[0])); | 721 langSubscription.reset(new Subscription(subscriptions[0])); |
699 } | 722 } |
700 ASSERT_NE(nullptr, aaSubscription); | 723 ASSERT_NE(nullptr, aaSubscription); |
701 ASSERT_NE(nullptr, langSubscription); | 724 ASSERT_NE(nullptr, langSubscription); |
702 EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url").AsString()
); | 725 EXPECT_EQ(langSubscriptionUrl, langSubscription->GetProperty("url").AsString()
); |
703 EXPECT_TRUE(filterEngine->IsAAEnabled()); | 726 EXPECT_TRUE(filterEngine.IsAAEnabled()); |
704 } | 727 } |
705 | 728 |
706 TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun) | 729 TEST_F(FilterEngineWithFreshFolder, DisableSubscriptionsAutoSelectOnFirstRun) |
707 { | 730 { |
708 InitPlatformAndAppInfo(); | 731 InitPlatformAndAppInfo(); |
709 FilterEngine::CreationParameters createParams; | 732 FilterEngine::CreationParameters createParams; |
710 createParams.preconfiguredPrefs.emplace("first_run_subscription_auto_select",
GetJsEngine().NewValue(false)); | 733 createParams.preconfiguredPrefs.emplace("first_run_subscription_auto_select",
GetJsEngine().NewValue(false)); |
711 auto filterEngine = CreateFilterEngine(createParams); | 734 auto& filterEngine = CreateFilterEngine(createParams); |
712 const auto subscriptions = filterEngine->GetListedSubscriptions(); | 735 const auto subscriptions = filterEngine.GetListedSubscriptions(); |
713 EXPECT_EQ(0u, subscriptions.size()); | 736 EXPECT_EQ(0u, subscriptions.size()); |
714 EXPECT_FALSE(filterEngine->IsAAEnabled()); | 737 EXPECT_FALSE(filterEngine.IsAAEnabled()); |
715 } | 738 } |
716 | 739 |
717 namespace AA_ApiTest | 740 namespace AA_ApiTest |
718 { | 741 { |
719 const std::string kOtherSubscriptionUrl = "https://non-existing-subscription.t
xt"; | 742 const std::string kOtherSubscriptionUrl = "https://non-existing-subscription.t
xt"; |
720 enum class AAStatus | 743 enum class AAStatus |
721 { | 744 { |
722 absent, | 745 absent, |
723 enabled, | 746 enabled, |
724 disabled_present | 747 disabled_present |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 return retValue; | 872 return retValue; |
850 } | 873 } |
851 protected: | 874 protected: |
852 void init(AAStatus aaStatus, uint8_t otherSubscriptionsNumber) | 875 void init(AAStatus aaStatus, uint8_t otherSubscriptionsNumber) |
853 { | 876 { |
854 // for the sake of simplicity test only with one suplimentary subscription | 877 // for the sake of simplicity test only with one suplimentary subscription |
855 ASSERT_TRUE(otherSubscriptionsNumber == 0u || otherSubscriptionsNumber ==
1u); | 878 ASSERT_TRUE(otherSubscriptionsNumber == 0u || otherSubscriptionsNumber ==
1u); |
856 | 879 |
857 // this method also tests the result of intermediate steps. | 880 // this method also tests the result of intermediate steps. |
858 | 881 |
| 882 auto& filterEngine = GetFilterEngine(); |
859 { | 883 { |
860 // no subscription (because of preconfigured prefs.json and patterns.ini
), | 884 // no subscription (because of preconfigured prefs.json and patterns.ini
), |
861 // though it should be enabled by default in a non-test environment, it'
s tested in | 885 // though it should be enabled by default in a non-test environment, it'
s tested in |
862 // corresponding tests. | 886 // corresponding tests. |
863 const auto subscriptions = filterEngine->GetListedSubscriptions(); | 887 const auto subscriptions = filterEngine.GetListedSubscriptions(); |
864 EXPECT_EQ(0u, subscriptions.size()); // no any subscription including AA | 888 EXPECT_EQ(0u, subscriptions.size()); // no any subscription including AA |
865 EXPECT_FALSE(filterEngine->IsAAEnabled()); | 889 EXPECT_FALSE(filterEngine.IsAAEnabled()); |
866 } | 890 } |
867 if (otherSubscriptionsNumber == 1u) | 891 if (otherSubscriptionsNumber == 1u) |
868 { | 892 { |
869 auto subscription = filterEngine->GetSubscription(kOtherSubscriptionUrl)
; | 893 auto subscription = filterEngine.GetSubscription(kOtherSubscriptionUrl); |
870 subscription.AddToList(); | 894 subscription.AddToList(); |
871 const auto subscriptions = filterEngine->GetListedSubscriptions(); | 895 const auto subscriptions = filterEngine.GetListedSubscriptions(); |
872 ASSERT_EQ(1u, subscriptions.size()); | 896 ASSERT_EQ(1u, subscriptions.size()); |
873 EXPECT_FALSE(subscriptions[0].IsAA()); | 897 EXPECT_FALSE(subscriptions[0].IsAA()); |
874 EXPECT_EQ(kOtherSubscriptionUrl, subscriptions[0].GetProperty("url").AsS
tring()); | 898 EXPECT_EQ(kOtherSubscriptionUrl, subscriptions[0].GetProperty("url").AsS
tring()); |
875 } | 899 } |
876 if (isAASatusPresent(aaStatus)) | 900 if (isAASatusPresent(aaStatus)) |
877 { | 901 { |
878 filterEngine->SetAAEnabled(true); // add AA by enabling it | 902 filterEngine.SetAAEnabled(true); // add AA by enabling it |
879 if (aaStatus == AAStatus::disabled_present) | 903 if (aaStatus == AAStatus::disabled_present) |
880 { | 904 { |
881 filterEngine->SetAAEnabled(false); | 905 filterEngine.SetAAEnabled(false); |
882 } | 906 } |
883 testSubscriptionState(aaStatus, otherSubscriptionsNumber); | 907 testSubscriptionState(aaStatus, otherSubscriptionsNumber); |
884 } | 908 } |
885 } | 909 } |
886 bool isAASatusPresent(AAStatus aaStatus) | 910 bool isAASatusPresent(AAStatus aaStatus) |
887 { | 911 { |
888 return aaStatus != AAStatus::absent; | 912 return aaStatus != AAStatus::absent; |
889 } | 913 } |
890 void testSubscriptionState(AAStatus aaStatus, int otherSubscriptionsNumber) | 914 void testSubscriptionState(AAStatus aaStatus, int otherSubscriptionsNumber) |
891 { | 915 { |
| 916 auto& filterEngine = GetFilterEngine(); |
892 if (aaStatus == AAStatus::enabled) | 917 if (aaStatus == AAStatus::enabled) |
893 EXPECT_TRUE(filterEngine->IsAAEnabled()); | 918 EXPECT_TRUE(filterEngine.IsAAEnabled()); |
894 else | 919 else |
895 EXPECT_FALSE(filterEngine->IsAAEnabled()); | 920 EXPECT_FALSE(filterEngine.IsAAEnabled()); |
896 | 921 |
897 std::unique_ptr<Subscription> aaSubscription; | 922 std::unique_ptr<Subscription> aaSubscription; |
898 std::unique_ptr<Subscription> otherSubscription; | 923 std::unique_ptr<Subscription> otherSubscription; |
899 auto subscriptions = filterEngine->GetListedSubscriptions(); | 924 auto subscriptions = filterEngine.GetListedSubscriptions(); |
900 for (auto& subscription : subscriptions) | 925 for (auto& subscription : subscriptions) |
901 { | 926 { |
902 auto& dstSubscription = subscription.IsAA() ? aaSubscription : otherSubs
cription; | 927 auto& dstSubscription = subscription.IsAA() ? aaSubscription : otherSubs
cription; |
903 dstSubscription.reset(new Subscription(std::move(subscription))); | 928 dstSubscription.reset(new Subscription(std::move(subscription))); |
904 } | 929 } |
905 if (otherSubscriptionsNumber == 1u) | 930 if (otherSubscriptionsNumber == 1u) |
906 { | 931 { |
907 if (isAASatusPresent(aaStatus)) | 932 if (isAASatusPresent(aaStatus)) |
908 { | 933 { |
909 EXPECT_EQ(2u, subscriptions.size()); | 934 EXPECT_EQ(2u, subscriptions.size()); |
(...skipping 23 matching lines...) Expand all Loading... |
933 } | 958 } |
934 }; | 959 }; |
935 | 960 |
936 INSTANTIATE_TEST_CASE_P(AA_ApiTests, Test, | 961 INSTANTIATE_TEST_CASE_P(AA_ApiTests, Test, |
937 ::testing::Combine(::testing::ValuesIn(Test::VaryPossibleCases()), ::testing
::Values<uint8_t>(0, 1))); | 962 ::testing::Combine(::testing::ValuesIn(Test::VaryPossibleCases()), ::testing
::Values<uint8_t>(0, 1))); |
938 | 963 |
939 TEST_P(Test, VaryPossibleCases) { | 964 TEST_P(Test, VaryPossibleCases) { |
940 const auto parameter = ::testing::get<0>(GetParam()); | 965 const auto parameter = ::testing::get<0>(GetParam()); |
941 uint8_t otherSubscriptionsNumber = ::testing::get<1>(GetParam()); | 966 uint8_t otherSubscriptionsNumber = ::testing::get<1>(GetParam()); |
942 init(parameter.initialAAStatus, otherSubscriptionsNumber); | 967 init(parameter.initialAAStatus, otherSubscriptionsNumber); |
| 968 auto& filterEngine = GetFilterEngine(); |
943 | 969 |
944 if (parameter.action == Action::enable) | 970 if (parameter.action == Action::enable) |
945 filterEngine->SetAAEnabled(true); | 971 filterEngine.SetAAEnabled(true); |
946 else if (parameter.action == Action::disable) | 972 else if (parameter.action == Action::disable) |
947 filterEngine->SetAAEnabled(false); | 973 filterEngine.SetAAEnabled(false); |
948 else if (parameter.action == Action::remove) | 974 else if (parameter.action == Action::remove) |
949 { | 975 { |
950 std::unique_ptr<Subscription> aaSubscription; | 976 std::unique_ptr<Subscription> aaSubscription; |
951 for (auto& subscription : filterEngine->GetListedSubscriptions()) | 977 for (auto& subscription : filterEngine.GetListedSubscriptions()) |
952 { | 978 { |
953 if (subscription.IsAA()) | 979 if (subscription.IsAA()) |
954 { | 980 { |
955 aaSubscription.reset(new Subscription(std::move(subscription))); | 981 aaSubscription.reset(new Subscription(std::move(subscription))); |
956 break; | 982 break; |
957 } | 983 } |
958 } | 984 } |
959 ASSERT_TRUE(aaSubscription); | 985 ASSERT_TRUE(aaSubscription); |
960 aaSubscription->RemoveFromList(); | 986 aaSubscription->RemoveFromList(); |
961 } | 987 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); | 1026 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); |
1001 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStrin
g()); | 1027 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStrin
g()); |
1002 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 1028 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); |
1003 ASSERT_EQ(1u, capturedConnectionTypes.size()); | 1029 ASSERT_EQ(1u, capturedConnectionTypes.size()); |
1004 EXPECT_TRUE(capturedConnectionTypes[0].first); | 1030 EXPECT_TRUE(capturedConnectionTypes[0].first); |
1005 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second); | 1031 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second); |
1006 } | 1032 } |
1007 | 1033 |
1008 TEST_F(FilterEngineIsSubscriptionDownloadAllowedTest, ConfiguredConnectionTypeIs
PassedToCallback) | 1034 TEST_F(FilterEngineIsSubscriptionDownloadAllowedTest, ConfiguredConnectionTypeIs
PassedToCallback) |
1009 { | 1035 { |
1010 // FilterEngine->RemoveSubscription is not usable here because subscriptions | 1036 // FilterEngine::RemoveSubscription is not usable here because subscriptions |
1011 // are cached internally by URL. So, different URLs are used in diffirent | 1037 // are cached internally by URL. So, different URLs are used in diffirent |
1012 // checks. | 1038 // checks. |
1013 { | 1039 { |
1014 std::string predefinedAllowedConnectionType = "non-metered"; | 1040 std::string predefinedAllowedConnectionType = "non-metered"; |
1015 createParams.preconfiguredPrefs.insert(std::make_pair( | 1041 createParams.preconfiguredPrefs.insert(std::make_pair( |
1016 "allowed_connection_type", GetJsEngine().NewValue(predefinedAllowedConnect
ionType))); | 1042 "allowed_connection_type", GetJsEngine().NewValue(predefinedAllowedConnect
ionType))); |
1017 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); | 1043 auto subscription = EnsureExampleSubscriptionAndForceUpdate(); |
1018 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
ing()); | 1044 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
ing()); |
1019 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 1045 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); |
1020 ASSERT_EQ(1u, capturedConnectionTypes.size()); | 1046 ASSERT_EQ(1u, capturedConnectionTypes.size()); |
1021 EXPECT_TRUE(capturedConnectionTypes[0].first); | 1047 EXPECT_TRUE(capturedConnectionTypes[0].first); |
1022 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second
); | 1048 EXPECT_EQ(predefinedAllowedConnectionType, capturedConnectionTypes[0].second
); |
1023 } | 1049 } |
1024 capturedConnectionTypes.clear(); | 1050 capturedConnectionTypes.clear(); |
1025 { | 1051 { |
1026 // set no value | 1052 // set no value |
1027 filterEngine->SetAllowedConnectionType(nullptr); | 1053 GetFilterEngine().SetAllowedConnectionType(nullptr); |
1028 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subA"); | 1054 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subA"); |
1029 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
ing()); | 1055 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
ing()); |
1030 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 1056 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); |
1031 ASSERT_EQ(1u, capturedConnectionTypes.size()); | 1057 ASSERT_EQ(1u, capturedConnectionTypes.size()); |
1032 EXPECT_FALSE(capturedConnectionTypes[0].first); | 1058 EXPECT_FALSE(capturedConnectionTypes[0].first); |
1033 subscription.RemoveFromList(); | 1059 subscription.RemoveFromList(); |
1034 } | 1060 } |
1035 capturedConnectionTypes.clear(); | 1061 capturedConnectionTypes.clear(); |
1036 { | 1062 { |
1037 // set some value | 1063 // set some value |
1038 std::string testConnection = "test connection"; | 1064 std::string testConnection = "test connection"; |
1039 filterEngine->SetAllowedConnectionType(&testConnection); | 1065 GetFilterEngine().SetAllowedConnectionType(&testConnection); |
1040 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); | 1066 auto subscription = EnsureExampleSubscriptionAndForceUpdate("subB"); |
1041 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
ing()); | 1067 EXPECT_EQ("synchronize_ok", subscription.GetProperty("downloadStatus").AsStr
ing()); |
1042 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); | 1068 EXPECT_EQ(1u, subscription.GetProperty("filters").AsList().size()); |
1043 ASSERT_EQ(1u, capturedConnectionTypes.size()); | 1069 ASSERT_EQ(1u, capturedConnectionTypes.size()); |
1044 EXPECT_TRUE(capturedConnectionTypes[0].first); | 1070 EXPECT_TRUE(capturedConnectionTypes[0].first); |
1045 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); | 1071 EXPECT_EQ(testConnection, capturedConnectionTypes[0].second); |
1046 } | 1072 } |
1047 } | 1073 } |
OLD | NEW |