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

Delta Between Two Patch Sets: test/matcher.js

Issue 30001564: Issue 7267 - Optimize memory layout of filter domain maps in matcher (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Feb. 8, 2019, 3:44 a.m.
Right Patch Set: Add tests Created Feb. 8, 2019, 5:20 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « lib/matcher.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 test.ok(!matcher.isWhitelisted("https://example.com/foo", 346 test.ok(!matcher.isWhitelisted("https://example.com/foo",
347 RegExpFilter.typeMap.SUBDOCUMENT)); 347 RegExpFilter.typeMap.SUBDOCUMENT));
348 348
349 test.done(); 349 test.done();
350 }; 350 };
351 351
352 exports.testAddRemoveByKeyword = function(test) 352 exports.testAddRemoveByKeyword = function(test)
353 { 353 {
354 let matcher = new CombinedMatcher(); 354 let matcher = new CombinedMatcher();
355 355
356 matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg")); 356 matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg^"));
357 357
358 // Add the same filter a second time to make sure it doesn't get added again 358 // Add the same filter a second time to make sure it doesn't get added again
359 // by a different keyword. 359 // by a different keyword.
360 matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg")); 360 matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg^"));
361 361
362 test.ok(!!matcher.matchesAny("https://example.com/foo/bar/image.jpg", 362 test.ok(!!matcher.matchesAny("https://example.com/foo/bar/image.jpg",
363 RegExpFilter.typeMap.IMAGE)); 363 RegExpFilter.typeMap.IMAGE));
364 364
365 matcher.remove(Filter.fromText("||example.com/foo/bar/image.jpg")); 365 matcher.remove(Filter.fromText("||example.com/foo/bar/image.jpg^"));
366 366
367 // Make sure the filter got removed so there is no match. 367 // Make sure the filter got removed so there is no match.
368 test.ok(!matcher.matchesAny("https://example.com/foo/bar/image.jpg", 368 test.ok(!matcher.matchesAny("https://example.com/foo/bar/image.jpg",
369 RegExpFilter.typeMap.IMAGE)); 369 RegExpFilter.typeMap.IMAGE));
370 370
371 test.done(); 371
372 }; 372 // Map { "example" => { text: "||example.com^$~third-party" } }
373 matcher.add(Filter.fromText("||example.com^$~third-party"));
374
375 test.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1);
376
377 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword)
378 {
379 test.equal(key, "example");
380 test.deepEqual(value, Filter.fromText("||example.com^$~third-party"));
381 break;
382 }
383
384 test.ok(!!matcher.matchesAny("https://example.com/example/image.jpg",
385 RegExpFilter.typeMap.IMAGE, "example.com",
386 false));
387
388 // Map {
389 // "example" => Map {
390 // "" => Map {
391 // { text: "||example.com^$~third-party" } => true,
392 // { text: "/example/*$~third-party" } => true
393 // }
394 // }
395 // }
396 matcher.add(Filter.fromText("/example/*$~third-party"));
397
398 test.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1);
399
400 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword)
401 {
402 test.equal(key, "example");
403 test.equal(value.size, 1);
404
405 let map = value.get("");
406 test.equal(map.size, 2);
407 test.equal(map.get(Filter.fromText("||example.com^$~third-party")), true);
408 test.equal(map.get(Filter.fromText("/example/*$~third-party")), true);
409
410 break;
411 }
412
413 test.ok(!!matcher.matchesAny("https://example.com/example/image.jpg",
414 RegExpFilter.typeMap.IMAGE, "example.com",
415 false));
416
417 // Map { "example" => { text: "/example/*$~third-party" } }
418 matcher.remove(Filter.fromText("||example.com^$~third-party"));
419
420 test.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1);
421
422 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword)
423 {
424 test.equal(key, "example");
425 test.deepEqual(value, Filter.fromText("/example/*$~third-party"));
426 break;
427 }
428
429 test.ok(!!matcher.matchesAny("https://example.com/example/image.jpg",
430 RegExpFilter.typeMap.IMAGE, "example.com",
431 false));
432
433 // Map {}
434 matcher.remove(Filter.fromText("/example/*$~third-party"));
435
436 test.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 0);
437
438 test.ok(!matcher.matchesAny("https://example.com/example/image.jpg",
439 RegExpFilter.typeMap.IMAGE, "example.com",
440 false));
441
442 test.done();
443 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld