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

Side by Side 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: Addressed comments Created April 13, 2017, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/subscriptionClasses.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 let {createSandbox} = require("./_common"); 20 let {createSandbox} = require("./_common");
21 21
22 let Filter = null;
22 let Subscription = null; 23 let Subscription = null;
23 let SpecialSubscription = null; 24 let SpecialSubscription = null;
24 let DownloadableSubscription = null; 25 let DownloadableSubscription = null;
25 let RegularSubscription = null; 26 let RegularSubscription = null;
26 let ExternalSubscription = null; 27 let ExternalSubscription = null;
27 28
28 exports.setUp = function(callback) 29 exports.setUp = function(callback)
29 { 30 {
30 let sandboxedRequire = createSandbox(); 31 let sandboxedRequire = createSandbox();
32 ({Filter} = sandboxedRequire("../lib/filterClasses"));
31 ( 33 (
32 { 34 {
33 Subscription, SpecialSubscription, DownloadableSubscription, 35 Subscription, SpecialSubscription, DownloadableSubscription
34 RegularSubscription, ExternalSubscription
35 } = sandboxedRequire("../lib/subscriptionClasses") 36 } = sandboxedRequire("../lib/subscriptionClasses")
36 ); 37 );
37 callback(); 38 callback();
38 }; 39 };
39 40
40 function compareSubscription(test, url, expected, postInit) 41 function compareSubscription(test, url, expected, postInit)
41 { 42 {
42 expected.push("[Subscription]") 43 expected.push("[Subscription]")
43 let subscription = Subscription.fromURL(url); 44 let subscription = Subscription.fromURL(url);
44 if (postInit) 45 if (postInit)
45 postInit(subscription) 46 postInit(subscription)
46 let result = []; 47 let result = subscription.serialize().trim().split("\n");
47 subscription.serialize(result);
48 test.equal(result.sort().join("\n"), expected.sort().join("\n"), url); 48 test.equal(result.sort().join("\n"), expected.sort().join("\n"), url);
49 49 subscription.delete();
50 let map = {__proto__: null};
51 for (let line of result.slice(1))
52 {
53 if (/(.*?)=(.*)/.test(line))
54 map[RegExp.$1] = RegExp.$2;
55 }
56 let subscription2 = Subscription.fromObject(map);
57 test.equal(subscription.toString(), subscription2.toString(), url + " deserial ization");
58 } 50 }
59 51
60 exports.testSubscriptionClassDefinitions = function(test) 52 exports.testSubscriptionClassDefinitions = function(test)
61 { 53 {
62 test.equal(typeof Subscription, "function", "typeof Subscription"); 54 test.equal(typeof Subscription, "function", "typeof Subscription");
63 test.equal(typeof SpecialSubscription, "function", "typeof SpecialSubscription "); 55 test.equal(typeof SpecialSubscription, "function", "typeof SpecialSubscription ");
64 test.equal(typeof RegularSubscription, "function", "typeof RegularSubscription ");
65 test.equal(typeof ExternalSubscription, "function", "typeof ExternalSubscripti on");
66 test.equal(typeof DownloadableSubscription, "function", "typeof DownloadableSu bscription"); 56 test.equal(typeof DownloadableSubscription, "function", "typeof DownloadableSu bscription");
67 57
68 test.done(); 58 test.done();
69 }; 59 };
70 60
71 exports.testSubscriptionsWithState = function(test) 61 exports.testSubscriptionsWithState = function(test)
72 { 62 {
73 compareSubscription(test, "~fl~", ["url=~fl~"]); 63 compareSubscription(test, "~fl~", ["url=~fl~"]);
74 compareSubscription(test, "http://test/default", ["url=http://test/default", " title=http://test/default"]); 64 compareSubscription(test, "http://test/default", ["url=http://test/default", " title=http://test/default"]);
75 compareSubscription(test, "http://test/default_titled", ["url=http://test/defa ult_titled", "title=test"], function(subscription) 65 compareSubscription(test, "http://test/default_titled", ["url=http://test/defa ult_titled", "title=test"], function(subscription)
76 { 66 {
77 subscription.title = "test"; 67 subscription.title = "test";
78 }); 68 });
79 compareSubscription(test, "http://test/non_default", ["url=http://test/non_def ault", "title=test", 69 compareSubscription(test, "http://test/non_default", [
80 "disabled=true", "lastSuccess= 8", "lastDownload=12", "lastCheck=16", "softExpiration=18", "expires=20", "downl oadStatus=foo", 70 "url=http://test/non_default", "title=test", "fixedTitle=true",
81 "errors=3", "version=24", "req uiredVersion=0.6"], function(subscription) 71 "disabled=true", "lastSuccess=20015998341138",
72 "lastDownload=5124097847590911", "lastCheck=18446744069414584320",
73 "softExpiration=2682143778081159", "expires=4294967295",
74 "downloadStatus=foo", "errors=3", "version=24", "requiredVersion=0.6"
75 ], function(subscription)
82 { 76 {
83 subscription.title = "test"; 77 subscription.title = "test";
78 subscription.fixedTitle = true;
84 subscription.disabled = true; 79 subscription.disabled = true;
85 subscription.lastSuccess = 8; 80 subscription.lastSuccess = 20015998341138; // 0x123456789012
86 subscription.lastDownload = 12; 81 subscription.lastDownload = 5124097847590911; // 0x123456FFFFFFFF
87 subscription.lastCheck = 16; 82 subscription.lastCheck = 18446744069414584320; // 0xFFFFFFFF00000000
88 subscription.softExpiration = 18; 83 subscription.softExpiration = 2682143778081159; // 0x9876543210987
89 subscription.expires = 20; 84 subscription.expires = 4294967295; // 0xFFFFFFFF
90 subscription.downloadStatus = "foo"; 85 subscription.downloadStatus = "foo";
91 subscription.errors = 3; 86 subscription.errors = 3;
92 subscription.version = 24 87 subscription.version = 24
93 subscription.requiredVersion = "0.6"; 88 subscription.requiredVersion = "0.6";
94 }); 89 });
95 compareSubscription(test, "~wl~", ["url=~wl~", "disabled=true", "title=Test gr oup"], function(subscription) 90 compareSubscription(test, "~wl~", ["url=~wl~", "disabled=true", "title=Test gr oup"], function(subscription)
96 { 91 {
97 subscription.title = "Test group"; 92 subscription.title = "Test group";
98 subscription.disabled = true; 93 subscription.disabled = true;
99 }); 94 });
100 95
101 test.done(); 96 test.done();
102 }; 97 };
98
99 exports.testDefaultSubscriptionIDs = function(test)
100 {
101 let subscription1 = Subscription.fromURL(null);
102 test.ok(subscription1 instanceof SpecialSubscription, "Special subscription re turned by default");
103 test.ok(subscription1.url.startsWith("~user~"), "Prefix for default subscripti on IDs");
104
105 let subscription2 = Subscription.fromURL(null);
106 test.ok(subscription2 instanceof SpecialSubscription, "Special subscription re turned by default");
107 test.ok(subscription2.url.startsWith("~user~"), "Prefix for default subscripti on IDs");
108 test.notEqual(subscription1.url, subscription2.url, "Second call creates new s ubscription");
109
110 subscription1.delete();
111 subscription2.delete();
112
113 test.done();
114 };
115
116 exports.testSubscriptionDefaults = function(test)
117 {
118 let tests = [
119 ["blocking", "test"],
120 ["whitelist", "@@test"],
121 ["elemhide", "##test"],
122 ["elemhide", "#@#test"],
123 ["elemhide", "foo##[-abp-properties='foo']"],
124 ["blocking", "!test"],
125 ["blocking", "/??/"],
126 ["blocking whitelist", "test", "@@test"],
127 ["blocking elemhide", "test", "##test"]
128 ];
129
130 for (let [defaults, ...filters] of tests)
131 {
132 compareSubscription(test, "~user~" + filters.join("~"), ["url=~user~" + filt ers.join("~"), "defaults= " + defaults], function(subscription)
133 {
134 for (let text of filters)
135 {
136 let filter = Filter.fromText(text);
137 subscription.makeDefaultFor(filter);
138 filter.delete();
139 }
140 });
141 }
142 test.done();
143 };
144
145 exports.testGC = function(test)
146 {
147 let subscription1 = Subscription.fromURL("http://example.com/");
148 test.equal(subscription1.lastDownload, 0, "Initial download time");
149
150 subscription1.lastDownload = 432;
151
152 let subscription2 = Subscription.fromURL("http://example.com/");
153 test.equal(subscription2.lastDownload, 432, "Known subscription returned");
154
155 subscription2.lastDownload = 234;
156 test.equal(subscription1.lastDownload, 234, "Changing second wrapper modifies original as well");
157
158 subscription1.delete();
159 subscription2.delete();
160
161 let subscription3 = Subscription.fromURL("http://example.com/");
162 test.equal(subscription3.lastDownload, 0, "Subscription data has been reset on ce previous instances have been released");
163 subscription3.delete();
164
165 test.done();
166 };
OLDNEW
« no previous file with comments | « lib/subscriptionClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld