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

Delta Between Two Patch Sets: test/filterClasses.js

Issue 29398669: Issue 5063 - [emscripten] Make FilterNotifier calls more efficient (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Rebased Created April 13, 2017, 1:07 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/subscription/Subscription.h ('k') | test/subscriptionClasses.js » ('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-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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 370 }
371 371
372 test.done(); 372 test.done();
373 }; 373 };
374 374
375 exports.testNotifications = function(test) 375 exports.testNotifications = function(test)
376 { 376 {
377 function checkNotifications(action, expected, message) 377 function checkNotifications(action, expected, message)
378 { 378 {
379 let result = null; 379 let result = null;
380 let listener = (topic, filter, newValue, oldValue) => 380 let listener = (topic, filter) =>
381 { 381 {
382 if (result) 382 if (result)
383 test.ok(false, "Got more that one notification - " + message); 383 test.ok(false, "Got more that one notification - " + message);
384 else 384 else
385 result = [topic, filter.text, newValue, oldValue]; 385 result = [topic, filter.text];
386 }; 386 };
387 FilterNotifier.addListener(listener); 387 FilterNotifier.addListener(listener);
388 action(); 388 action();
389 FilterNotifier.removeListener(listener); 389 FilterNotifier.removeListener(listener);
390 test.deepEqual(result, expected, message); 390 test.deepEqual(result, expected, message);
391 } 391 }
392 392
393 let filter = Filter.fromText("foobar"); 393 let filter = Filter.fromText("foobar");
394 checkNotifications(() => 394 checkNotifications(() =>
395 { 395 {
396 filter.disabled = true; 396 filter.disabled = true;
397 }, ["filter.disabled", "foobar", true, false], "Disabling filter"); 397 }, ["filter.disabled", "foobar"], "Disabling filter");
398 checkNotifications(() => 398 checkNotifications(() =>
399 { 399 {
400 filter.disabled = true; 400 filter.disabled = true;
401 }, null, "Disabling already disabled filter"); 401 }, null, "Disabling already disabled filter");
402 checkNotifications(() => 402 checkNotifications(() =>
403 { 403 {
404 filter.disabled = false; 404 filter.disabled = false;
405 }, ["filter.disabled", "foobar", false, true], "Enabling filter"); 405 }, ["filter.disabled", "foobar"], "Enabling filter");
406 406
407 checkNotifications(() => 407 checkNotifications(() =>
408 { 408 {
409 filter.lastHit = 1234; 409 filter.lastHit = 1234;
410 }, ["filter.lastHit", "foobar", 1234, 0], "Changing last filter hit"); 410 }, ["filter.lastHit", "foobar"], "Changing last filter hit");
411 checkNotifications(() => 411 checkNotifications(() =>
412 { 412 {
413 filter.lastHit = 1234; 413 filter.lastHit = 1234;
414 }, null, "Changing last filter hit to same value"); 414 }, null, "Changing last filter hit to same value");
415 checkNotifications(() => 415 checkNotifications(() =>
416 { 416 {
417 filter.lastHit = 0; 417 filter.lastHit = 0;
418 }, ["filter.lastHit", "foobar", 0, 1234], "Resetting last filter hit"); 418 }, ["filter.lastHit", "foobar"], "Resetting last filter hit");
419 419
420 checkNotifications(() => 420 checkNotifications(() =>
421 { 421 {
422 filter.hitCount++; 422 filter.hitCount++;
423 }, ["filter.hitCount", "foobar", 1, 0], "Increasing filter hit counts"); 423 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts");
424 checkNotifications(() => 424 checkNotifications(() =>
425 { 425 {
426 filter.hitCount = 0; 426 filter.hitCount = 0;
427 }, ["filter.hitCount", "foobar", 0, 1], "Resetting filter hit counts"); 427 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts");
428 428
429 filter.delete(); 429 filter.delete();
430 test.done(); 430 test.done();
431 }; 431 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld