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: Added missing files Created April 6, 2017, 8:08 a.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
« no previous file with comments | « compiled/subscription/Subscription.h ('k') | test/subscriptionClasses.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, newValue, oldValue) =>
+ {
+ if (result)
+ test.ok(false, "Got more that one notification - " + message);
+ else
+ result = [topic, filter.text, newValue, oldValue];
+ };
+ FilterNotifier.addListener(listener);
+ action();
+ FilterNotifier.removeListener(listener);
+ test.deepEqual(result, expected, message);
+ }
+
+ let filter = Filter.fromText("foobar");
+ checkNotifications(() =>
+ {
+ filter.disabled = true;
+ }, ["filter.disabled", "foobar", true, false], "Disabling filter");
+ checkNotifications(() =>
+ {
+ filter.disabled = true;
+ }, null, "Disabling already disabled filter");
+ checkNotifications(() =>
+ {
+ filter.disabled = false;
+ }, ["filter.disabled", "foobar", false, true], "Enabling filter");
+
+ checkNotifications(() =>
+ {
+ filter.lastHit = 1234;
+ }, ["filter.lastHit", "foobar", 1234, 0], "Changing last filter hit");
+ checkNotifications(() =>
+ {
+ filter.lastHit = 1234;
+ }, null, "Changing last filter hit to same value");
+ checkNotifications(() =>
+ {
+ filter.lastHit = 0;
+ }, ["filter.lastHit", "foobar", 0, 1234], "Resetting last filter hit");
+
+ checkNotifications(() =>
+ {
+ filter.hitCount++;
+ }, ["filter.hitCount", "foobar", 1, 0], "Increasing filter hit counts");
+ checkNotifications(() =>
+ {
+ filter.hitCount = 0;
+ }, ["filter.hitCount", "foobar", 0, 1], "Resetting filter hit counts");
+
+ filter.delete();
+ test.done();
+};
« 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