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

Delta Between Two Patch Sets: test/FilterEngine.cpp

Issue 6233220328718336: Issue #3593, #1197- fix isolate management (Closed)
Left Patch Set: fix typo Created Jan. 29, 2016, 11:29 a.m.
Right Patch Set: rebase fix v8 initialization Created May 20, 2016, 3:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/BaseJsTest.cpp ('k') | test/Prefs.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 ASSERT_TRUE(match1); 273 ASSERT_TRUE(match1);
274 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType()); 274 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match1->GetType());
275 275
276 AdblockPlus::FilterPtr match2 = 276 AdblockPlus::FilterPtr match2 =
277 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 277 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
278 "http://example.org/"); 278 "http://example.org/");
279 ASSERT_TRUE(match2); 279 ASSERT_TRUE(match2);
280 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType()); 280 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, match2->GetType());
281 } 281 }
282 282
283 TEST_F(FilterEngineTest, MatchesWithContentTypeMask)
284 {
285 filterEngine->GetFilter("adbanner.gif.js$script,image")->AddToList();
286 filterEngine->GetFilter("@@notbanner.gif")->AddToList();
287 filterEngine->GetFilter("blockme")->AddToList();
288 filterEngine->GetFilter("@@||example.doc^$document")->AddToList();
289
290 EXPECT_FALSE(filterEngine->Matches("http://example.org/foobar.gif",
291 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE, ""))
292 << "another url should not match";
293
294 EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js",
295 /*mask*/ 0, "")) << "zero mask should not match (filter with some options)";
296
297 EXPECT_FALSE(filterEngine->Matches("http://example.xxx/blockme",
298 /*mask*/ 0, "")) << "zero mask should not match (filter without any option)" ;
299
300 EXPECT_FALSE(filterEngine->Matches("http://example.org/adbanner.gif.js",
301 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, ""))
302 << "one arbitrary flag in mask should not match";
303
304 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js",
305 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE |
306 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, ""))
307 << "one of flags in mask should match";
308
309 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js",
310 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE |
311 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT, ""))
312 << "both flags in mask should match";
313
314 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js",
315 AdblockPlus::FilterEngine::CONTENT_TYPE_IMAGE |
316 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT |
317 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, ""))
318 << "both flags with another flag in mask should match";
319
320 EXPECT_TRUE(filterEngine->Matches("http://example.org/adbanner.gif.js",
321 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT |
322 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, ""))
323 << "one of flags in mask should match";
324
325 {
326 AdblockPlus::FilterPtr filter;
327 ASSERT_TRUE(filter = filterEngine->Matches("http://child.any/blockme",
328 AdblockPlus::FilterEngine::CONTENT_TYPE_SCRIPT |
329 AdblockPlus::FilterEngine::CONTENT_TYPE_OBJECT, "http://example.doc"))
330 << "non-zero mask should match on whitelisted document";
331
332 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType());
333 }
334
335 {
336 AdblockPlus::FilterPtr filter;
337 ASSERT_TRUE(filter = filterEngine->Matches("http://example.doc/blockme",
338 /*mask*/0, "http://example.doc"))
339 << "zero mask should match when document is whitelisted";
340
341 EXPECT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter->GetType());
342 }
343 }
344
283 TEST_F(FilterEngineTest, MatchesNestedFrameRequest) 345 TEST_F(FilterEngineTest, MatchesNestedFrameRequest)
284 { 346 {
285 filterEngine->GetFilter("adbanner.gif")->AddToList(); 347 filterEngine->GetFilter("adbanner.gif")->AddToList();
286 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList(); 348 filterEngine->GetFilter("@@adbanner.gif$domain=example.org")->AddToList();
287 349
288 std::vector<std::string> documentUrls1; 350 std::vector<std::string> documentUrls1;
289 documentUrls1.push_back("http://ads.com/frame/"); 351 documentUrls1.push_back("http://ads.com/frame/");
290 documentUrls1.push_back("http://example.com/"); 352 documentUrls1.push_back("http://example.com/");
291 AdblockPlus::FilterPtr match1 = 353 AdblockPlus::FilterPtr match1 =
292 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE, 354 filterEngine->Matches("http://ads.com/adbanner.gif", AdblockPlus::FilterEngi ne::CONTENT_TYPE_IMAGE,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 ASSERT_TRUE(filterEngine->IsFirstRun()); 436 ASSERT_TRUE(filterEngine->IsFirstRun());
375 } 437 }
376 438
377 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback) 439 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback)
378 { 440 {
379 int timesCalled = 0; 441 int timesCalled = 0;
380 MockFilterChangeCallback mockFilterChangeCallback(timesCalled); 442 MockFilterChangeCallback mockFilterChangeCallback(timesCalled);
381 443
382 filterEngine->SetFilterChangeCallback(mockFilterChangeCallback); 444 filterEngine->SetFilterChangeCallback(mockFilterChangeCallback);
383 filterEngine->GetFilter("foo")->AddToList(); 445 filterEngine->GetFilter("foo")->AddToList();
384 EXPECT_EQ(2, timesCalled); 446 EXPECT_EQ(1, timesCalled);
385 447
386 filterEngine->RemoveFilterChangeCallback(); 448 filterEngine->RemoveFilterChangeCallback();
387 filterEngine->GetFilter("foo")->RemoveFromList(); 449 filterEngine->GetFilter("foo")->RemoveFromList();
388 EXPECT_EQ(2, timesCalled); 450 EXPECT_EQ(1, timesCalled);
389 } 451 }
390 452
391 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback) 453 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback)
392 { 454 {
393 mockWebRequest->response.status = 0; 455 mockWebRequest->response.status = 0;
394 mockWebRequest->response.responseStatus = 200; 456 mockWebRequest->response.responseStatus = 200;
395 mockWebRequest->response.responseText = "\ 457 mockWebRequest->response.responseText = "\
396 {\ 458 {\
397 \"test\": {\ 459 \"test\": {\
398 \"version\": \"1.0.2\",\ 460 \"version\": \"1.0.2\",\
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 documentUrls1.push_back("http://example.de"); 526 documentUrls1.push_back("http://example.de");
465 527
466 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted( 528 ASSERT_TRUE(filterEngine->IsElemhideWhitelisted(
467 "http://example.com", 529 "http://example.com",
468 documentUrls1)); 530 documentUrls1));
469 531
470 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted( 532 ASSERT_FALSE(filterEngine->IsElemhideWhitelisted(
471 "http://example.co.uk", 533 "http://example.co.uk",
472 documentUrls1)); 534 documentUrls1));
473 } 535 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld