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

Side by Side Diff: test/FilterEngine.cpp

Issue 10862008: Automatically add default filter subscription when necessary. (Closed)
Patch Set: Created May 27, 2013, 2:12 p.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 | « test/BaseJsTest.h ('k') | test/JsEngine.cpp » ('j') | 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 FilterEngineTest : public BaseJsTest 24 class VeryLazyFileSystem : public LazyFileSystem
25 {
26 std::tr1::shared_ptr<std::istream> Read(const std::string& path) const
27 {
28 std::string dummyData("# Adblock Plus preferences");
29 return std::tr1::shared_ptr<std::istream>(new std::istringstream(dummyData ));
30 }
31 };
32
33 template<class FileSystem, class LogSystem>
34 class FilterEngineTestGeneric : public BaseJsTest
25 { 35 {
26 protected: 36 protected:
27 FilterEnginePtr filterEngine; 37 FilterEnginePtr filterEngine;
28 38
29 void SetUp() 39 void SetUp()
30 { 40 {
31 BaseJsTest::SetUp(); 41 BaseJsTest::SetUp();
32 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); 42 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem));
33 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); 43 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest));
34 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new AdblockPlus::DefaultL ogSystem)); 44 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem));
35 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); 45 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
36 } 46 }
37 }; 47 };
48
49 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem> FilterEngineTest;
50 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin eTestNoData;
38 } 51 }
39 52
40 TEST_F(FilterEngineTest, FilterCreation) 53 TEST_F(FilterEngineTest, FilterCreation)
41 { 54 {
42 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); 55 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo");
43 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); 56 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType());
44 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); 57 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo");
45 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); 58 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType());
46 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); 59 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo");
47 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); 60 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 subscription->SetProperty("stringFoo", "y"); 108 subscription->SetProperty("stringFoo", "y");
96 subscription->SetProperty("intFoo", 24); 109 subscription->SetProperty("intFoo", 24);
97 subscription->SetProperty("boolFoo", true); 110 subscription->SetProperty("boolFoo", true);
98 ASSERT_EQ("y", subscription->GetProperty("stringFoo")->AsString()); 111 ASSERT_EQ("y", subscription->GetProperty("stringFoo")->AsString());
99 ASSERT_EQ(24, subscription->GetProperty("intFoo")->AsInt()); 112 ASSERT_EQ(24, subscription->GetProperty("intFoo")->AsInt());
100 ASSERT_TRUE(subscription->GetProperty("boolFoo")->AsBool()); 113 ASSERT_TRUE(subscription->GetProperty("boolFoo")->AsBool());
101 } 114 }
102 115
103 TEST_F(FilterEngineTest, AddRemoveSubscriptions) 116 TEST_F(FilterEngineTest, AddRemoveSubscriptions)
104 { 117 {
105 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); 118 // There should be only the default subscription initially
119 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
106 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo "); 120 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo ");
107 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size()); 121 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
108 subscription->AddToList(); 122 subscription->AddToList();
123 ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size());
124 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]);
125 subscription->AddToList();
126 ASSERT_EQ(2u, filterEngine->GetListedSubscriptions().size());
127 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[1]);
128 subscription->RemoveFromList();
109 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); 129 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
110 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]); 130 subscription->RemoveFromList();
111 subscription->AddToList();
112 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size()); 131 ASSERT_EQ(1u, filterEngine->GetListedSubscriptions().size());
113 ASSERT_EQ(*subscription, *filterEngine->GetListedSubscriptions()[0]);
114 subscription->RemoveFromList();
115 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
116 subscription->RemoveFromList();
117 ASSERT_EQ(0u, filterEngine->GetListedSubscriptions().size());
118 } 132 }
119 133
120 TEST_F(FilterEngineTest, SubscriptionUpdates) 134 TEST_F(FilterEngineTest, SubscriptionUpdates)
121 { 135 {
122 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo "); 136 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription("foo ");
123 ASSERT_FALSE(subscription->IsUpdating()); 137 ASSERT_FALSE(subscription->IsUpdating());
124 subscription->UpdateFilters(); 138 subscription->UpdateFilters();
125 } 139 }
126 140
127 TEST_F(FilterEngineTest, Matches) 141 TEST_F(FilterEngineTest, Matches)
(...skipping 25 matching lines...) Expand all
153 ASSERT_TRUE(match6); 167 ASSERT_TRUE(match6);
154 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); 168 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
155 169
156 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.com/"); 170 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.com/");
157 ASSERT_TRUE(match7); 171 ASSERT_TRUE(match7);
158 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); 172 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
159 173
160 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.com/"); 174 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.com/");
161 ASSERT_FALSE(match8); 175 ASSERT_FALSE(match8);
162 } 176 }
177
178 TEST_F(FilterEngineTest, FirstRunFlag)
179 {
180 ASSERT_FALSE(filterEngine->IsFirstRun());
181 }
182
183 TEST_F(FilterEngineTestNoData, FirstRunFlag)
184 {
185 ASSERT_FALSE(filterEngine->IsFirstRun());
186 }
OLDNEW
« no previous file with comments | « test/BaseJsTest.h ('k') | test/JsEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld