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: Safe buffer manipulation Created April 4, 2017, 2:45 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", ["url=http://test/non_def ault", "title=test", "fixedTitle=true",
80 "disabled=true", "lastSuccess= 8", "lastDownload=12", "lastCheck=16", "softExpiration=18", "expires=20", "downl oadStatus=foo", 70 "disabled=true", "lastSuccess= 8", "lastDownload=12", "lastCheck=16", "softExpiration=18", "expires=20", "downl oadStatus=foo",
81 "errors=3", "version=24", "req uiredVersion=0.6"], function(subscription) 71 "errors=3", "version=24", "req uiredVersion=0.6"], function(subscription)
82 { 72 {
83 subscription.title = "test"; 73 subscription.title = "test";
74 subscription.fixedTitle = true;
84 subscription.disabled = true; 75 subscription.disabled = true;
85 subscription.lastSuccess = 8; 76 subscription.lastSuccess = 8;
86 subscription.lastDownload = 12; 77 subscription.lastDownload = 12;
87 subscription.lastCheck = 16; 78 subscription.lastCheck = 16;
88 subscription.softExpiration = 18; 79 subscription.softExpiration = 18;
89 subscription.expires = 20; 80 subscription.expires = 20;
90 subscription.downloadStatus = "foo"; 81 subscription.downloadStatus = "foo";
91 subscription.errors = 3; 82 subscription.errors = 3;
92 subscription.version = 24 83 subscription.version = 24
93 subscription.requiredVersion = "0.6"; 84 subscription.requiredVersion = "0.6";
94 }); 85 });
95 compareSubscription(test, "~wl~", ["url=~wl~", "disabled=true", "title=Test gr oup"], function(subscription) 86 compareSubscription(test, "~wl~", ["url=~wl~", "disabled=true", "title=Test gr oup"], function(subscription)
96 { 87 {
97 subscription.title = "Test group"; 88 subscription.title = "Test group";
98 subscription.disabled = true; 89 subscription.disabled = true;
99 }); 90 });
100 91
101 test.done(); 92 test.done();
102 }; 93 };
94
95 exports.testDefaultSubscriptionIDs = function(test)
96 {
97 let subscription1 = Subscription.fromURL(null);
98 test.ok(subscription1 instanceof SpecialSubscription, "Special subscription re turned by default");
99 test.ok(subscription1.url.startsWith("~user~"), "Prefix for default subscripti on IDs");
100
101 let subscription2 = Subscription.fromURL(null);
102 test.ok(subscription2 instanceof SpecialSubscription, "Special subscription re turned by default");
103 test.ok(subscription2.url.startsWith("~user~"), "Prefix for default subscripti on IDs");
104 test.notEqual(subscription1.url, subscription2.url, "Second call creates new s ubscription");
105
106 subscription1.delete();
107 subscription2.delete();
108
109 test.done();
110 };
111
112 exports.testSubscriptionDefaults = function(test)
113 {
114 let tests = [
115 ["blocking", "test"],
116 ["whitelist", "@@test"],
117 ["elemhide", "##test"],
118 ["elemhide", "#@#test"],
119 ["elemhide", "foo##[-abp-properties='foo']"],
120 ["blocking", "!test"],
121 ["blocking", "/??/"],
122 ["blocking whitelist", "test", "@@test"],
123 ["blocking elemhide", "test", "##test"]
124 ];
125
126 for (let [defaults, ...filters] of tests)
127 {
128 compareSubscription(test, "~user~" + filters.join("~"), ["url=~user~" + filt ers.join("~"), "defaults= " + defaults], function(subscription)
129 {
130 for (let text of filters)
131 {
132 let filter = Filter.fromText(text);
133 subscription.makeDefaultFor(filter);
134 filter.delete();
135 }
136 });
137 }
138 test.done();
139 };
140
141 exports.testGC = function(test)
142 {
143 let subscription1 = Subscription.fromURL("http://example.com/");
144 test.equal(subscription1.lastDownload, 0, "Initial download time");
145
146 subscription1.lastDownload = 432;
147
148 let subscription2 = Subscription.fromURL("http://example.com/");
149 test.equal(subscription2.lastDownload, 432, "Known subscription returned");
150
151 subscription2.lastDownload = 234;
152 test.equal(subscription1.lastDownload, 234, "Changing second wrapper modifies original as well");
153
154 subscription1.delete();
155 subscription2.delete();
156
157 let subscription3 = Subscription.fromURL("http://example.com/");
158 test.equal(subscription3.lastDownload, 0, "Subscription data has been reset on ce previous instances have been released");
159 subscription3.delete();
160
161 test.done();
162 };
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