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

Unified Diff: test/filterStorage.js

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased. Created April 5, 2019, 4:16 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
« no previous file with comments | « test/filterNotifier.js ('k') | test/filterStorage_readwrite.js » ('j') | 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
@@ -12,515 +12,501 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
+const assert = require("assert");
const {createSandbox} = require("./_common");
let Filter = null;
let filterNotifier = null;
let filterStorage = null;
let Subscription = null;
-exports.setUp = function(callback)
-{
- let sandboxedRequire = createSandbox();
-
- sandboxedRequire("../lib/filterListener");
- (
- {Filter} = sandboxedRequire("../lib/filterClasses"),
- {filterNotifier} = sandboxedRequire("../lib/filterNotifier"),
- {filterStorage} = sandboxedRequire("../lib/filterStorage"),
- {Subscription} = sandboxedRequire("../lib/subscriptionClasses")
- );
-
- callback();
-};
-
-function addListener(listener)
-{
- let makeWrapper = name => (...args) => listener(name, ...args);
-
- filterNotifier.on("subscription.added", makeWrapper("subscription.added"));
- filterNotifier.on("subscription.removed",
- makeWrapper("subscription.removed"));
-
- filterNotifier.on("filter.added", makeWrapper("filter.added"));
- filterNotifier.on("filter.removed", makeWrapper("filter.removed"));
- filterNotifier.on("filter.moved", makeWrapper("filter.moved"));
-
- filterNotifier.on("filter.hitCount", makeWrapper("filter.hitCount"));
- filterNotifier.on("filter.lastHit", makeWrapper("filter.lastHit"));
-}
-
-function compareSubscriptionList(test, testMessage, list,
- knownSubscriptions = null)
-{
- let result = [...filterStorage.knownSubscriptions.keys()];
- 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.filterText()]);
- test.deepEqual(result, list, testMessage);
-}
-
-function compareFilterSubscriptions(test, testMessage, filter, list)
-{
- let result = [...filter.subscriptions()].map(subscription => subscription.url);
- let expected = list.map(subscription => subscription.url);
- test.deepEqual(result, expected, testMessage);
-}
-
-exports.testAddingSubscriptions = function(test)
+describe("Filter Storage", () =>
{
- let subscription1 = Subscription.fromURL("http://test1/");
- let subscription2 = Subscription.fromURL("http://test2/");
-
- let changes = [];
- function listener(action, subscription)
+ beforeEach(() =>
{
- if (action.indexOf("subscription.") == 0)
- changes.push(action + " " + subscription.url);
- }
- addListener(listener);
+ let sandboxedRequire = createSandbox();
+
+ sandboxedRequire("../lib/filterListener");
+ (
+ {Filter} = sandboxedRequire("../lib/filterClasses"),
+ {filterNotifier} = sandboxedRequire("../lib/filterNotifier"),
+ {filterStorage} = sandboxedRequire("../lib/filterStorage"),
+ {Subscription} = sandboxedRequire("../lib/subscriptionClasses")
+ );
+ });
- compareSubscriptionList(test, "Initial state", []);
- test.deepEqual(changes, [], "Received changes");
+ function addListener(listener)
+ {
+ let makeWrapper = name => (...args) => listener(name, ...args);
+
+ filterNotifier.on("subscription.added", makeWrapper("subscription.added"));
+ filterNotifier.on("subscription.removed",
+ makeWrapper("subscription.removed"));
+
+ filterNotifier.on("filter.added", makeWrapper("filter.added"));
+ filterNotifier.on("filter.removed", makeWrapper("filter.removed"));
+ filterNotifier.on("filter.moved", makeWrapper("filter.moved"));
- changes = [];
- filterStorage.addSubscription(subscription1);
- compareSubscriptionList(test, "Adding first subscription", [subscription1]);
- test.deepEqual(changes, ["subscription.added http://test1/"], "Received changes");
+ filterNotifier.on("filter.hitCount", makeWrapper("filter.hitCount"));
+ filterNotifier.on("filter.lastHit", makeWrapper("filter.lastHit"));
+ }
+
+ function compareSubscriptionList(testMessage, list,
+ knownSubscriptions = null)
+ {
+ let result = [...filterStorage.knownSubscriptions.keys()];
+ let expected = list.map(subscription => subscription.url);
+ assert.deepEqual(result, expected, testMessage);
- changes = [];
- filterStorage.addSubscription(subscription1);
- compareSubscriptionList(test, "Adding already added subscription", [subscription1]);
- test.deepEqual(changes, [], "Received changes");
+ if (knownSubscriptions)
+ {
+ assert.deepEqual([...Subscription.knownSubscriptions.values()],
+ knownSubscriptions, testMessage);
+ }
+ }
- changes = [];
- filterStorage.addSubscription(subscription2);
- compareSubscriptionList(test, "Adding second", [subscription1, subscription2]);
- test.deepEqual(changes, ["subscription.added http://test2/"], "Received changes");
+ function compareFiltersList(testMessage, list)
+ {
+ let result = [...filterStorage.subscriptions()].map(
+ subscription => [...subscription.filterText()]);
+ assert.deepEqual(result, list, testMessage);
+ }
+
+ function compareFilterSubscriptions(testMessage, filter, list)
+ {
+ let result = [...filter.subscriptions()].map(subscription => subscription.url);
+ let expected = list.map(subscription => subscription.url);
+ assert.deepEqual(result, expected, testMessage);
+ }
- filterStorage.removeSubscription(subscription1);
- compareSubscriptionList(test, "Remove", [subscription2]);
+ it("Adding Subscriptions", () =>
+ {
+ let subscription1 = Subscription.fromURL("http://test1/");
+ let subscription2 = Subscription.fromURL("http://test2/");
- changes = [];
- filterStorage.addSubscription(subscription1);
- compareSubscriptionList(test, "Re-adding previously removed subscription", [subscription2, subscription1]);
- test.deepEqual(changes, ["subscription.added http://test1/"], "Received changes");
+ let changes = [];
+ function listener(action, subscription)
+ {
+ if (action.indexOf("subscription.") == 0)
+ changes.push(action + " " + subscription.url);
+ }
+ addListener(listener);
- test.done();
-};
+ compareSubscriptionList("Initial state", []);
+ assert.deepEqual(changes, [], "Received changes");
-exports.testRemovingSubscriptions = function(test)
-{
- let subscription1 = Subscription.fromURL("http://test1/");
- let subscription2 = Subscription.fromURL("http://test2/");
+ changes = [];
+ filterStorage.addSubscription(subscription1);
+ compareSubscriptionList("Adding first subscription", [subscription1]);
+ assert.deepEqual(changes, ["subscription.added http://test1/"], "Received changes");
+
+ changes = [];
+ filterStorage.addSubscription(subscription1);
+ compareSubscriptionList("Adding already added subscription", [subscription1]);
+ assert.deepEqual(changes, [], "Received changes");
- test.equal(Subscription.fromURL(subscription1.url), subscription1,
- "Subscription known before addition");
+ changes = [];
+ filterStorage.addSubscription(subscription2);
+ compareSubscriptionList("Adding second", [subscription1, subscription2]);
+ assert.deepEqual(changes, ["subscription.added http://test2/"], "Received changes");
+
+ filterStorage.removeSubscription(subscription1);
+ compareSubscriptionList("Remove", [subscription2]);
- filterStorage.addSubscription(subscription1);
- filterStorage.addSubscription(subscription2);
+ changes = [];
+ filterStorage.addSubscription(subscription1);
+ compareSubscriptionList("Re-adding previously removed subscription", [subscription2, subscription1]);
+ assert.deepEqual(changes, ["subscription.added http://test1/"], "Received changes");
+ });
- let changes = [];
- function listener(action, subscription)
+ it("Removing Subscriptions", () =>
{
- if (action.indexOf("subscription.") == 0)
- changes.push(action + " " + subscription.url);
- }
- addListener(listener);
+ let subscription1 = Subscription.fromURL("http://test1/");
+ let subscription2 = Subscription.fromURL("http://test2/");
+
+ assert.equal(Subscription.fromURL(subscription1.url), subscription1,
+ "Subscription known before addition");
- compareSubscriptionList(test, "Initial state", [subscription1, subscription2],
- [subscription1, subscription2]);
- test.deepEqual(changes, [], "Received changes");
+ filterStorage.addSubscription(subscription1);
+ filterStorage.addSubscription(subscription2);
+
+ let changes = [];
+ function listener(action, subscription)
+ {
+ if (action.indexOf("subscription.") == 0)
+ changes.push(action + " " + subscription.url);
+ }
+ addListener(listener);
- test.equal(Subscription.fromURL(subscription1.url), subscription1,
- "Subscription known after addition");
+ compareSubscriptionList("Initial state", [subscription1, subscription2],
+ [subscription1, subscription2]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.removeSubscription(subscription1);
- compareSubscriptionList(test, "Removing first subscription", [subscription2],
- [subscription2]);
- test.deepEqual(changes, ["subscription.removed http://test1/"], "Received changes");
+ assert.equal(Subscription.fromURL(subscription1.url), subscription1,
+ "Subscription known after addition");
+
+ changes = [];
+ filterStorage.removeSubscription(subscription1);
+ compareSubscriptionList("Removing first subscription", [subscription2],
+ [subscription2]);
+ assert.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);
+ // Once a subscription has been removed, it is forgotten; a new object is
+ // created for the previously known subscription URL.
+ assert.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],
- [subscription2]);
- test.deepEqual(changes, [], "Received changes");
+ changes = [];
+ filterStorage.removeSubscription(subscription1);
+ compareSubscriptionList("Removing already removed subscription", [subscription2],
+ [subscription2]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.removeSubscription(subscription2);
- compareSubscriptionList(test, "Removing remaining subscription", [], []);
- test.deepEqual(changes, ["subscription.removed http://test2/"], "Received changes");
-
- filterStorage.addSubscription(subscription1);
- compareSubscriptionList(test, "Add", [subscription1], []);
+ changes = [];
+ filterStorage.removeSubscription(subscription2);
+ compareSubscriptionList("remaining subscription", [], []);
+ assert.deepEqual(changes, ["subscription.removed http://test2/"], "Received changes");
- changes = [];
- filterStorage.removeSubscription(subscription1);
- compareSubscriptionList(test, "Re-removing previously added subscription", [], []);
- test.deepEqual(changes, ["subscription.removed http://test1/"], "Received changes");
+ filterStorage.addSubscription(subscription1);
+ compareSubscriptionList("Add", [subscription1], []);
- test.done();
-};
+ changes = [];
+ filterStorage.removeSubscription(subscription1);
+ compareSubscriptionList("Re-removing previously added subscription", [], []);
+ assert.deepEqual(changes, ["subscription.removed http://test1/"], "Received changes");
+ });
-exports.testMovingSubscriptions = function(test)
-{
- let subscription1 = Subscription.fromURL("http://test1/");
- let subscription2 = Subscription.fromURL("http://test2/");
- let subscription3 = Subscription.fromURL("http://test3/");
+ it("Moving Subscriptions", () =>
+ {
+ let subscription1 = Subscription.fromURL("http://test1/");
+ let subscription2 = Subscription.fromURL("http://test2/");
+ let subscription3 = Subscription.fromURL("http://test3/");
- filterStorage.addSubscription(subscription1);
- filterStorage.addSubscription(subscription2);
- filterStorage.addSubscription(subscription3);
+ filterStorage.addSubscription(subscription1);
+ filterStorage.addSubscription(subscription2);
+ filterStorage.addSubscription(subscription3);
- let changes = [];
- function listener(action, subscription)
- {
- if (action.indexOf("subscription.") == 0)
- changes.push(action + " " + subscription.url);
- }
- addListener(listener);
+ let changes = [];
+ function listener(action, subscription)
+ {
+ if (action.indexOf("subscription.") == 0)
+ changes.push(action + " " + subscription.url);
+ }
+ addListener(listener);
- compareSubscriptionList(test, "Initial state", [subscription1, subscription2, subscription3]);
- test.deepEqual(changes, [], "Received changes");
-
- filterStorage.removeSubscription(subscription2);
- compareSubscriptionList(test, "Remove", [subscription1, subscription3]);
+ compareSubscriptionList("Initial state", [subscription1, subscription2, subscription3]);
+ assert.deepEqual(changes, [], "Received changes");
- test.done();
-};
+ filterStorage.removeSubscription(subscription2);
+ compareSubscriptionList("Remove", [subscription1, subscription3]);
+ });
-exports.testAddingFilters = function(test)
-{
- let subscription1 = Subscription.fromURL("~blocking");
- subscription1.defaults = ["blocking"];
+ it("Adding Filters", () =>
+ {
+ let subscription1 = Subscription.fromURL("~blocking");
+ subscription1.defaults = ["blocking"];
- let subscription2 = Subscription.fromURL("~exceptions");
- subscription2.defaults = ["whitelist", "elemhide"];
+ let subscription2 = Subscription.fromURL("~exceptions");
+ subscription2.defaults = ["whitelist", "elemhide"];
- let subscription3 = Subscription.fromURL("~other");
+ let subscription3 = Subscription.fromURL("~other");
- filterStorage.addSubscription(subscription1);
- filterStorage.addSubscription(subscription2);
- filterStorage.addSubscription(subscription3);
+ filterStorage.addSubscription(subscription1);
+ filterStorage.addSubscription(subscription2);
+ filterStorage.addSubscription(subscription3);
- let changes = [];
- function listener(action, filter)
- {
- if (action.indexOf("filter.") == 0)
- changes.push(action + " " + filter.text);
- }
- addListener(listener);
+ let changes = [];
+ function listener(action, filter)
+ {
+ if (action.indexOf("filter.") == 0)
+ changes.push(action + " " + filter.text);
+ }
+ addListener(listener);
- compareFiltersList(test, "Initial state", [[], [], []]);
- test.deepEqual(changes, [], "Received changes");
+ compareFiltersList("Initial state", [[], [], []]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("foo"));
- compareFiltersList(test, "Adding blocking filter", [["foo"], [], []]);
- test.deepEqual(changes, ["filter.added foo"], "Received changes");
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("foo"));
+ compareFiltersList("Adding blocking filter", [["foo"], [], []]);
+ assert.deepEqual(changes, ["filter.added foo"], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("@@bar"));
- compareFiltersList(test, "Adding exception rule", [["foo"], ["@@bar"], []]);
- test.deepEqual(changes, ["filter.added @@bar"], "Received changes");
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("@@bar"));
+ compareFiltersList("Adding exception rule", [["foo"], ["@@bar"], []]);
+ assert.deepEqual(changes, ["filter.added @@bar"], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("foo##bar"));
- compareFiltersList(test, "Adding hiding rule", [["foo"], ["@@bar", "foo##bar"], []]);
- test.deepEqual(changes, ["filter.added foo##bar"], "Received changes");
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("foo##bar"));
+ compareFiltersList("Adding hiding rule", [["foo"], ["@@bar", "foo##bar"], []]);
+ assert.deepEqual(changes, ["filter.added foo##bar"], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("foo#@#bar"));
- compareFiltersList(test, "Adding hiding exception", [["foo"], ["@@bar", "foo##bar", "foo#@#bar"], []]);
- test.deepEqual(changes, ["filter.added foo#@#bar"], "Received changes");
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("foo#@#bar"));
+ compareFiltersList("Adding hiding exception", [["foo"], ["@@bar", "foo##bar", "foo#@#bar"], []]);
+ assert.deepEqual(changes, ["filter.added foo#@#bar"], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("example.com#$#foobar"));
- compareFiltersList(test, "Adding snippet filter", [["foo"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar"]]);
- test.deepEqual(changes, ["filter.added example.com#$#foobar"], "Received changes");
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("example.com#$#foobar"));
+ compareFiltersList("Adding snippet filter", [["foo"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar"]]);
+ assert.deepEqual(changes, ["filter.added example.com#$#foobar"], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("!foobar"));
- compareFiltersList(test, "Adding comment", [["foo", "!foobar"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar"]]);
- test.deepEqual(changes, ["filter.added !foobar"], "Received changes");
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("!foobar"));
+ compareFiltersList("Adding comment", [["foo", "!foobar"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar"]]);
+ assert.deepEqual(changes, ["filter.added !foobar"], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("foo"));
- compareFiltersList(test, "Adding already added filter", [["foo", "!foobar"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar"]]);
- test.deepEqual(changes, [], "Received changes");
-
- subscription1.disabled = true;
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("foo"));
+ compareFiltersList("Adding already added filter", [["foo", "!foobar"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar"]]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("foo"));
- compareFiltersList(test, "Adding filter already in a disabled subscription", [["foo", "!foobar"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar", "foo"]]);
- test.deepEqual(changes, ["filter.added foo"], "Received changes");
+ subscription1.disabled = true;
- changes = [];
- filterStorage.addFilter(Filter.fromText("foo"), subscription1);
- compareFiltersList(test, "Adding filter to an explicit subscription", [["foo", "!foobar", "foo"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar", "foo"]]);
- test.deepEqual(changes, ["filter.added foo"], "Received changes");
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("foo"));
+ compareFiltersList("Adding filter already in a disabled subscription", [["foo", "!foobar"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar", "foo"]]);
+ assert.deepEqual(changes, ["filter.added foo"], "Received changes");
+
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("foo"), subscription1);
+ compareFiltersList("Adding filter to an explicit subscription", [["foo", "!foobar", "foo"], ["@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar", "foo"]]);
+ assert.deepEqual(changes, ["filter.added foo"], "Received changes");
- changes = [];
- filterStorage.addFilter(Filter.fromText("example.com#$#foobar"), subscription2, 0);
- compareFiltersList(test, "Adding filter to an explicit subscription with position", [["foo", "!foobar", "foo"], ["example.com#$#foobar", "@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar", "foo"]]);
- test.deepEqual(changes, ["filter.added example.com#$#foobar"], "Received changes");
+ changes = [];
+ filterStorage.addFilter(Filter.fromText("example.com#$#foobar"), subscription2, 0);
+ compareFiltersList("Adding filter to an explicit subscription with position", [["foo", "!foobar", "foo"], ["example.com#$#foobar", "@@bar", "foo##bar", "foo#@#bar"], ["example.com#$#foobar", "foo"]]);
+ assert.deepEqual(changes, ["filter.added example.com#$#foobar"], "Received changes");
+ });
- test.done();
-};
-
-exports.testRemovingFilters = function(test)
-{
- let subscription1 = Subscription.fromURL("~foo");
- subscription1.addFilter(Filter.fromText("foo"));
- subscription1.addFilter(Filter.fromText("foo"));
- subscription1.addFilter(Filter.fromText("bar"));
+ it("Removing Filters", () =>
+ {
+ let subscription1 = Subscription.fromURL("~foo");
+ subscription1.addFilter(Filter.fromText("foo"));
+ subscription1.addFilter(Filter.fromText("foo"));
+ subscription1.addFilter(Filter.fromText("bar"));
- let subscription2 = Subscription.fromURL("~bar");
- subscription2.addFilter(Filter.fromText("foo"));
- subscription2.addFilter(Filter.fromText("bar"));
- subscription2.addFilter(Filter.fromText("foo"));
+ let subscription2 = Subscription.fromURL("~bar");
+ subscription2.addFilter(Filter.fromText("foo"));
+ subscription2.addFilter(Filter.fromText("bar"));
+ subscription2.addFilter(Filter.fromText("foo"));
- let subscription3 = Subscription.fromURL("http://test/");
- subscription3.addFilter(Filter.fromText("foo"));
- subscription3.addFilter(Filter.fromText("bar"));
+ let subscription3 = Subscription.fromURL("http://test/");
+ subscription3.addFilter(Filter.fromText("foo"));
+ subscription3.addFilter(Filter.fromText("bar"));
- filterStorage.addSubscription(subscription1);
- filterStorage.addSubscription(subscription2);
- filterStorage.addSubscription(subscription3);
+ filterStorage.addSubscription(subscription1);
+ filterStorage.addSubscription(subscription2);
+ filterStorage.addSubscription(subscription3);
- let changes = [];
- function listener(action, filter)
- {
- if (action.indexOf("filter.") == 0)
- changes.push(action + " " + filter.text);
- }
- addListener(listener);
+ let changes = [];
+ function listener(action, filter)
+ {
+ if (action.indexOf("filter.") == 0)
+ changes.push(action + " " + filter.text);
+ }
+ addListener(listener);
- compareFiltersList(test, "Initial state", [["foo", "foo", "bar"], ["foo", "bar", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, [], "Received changes");
+ compareFiltersList("Initial state", [["foo", "foo", "bar"], ["foo", "bar", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.removeFilter(Filter.fromText("foo"), subscription2, 0);
- compareFiltersList(test, "Remove with explicit subscription and position", [["foo", "foo", "bar"], ["bar", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, ["filter.removed foo"], "Received changes");
+ changes = [];
+ filterStorage.removeFilter(Filter.fromText("foo"), subscription2, 0);
+ compareFiltersList("Remove with explicit subscription and position", [["foo", "foo", "bar"], ["bar", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, ["filter.removed foo"], "Received changes");
- changes = [];
- filterStorage.removeFilter(Filter.fromText("foo"), subscription2, 0);
- compareFiltersList(test, "Remove with explicit subscription and wrong position", [["foo", "foo", "bar"], ["bar", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, [], "Received changes");
+ changes = [];
+ filterStorage.removeFilter(Filter.fromText("foo"), subscription2, 0);
+ compareFiltersList("Remove with explicit subscription and wrong position", [["foo", "foo", "bar"], ["bar", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.removeFilter(Filter.fromText("foo"), subscription1);
- compareFiltersList(test, "Remove with explicit subscription", [["bar"], ["bar", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, ["filter.removed foo", "filter.removed foo"], "Received changes");
+ changes = [];
+ filterStorage.removeFilter(Filter.fromText("foo"), subscription1);
+ compareFiltersList("Remove with explicit subscription", [["bar"], ["bar", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, ["filter.removed foo", "filter.removed foo"], "Received changes");
- changes = [];
- filterStorage.removeFilter(Filter.fromText("foo"), subscription1);
- compareFiltersList(test, "Remove from subscription not having the filter", [["bar"], ["bar", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, [], "Received changes");
-
- changes = [];
- filterStorage.removeFilter(Filter.fromText("bar"));
- compareFiltersList(test, "Remove everywhere", [[], ["foo"], ["foo", "bar"]]);
- test.deepEqual(changes, ["filter.removed bar", "filter.removed bar"], "Received changes");
+ changes = [];
+ filterStorage.removeFilter(Filter.fromText("foo"), subscription1);
+ compareFiltersList("Remove from subscription not having the filter", [["bar"], ["bar", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.removeFilter(Filter.fromText("bar"));
- compareFiltersList(test, "Remove of unknown filter", [[], ["foo"], ["foo", "bar"]]);
- test.deepEqual(changes, [], "Received changes");
-
- test.done();
-};
+ changes = [];
+ filterStorage.removeFilter(Filter.fromText("bar"));
+ compareFiltersList("Remove everywhere", [[], ["foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, ["filter.removed bar", "filter.removed bar"], "Received changes");
-exports.testMovingFilters = function(test)
-{
- let subscription1 = Subscription.fromURL("~foo");
- subscription1.addFilter(Filter.fromText("foo"));
- subscription1.addFilter(Filter.fromText("bar"));
- subscription1.addFilter(Filter.fromText("bas"));
- subscription1.addFilter(Filter.fromText("foo"));
+ changes = [];
+ filterStorage.removeFilter(Filter.fromText("bar"));
+ compareFiltersList("Remove of unknown filter", [[], ["foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, [], "Received changes");
+ });
+
+ it("Moving Filters", () =>
+ {
+ let subscription1 = Subscription.fromURL("~foo");
+ subscription1.addFilter(Filter.fromText("foo"));
+ subscription1.addFilter(Filter.fromText("bar"));
+ subscription1.addFilter(Filter.fromText("bas"));
+ subscription1.addFilter(Filter.fromText("foo"));
- let subscription2 = Subscription.fromURL("http://test/");
- subscription2.addFilter(Filter.fromText("foo"));
- subscription2.addFilter(Filter.fromText("bar"));
+ let subscription2 = Subscription.fromURL("http://test/");
+ subscription2.addFilter(Filter.fromText("foo"));
+ subscription2.addFilter(Filter.fromText("bar"));
- filterStorage.addSubscription(subscription1);
- filterStorage.addSubscription(subscription2);
+ filterStorage.addSubscription(subscription1);
+ filterStorage.addSubscription(subscription2);
- let changes = [];
- function listener(action, filter)
- {
- if (action.indexOf("filter.") == 0)
- changes.push(action + " " + filter.text);
- }
- addListener(listener);
+ let changes = [];
+ function listener(action, filter)
+ {
+ if (action.indexOf("filter.") == 0)
+ changes.push(action + " " + filter.text);
+ }
+ addListener(listener);
- compareFiltersList(test, "Initial state", [["foo", "bar", "bas", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, [], "Received changes");
+ compareFiltersList("Initial state", [["foo", "bar", "bas", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.moveFilter(Filter.fromText("foo"), subscription1, 0, 1);
- compareFiltersList(test, "Regular move", [["bar", "foo", "bas", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, ["filter.moved foo"], "Received changes");
+ changes = [];
+ filterStorage.moveFilter(Filter.fromText("foo"), subscription1, 0, 1);
+ compareFiltersList("Regular move", [["bar", "foo", "bas", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, ["filter.moved foo"], "Received changes");
- changes = [];
- filterStorage.moveFilter(Filter.fromText("foo"), subscription1, 0, 3);
- compareFiltersList(test, "Invalid move", [["bar", "foo", "bas", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, [], "Received changes");
+ changes = [];
+ filterStorage.moveFilter(Filter.fromText("foo"), subscription1, 0, 3);
+ compareFiltersList("Invalid move", [["bar", "foo", "bas", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.moveFilter(Filter.fromText("foo"), subscription2, 0, 1);
- compareFiltersList(test, "Invalid subscription", [["bar", "foo", "bas", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, [], "Received changes");
+ changes = [];
+ filterStorage.moveFilter(Filter.fromText("foo"), subscription2, 0, 1);
+ compareFiltersList("Invalid subscription", [["bar", "foo", "bas", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.moveFilter(Filter.fromText("foo"), subscription1, 1, 1);
- compareFiltersList(test, "Move to current position", [["bar", "foo", "bas", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, [], "Received changes");
+ changes = [];
+ filterStorage.moveFilter(Filter.fromText("foo"), subscription1, 1, 1);
+ compareFiltersList("Move to current position", [["bar", "foo", "bas", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, [], "Received changes");
- changes = [];
- filterStorage.moveFilter(Filter.fromText("bar"), subscription1, 0, 1);
- compareFiltersList(test, "Regular move", [["foo", "bar", "bas", "foo"], ["foo", "bar"]]);
- test.deepEqual(changes, ["filter.moved bar"], "Received changes");
-
- test.done();
-};
+ changes = [];
+ filterStorage.moveFilter(Filter.fromText("bar"), subscription1, 0, 1);
+ compareFiltersList("Regular move", [["foo", "bar", "bas", "foo"], ["foo", "bar"]]);
+ assert.deepEqual(changes, ["filter.moved bar"], "Received changes");
+ });
-exports.testHitCounts = function(test)
-{
- let changes = [];
- function listener(action, filter)
+ it("Hit Counts", () =>
{
- if (action.indexOf("filter.") == 0)
- changes.push(action + " " + filter.text);
- }
- addListener(listener);
+ let changes = [];
+ function listener(action, filter)
+ {
+ if (action.indexOf("filter.") == 0)
+ changes.push(action + " " + filter.text);
+ }
+ addListener(listener);
- let filter1 = Filter.fromText("filter1");
- let filter2 = Filter.fromText("filter2");
+ let filter1 = Filter.fromText("filter1");
+ let filter2 = Filter.fromText("filter2");
- filterStorage.addFilter(filter1);
+ filterStorage.addFilter(filter1);
- test.equal(filter1.hitCount, 0, "filter1 initial hit count");
- test.equal(filter2.hitCount, 0, "filter2 initial hit count");
- test.equal(filter1.lastHit, 0, "filter1 initial last hit");
- test.equal(filter2.lastHit, 0, "filter2 initial last hit");
+ assert.equal(filter1.hitCount, 0, "filter1 initial hit count");
+ assert.equal(filter2.hitCount, 0, "filter2 initial hit count");
+ assert.equal(filter1.lastHit, 0, "filter1 initial last hit");
+ assert.equal(filter2.lastHit, 0, "filter2 initial last hit");
- changes = [];
- filterStorage.increaseHitCount(filter1);
- test.equal(filter1.hitCount, 1, "Hit count after increase (filter in list)");
- test.ok(filter1.lastHit > 0, "Last hit changed after increase");
- test.deepEqual(changes, ["filter.hitCount filter1", "filter.lastHit filter1"], "Received changes");
+ changes = [];
+ filterStorage.increaseHitCount(filter1);
+ assert.equal(filter1.hitCount, 1, "Hit count after increase (filter in list)");
+ assert.ok(filter1.lastHit > 0, "Last hit changed after increase");
+ assert.deepEqual(changes, ["filter.hitCount filter1", "filter.lastHit filter1"], "Received changes");
- changes = [];
- filterStorage.increaseHitCount(filter2);
- test.equal(filter2.hitCount, 1, "Hit count after increase (filter not in list)");
- test.ok(filter2.lastHit > 0, "Last hit changed after increase");
- test.deepEqual(changes, ["filter.hitCount filter2", "filter.lastHit filter2"], "Received changes");
+ changes = [];
+ filterStorage.increaseHitCount(filter2);
+ assert.equal(filter2.hitCount, 1, "Hit count after increase (filter not in list)");
+ assert.ok(filter2.lastHit > 0, "Last hit changed after increase");
+ assert.deepEqual(changes, ["filter.hitCount filter2", "filter.lastHit filter2"], "Received changes");
- changes = [];
- filterStorage.resetHitCounts([filter1]);
- test.equal(filter1.hitCount, 0, "Hit count after reset");
- test.equal(filter1.lastHit, 0, "Last hit after reset");
- test.deepEqual(changes, ["filter.hitCount filter1", "filter.lastHit filter1"], "Received changes");
+ changes = [];
+ filterStorage.resetHitCounts([filter1]);
+ assert.equal(filter1.hitCount, 0, "Hit count after reset");
+ assert.equal(filter1.lastHit, 0, "Last hit after reset");
+ assert.deepEqual(changes, ["filter.hitCount filter1", "filter.lastHit filter1"], "Received changes");
- changes = [];
- filterStorage.resetHitCounts(null);
- test.equal(filter2.hitCount, 0, "Hit count after complete reset");
- test.equal(filter2.lastHit, 0, "Last hit after complete reset");
- test.deepEqual(changes, ["filter.hitCount filter2", "filter.lastHit filter2"], "Received changes");
-
- test.done();
-};
+ changes = [];
+ filterStorage.resetHitCounts(null);
+ assert.equal(filter2.hitCount, 0, "Hit count after complete reset");
+ assert.equal(filter2.lastHit, 0, "Last hit after complete reset");
+ assert.deepEqual(changes, ["filter.hitCount filter2", "filter.lastHit filter2"], "Received changes");
+ });
-exports.testFilterSubscriptionRelationship = function(test)
-{
- let filter1 = Filter.fromText("filter1");
- let filter2 = Filter.fromText("filter2");
- let filter3 = Filter.fromText("filter3");
+ it("Subscription Relationship", () =>
+ {
+ let filter1 = Filter.fromText("filter1");
+ let filter2 = Filter.fromText("filter2");
+ let filter3 = Filter.fromText("filter3");
- let subscription1 = Subscription.fromURL("http://test1/");
- subscription1.addFilter(filter1);
- subscription1.addFilter(filter2);
+ let subscription1 = Subscription.fromURL("http://test1/");
+ subscription1.addFilter(filter1);
+ subscription1.addFilter(filter2);
- let subscription2 = Subscription.fromURL("http://test2/");
- subscription2.addFilter(filter2);
- subscription2.addFilter(filter3);
+ let subscription2 = Subscription.fromURL("http://test2/");
+ subscription2.addFilter(filter2);
+ subscription2.addFilter(filter3);
- let subscription3 = Subscription.fromURL("http://test3/");
- subscription3.addFilter(filter1);
- subscription3.addFilter(filter2);
- subscription3.addFilter(filter3);
+ let subscription3 = Subscription.fromURL("http://test3/");
+ subscription3.addFilter(filter1);
+ subscription3.addFilter(filter2);
+ subscription3.addFilter(filter3);
- compareFilterSubscriptions(test, "Initial filter1 subscriptions", filter1, []);
- compareFilterSubscriptions(test, "Initial filter2 subscriptions", filter2, []);
- compareFilterSubscriptions(test, "Initial filter3 subscriptions", filter3, []);
+ compareFilterSubscriptions("Initial filter1 subscriptions", filter1, []);
+ compareFilterSubscriptions("Initial filter2 subscriptions", filter2, []);
+ compareFilterSubscriptions("Initial filter3 subscriptions", filter3, []);
- filterStorage.addSubscription(subscription1);
+ filterStorage.addSubscription(subscription1);
- compareFilterSubscriptions(test, "filter1 subscriptions after adding http://test1/", filter1, [subscription1]);
- compareFilterSubscriptions(test, "filter2 subscriptions after adding http://test1/", filter2, [subscription1]);
- compareFilterSubscriptions(test, "filter3 subscriptions after adding http://test1/", filter3, []);
+ compareFilterSubscriptions("filter1 subscriptions after adding http://test1/", filter1, [subscription1]);
+ compareFilterSubscriptions("filter2 subscriptions after adding http://test1/", filter2, [subscription1]);
+ compareFilterSubscriptions("filter3 subscriptions after adding http://test1/", filter3, []);
- filterStorage.addSubscription(subscription2);
+ filterStorage.addSubscription(subscription2);
- compareFilterSubscriptions(test, "filter1 subscriptions after adding http://test2/", filter1, [subscription1]);
- compareFilterSubscriptions(test, "filter2 subscriptions after adding http://test2/", filter2, [subscription1, subscription2]);
- compareFilterSubscriptions(test, "filter3 subscriptions after adding http://test2/", filter3, [subscription2]);
+ compareFilterSubscriptions("filter1 subscriptions after adding http://test2/", filter1, [subscription1]);
+ compareFilterSubscriptions("filter2 subscriptions after adding http://test2/", filter2, [subscription1, subscription2]);
+ compareFilterSubscriptions("filter3 subscriptions after adding http://test2/", filter3, [subscription2]);
- filterStorage.removeSubscription(subscription1);
+ filterStorage.removeSubscription(subscription1);
- compareFilterSubscriptions(test, "filter1 subscriptions after removing http://test1/", filter1, []);
- compareFilterSubscriptions(test, "filter2 subscriptions after removing http://test1/", filter2, [subscription2]);
- compareFilterSubscriptions(test, "filter3 subscriptions after removing http://test1/", filter3, [subscription2]);
+ compareFilterSubscriptions("filter1 subscriptions after removing http://test1/", filter1, []);
+ compareFilterSubscriptions("filter2 subscriptions after removing http://test1/", filter2, [subscription2]);
+ compareFilterSubscriptions("filter3 subscriptions after removing http://test1/", filter3, [subscription2]);
- filterStorage.updateSubscriptionFilters(subscription3, [filter3.text]);
+ filterStorage.updateSubscriptionFilters(subscription3, [filter3.text]);
- compareFilterSubscriptions(test, "filter1 subscriptions after updating http://test3/ filters", filter1, []);
- compareFilterSubscriptions(test, "filter2 subscriptions after updating http://test3/ filters", filter2, [subscription2]);
- compareFilterSubscriptions(test, "filter3 subscriptions after updating http://test3/ filters", filter3, [subscription2]);
+ compareFilterSubscriptions("filter1 subscriptions after updating http://test3/ filters", filter1, []);
+ compareFilterSubscriptions("filter2 subscriptions after updating http://test3/ filters", filter2, [subscription2]);
+ compareFilterSubscriptions("filter3 subscriptions after updating http://test3/ filters", filter3, [subscription2]);
- filterStorage.addSubscription(subscription3);
+ filterStorage.addSubscription(subscription3);
- compareFilterSubscriptions(test, "filter1 subscriptions after adding http://test3/", filter1, []);
- compareFilterSubscriptions(test, "filter2 subscriptions after adding http://test3/", filter2, [subscription2]);
- compareFilterSubscriptions(test, "filter3 subscriptions after adding http://test3/", filter3, [subscription2, subscription3]);
+ compareFilterSubscriptions("filter1 subscriptions after adding http://test3/", filter1, []);
+ compareFilterSubscriptions("filter2 subscriptions after adding http://test3/", filter2, [subscription2]);
+ compareFilterSubscriptions("filter3 subscriptions after adding http://test3/", filter3, [subscription2, subscription3]);
- filterStorage.updateSubscriptionFilters(subscription3, [filter1.text, filter2.text]);
+ filterStorage.updateSubscriptionFilters(subscription3, [filter1.text, filter2.text]);
- compareFilterSubscriptions(test, "filter1 subscriptions after updating http://test3/ filters", filter1, [subscription3]);
- compareFilterSubscriptions(test, "filter2 subscriptions after updating http://test3/ filters", filter2, [subscription2, subscription3]);
- compareFilterSubscriptions(test, "filter3 subscriptions after updating http://test3/ filters", filter3, [subscription2]);
+ compareFilterSubscriptions("filter1 subscriptions after updating http://test3/ filters", filter1, [subscription3]);
+ compareFilterSubscriptions("filter2 subscriptions after updating http://test3/ filters", filter2, [subscription2, subscription3]);
+ compareFilterSubscriptions("filter3 subscriptions after updating http://test3/ filters", filter3, [subscription2]);
- filterStorage.removeSubscription(subscription3);
+ filterStorage.removeSubscription(subscription3);
- compareFilterSubscriptions(test, "filter1 subscriptions after removing http://test3/", filter1, []);
- compareFilterSubscriptions(test, "filter2 subscriptions after removing http://test3/", filter2, [subscription2]);
- compareFilterSubscriptions(test, "filter3 subscriptions after removing http://test3/", filter3, [subscription2]);
-
- test.done();
-};
+ compareFilterSubscriptions("filter1 subscriptions after removing http://test3/", filter1, []);
+ compareFilterSubscriptions("filter2 subscriptions after removing http://test3/", filter2, [subscription2]);
+ compareFilterSubscriptions("filter3 subscriptions after removing http://test3/", filter3, [subscription2]);
+ });
+});
« no previous file with comments | « test/filterNotifier.js ('k') | test/filterStorage_readwrite.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld