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

Unified Diff: test/subscriptionClasses.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.
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 | « test/filterClasses.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/subscriptionClasses.js
===================================================================
--- a/test/subscriptionClasses.js
+++ b/test/subscriptionClasses.js
@@ -20,26 +20,28 @@
let {createSandbox} = require("./_common");
let Filter = null;
let Subscription = null;
let SpecialSubscription = null;
let DownloadableSubscription = null;
let RegularSubscription = null;
let ExternalSubscription = null;
+let FilterNotifier = null;
exports.setUp = function(callback)
{
let sandboxedRequire = createSandbox();
({Filter} = sandboxedRequire("../lib/filterClasses"));
(
{
Subscription, SpecialSubscription, DownloadableSubscription
} = sandboxedRequire("../lib/subscriptionClasses")
);
+ ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier"));
callback();
};
function compareSubscription(test, url, expected, postInit)
{
expected.push("[Subscription]")
let subscription = Subscription.fromURL(url);
if (postInit)
@@ -253,8 +255,115 @@ exports.testFilterSerialization = functi
test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\nfilter1\n", "One filter removed");
subscription.delete();
filter1.delete();
filter2.delete();
test.done();
};
+
+exports.testNotifications = function(test)
+{
+ function checkNotifications(action, expected, message)
+ {
+ let result = null;
+ let listener = (topic, subscription) =>
+ {
+ if (result)
+ test.ok(false, "Got more that one notification - " + message);
+ else
+ result = [topic, subscription.url];
+ };
+ FilterNotifier.addListener(listener);
+ action();
+ FilterNotifier.removeListener(listener);
+ test.deepEqual(result, expected, message);
+ }
+
+ let subscription = Subscription.fromURL("http://example.com/");
+ checkNotifications(() =>
+ {
+ subscription.title = "foobar";
+ }, ["subscription.title", "http://example.com/"], "Changing subscription title");
+ checkNotifications(() =>
+ {
+ subscription.title = "foobar";
+ }, null, "Setting subscription title to same value");
+ checkNotifications(() =>
+ {
+ subscription.title = null;
+ }, ["subscription.title", "http://example.com/"], "Resetting subscription title");
+
+ checkNotifications(() =>
+ {
+ subscription.disabled = true;
+ }, ["subscription.disabled", "http://example.com/"], "Disabling subscription");
+ checkNotifications(() =>
+ {
+ subscription.disabled = true;
+ }, null, "Disabling already disabled subscription");
+ checkNotifications(() =>
+ {
+ subscription.disabled = false;
+ }, ["subscription.disabled", "http://example.com/"], "Enabling subscription");
+
+ checkNotifications(() =>
+ {
+ subscription.fixedTitle = true;
+ }, ["subscription.fixedTitle", "http://example.com/"], "Marking title as fixed");
+ checkNotifications(() =>
+ {
+ subscription.fixedTitle = false;
+ }, ["subscription.fixedTitle", "http://example.com/"], "Marking title as editable");
+
+ checkNotifications(() =>
+ {
+ subscription.homepage = "http://example.info/";
+ }, ["subscription.homepage", "http://example.com/"], "Changing subscription homepage");
+ checkNotifications(() =>
+ {
+ subscription.homepage = null;
+ }, ["subscription.homepage", "http://example.com/"], "Resetting subscription homepage");
+
+ checkNotifications(() =>
+ {
+ subscription.lastCheck = 1234;
+ }, ["subscription.lastCheck", "http://example.com/"], "Changing subscription.lastCheck");
+ checkNotifications(() =>
+ {
+ subscription.lastCheck = 1234;
+ }, null, "Setting subscription.lastCheck to same value");
+ checkNotifications(() =>
+ {
+ subscription.lastCheck = 0;
+ }, ["subscription.lastCheck", "http://example.com/"], "Resetting subscription.lastCheck");
+
+ checkNotifications(() =>
+ {
+ subscription.lastDownload = 4321;
+ }, ["subscription.lastDownload", "http://example.com/"], "Changing subscription.lastDownload");
+ checkNotifications(() =>
+ {
+ subscription.lastDownload = 0;
+ }, ["subscription.lastDownload", "http://example.com/"], "Resetting subscription.lastDownload");
+
+ checkNotifications(() =>
+ {
+ subscription.downloadStatus = "ok";
+ }, ["subscription.downloadStatus", "http://example.com/"], "Changing subscription.downloadStatus");
+ checkNotifications(() =>
+ {
+ subscription.downloadStatus = null;
+ }, ["subscription.downloadStatus", "http://example.com/"], "Resetting subscription.downloadStatus");
+
+ checkNotifications(() =>
+ {
+ subscription.errors++;
+ }, ["subscription.errors", "http://example.com/"], "Increasing subscription.errors");
+ checkNotifications(() =>
+ {
+ subscription.errors = 0;
+ }, ["subscription.errors", "http://example.com/"], "Resetting subscription.erros");
+
+ subscription.delete();
+ test.done();
+};
« no previous file with comments | « test/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld