OLD | NEW |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 { | 20 let { |
21 createSandbox, setupTimerAndXMLHttp, setupRandomResult, unexpectedError, Cr, | 21 createSandbox, setupTimerAndXMLHttp, setupRandomResult, unexpectedError, Cr, |
22 MILLIS_IN_SECOND, MILLIS_IN_HOUR | 22 MILLIS_IN_SECOND, MILLIS_IN_HOUR |
23 } = require("./_common"); | 23 } = require("./_common"); |
24 | 24 |
25 let Filter = null; | |
26 let filterStorage = null; | 25 let filterStorage = null; |
27 let Prefs = null; | 26 let Prefs = null; |
28 let Subscription = null; | 27 let Subscription = null; |
29 | 28 |
30 exports.setUp = function(callback) | 29 exports.setUp = function(callback) |
31 { | 30 { |
32 let globals = Object.assign({}, setupTimerAndXMLHttp.call(this), | 31 let globals = Object.assign({}, setupTimerAndXMLHttp.call(this), |
33 setupRandomResult.call(this)); | 32 setupRandomResult.call(this)); |
34 | 33 |
35 let sandboxedRequire = createSandbox({globals}); | 34 let sandboxedRequire = createSandbox({globals}); |
36 ( | 35 ( |
37 {Filter} = sandboxedRequire("../lib/filterClasses"), | |
38 {filterStorage} = sandboxedRequire("../lib/filterStorage"), | 36 {filterStorage} = sandboxedRequire("../lib/filterStorage"), |
39 {Prefs} = sandboxedRequire("./stub-modules/prefs"), | 37 {Prefs} = sandboxedRequire("./stub-modules/prefs"), |
40 {Subscription} = sandboxedRequire("../lib/subscriptionClasses"), | 38 {Subscription} = sandboxedRequire("../lib/subscriptionClasses"), |
41 sandboxedRequire("../lib/synchronizer") | 39 sandboxedRequire("../lib/synchronizer") |
42 ); | 40 ); |
43 | 41 |
44 callback(); | 42 callback(); |
45 }; | 43 }; |
46 | 44 |
47 function resetSubscription(subscription) | 45 function resetSubscription(subscription) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return [Cr.NS_OK, 200, currentTest.header + "\n!Expires: 8 hours\nfoo\n!ba
r\n\n@@bas\n#bam"]; | 134 return [Cr.NS_OK, 200, currentTest.header + "\n!Expires: 8 hours\nfoo\n!ba
r\n\n@@bas\n#bam"]; |
137 }); | 135 }); |
138 | 136 |
139 this.runScheduledTasks(2).then(() => | 137 this.runScheduledTasks(2).then(() => |
140 { | 138 { |
141 test.equal(subscription.downloadStatus, currentTest.downloadStatus, "Downl
oad status"); | 139 test.equal(subscription.downloadStatus, currentTest.downloadStatus, "Downl
oad status"); |
142 test.equal(subscription.requiredVersion, currentTest.requiredVersion, "Req
uired version"); | 140 test.equal(subscription.requiredVersion, currentTest.requiredVersion, "Req
uired version"); |
143 | 141 |
144 if (currentTest.downloadStatus == "synchronize_ok") | 142 if (currentTest.downloadStatus == "synchronize_ok") |
145 { | 143 { |
146 test.deepEqual(subscription.filters, [ | 144 test.deepEqual([...subscription.filterText()], ["foo", "!bar", "@@bas",
"#bam"], "Resulting subscription filters"); |
147 Filter.fromText("foo"), | |
148 Filter.fromText("!bar"), | |
149 Filter.fromText("@@bas"), | |
150 Filter.fromText("#bam") | |
151 ], "Resulting subscription filters"); | |
152 } | 145 } |
153 else | 146 else |
154 { | 147 { |
155 test.deepEqual(subscription.filters, [ | 148 test.deepEqual([...subscription.filterText()], [ |
156 ], "Resulting subscription filters"); | 149 ], "Resulting subscription filters"); |
157 } | 150 } |
158 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 151 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
159 }; | 152 }; |
160 } | 153 } |
161 | 154 |
162 exports.testsDisabledUpdates = function(test) | 155 exports.testsDisabledUpdates = function(test) |
163 { | 156 { |
164 Prefs.subscriptions_autoupdate = false; | 157 Prefs.subscriptions_autoupdate = false; |
165 | 158 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 filterStorage.addSubscription(subscription); | 293 filterStorage.addSubscription(subscription); |
301 | 294 |
302 this.registerHandler("/subscription", metadata => | 295 this.registerHandler("/subscription", metadata => |
303 { | 296 { |
304 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"]; | 297 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"]; |
305 }); | 298 }); |
306 | 299 |
307 this.runScheduledTasks(2).then(() => | 300 this.runScheduledTasks(2).then(() => |
308 { | 301 { |
309 check(test, subscription); | 302 check(test, subscription); |
310 test.deepEqual(subscription.filters, [Filter.fromText("foo"), Filter.fromT
ext("bar")], "Special comment not added to filters"); | 303 test.deepEqual([...subscription.filterText()], ["foo", "bar"], "Special co
mment not added to filters"); |
311 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 304 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
312 }; | 305 }; |
313 } | 306 } |
314 | 307 |
315 exports.testRedirects = function(test) | 308 exports.testRedirects = function(test) |
316 { | 309 { |
317 let subscription = Subscription.fromURL("http://example.com/subscription"); | 310 let subscription = Subscription.fromURL("http://example.com/subscription"); |
318 filterStorage.addSubscription(subscription); | 311 filterStorage.addSubscription(subscription); |
319 | 312 |
320 this.registerHandler("/subscription", metadata => | 313 this.registerHandler("/subscription", metadata => |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 return this.runScheduledTasks(24); | 496 return this.runScheduledTasks(24); |
504 }).then(() => | 497 }).then(() => |
505 { | 498 { |
506 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); | 499 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); |
507 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); | 500 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); |
508 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after download error"); | 501 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after download error"); |
509 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); | 502 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); |
510 test.equal(subscription.errors, 2, "errors after download error"); | 503 test.equal(subscription.errors, 2, "errors after download error"); |
511 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 504 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
512 }; | 505 }; |
OLD | NEW |