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

Unified Diff: test/filterStorage.js

Issue 29853574: Issue 6855 - Release all references to Subscription object once removed (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Improve tests Created Aug. 16, 2018, 5:33 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 | « lib/filterStorage.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/filterStorage.js
===================================================================
--- a/test/filterStorage.js
+++ b/test/filterStorage.js
@@ -34,21 +34,28 @@
{FilterNotifier} = sandboxedRequire("../lib/filterNotifier"),
{FilterStorage} = sandboxedRequire("../lib/filterStorage"),
{Subscription} = sandboxedRequire("../lib/subscriptionClasses")
);
callback();
};
-function compareSubscriptionList(test, testMessage, list)
+function compareSubscriptionList(test, testMessage, list,
+ knownSubscriptions = null)
{
let result = FilterStorage.subscriptions.map(subscription => subscription.url);
let expected = list.map(subscription => subscription.url);
test.deepEqual(result, expected, testMessage);
+
+ if (knownSubscriptions)
+ {
+ test.deepEqual([...Subscription.knownSubscriptions.values()],
+ knownSubscriptions, testMessage);
+ }
}
function compareFiltersList(test, testMessage, list)
{
let result = FilterStorage.subscriptions.map(
subscription => subscription.filters.map(
filter => filter.text));
test.deepEqual(result, list, testMessage);
@@ -102,51 +109,67 @@
test.done();
};
exports.testRemovingSubscriptions = function(test)
{
let subscription1 = Subscription.fromURL("http://test1/");
let subscription2 = Subscription.fromURL("http://test2/");
+
+ test.equal(Subscription.fromURL(subscription1.url), subscription1,
+ "Subscription known before addition");
+
FilterStorage.addSubscription(subscription1);
FilterStorage.addSubscription(subscription2);
let changes = [];
function listener(action, subscription)
{
if (action.indexOf("subscription.") == 0)
changes.push(action + " " + subscription.url);
}
FilterNotifier.addListener(listener);
- compareSubscriptionList(test, "Initial state", [subscription1, subscription2]);
+ compareSubscriptionList(test, "Initial state", [subscription1, subscription2],
+ [subscription1, subscription2]);
test.deepEqual(changes, [], "Received changes");
+ test.equal(Subscription.fromURL(subscription1.url), subscription1,
+ "Subscription known after addition");
+
changes = [];
FilterStorage.removeSubscription(subscription1);
- compareSubscriptionList(test, "Removing first subscription", [subscription2]);
+ compareSubscriptionList(test, "Removing first subscription", [subscription2],
+ [subscription2]);
test.deepEqual(changes, ["subscription.removed http://test1/"], "Received changes");
+ // Once a subscription has been removed, it is forgotten; a new object is
+ // created for the previously known subscription URL.
+ test.notEqual(Subscription.fromURL(subscription1.url), subscription1,
+ "Subscription forgotten upon removal");
+ Subscription.knownSubscriptions.delete(subscription1.url);
+
changes = [];
FilterStorage.removeSubscription(subscription1);
- compareSubscriptionList(test, "Removing already removed subscription", [subscription2]);
+ compareSubscriptionList(test, "Removing already removed subscription", [subscription2],
+ [subscription2]);
test.deepEqual(changes, [], "Received changes");
changes = [];
FilterStorage.removeSubscription(subscription2);
- compareSubscriptionList(test, "Removing remaining subscription", []);
+ compareSubscriptionList(test, "Removing remaining subscription", [], []);
test.deepEqual(changes, ["subscription.removed http://test2/"], "Received changes");
FilterStorage.addSubscription(subscription1);
- compareSubscriptionList(test, "Add", [subscription1]);
+ compareSubscriptionList(test, "Add", [subscription1], []);
changes = [];
FilterStorage.removeSubscription(subscription1);
- compareSubscriptionList(test, "Re-removing previously added subscription", []);
+ compareSubscriptionList(test, "Re-removing previously added subscription", [], []);
test.deepEqual(changes, ["subscription.removed http://test1/"], "Received changes");
test.done();
};
exports.testMovingSubscriptions = function(test)
{
let subscription1 = Subscription.fromURL("http://test1/");
« no previous file with comments | « lib/filterStorage.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld