LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 * |
(...skipping 27 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 class UpdaterTest : public ::testing::Test |
| 53 { |
| 54 protected: |
| 55 class MockWebRequest : public AdblockPlus::WebRequest |
| 56 { |
| 57 public: |
| 58 AdblockPlus::ServerResponse response; |
| 59 |
| 60 AdblockPlus::ServerResponse GET(const std::string& url, |
| 61 const AdblockPlus::HeaderList& requestHeaders) const |
| 62 { |
| 63 return response; |
| 64 } |
| 65 }; |
| 66 |
| 67 MockWebRequest* mockWebRequest; |
| 68 FilterEnginePtr filterEngine; |
| 69 |
| 70 void SetUp() |
| 71 { |
| 72 AdblockPlus::AppInfo appInfo; |
| 73 appInfo.name = "test"; |
| 74 appInfo.version = "1.0.1"; |
| 75 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); |
| 76 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); |
| 77 mockWebRequest = new MockWebRequest; |
| 78 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(mockWebRequest)); |
| 79 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); |
| 80 } |
| 81 }; |
| 82 |
| 83 struct MockUpdateAvailableCallback |
| 84 { |
| 85 MockUpdateAvailableCallback(int& timesCalled) : timesCalled(timesCalled) {} |
| 86 |
| 87 void operator()(const std::string&) |
| 88 { |
| 89 timesCalled++; |
| 90 } |
| 91 |
| 92 private: |
| 93 // We currently cannot store timesCalled in the functor, see: |
| 94 // https://issues.adblockplus.org/ticket/1378. |
| 95 int& timesCalled; |
| 96 }; |
| 97 |
| 98 // Workaround for https://issues.adblockplus.org/ticket/1397. |
| 99 void NoOpUpdaterCallback(const std::string&) {} |
51 } | 100 } |
52 | 101 |
53 TEST_F(FilterEngineTest, FilterCreation) | 102 TEST_F(FilterEngineTest, FilterCreation) |
54 { | 103 { |
55 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); | 104 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); |
56 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); | 105 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); |
57 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); | 106 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); |
58 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); | 107 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); |
59 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); | 108 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); |
60 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); | 109 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 198 |
150 TEST_F(FilterEngineTest, Matches) | 199 TEST_F(FilterEngineTest, Matches) |
151 { | 200 { |
152 filterEngine->GetFilter("adbanner.gif")->AddToList(); | 201 filterEngine->GetFilter("adbanner.gif")->AddToList(); |
153 filterEngine->GetFilter("@@notbanner.gif")->AddToList(); | 202 filterEngine->GetFilter("@@notbanner.gif")->AddToList(); |
154 filterEngine->GetFilter("tpbanner.gif$third-party")->AddToList(); | 203 filterEngine->GetFilter("tpbanner.gif$third-party")->AddToList(); |
155 filterEngine->GetFilter("fpbanner.gif$~third-party")->AddToList(); | 204 filterEngine->GetFilter("fpbanner.gif$~third-party")->AddToList(); |
156 filterEngine->GetFilter("combanner.gif$domain=example.com")->AddToList(); | 205 filterEngine->GetFilter("combanner.gif$domain=example.com")->AddToList(); |
157 filterEngine->GetFilter("orgbanner.gif$domain=~example.com")->AddToList(); | 206 filterEngine->GetFilter("orgbanner.gif$domain=~example.com")->AddToList(); |
158 | 207 |
159 AdblockPlus::FilterPtr match1 = filterEngine->Matches("http://example.org/foob
ar.gif", "IMAGE", ""); | 208 AdblockPlus::FilterPtr match1 = filterEngine->Matches("http://example.org/foob
ar.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); |
160 ASSERT_FALSE(match1); | 209 ASSERT_FALSE(match1); |
161 | 210 |
162 AdblockPlus::FilterPtr match2 = filterEngine->Matches("http://example.org/adba
nner.gif", "IMAGE", ""); | 211 AdblockPlus::FilterPtr match2 = filterEngine->Matches("http://example.org/adba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); |
163 ASSERT_TRUE(match2); | 212 ASSERT_TRUE(match2); |
164 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetType()); | 213 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match2->GetType()); |
165 | 214 |
166 AdblockPlus::FilterPtr match3 = filterEngine->Matches("http://example.org/notb
anner.gif", "IMAGE", ""); | 215 AdblockPlus::FilterPtr match3 = filterEngine->Matches("http://example.org/notb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); |
167 ASSERT_TRUE(match3); | 216 ASSERT_TRUE(match3); |
168 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetType()); | 217 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match3->GetType()); |
169 | 218 |
170 AdblockPlus::FilterPtr match4 = filterEngine->Matches("http://example.org/notb
anner.gif", "IMAGE", ""); | 219 AdblockPlus::FilterPtr match4 = filterEngine->Matches("http://example.org/notb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""); |
171 ASSERT_TRUE(match4); | 220 ASSERT_TRUE(match4); |
172 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetType()); | 221 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match4->GetType()); |
173 | 222 |
174 AdblockPlus::FilterPtr match5 = filterEngine->Matches("http://example.org/tpba
nner.gif", "IMAGE", "http://example.org/"); | 223 AdblockPlus::FilterPtr match5 = filterEngine->Matches("http://example.org/tpba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/")
; |
175 ASSERT_FALSE(match5); | 224 ASSERT_FALSE(match5); |
176 | 225 |
177 AdblockPlus::FilterPtr match6 = filterEngine->Matches("http://example.org/fpba
nner.gif", "IMAGE", "http://example.org/"); | 226 AdblockPlus::FilterPtr match6 = filterEngine->Matches("http://example.org/fpba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/")
; |
178 ASSERT_TRUE(match6); | 227 ASSERT_TRUE(match6); |
179 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); | 228 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); |
180 | 229 |
181 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba
nner.gif", "IMAGE", "http://example.com/"); | 230 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/")
; |
182 ASSERT_TRUE(match7); | 231 ASSERT_TRUE(match7); |
183 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match7->GetType()); | 232 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match7->GetType()); |
184 | 233 |
185 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba
nner.gif", "IMAGE", "http://example.com/"); | 234 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba
nner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/")
; |
186 ASSERT_FALSE(match8); | 235 ASSERT_FALSE(match8); |
187 | 236 |
188 AdblockPlus::FilterPtr match9 = filterEngine->Matches("http://example.org/comb
anner.gif", "IMAGE", "http://example.com/"); | 237 AdblockPlus::FilterPtr match9 = filterEngine->Matches("http://example.org/comb
anner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/"
); |
189 ASSERT_TRUE(match9); | 238 ASSERT_TRUE(match9); |
190 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match9->GetType()); | 239 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match9->GetType()); |
191 | 240 |
192 AdblockPlus::FilterPtr match10 = filterEngine->Matches("http://example.org/com
banner.gif", "IMAGE", "http://example.org/"); | 241 AdblockPlus::FilterPtr match10 = filterEngine->Matches("http://example.org/com
banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/
"); |
193 ASSERT_FALSE(match10); | 242 ASSERT_FALSE(match10); |
194 | 243 |
195 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org
banner.gif", "IMAGE", "http://example.com/"); | 244 AdblockPlus::FilterPtr match11 = filterEngine->Matches("http://example.org/org
banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.com/
"); |
196 ASSERT_FALSE(match11); | 245 ASSERT_FALSE(match11); |
197 | 246 |
198 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org
banner.gif", "IMAGE", "http://example.org/"); | 247 AdblockPlus::FilterPtr match12 = filterEngine->Matches("http://example.org/org
banner.gif", AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, "http://example.org/
"); |
199 ASSERT_TRUE(match12); | 248 ASSERT_TRUE(match12); |
200 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType()); | 249 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match12->GetType()); |
201 } | 250 } |
202 | 251 |
203 TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain) | 252 TEST_F(FilterEngineTest, MatchesOnWhitelistedDomain) |
204 { | 253 { |
205 filterEngine->GetFilter("adbanner.gif")->AddToList(); | 254 filterEngine->GetFilter("adbanner.gif")->AddToList(); |
206 filterEngine->GetFilter("@@||example.org^$document")->AddToList(); | 255 filterEngine->GetFilter("@@||example.org^$document")->AddToList(); |
207 | 256 |
208 AdblockPlus::FilterPtr match1 = | 257 AdblockPlus::FilterPtr match1 = |
209 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 258 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
210 "http://example.com/"); | 259 "http://example.com/"); |
211 ASSERT_TRUE(match1); | 260 ASSERT_TRUE(match1); |
212 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); | 261 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); |
213 | 262 |
214 AdblockPlus::FilterPtr match2 = | 263 AdblockPlus::FilterPtr match2 = |
215 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 264 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
216 "http://example.org/"); | 265 "http://example.org/"); |
217 ASSERT_TRUE(match2); | 266 ASSERT_TRUE(match2); |
218 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); | 267 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); |
219 } | 268 } |
220 | 269 |
221 TEST_F(FilterEngineTest, MatchesNestedFrameRequest) | 270 TEST_F(FilterEngineTest, MatchesNestedFrameRequest) |
222 { | 271 { |
223 filterEngine->GetFilter("adbanner.gif")->AddToList(); | 272 filterEngine->GetFilter("adbanner.gif")->AddToList(); |
224 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList(); | 273 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList(); |
225 | 274 |
226 std::vector<std::string> documentUrls1; | 275 std::vector<std::string> documentUrls1; |
227 documentUrls1.push_back("http://ads.com/frame/"); | 276 documentUrls1.push_back("http://ads.com/frame/"); |
228 documentUrls1.push_back("http://example.com/"); | 277 documentUrls1.push_back("http://example.com/"); |
229 AdblockPlus::FilterPtr match1 = | 278 AdblockPlus::FilterPtr match1 = |
230 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 279 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
231 documentUrls1); | 280 documentUrls1); |
232 ASSERT_TRUE(match1); | 281 ASSERT_TRUE(match1); |
233 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); | 282 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); |
234 | 283 |
235 std::vector<std::string> documentUrls2; | 284 std::vector<std::string> documentUrls2; |
236 documentUrls2.push_back("http://ads.com/frame/"); | 285 documentUrls2.push_back("http://ads.com/frame/"); |
237 documentUrls2.push_back("http://example.org/"); | 286 documentUrls2.push_back("http://example.org/"); |
238 AdblockPlus::FilterPtr match2 = | 287 AdblockPlus::FilterPtr match2 = |
239 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 288 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
240 documentUrls2); | 289 documentUrls2); |
241 ASSERT_TRUE(match2); | 290 ASSERT_TRUE(match2); |
242 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); | 291 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); |
243 | 292 |
244 std::vector<std::string> documentUrls3; | 293 std::vector<std::string> documentUrls3; |
245 documentUrls3.push_back("http://example.org/"); | 294 documentUrls3.push_back("http://example.org/"); |
246 documentUrls3.push_back("http://ads.com/frame/"); | 295 documentUrls3.push_back("http://ads.com/frame/"); |
247 AdblockPlus::FilterPtr match3 = | 296 AdblockPlus::FilterPtr match3 = |
248 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 297 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
249 documentUrls3); | 298 documentUrls3); |
250 ASSERT_TRUE(match3); | 299 ASSERT_TRUE(match3); |
251 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); | 300 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); |
252 } | 301 } |
253 | 302 |
254 TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain) | 303 TEST_F(FilterEngineTest, MatchesNestedFrameOnWhitelistedDomain) |
255 { | 304 { |
256 filterEngine->GetFilter("adbanner.gif")->AddToList(); | 305 filterEngine->GetFilter("adbanner.gif")->AddToList(); |
257 filterEngine->GetFilter("@@||example.org^$document,domain=ads.com")->AddToList
(); | 306 filterEngine->GetFilter("@@||example.org^$document,domain=ads.com")->AddToList
(); |
258 | 307 |
259 std::vector<std::string> documentUrls1; | 308 std::vector<std::string> documentUrls1; |
260 documentUrls1.push_back("http://ads.com/frame/"); | 309 documentUrls1.push_back("http://ads.com/frame/"); |
261 documentUrls1.push_back("http://example.com/"); | 310 documentUrls1.push_back("http://example.com/"); |
262 AdblockPlus::FilterPtr match1 = | 311 AdblockPlus::FilterPtr match1 = |
263 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 312 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
264 documentUrls1); | 313 documentUrls1); |
265 ASSERT_TRUE(match1); | 314 ASSERT_TRUE(match1); |
266 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); | 315 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); |
267 | 316 |
268 std::vector<std::string> documentUrls2; | 317 std::vector<std::string> documentUrls2; |
269 documentUrls2.push_back("http://ads.com/frame/"); | 318 documentUrls2.push_back("http://ads.com/frame/"); |
270 documentUrls2.push_back("http://example.org/"); | 319 documentUrls2.push_back("http://example.org/"); |
271 AdblockPlus::FilterPtr match2 = | 320 AdblockPlus::FilterPtr match2 = |
272 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 321 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
273 documentUrls2); | 322 documentUrls2); |
274 ASSERT_TRUE(match2); | 323 ASSERT_TRUE(match2); |
275 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); | 324 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); |
276 | 325 |
277 std::vector<std::string> documentUrls3; | 326 std::vector<std::string> documentUrls3; |
278 documentUrls3.push_back("http://example.org/"); | 327 documentUrls3.push_back("http://example.org/"); |
279 AdblockPlus::FilterPtr match3 = | 328 AdblockPlus::FilterPtr match3 = |
280 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 329 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
281 documentUrls3); | 330 documentUrls3); |
282 ASSERT_TRUE(match3); | 331 ASSERT_TRUE(match3); |
283 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); | 332 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match3->GetType()); |
284 | 333 |
285 std::vector<std::string> documentUrls4; | 334 std::vector<std::string> documentUrls4; |
286 documentUrls4.push_back("http://example.org/"); | 335 documentUrls4.push_back("http://example.org/"); |
287 documentUrls4.push_back("http://ads.com/frame/"); | 336 documentUrls4.push_back("http://ads.com/frame/"); |
288 AdblockPlus::FilterPtr match4 = | 337 AdblockPlus::FilterPtr match4 = |
289 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 338 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
290 documentUrls4); | 339 documentUrls4); |
291 ASSERT_TRUE(match4); | 340 ASSERT_TRUE(match4); |
292 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match4->GetType()); | 341 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match4->GetType()); |
293 | 342 |
294 std::vector<std::string> documentUrls5; | 343 std::vector<std::string> documentUrls5; |
295 documentUrls5.push_back("http://ads.com/frame/"); | 344 documentUrls5.push_back("http://ads.com/frame/"); |
296 documentUrls5.push_back("http://example.org/"); | 345 documentUrls5.push_back("http://example.org/"); |
297 documentUrls5.push_back("http://example.com/"); | 346 documentUrls5.push_back("http://example.com/"); |
298 AdblockPlus::FilterPtr match5 = | 347 AdblockPlus::FilterPtr match5 = |
299 filterEngine->Matches("http://ads.com/adbanner.gif", "IMAGE", | 348 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi
ne::CONTENT_TYPE_IMAGE, |
300 documentUrls5); | 349 documentUrls5); |
301 ASSERT_TRUE(match5); | 350 ASSERT_TRUE(match5); |
302 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType()); | 351 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match5->GetType()); |
303 } | 352 } |
304 | 353 |
305 TEST_F(FilterEngineTest, FirstRunFlag) | 354 TEST_F(FilterEngineTest, FirstRunFlag) |
306 { | 355 { |
307 ASSERT_FALSE(filterEngine->IsFirstRun()); | 356 ASSERT_FALSE(filterEngine->IsFirstRun()); |
308 } | 357 } |
309 | 358 |
310 TEST_F(FilterEngineTestNoData, FirstRunFlag) | 359 TEST_F(FilterEngineTestNoData, FirstRunFlag) |
311 { | 360 { |
312 ASSERT_TRUE(filterEngine->IsFirstRun()); | 361 ASSERT_TRUE(filterEngine->IsFirstRun()); |
313 } | 362 } |
| 363 |
| 364 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback) |
| 365 { |
| 366 mockWebRequest->response.status = 0; |
| 367 mockWebRequest->response.responseStatus = 200; |
| 368 mockWebRequest->response.responseText = "\ |
| 369 {\ |
| 370 \"test\": {\ |
| 371 \"version\": \"1.0.2\",\ |
| 372 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\ |
| 373 }\ |
| 374 }"; |
| 375 |
| 376 int timesCalled = 0; |
| 377 MockUpdateAvailableCallback mockUpdateAvailableCallback(timesCalled); |
| 378 |
| 379 filterEngine->SetUpdateAvailableCallback(mockUpdateAvailableCallback); |
| 380 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback); |
| 381 AdblockPlus::Sleep(100); |
| 382 ASSERT_EQ(1, timesCalled); |
| 383 |
| 384 filterEngine->RemoveUpdateAvailableCallback(); |
| 385 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback); |
| 386 AdblockPlus::Sleep(100); |
| 387 ASSERT_EQ(1, timesCalled); |
| 388 } |
LEFT | RIGHT |