| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include "BaseJsTest.h" | 18 #include "BaseJsTest.h" |
| 19 | 19 |
| 20 namespace | 20 namespace |
| 21 { | 21 { |
| 22 typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; | 22 typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; |
| 23 | 23 |
| 24 class VeryLazyFileSystem : public LazyFileSystem | 24 class VeryLazyFileSystem : public LazyFileSystem |
| 25 { | 25 { |
| 26 public: | 26 public: |
| 27 std::tr1::shared_ptr<std::istream> Read(const std::string& path) const | 27 StatResult Stat(const std::string& path) const |
| 28 { | 28 { |
| 29 std::string dummyData("# Adblock Plus preferences"); | 29 return StatResult(); |
| 30 return std::tr1::shared_ptr<std::istream>(new std::istringstream(dummyData
)); | |
| 31 } | 30 } |
| 32 }; | 31 }; |
| 33 | 32 |
| 34 template<class FileSystem, class LogSystem> | 33 template<class FileSystem, class LogSystem> |
| 35 class FilterEngineTestGeneric : public BaseJsTest | 34 class FilterEngineTestGeneric : public BaseJsTest |
| 36 { | 35 { |
| 37 protected: | 36 protected: |
| 38 FilterEnginePtr filterEngine; | 37 FilterEnginePtr filterEngine; |
| 39 | 38 |
| 40 void SetUp() | 39 void SetUp() |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 subscription->SetProperty("stringFoo", "y"); | 113 subscription->SetProperty("stringFoo", "y"); |
| 115 subscription->SetProperty("intFoo", 24); | 114 subscription->SetProperty("intFoo", 24); |
| 116 subscription->SetProperty("boolFoo", true); | 115 subscription->SetProperty("boolFoo", true); |
| 117 ASSERT_EQ("y", subscription->GetProperty("stringFoo")->AsString()); | 116 ASSERT_EQ("y", subscription->GetProperty("stringFoo")->AsString()); |
| 118 ASSERT_EQ(24, subscription->GetProperty("intFoo")->AsInt()); | 117 ASSERT_EQ(24, subscription->GetProperty("intFoo")->AsInt()); |
| 119 ASSERT_TRUE(subscription->GetProperty("boolFoo")->AsBool()); | 118 ASSERT_TRUE(subscription->GetProperty("boolFoo")->AsBool()); |
| 120 } | 119 } |
| 121 | 120 |
| 122 TEST_F(FilterEngineTest, AddRemoveSubscriptions) | 121 TEST_F(FilterEngineTest, AddRemoveSubscriptions) |
| 123 { | 122 { |
| 124 // There should be only the default subscription initially | 123 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); |
| 125 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); | |
| 126 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo
"); | 124 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo
"); |
| 127 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); | 125 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); |
| 128 ASSERT_FALSE(subscription->IsListed()); | 126 ASSERT_FALSE(subscription->IsListed()); |
| 129 subscription->AddToList(); | 127 subscription->AddToList(); |
| 130 ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size()); | 128 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); |
| 131 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]); | 129 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]); |
| 132 ASSERT_TRUE(subscription->IsListed()); | 130 ASSERT_TRUE(subscription->IsListed()); |
| 133 subscription->AddToList(); | 131 subscription->AddToList(); |
| 134 ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size()); | 132 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); |
| 135 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]); | 133 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]); |
| 136 ASSERT_TRUE(subscription->IsListed()); | 134 ASSERT_TRUE(subscription->IsListed()); |
| 137 subscription->RemoveFromList(); | 135 subscription->RemoveFromList(); |
| 138 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); | 136 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); |
| 139 ASSERT_FALSE(subscription->IsListed()); | 137 ASSERT_FALSE(subscription->IsListed()); |
| 140 subscription->RemoveFromList(); | 138 subscription->RemoveFromList(); |
| 141 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); | 139 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); |
| 142 ASSERT_FALSE(subscription->IsListed()); | 140 ASSERT_FALSE(subscription->IsListed()); |
| 143 } | 141 } |
| 144 | 142 |
| 145 TEST_F(FilterEngineTest, SubscriptionUpdates) | 143 TEST_F(FilterEngineTest, SubscriptionUpdates) |
| 146 { | 144 { |
| 147 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo
"); | 145 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo
"); |
| 148 ASSERT_FALSE(subscription->IsUpdating()); | 146 ASSERT_FALSE(subscription->IsUpdating()); |
| 149 subscription->UpdateFilters(); | 147 subscription->UpdateFilters(); |
| 150 } | 148 } |
| 151 | 149 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType()); | 302 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType()); |
| 305 } | 303 } |
| 306 | 304 |
| 307 TEST_F(FilterEngineTest, FirstRunFlag) | 305 TEST_F(FilterEngineTest, FirstRunFlag) |
| 308 { | 306 { |
| 309 ASSERT_FALSE(filterEngine->IsFirstRun()); | 307 ASSERT_FALSE(filterEngine->IsFirstRun()); |
| 310 } | 308 } |
| 311 | 309 |
| 312 TEST_F(FilterEngineTestNoData, FirstRunFlag) | 310 TEST_F(FilterEngineTestNoData, FirstRunFlag) |
| 313 { | 311 { |
| 314 ASSERT_FALSE(filterEngine->IsFirstRun()); | 312 ASSERT_TRUE(filterEngine->IsFirstRun()); |
| 315 } | 313 } |
| OLD | NEW |