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

Unified Diff: test/filterNotifier.js

Issue 29853561: Issue 6854 - Remove deprecated FilterNotifier methods (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Aug. 11, 2018, 2:43 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/filterNotifier.js
===================================================================
--- a/test/filterNotifier.js
+++ b/test/filterNotifier.js
@@ -28,80 +28,90 @@
{FilterNotifier} = sandboxedRequire("../lib/filterNotifier")
);
callback();
};
let triggeredListeners = [];
let listeners = [
- (action, item) => triggeredListeners.push(["listener1", action, item]),
- (action, item) => triggeredListeners.push(["listener2", action, item]),
- (action, item) => triggeredListeners.push(["listener3", action, item])
+ (...args) => triggeredListeners.push(["listener1", ...args]),
+ (...args) => triggeredListeners.push(["listener2", ...args]),
+ (...args) => triggeredListeners.push(["listener3", ...args])
];
+function addListener(listener)
+{
+ FilterNotifier.on("foo", listener);
+}
+
+function removeListener(listener)
+{
+ FilterNotifier.off("foo", listener);
+}
+
function compareListeners(test, testDescription, list)
{
let result1 = triggeredListeners = [];
- FilterNotifier.triggerListeners("foo", {bar: true});
+ FilterNotifier.emit("foo", {bar: true});
let result2 = triggeredListeners = [];
for (let observer of list)
- observer("foo", {bar: true});
+ observer({bar: true});
test.deepEqual(result1, result2, testDescription);
}
exports.testAddingRemovingListeners = function(test)
{
let [listener1, listener2, listener3] = listeners;
compareListeners(test, "No listeners", []);
- FilterNotifier.addListener(listener1);
+ addListener(listener1);
compareListeners(test, "addListener(listener1)", [listener1]);
- FilterNotifier.addListener(listener1);
- compareListeners(test, "addListener(listener1) again", [listener1]);
+ addListener(listener1);
+ compareListeners(test, "addListener(listener1) again", [listener1, listener1]);
Manish Jethani 2018/08/11 14:47:06 Note that there is a difference in behavior here b
+
+ addListener(listener2);
+ compareListeners(test, "addListener(listener2)", [listener1, listener1, listener2]);
+
+ removeListener(listener1);
+ compareListeners(test, "removeListener(listener1)", [listener1, listener2]);
- FilterNotifier.addListener(listener2);
- compareListeners(test, "addListener(listener2)", [listener1, listener2]);
+ removeListener(listener1);
+ compareListeners(test, "removeListener(listener1) again", [listener2]);
+
+ addListener(listener3);
+ compareListeners(test, "addListener(listener3)", [listener2, listener3]);
- FilterNotifier.removeListener(listener1);
+ addListener(listener1);
+ compareListeners(test, "addListener(listener1)", [listener2, listener3, listener1]);
+
+ removeListener(listener3);
+ compareListeners(test, "removeListener(listener3)", [listener2, listener1]);
+
+ removeListener(listener1);
compareListeners(test, "removeListener(listener1)", [listener2]);
- FilterNotifier.removeListener(listener1);
- compareListeners(test, "removeListener(listener1) again", [listener2]);
-
- FilterNotifier.addListener(listener3);
- compareListeners(test, "addListener(listener3)", [listener2, listener3]);
-
- FilterNotifier.addListener(listener1);
- compareListeners(test, "addListener(listener1)", [listener2, listener3, listener1]);
-
- FilterNotifier.removeListener(listener3);
- compareListeners(test, "removeListener(listener3)", [listener2, listener1]);
-
- FilterNotifier.removeListener(listener1);
- compareListeners(test, "removeListener(listener1)", [listener2]);
-
- FilterNotifier.removeListener(listener2);
+ removeListener(listener2);
compareListeners(test, "removeListener(listener2)", []);
test.done();
};
exports.testRemovingListenersWhileBeingCalled = function(test)
{
let listener1 = function(...args)
{
listeners[0](...args);
- FilterNotifier.removeListener(listener1);
+ removeListener(listener1);
};
let listener2 = listeners[1];
- FilterNotifier.addListener(listener1);
- FilterNotifier.addListener(listener2);
+ addListener(listener1);
+ addListener(listener2);
compareListeners(test, "Initial call", [listener1, listener2]);
compareListeners(test, "Subsequent calls", [listener2]);
test.done();
};
« no previous file with comments | « lib/synchronizer.js ('k') | test/filterStorage.js » ('j') | test/filterStorage.js » ('J')

Powered by Google App Engine
This is Rietveld