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

Side by Side Diff: test/filterClasses.js

Issue 29398669: Issue 5063 - [emscripten] Make FilterNotifier calls more efficient (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Addressed comments Created April 20, 2017, 8 a.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 | « compiled/subscription/Subscription.h ('k') | test/subscriptionClasses.js » ('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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 12 matching lines...) Expand all
23 let InvalidFilter = null; 23 let InvalidFilter = null;
24 let CommentFilter = null; 24 let CommentFilter = null;
25 let ActiveFilter = null; 25 let ActiveFilter = null;
26 let RegExpFilter = null; 26 let RegExpFilter = null;
27 let BlockingFilter = null; 27 let BlockingFilter = null;
28 let WhitelistFilter = null; 28 let WhitelistFilter = null;
29 let ElemHideBase = null; 29 let ElemHideBase = null;
30 let ElemHideFilter = null; 30 let ElemHideFilter = null;
31 let ElemHideException = null; 31 let ElemHideException = null;
32 let ElemHideEmulationFilter = null; 32 let ElemHideEmulationFilter = null;
33 let FilterNotifier = null;
33 34
34 exports.setUp = function(callback) 35 exports.setUp = function(callback)
35 { 36 {
36 let sandboxedRequire = createSandbox(); 37 let sandboxedRequire = createSandbox();
37 ( 38 (
38 { 39 {
39 Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, 40 Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter,
40 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, 41 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter,
41 ElemHideException, ElemHideEmulationFilter 42 ElemHideException, ElemHideEmulationFilter
42 } = sandboxedRequire("../lib/filterClasses") 43 } = sandboxedRequire("../lib/filterClasses")
43 ); 44 );
45 ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier"));
44 callback(); 46 callback();
45 }; 47 };
46 48
47 exports.testFromText = function(test) 49 exports.testFromText = function(test)
48 { 50 {
49 let tests = [ 51 let tests = [
50 ["!asdf", CommentFilter, "comment"], 52 ["!asdf", CommentFilter, "comment"],
51 ["asdf", BlockingFilter, "blocking"], 53 ["asdf", BlockingFilter, "blocking"],
52 ["asdf$image,~collapse", BlockingFilter, "blocking"], 54 ["asdf$image,~collapse", BlockingFilter, "blocking"],
53 ["/asdf/", BlockingFilter, "blocking"], 55 ["/asdf/", BlockingFilter, "blocking"],
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 ]; 364 ];
363 365
364 for (let [text, selector, selectorDomain] of tests) 366 for (let [text, selector, selectorDomain] of tests)
365 { 367 {
366 doTest(text, selector, selectorDomain); 368 doTest(text, selector, selectorDomain);
367 doTest(text.replace("##", "#@#"), selector, selectorDomain); 369 doTest(text.replace("##", "#@#"), selector, selectorDomain);
368 } 370 }
369 371
370 test.done(); 372 test.done();
371 }; 373 };
374
375 exports.testNotifications = function(test)
376 {
377 function checkNotifications(action, expected, message)
378 {
379 let result = null;
380 let listener = (topic, filter) =>
381 {
382 if (result)
383 test.ok(false, "Got more that one notification - " + message);
384 else
385 result = [topic, filter.text];
386 };
387 FilterNotifier.addListener(listener);
388 action();
389 FilterNotifier.removeListener(listener);
390 test.deepEqual(result, expected, message);
391 }
392
393 let filter = Filter.fromText("foobar");
394 checkNotifications(() =>
395 {
396 filter.disabled = true;
397 }, ["filter.disabled", "foobar"], "Disabling filter");
398 checkNotifications(() =>
399 {
400 filter.disabled = true;
401 }, null, "Disabling already disabled filter");
402 checkNotifications(() =>
403 {
404 filter.disabled = false;
405 }, ["filter.disabled", "foobar"], "Enabling filter");
406
407 checkNotifications(() =>
408 {
409 filter.lastHit = 1234;
410 }, ["filter.lastHit", "foobar"], "Changing last filter hit");
411 checkNotifications(() =>
412 {
413 filter.lastHit = 1234;
414 }, null, "Changing last filter hit to same value");
415 checkNotifications(() =>
416 {
417 filter.lastHit = 0;
418 }, ["filter.lastHit", "foobar"], "Resetting last filter hit");
419
420 checkNotifications(() =>
421 {
422 filter.hitCount++;
423 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts");
424 checkNotifications(() =>
425 {
426 filter.hitCount = 0;
427 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts");
428
429 filter.delete();
430 test.done();
431 };
OLDNEW
« no previous file with comments | « compiled/subscription/Subscription.h ('k') | test/subscriptionClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld