| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 30 matching lines...) Expand all Loading... | |
| 41 BaseJsTest::SetUp(); | 41 BaseJsTest::SetUp(); |
| 42 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem)); | 42 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem)); |
| 43 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); | 43 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); |
| 44 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem)); | 44 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem)); |
| 45 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); | 45 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem> FilterEngineTest; | 49 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem> FilterEngineTest; |
| 50 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin eTestNoData; | 50 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin eTestNoData; |
| 51 | |
| 52 struct MockFilterChangeCallback | |
| 53 { | |
| 54 MockFilterChangeCallback(int& timesCalled) : timesCalled(timesCalled) {} | |
|
Felix Dahlke
2014/09/16 09:37:19
It's somewhat unintuitive that the functor doesn't
Wladimir Palant
2014/12/09 21:44:41
Yes, that's a footgun. Should we at least have a c
Felix Dahlke
2015/05/29 23:06:40
It just occurred to me that a shared_ptr should be
| |
| 55 | |
| 56 void operator()(const std::string&, const AdblockPlus::JsValuePtr) | |
| 57 { | |
| 58 timesCalled++; | |
| 59 } | |
| 60 | |
| 61 private: | |
| 62 int& timesCalled; | |
| 63 }; | |
| 51 } | 64 } |
| 52 | 65 |
| 53 TEST_F(FilterEngineTest, FilterCreation) | 66 TEST_F(FilterEngineTest, FilterCreation) |
| 54 { | 67 { |
| 55 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); | 68 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); |
| 56 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); | 69 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); |
| 57 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); | 70 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); |
| 58 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); | 71 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); |
| 59 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); | 72 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); |
| 60 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); | 73 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 | 317 |
| 305 TEST_F(FilterEngineTest, FirstRunFlag) | 318 TEST_F(FilterEngineTest, FirstRunFlag) |
| 306 { | 319 { |
| 307 ASSERT_FALSE(filterEngine->IsFirstRun()); | 320 ASSERT_FALSE(filterEngine->IsFirstRun()); |
| 308 } | 321 } |
| 309 | 322 |
| 310 TEST_F(FilterEngineTestNoData, FirstRunFlag) | 323 TEST_F(FilterEngineTestNoData, FirstRunFlag) |
| 311 { | 324 { |
| 312 ASSERT_TRUE(filterEngine->IsFirstRun()); | 325 ASSERT_TRUE(filterEngine->IsFirstRun()); |
| 313 } | 326 } |
| 327 | |
| 328 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback) | |
| 329 { | |
| 330 int timesCalled = 0; | |
| 331 MockFilterChangeCallback mockFilterChangeCallback(timesCalled); | |
| 332 | |
| 333 filterEngine->SetFilterChangeCallback(mockFilterChangeCallback); | |
| 334 filterEngine->GetSubscription("foo")->AddToList(); | |
|
Felix Dahlke
2014/09/16 09:37:19
I tried this with fitlerEngine->GetFilter("foo")->
Wladimir Palant
2014/12/09 21:44:41
Not really, no. If the filter was added it should
Felix Dahlke
2015/05/29 23:06:40
Debugged this a bit. filter.added is actually not
| |
| 335 ASSERT_EQ(1, timesCalled); | |
| 336 | |
| 337 filterEngine->RemoveFilterChangeCallback(); | |
| 338 filterEngine->GetSubscription("foo")->RemoveFromList(); | |
| 339 ASSERT_EQ(1, timesCalled); | |
| 340 } | |
| OLD | NEW |