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

Unified Diff: test/synchronizer.js

Issue 29912619: Issue 6891, 6741 - Rename FilterStorage to filterStorage (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Minor update Created Oct. 16, 2018, 10:02 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/filterStorage_readwrite.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/synchronizer.js
===================================================================
--- a/test/synchronizer.js
+++ b/test/synchronizer.js
@@ -18,56 +18,56 @@
"use strict";
let {
createSandbox, setupTimerAndXMLHttp, setupRandomResult, unexpectedError, Cr,
MILLIS_IN_SECOND, MILLIS_IN_HOUR
} = require("./_common");
let Filter = null;
-let FilterStorage = null;
+let filterStorage = null;
let Prefs = null;
let Subscription = null;
exports.setUp = function(callback)
{
let globals = Object.assign({}, setupTimerAndXMLHttp.call(this),
setupRandomResult.call(this));
let sandboxedRequire = createSandbox({globals});
(
{Filter} = sandboxedRequire("../lib/filterClasses"),
- {FilterStorage} = sandboxedRequire("../lib/filterStorage"),
+ {filterStorage} = sandboxedRequire("../lib/filterStorage"),
{Prefs} = sandboxedRequire("./stub-modules/prefs"),
{Subscription} = sandboxedRequire("../lib/subscriptionClasses"),
sandboxedRequire("../lib/synchronizer")
);
callback();
};
function resetSubscription(subscription)
{
- FilterStorage.updateSubscriptionFilters(subscription, []);
+ filterStorage.updateSubscriptionFilters(subscription, []);
subscription.lastCheck = subscription.lastDownload =
subscription.version = subscription.lastSuccess =
subscription.expires = subscription.softExpiration = 0;
subscription.title = "";
subscription.homepage = null;
subscription.errors = 0;
subscription.downloadStatus = null;
subscription.requiredVersion = null;
}
let initialDelay = 1 / 60;
exports.testOneSubscriptionDownloads = function(test)
{
let subscription = Subscription.fromURL("http://example.com/subscription");
- FilterStorage.addSubscription(subscription);
+ filterStorage.addSubscription(subscription);
let requests = [];
this.registerHandler("/subscription", metadata =>
{
requests.push([this.getTimeOffset(), metadata.method, metadata.path]);
return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"];
});
@@ -79,23 +79,23 @@
[48 + initialDelay, "GET", "/subscription"]
], "Requests after 50 hours");
}).catch(unexpectedError.bind(test)).then(() => test.done());
};
exports.testTwoSubscriptionsDownloads = function(test)
{
let subscription1 = Subscription.fromURL("http://example.com/subscription1");
- FilterStorage.addSubscription(subscription1);
+ filterStorage.addSubscription(subscription1);
let subscription2 = Subscription.fromURL("http://example.com/subscription2");
subscription2.expires =
subscription2.softExpiration =
(this.currentTime + 2 * MILLIS_IN_HOUR) / MILLIS_IN_SECOND;
- FilterStorage.addSubscription(subscription2);
+ filterStorage.addSubscription(subscription2);
let requests = [];
let handler = metadata =>
{
requests.push([this.getTimeOffset(), metadata.method, metadata.path]);
return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"];
};
@@ -124,17 +124,17 @@
{header: "[Adblock Plus 0.0.1]", downloadStatus: "synchronize_ok", requiredVersion: "0.0.1"},
{header: "[Adblock Plus 99.9]", downloadStatus: "synchronize_ok", requiredVersion: "99.9"},
{header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVersion: null}
])
{
exports.testSubscriptionHeaders[currentTest.header] = function(test)
{
let subscription = Subscription.fromURL("http://example.com/subscription");
- FilterStorage.addSubscription(subscription);
+ filterStorage.addSubscription(subscription);
this.registerHandler("/subscription", metadata =>
{
return [Cr.NS_OK, 200, currentTest.header + "\n!Expires: 8 hours\nfoo\n!bar\n\n@@bas\n#bam"];
});
this.runScheduledTasks(2).then(() =>
{
@@ -159,17 +159,17 @@
};
}
exports.testsDisabledUpdates = function(test)
{
Prefs.subscriptions_autoupdate = false;
let subscription = Subscription.fromURL("http://example.com/subscription");
- FilterStorage.addSubscription(subscription);
+ filterStorage.addSubscription(subscription);
let requests = 0;
this.registerHandler("/subscription", metadata =>
{
requests++;
throw new Error("Unexpected request");
});
@@ -248,17 +248,17 @@
let testId = `"${currentTest.expiration}"`;
if (currentTest.randomResult != 0.5)
testId += " with Math.random() returning " + currentTest.randomResult;
if (currentTest.skip)
testId += " skipping " + currentTest.skip + " hours after " + currentTest.skipAfter + " hours";
exports.testExpirationTime[testId] = function(test)
{
let subscription = Subscription.fromURL("http://example.com/subscription");
- FilterStorage.addSubscription(subscription);
+ filterStorage.addSubscription(subscription);
let requests = [];
this.registerHandler("/subscription", metadata =>
{
requests.push(this.getTimeOffset());
return [Cr.NS_OK, 200, "[Adblock]\n!Expires: " + currentTest.expiration + "\nbar"];
});
@@ -292,17 +292,17 @@
{
test.equal(subscription.version, 1234, "Version comment");
}]
])
{
exports.testSpecialComments[comment] = function(test)
{
let subscription = Subscription.fromURL("http://example.com/subscription");
- FilterStorage.addSubscription(subscription);
+ filterStorage.addSubscription(subscription);
this.registerHandler("/subscription", metadata =>
{
return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"];
});
this.runScheduledTasks(2).then(() =>
{
@@ -310,71 +310,71 @@
test.deepEqual(subscription.filters, [Filter.fromText("foo"), Filter.fromText("bar")], "Special comment not added to filters");
}).catch(unexpectedError.bind(test)).then(() => test.done());
};
}
exports.testRedirects = function(test)
{
let subscription = Subscription.fromURL("http://example.com/subscription");
- FilterStorage.addSubscription(subscription);
+ filterStorage.addSubscription(subscription);
this.registerHandler("/subscription", metadata =>
{
return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/redirected\nbar"];
});
let requests;
this.runScheduledTasks(30).then(() =>
{
- test.equal([...FilterStorage.subscriptions()][0], subscription, "Invalid redirect ignored");
+ test.equal([...filterStorage.subscriptions()][0], subscription, "Invalid redirect ignored");
test.equal(subscription.downloadStatus, "synchronize_connection_error", "Connection error recorded");
test.equal(subscription.errors, 2, "Number of download errors");
requests = [];
this.registerHandler("/redirected", metadata =>
{
requests.push(this.getTimeOffset());
return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 8 hours\nbar"];
});
resetSubscription(subscription);
return this.runScheduledTasks(15);
}).then(() =>
{
- test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/redirected", "Redirect followed");
+ test.equal([...filterStorage.subscriptions()][0].url, "http://example.com/redirected", "Redirect followed");
test.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resulting requests");
this.registerHandler("/redirected", metadata =>
{
return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/subscription\nbar"];
});
subscription = Subscription.fromURL("http://example.com/subscription");
resetSubscription(subscription);
- FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]);
- FilterStorage.addSubscription(subscription);
+ filterStorage.removeSubscription([...filterStorage.subscriptions()][0]);
+ filterStorage.addSubscription(subscription);
return this.runScheduledTasks(2);
}).then(() =>
{
- test.equal([...FilterStorage.subscriptions()][0], subscription, "Redirect not followed on redirect loop");
+ test.equal([...filterStorage.subscriptions()][0], subscription, "Redirect not followed on redirect loop");
test.equal(subscription.downloadStatus, "synchronize_connection_error", "Download status after redirect loop");
}).catch(unexpectedError.bind(test)).then(() => test.done());
};
exports.testFallback = function(test)
{
Prefs.subscriptions_fallbackerrors = 3;
Prefs.subscriptions_fallbackurl = "http://example.com/fallback?%SUBSCRIPTION%&%CHANNELSTATUS%&%RESPONSESTATUS%";
let subscription = Subscription.fromURL("http://example.com/subscription");
- FilterStorage.addSubscription(subscription);
+ filterStorage.addSubscription(subscription);
// No valid response from fallback
let requests = [];
let fallbackParams;
let redirectedRequests;
this.registerHandler("/subscription", metadata =>
{
@@ -402,75 +402,75 @@
{
test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialDelay], "Stop trying if the fallback responds with Gone");
test.equal(fallbackParams, "http://example.com/subscription&0&404", "Fallback arguments");
// Fallback redirecting to a missing file
subscription = Subscription.fromURL("http://example.com/subscription");
resetSubscription(subscription);
- FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]);
- FilterStorage.addSubscription(subscription);
+ filterStorage.removeSubscription([...filterStorage.subscriptions()][0]);
+ filterStorage.addSubscription(subscription);
requests = [];
this.registerHandler("/fallback", metadata =>
{
return [Cr.NS_OK, 200, "301 http://example.com/redirected"];
});
return this.runScheduledTasks(100);
}).then(() =>
{
- test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/subscription", "Ignore invalid redirect from fallback");
+ test.equal([...filterStorage.subscriptions()][0].url, "http://example.com/subscription", "Ignore invalid redirect from fallback");
test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialDelay, 72 + initialDelay, 96 + initialDelay], "Requests not affected by invalid redirect");
// Fallback redirecting to an existing file
resetSubscription(subscription);
requests = [];
redirectedRequests = [];
this.registerHandler("/redirected", metadata =>
{
redirectedRequests.push(this.getTimeOffset());
return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"];
});
return this.runScheduledTasks(100);
}).then(() =>
{
- test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/redirected", "Valid redirect from fallback is followed");
+ test.equal([...filterStorage.subscriptions()][0].url, "http://example.com/redirected", "Valid redirect from fallback is followed");
test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialDelay], "Stop polling original URL after a valid redirect from fallback");
test.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay, 96 + initialDelay], "Request new URL after a valid redirect from fallback");
// Redirect loop
this.registerHandler("/subscription", metadata =>
{
return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscription2"];
});
this.registerHandler("/subscription2", metadata =>
{
return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscription"];
});
subscription = Subscription.fromURL("http://example.com/subscription");
resetSubscription(subscription);
- FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]);
- FilterStorage.addSubscription(subscription);
+ filterStorage.removeSubscription([...filterStorage.subscriptions()][0]);
+ filterStorage.addSubscription(subscription);
return this.runScheduledTasks(100);
}).then(() =>
{
- test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/redirected", "Fallback can still redirect even after a redirect loop");
+ test.equal([...filterStorage.subscriptions()][0].url, "http://example.com/redirected", "Fallback can still redirect even after a redirect loop");
}).catch(unexpectedError.bind(test)).then(() => test.done());
};
exports.testStateFields = function(test)
{
let subscription = Subscription.fromURL("http://example.com/subscription");
- FilterStorage.addSubscription(subscription);
+ filterStorage.addSubscription(subscription);
this.registerHandler("/subscription", metadata =>
{
return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 2 hours\nfoo\nbar"];
});
let startTime = this.currentTime;
this.runScheduledTasks(2).then(() =>
« no previous file with comments | « test/filterStorage_readwrite.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld