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

Unified Diff: test/subscriptionClasses.js

Issue 29384812: Issue 4127 - [emscripten] Convert subscription classes to C++ - Part 1 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created March 15, 2017, 3:05 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 | « lib/subscriptionClassesNew.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
@@ -14,78 +14,69 @@
* 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";
let {createSandbox} = require("./_common");
+let Filter = null;
let Subscription = null;
let SpecialSubscription = null;
let DownloadableSubscription = null;
let RegularSubscription = null;
let ExternalSubscription = null;
exports.setUp = function(callback)
{
let sandboxedRequire = createSandbox();
+ ({Filter} = sandboxedRequire("../lib/filterClassesNew"));
(
{
- Subscription, SpecialSubscription, DownloadableSubscription,
- RegularSubscription, ExternalSubscription
- } = sandboxedRequire("../lib/subscriptionClasses")
+ Subscription, SpecialSubscription, DownloadableSubscription
+ } = sandboxedRequire("../lib/subscriptionClassesNew")
);
callback();
};
function compareSubscription(test, url, expected, postInit)
{
expected.push("[Subscription]")
let subscription = Subscription.fromURL(url);
if (postInit)
postInit(subscription)
- let result = [];
- subscription.serialize(result);
+ let result = subscription.serialize().trim().split("\n");
test.equal(result.sort().join("\n"), expected.sort().join("\n"), url);
-
- let map = {__proto__: null};
- for (let line of result.slice(1))
- {
- if (/(.*?)=(.*)/.test(line))
- map[RegExp.$1] = RegExp.$2;
- }
- let subscription2 = Subscription.fromObject(map);
- test.equal(subscription.toString(), subscription2.toString(), url + " deserialization");
+ subscription.delete();
}
exports.testSubscriptionClassDefinitions = function(test)
{
test.equal(typeof Subscription, "function", "typeof Subscription");
test.equal(typeof SpecialSubscription, "function", "typeof SpecialSubscription");
- test.equal(typeof RegularSubscription, "function", "typeof RegularSubscription");
- test.equal(typeof ExternalSubscription, "function", "typeof ExternalSubscription");
test.equal(typeof DownloadableSubscription, "function", "typeof DownloadableSubscription");
test.done();
};
exports.testSubscriptionsWithState = function(test)
{
compareSubscription(test, "~fl~", ["url=~fl~"]);
compareSubscription(test, "http://test/default", ["url=http://test/default", "title=http://test/default"]);
compareSubscription(test, "http://test/default_titled", ["url=http://test/default_titled", "title=test"], function(subscription)
{
subscription.title = "test";
});
- compareSubscription(test, "http://test/non_default", ["url=http://test/non_default", "title=test",
+ compareSubscription(test, "http://test/non_default", ["url=http://test/non_default", "title=test", "fixedTitle=true",
"disabled=true", "lastSuccess=8", "lastDownload=12", "lastCheck=16", "softExpiration=18", "expires=20", "downloadStatus=foo",
"errors=3", "version=24", "requiredVersion=0.6"], function(subscription)
{
subscription.title = "test";
+ subscription.fixedTitle = true;
subscription.disabled = true;
subscription.lastSuccess = 8;
subscription.lastDownload = 12;
subscription.lastCheck = 16;
subscription.softExpiration = 18;
subscription.expires = 20;
subscription.downloadStatus = "foo";
subscription.errors = 3;
@@ -95,8 +86,77 @@ exports.testSubscriptionsWithState = fun
compareSubscription(test, "~wl~", ["url=~wl~", "disabled=true", "title=Test group"], function(subscription)
{
subscription.title = "Test group";
subscription.disabled = true;
});
test.done();
};
+
+exports.testDefaultSubscriptionIDs = function(test)
+{
+ let subscription1 = Subscription.fromURL(null);
+ test.ok(subscription1 instanceof SpecialSubscription, "Special subscription returned by default");
+ test.ok(subscription1.url.startsWith("~user~"), "Prefix for default subscription IDs");
+
+ let subscription2 = Subscription.fromURL(null);
+ test.ok(subscription2 instanceof SpecialSubscription, "Special subscription returned by default");
+ test.ok(subscription2.url.startsWith("~user~"), "Prefix for default subscription IDs");
+ test.notEqual(subscription1.url, subscription2.url, "Second call creates new subscription");
+
+ subscription1.delete();
+ subscription2.delete();
+
+ test.done();
+};
+
+exports.testSubscriptionDefaults = function(test)
+{
+ let tests = [
+ ["blocking", "test"],
+ ["whitelist", "@@test"],
+ ["elemhide", "##test"],
+ ["elemhide", "#@#test"],
+ ["elemhide", "foo##[-abp-properties='foo']"],
+ ["blocking", "!test"],
+ ["blocking", "/??/"],
+ ["blocking whitelist", "test", "@@test"],
+ ["blocking elemhide", "test", "##test"]
+ ];
+
+ for (let [defaults, ...filters] of tests)
+ {
+ compareSubscription(test, "~user~" + filters.join("~"), ["url=~user~" + filters.join("~"), "defaults= " + defaults], function(subscription)
+ {
+ for (let text of filters)
+ {
+ let filter = Filter.fromText(text);
+ subscription.makeDefaultFor(filter);
+ filter.delete();
+ }
+ });
+ }
+ test.done();
+};
+
+exports.testGC = function(test)
+{
+ let subscription1 = Subscription.fromURL("http://example.com/");
+ test.equal(subscription1.lastDownload, 0, "Initial download time");
+
+ subscription1.lastDownload = 432;
+
+ let subscription2 = Subscription.fromURL("http://example.com/");
+ test.equal(subscription2.lastDownload, 432, "Known subscription returned");
+
+ subscription2.lastDownload = 234;
+ test.equal(subscription1.lastDownload, 234, "Changing second wrapper modifies original as well");
+
+ subscription1.delete();
+ subscription2.delete();
+
+ let subscription3 = Subscription.fromURL("http://example.com/");
+ test.equal(subscription3.lastDownload, 0, "Subscription data has been reset once previous instances have been released");
+ subscription3.delete();
+
+ test.done();
+};
« no previous file with comments | « lib/subscriptionClassesNew.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld