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: 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 | « 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)
@@ -249,8 +251,117 @@ 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, newValue, oldValue) =>
+ {
+ if (result)
+ test.ok(false, "Got more that one notification - " + message);
+ else
+ result = [topic, subscription.url, newValue, oldValue];
+ };
+ 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/", "foobar", "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/", "", "foobar"], "Resetting subscription title");
+
+ checkNotifications(() =>
+ {
+ subscription.disabled = true;
+ }, ["subscription.disabled", "http://example.com/", true, false], "Disabling subscription");
+ checkNotifications(() =>
+ {
+ subscription.disabled = true;
+ }, null, "Disabling already disabled subscription");
+ checkNotifications(() =>
+ {
+ subscription.disabled = false;
+ }, ["subscription.disabled", "http://example.com/", false, true], "Enabling subscription");
+
+ checkNotifications(() =>
+ {
+ subscription.fixedTitle = true;
+ }, ["subscription.fixedTitle", "http://example.com/", true, false], "Marking title as fixed");
+ checkNotifications(() =>
+ {
+ subscription.fixedTitle = false;
+ }, ["subscription.fixedTitle", "http://example.com/", false, true], "Marking title as editable");
+
+ checkNotifications(() =>
+ {
+ subscription.homepage = "http://example.info/";
+ }, ["subscription.homepage", "http://example.com/", "http://example.info/", ""], "Changing subscription homepage");
+ checkNotifications(() =>
+ {
+ subscription.homepage = null;
+ }, ["subscription.homepage", "http://example.com/", "", "http://example.info/"], "Resetting subscription homepage");
+
+ checkNotifications(() =>
+ {
+ // Using a large number that will only fit into double but not int
+ subscription.lastCheck = 123456789012345;
+ }, ["subscription.lastCheck", "http://example.com/", 123456789012345, 0], "Changing subscription.lastCheck");
+ checkNotifications(() =>
+ {
+ subscription.lastCheck = 123456789012345;
+ }, null, "Setting subscription.lastCheck to same value");
+ checkNotifications(() =>
+ {
+ subscription.lastCheck = 0;
+ }, ["subscription.lastCheck", "http://example.com/", 0, 123456789012345], "Resetting subscription.lastCheck");
+
+ checkNotifications(() =>
+ {
+ // Using a large number that will only fit into double but not int
+ subscription.lastDownload = 543210987654321;
+ }, ["subscription.lastDownload", "http://example.com/", 543210987654321, 0], "Changing subscription.lastDownload");
+ checkNotifications(() =>
+ {
+ subscription.lastDownload = 0;
+ }, ["subscription.lastDownload", "http://example.com/", 0, 543210987654321], "Resetting subscription.lastDownload");
+
+ checkNotifications(() =>
+ {
+ subscription.downloadStatus = "ok";
+ }, ["subscription.downloadStatus", "http://example.com/", "ok", ""], "Changing subscription.downloadStatus");
+ checkNotifications(() =>
+ {
+ subscription.downloadStatus = null;
+ }, ["subscription.downloadStatus", "http://example.com/", "", "ok"], "Resetting subscription.downloadStatus");
+
+ checkNotifications(() =>
+ {
+ subscription.errors++;
+ }, ["subscription.errors", "http://example.com/", 1, 0], "Increasing subscription.errors");
+ checkNotifications(() =>
+ {
+ subscription.errors = 0;
+ }, ["subscription.errors", "http://example.com/", 0, 1], "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