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

Side by Side Diff: test/FilterEngineStubs.cpp

Issue 10198022: Pass application data into libadblockplus (Closed)
Patch Set: Merged upstream, addressed issues, renamed AppInfo fields Created April 17, 2013, 2:47 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
OLDNEW
1 #include <iostream> 1 #include <iostream>
2 #include <AdblockPlus.h> 2 #include <AdblockPlus.h>
3 #include <gtest/gtest.h> 3 #include <gtest/gtest.h>
4 4
5 class DummyFileSystem : public AdblockPlus::FileSystem 5 class DummyFileSystem : public AdblockPlus::FileSystem
6 { 6 {
7 std::tr1::shared_ptr<std::istream> Read(const std::string& path) const 7 std::tr1::shared_ptr<std::istream> Read(const std::string& path) const
8 { 8 {
9 throw std::runtime_error("Not implemented"); 9 throw std::runtime_error("Not implemented");
10 } 10 }
(...skipping 26 matching lines...) Expand all
37 void operator()(const std::string& message) 37 void operator()(const std::string& message)
38 { 38 {
39 std::cout << message << std::endl; 39 std::cout << message << std::endl;
40 } 40 }
41 }; 41 };
42 42
43 TEST(FilterEngineStubsTest, FilterCreation) 43 TEST(FilterEngineStubsTest, FilterCreation)
44 { 44 {
45 DummyFileSystem fileSystem; 45 DummyFileSystem fileSystem;
46 DummyErrorCallback errorCallback; 46 DummyErrorCallback errorCallback;
47 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); 47 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0,
48 &errorCallback);
48 AdblockPlus::FilterEngine filterEngine(jsEngine); 49 AdblockPlus::FilterEngine filterEngine(jsEngine);
49 50
50 AdblockPlus::FilterPtr filter1 = filterEngine.GetFilter("foo"); 51 AdblockPlus::FilterPtr filter1 = filterEngine.GetFilter("foo");
51 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetProperty("type", -1) ); 52 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetProperty("type", -1) );
52 AdblockPlus::FilterPtr filter2 = filterEngine.GetFilter("@@foo"); 53 AdblockPlus::FilterPtr filter2 = filterEngine.GetFilter("@@foo");
53 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetProperty("type", -1 )); 54 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetProperty("type", -1 ));
54 AdblockPlus::FilterPtr filter3 = filterEngine.GetFilter("example.com##foo"); 55 AdblockPlus::FilterPtr filter3 = filterEngine.GetFilter("example.com##foo");
55 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetProperty("type", -1) ); 56 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetProperty("type", -1) );
56 AdblockPlus::FilterPtr filter4 = filterEngine.GetFilter("example.com#@#foo"); 57 AdblockPlus::FilterPtr filter4 = filterEngine.GetFilter("example.com#@#foo");
57 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetProperty(" type", -1)); 58 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION, filter4->GetProperty(" type", -1));
58 AdblockPlus::FilterPtr filter5 = filterEngine.GetFilter(" foo "); 59 AdblockPlus::FilterPtr filter5 = filterEngine.GetFilter(" foo ");
59 ASSERT_EQ(*filter1, *filter5); 60 ASSERT_EQ(*filter1, *filter5);
60 } 61 }
61 62
62 TEST(FilterEngineStubsTest, FilterProperties) 63 TEST(FilterEngineStubsTest, FilterProperties)
63 { 64 {
64 DummyFileSystem fileSystem; 65 DummyFileSystem fileSystem;
65 DummyErrorCallback errorCallback; 66 DummyErrorCallback errorCallback;
66 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); 67 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0,
68 &errorCallback);
67 AdblockPlus::FilterEngine filterEngine(jsEngine); 69 AdblockPlus::FilterEngine filterEngine(jsEngine);
68 AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo"); 70 AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo");
69 71
70 ASSERT_EQ("x", filter->GetProperty("stringFoo", "x")); 72 ASSERT_EQ("x", filter->GetProperty("stringFoo", "x"));
71 ASSERT_EQ(42, filter->GetProperty("intFoo", 42)); 73 ASSERT_EQ(42, filter->GetProperty("intFoo", 42));
72 ASSERT_FALSE(filter->GetProperty("boolFoo", false)); 74 ASSERT_FALSE(filter->GetProperty("boolFoo", false));
73 75
74 filter->SetProperty("stringFoo", "y"); 76 filter->SetProperty("stringFoo", "y");
75 filter->SetProperty("intFoo", 24); 77 filter->SetProperty("intFoo", 24);
76 filter->SetProperty("boolFoo", true); 78 filter->SetProperty("boolFoo", true);
77 ASSERT_EQ("y", filter->GetProperty("stringFoo", "x")); 79 ASSERT_EQ("y", filter->GetProperty("stringFoo", "x"));
78 ASSERT_EQ(24, filter->GetProperty("intFoo", 42)); 80 ASSERT_EQ(24, filter->GetProperty("intFoo", 42));
79 ASSERT_TRUE(filter->GetProperty("boolFoo", false)); 81 ASSERT_TRUE(filter->GetProperty("boolFoo", false));
80 } 82 }
81 83
82 TEST(FilterEngineStubsTest, AddRemoveFilters) 84 TEST(FilterEngineStubsTest, AddRemoveFilters)
83 { 85 {
84 DummyFileSystem fileSystem; 86 DummyFileSystem fileSystem;
85 DummyErrorCallback errorCallback; 87 DummyErrorCallback errorCallback;
86 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); 88 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0,
89 &errorCallback);
87 AdblockPlus::FilterEngine filterEngine(jsEngine); 90 AdblockPlus::FilterEngine filterEngine(jsEngine);
88 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); 91 ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
89 AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo"); 92 AdblockPlus::FilterPtr filter = filterEngine.GetFilter("foo");
90 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); 93 ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
91 filter->AddToList(); 94 filter->AddToList();
92 ASSERT_EQ(1u, filterEngine.GetListedFilters().size()); 95 ASSERT_EQ(1u, filterEngine.GetListedFilters().size());
93 ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]); 96 ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]);
94 filter->AddToList(); 97 filter->AddToList();
95 ASSERT_EQ(1u, filterEngine.GetListedFilters().size()); 98 ASSERT_EQ(1u, filterEngine.GetListedFilters().size());
96 ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]); 99 ASSERT_EQ(*filter, *filterEngine.GetListedFilters()[0]);
97 filter->RemoveFromList(); 100 filter->RemoveFromList();
98 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); 101 ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
99 filter->RemoveFromList(); 102 filter->RemoveFromList();
100 ASSERT_EQ(0u, filterEngine.GetListedFilters().size()); 103 ASSERT_EQ(0u, filterEngine.GetListedFilters().size());
101 } 104 }
102 105
103 TEST(FilterEngineStubsTest, SubscriptionProperties) 106 TEST(FilterEngineStubsTest, SubscriptionProperties)
104 { 107 {
105 DummyFileSystem fileSystem; 108 DummyFileSystem fileSystem;
106 DummyErrorCallback errorCallback; 109 DummyErrorCallback errorCallback;
107 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); 110 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0,
111 &errorCallback);
108 AdblockPlus::FilterEngine filterEngine(jsEngine); 112 AdblockPlus::FilterEngine filterEngine(jsEngine);
109 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo" ); 113 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo" );
110 114
111 ASSERT_EQ("x", subscription->GetProperty("stringFoo", "x")); 115 ASSERT_EQ("x", subscription->GetProperty("stringFoo", "x"));
112 ASSERT_EQ(42, subscription->GetProperty("intFoo", 42)); 116 ASSERT_EQ(42, subscription->GetProperty("intFoo", 42));
113 ASSERT_FALSE(subscription->GetProperty("boolFoo", false)); 117 ASSERT_FALSE(subscription->GetProperty("boolFoo", false));
114 118
115 subscription->SetProperty("stringFoo", "y"); 119 subscription->SetProperty("stringFoo", "y");
116 subscription->SetProperty("intFoo", 24); 120 subscription->SetProperty("intFoo", 24);
117 subscription->SetProperty("boolFoo", true); 121 subscription->SetProperty("boolFoo", true);
118 ASSERT_EQ("y", subscription->GetProperty("stringFoo", "x")); 122 ASSERT_EQ("y", subscription->GetProperty("stringFoo", "x"));
119 ASSERT_EQ(24, subscription->GetProperty("intFoo", 42)); 123 ASSERT_EQ(24, subscription->GetProperty("intFoo", 42));
120 ASSERT_TRUE(subscription->GetProperty("boolFoo", false)); 124 ASSERT_TRUE(subscription->GetProperty("boolFoo", false));
121 } 125 }
122 126
123 TEST(FilterEngineStubsTest, AddRemoveSubscriptions) 127 TEST(FilterEngineStubsTest, AddRemoveSubscriptions)
124 { 128 {
125 DummyFileSystem fileSystem; 129 DummyFileSystem fileSystem;
126 DummyErrorCallback errorCallback; 130 DummyErrorCallback errorCallback;
127 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); 131 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0,
132 &errorCallback);
128 AdblockPlus::FilterEngine filterEngine(jsEngine); 133 AdblockPlus::FilterEngine filterEngine(jsEngine);
129 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); 134 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
130 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo" ); 135 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo" );
131 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); 136 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
132 subscription->AddToList(); 137 subscription->AddToList();
133 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size()); 138 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size());
134 ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]); 139 ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]);
135 subscription->AddToList(); 140 subscription->AddToList();
136 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size()); 141 ASSERT_EQ(1u, filterEngine.GetListedSubscriptions().size());
137 ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]); 142 ASSERT_EQ(*subscription, *filterEngine.GetListedSubscriptions()[0]);
138 subscription->RemoveFromList(); 143 subscription->RemoveFromList();
139 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); 144 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
140 subscription->RemoveFromList(); 145 subscription->RemoveFromList();
141 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size()); 146 ASSERT_EQ(0u, filterEngine.GetListedSubscriptions().size());
142 } 147 }
143 148
144 TEST(FilterEngineStubsTest, SubscriptionUpdates) 149 TEST(FilterEngineStubsTest, SubscriptionUpdates)
145 { 150 {
146 DummyFileSystem fileSystem; 151 DummyFileSystem fileSystem;
147 DummyErrorCallback errorCallback; 152 DummyErrorCallback errorCallback;
148 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); 153 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0,
154 &errorCallback);
149 AdblockPlus::FilterEngine filterEngine(jsEngine); 155 AdblockPlus::FilterEngine filterEngine(jsEngine);
150 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo" ); 156 AdblockPlus::SubscriptionPtr subscription = filterEngine.GetSubscription("foo" );
151 ASSERT_FALSE(subscription->IsUpdating()); 157 ASSERT_FALSE(subscription->IsUpdating());
152 158
153 //TODO: This currently crashes due to errors reported on a different thread 159 //TODO: This currently crashes due to errors reported on a different thread
154 //subscription->UpdateFilters(); 160 //subscription->UpdateFilters();
155 } 161 }
156 162
157 TEST(FilterEngineStubsTest, Matches) 163 TEST(FilterEngineStubsTest, Matches)
158 { 164 {
159 DummyFileSystem fileSystem; 165 DummyFileSystem fileSystem;
160 DummyErrorCallback errorCallback; 166 DummyErrorCallback errorCallback;
161 AdblockPlus::JsEngine jsEngine(&fileSystem, 0, &errorCallback); 167 AdblockPlus::JsEngine jsEngine(AdblockPlus::AppInfo(), &fileSystem, 0,
168 &errorCallback);
162 AdblockPlus::FilterEngine filterEngine(jsEngine); 169 AdblockPlus::FilterEngine filterEngine(jsEngine);
163 170
164 filterEngine.GetFilter("adbanner.gif")->AddToList(); 171 filterEngine.GetFilter("adbanner.gif")->AddToList();
165 filterEngine.GetFilter("@@notbanner.gif")->AddToList(); 172 filterEngine.GetFilter("@@notbanner.gif")->AddToList();
166 173
167 AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org/fooba r.gif", "IMAGE", ""); 174 AdblockPlus::FilterPtr match1 = filterEngine.Matches("http://example.org/fooba r.gif", "IMAGE", "");
168 ASSERT_FALSE(match1); 175 ASSERT_FALSE(match1);
169 176
170 AdblockPlus::FilterPtr match2 = filterEngine.Matches("http://example.org/adban ner.gif", "IMAGE", ""); 177 AdblockPlus::FilterPtr match2 = filterEngine.Matches("http://example.org/adban ner.gif", "IMAGE", "");
171 ASSERT_TRUE(match2); 178 ASSERT_TRUE(match2);
172 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetProperty("type", -1)) ; 179 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetProperty("type", -1)) ;
173 180
174 AdblockPlus::FilterPtr match3 = filterEngine.Matches("http://example.org/notba nner.gif", "IMAGE", ""); 181 AdblockPlus::FilterPtr match3 = filterEngine.Matches("http://example.org/notba nner.gif", "IMAGE", "");
175 ASSERT_TRUE(match3); 182 ASSERT_TRUE(match3);
176 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetProperty("type", -1) ); 183 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetProperty("type", -1) );
177 184
178 AdblockPlus::FilterPtr match4 = filterEngine.Matches("http://example.org/notba nner.gif", "IMAGE", ""); 185 AdblockPlus::FilterPtr match4 = filterEngine.Matches("http://example.org/notba nner.gif", "IMAGE", "");
179 ASSERT_TRUE(match4); 186 ASSERT_TRUE(match4);
180 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetProperty("type", -1) ); 187 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetProperty("type", -1) );
181 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld