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

Unified Diff: test/filterClasses.js

Issue 29398669: Issue 5063 - [emscripten] Make FilterNotifier calls more efficient (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Removed newValue and oldValue parameters Created April 15, 2017, 3:05 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/filterClasses.js
===================================================================
--- a/test/filterClasses.js
+++ b/test/filterClasses.js
@@ -25,27 +25,29 @@ let CommentFilter = null;
let ActiveFilter = null;
let RegExpFilter = null;
let BlockingFilter = null;
let WhitelistFilter = null;
let ElemHideBase = null;
let ElemHideFilter = null;
let ElemHideException = null;
let ElemHideEmulationFilter = null;
+let FilterNotifier = null;
exports.setUp = function(callback)
{
let sandboxedRequire = createSandbox();
(
{
Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter,
BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter,
ElemHideException, ElemHideEmulationFilter
} = sandboxedRequire("../lib/filterClasses")
);
+ ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier"));
callback();
};
exports.testFromText = function(test)
{
let tests = [
["!asdf", CommentFilter, "comment"],
["asdf", BlockingFilter, "blocking"],
@@ -364,8 +366,66 @@ exports.testElemHideSelector = function(
for (let [text, selector, selectorDomain] of tests)
{
doTest(text, selector, selectorDomain);
doTest(text.replace("##", "#@#"), selector, selectorDomain);
}
test.done();
};
+
+exports.testNotifications = function(test)
+{
+ function checkNotifications(action, expected, message)
+ {
+ let result = null;
+ let listener = (topic, filter) =>
+ {
+ if (result)
+ test.ok(false, "Got more that one notification - " + message);
+ else
+ result = [topic, filter.text];
+ };
+ FilterNotifier.addListener(listener);
+ action();
+ FilterNotifier.removeListener(listener);
+ test.deepEqual(result, expected, message);
+ }
+
+ let filter = Filter.fromText("foobar");
+ checkNotifications(() =>
+ {
+ filter.disabled = true;
+ }, ["filter.disabled", "foobar"], "Disabling filter");
+ checkNotifications(() =>
+ {
+ filter.disabled = true;
+ }, null, "Disabling already disabled filter");
+ checkNotifications(() =>
+ {
+ filter.disabled = false;
+ }, ["filter.disabled", "foobar"], "Enabling filter");
+
+ checkNotifications(() =>
+ {
+ filter.lastHit = 1234;
+ }, ["filter.lastHit", "foobar"], "Changing last filter hit");
+ checkNotifications(() =>
+ {
+ filter.lastHit = 1234;
+ }, null, "Changing last filter hit to same value");
+ checkNotifications(() =>
+ {
+ filter.lastHit = 0;
+ }, ["filter.lastHit", "foobar"], "Resetting last filter hit");
+
+ checkNotifications(() =>
+ {
+ filter.hitCount++;
+ }, ["filter.hitCount", "foobar"], "Increasing filter hit counts");
+ checkNotifications(() =>
+ {
+ filter.hitCount = 0;
+ }, ["filter.hitCount", "foobar"], "Resetting filter hit counts");
+
+ filter.delete();
+ test.done();
+};

Powered by Google App Engine
This is Rietveld