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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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; | 25 let Filter = null; |
26 let FilterStorage = null; | 26 let FilterStorage = null; |
27 let Prefs = null; | 27 let Prefs = null; |
28 let Subscription = null; | 28 let Subscription = null; |
29 let Synchronizer = null; | |
30 | 29 |
31 exports.setUp = function(callback) | 30 exports.setUp = function(callback) |
32 { | 31 { |
33 let globals = Object.assign({}, setupTimerAndXMLHttp.call(this), | 32 let globals = Object.assign({}, setupTimerAndXMLHttp.call(this), |
34 setupRandomResult.call(this)); | 33 setupRandomResult.call(this)); |
35 | 34 |
36 let sandboxedRequire = createSandbox({globals}); | 35 let sandboxedRequire = createSandbox({globals}); |
37 ( | 36 ( |
38 {Filter} = sandboxedRequire("../lib/filterClasses"), | 37 {Filter} = sandboxedRequire("../lib/filterClasses"), |
39 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), | 38 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), |
40 {Prefs} = sandboxedRequire("./stub-modules/prefs"), | 39 {Prefs} = sandboxedRequire("./stub-modules/prefs"), |
41 {Subscription} = sandboxedRequire("../lib/subscriptionClasses"), | 40 {Subscription} = sandboxedRequire("../lib/subscriptionClasses"), |
42 {Synchronizer} = sandboxedRequire("../lib/synchronizer") | 41 sandboxedRequire("../lib/synchronizer") |
43 ); | 42 ); |
44 | 43 |
45 callback(); | 44 callback(); |
46 }; | 45 }; |
47 | 46 |
48 function resetSubscription(subscription) | 47 function resetSubscription(subscription) |
49 { | 48 { |
50 FilterStorage.updateSubscriptionFilters(subscription, []); | 49 FilterStorage.updateSubscriptionFilters(subscription, []); |
51 subscription.lastCheck = subscription.lastDownload = | 50 subscription.lastCheck = subscription.lastDownload = |
52 subscription.version = subscription.lastSuccess = | 51 subscription.version = subscription.lastSuccess = |
53 subscription.expires = subscription.softExpiration = 0; | 52 subscription.expires = subscription.softExpiration = 0; |
54 subscription.title = ""; | 53 subscription.title = ""; |
55 subscription.homepage = null; | 54 subscription.homepage = null; |
56 subscription.errors = 0; | 55 subscription.errors = 0; |
57 subscription.downloadStatus = null; | 56 subscription.downloadStatus = null; |
58 subscription.requiredVersion = null; | 57 subscription.requiredVersion = null; |
59 } | 58 } |
60 | 59 |
61 let initialDelay = 1 / 60; | 60 let initialDelay = 1 / 60; |
62 | 61 |
63 exports.testOneSubscriptionDownloads = function(test) | 62 exports.testOneSubscriptionDownloads = function(test) |
64 { | 63 { |
65 let subscription = Subscription.fromURL("http://example.com/subscription"); | 64 let subscription = Subscription.fromURL("http://example.com/subscription"); |
66 FilterStorage.addSubscription(subscription); | 65 FilterStorage.addSubscription(subscription); |
67 | 66 |
68 let requests = []; | 67 let requests = []; |
69 this.registerHandler("/subscription", metadata => | 68 this.registerHandler("/subscription", metadata => |
70 { | 69 { |
71 requests.push([this.getTimeOffset(), metadata.method, metadata.path]); | 70 requests.push([this.getTimeOffset(), metadata.method, metadata.path]); |
72 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; | 71 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; |
73 }); | 72 }); |
74 | 73 |
75 this.runScheduledTasks(50).then(() => | 74 this.runScheduledTasks(50).then(() => |
76 { | 75 { |
77 test.deepEqual(requests, [ | 76 test.deepEqual(requests, [ |
78 [0 + initialDelay, "GET", "/subscription"], | 77 [0 + initialDelay, "GET", "/subscription"], |
79 [24 + initialDelay, "GET", "/subscription"], | 78 [24 + initialDelay, "GET", "/subscription"], |
80 [48 + initialDelay, "GET", "/subscription"], | 79 [48 + initialDelay, "GET", "/subscription"] |
81 ], "Requests after 50 hours"); | 80 ], "Requests after 50 hours"); |
82 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 81 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
83 }; | 82 }; |
84 | 83 |
85 exports.testTwoSubscriptionsDownloads = function(test) | 84 exports.testTwoSubscriptionsDownloads = function(test) |
86 { | 85 { |
87 let subscription1 = Subscription.fromURL("http://example.com/subscription1"); | 86 let subscription1 = Subscription.fromURL("http://example.com/subscription1"); |
88 FilterStorage.addSubscription(subscription1); | 87 FilterStorage.addSubscription(subscription1); |
89 | 88 |
90 let subscription2 = Subscription.fromURL("http://example.com/subscription2"); | 89 let subscription2 = Subscription.fromURL("http://example.com/subscription2"); |
(...skipping 13 matching lines...) Expand all Loading... |
104 this.registerHandler("/subscription2", handler); | 103 this.registerHandler("/subscription2", handler); |
105 | 104 |
106 this.runScheduledTasks(55).then(() => | 105 this.runScheduledTasks(55).then(() => |
107 { | 106 { |
108 test.deepEqual(requests, [ | 107 test.deepEqual(requests, [ |
109 [0 + initialDelay, "GET", "/subscription1"], | 108 [0 + initialDelay, "GET", "/subscription1"], |
110 [2 + initialDelay, "GET", "/subscription2"], | 109 [2 + initialDelay, "GET", "/subscription2"], |
111 [24 + initialDelay, "GET", "/subscription1"], | 110 [24 + initialDelay, "GET", "/subscription1"], |
112 [26 + initialDelay, "GET", "/subscription2"], | 111 [26 + initialDelay, "GET", "/subscription2"], |
113 [48 + initialDelay, "GET", "/subscription1"], | 112 [48 + initialDelay, "GET", "/subscription1"], |
114 [50 + initialDelay, "GET", "/subscription2"], | 113 [50 + initialDelay, "GET", "/subscription2"] |
115 ], "Requests after 55 hours"); | 114 ], "Requests after 55 hours"); |
116 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 115 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
117 }; | 116 }; |
118 | 117 |
119 exports.testSubscriptionHeaders = {}; | 118 exports.testSubscriptionHeaders = {}; |
120 | 119 |
121 for (let currentTest of [ | 120 for (let currentTest of [ |
122 {header: "[Adblock]", downloadStatus: "synchronize_ok", requiredVersion: null}
, | 121 {header: "[Adblock]", downloadStatus: "synchronize_ok", requiredVersion: null}
, |
123 {header: "[Adblock Plus]", downloadStatus: "synchronize_ok", requiredVersion:
null}, | 122 {header: "[Adblock Plus]", downloadStatus: "synchronize_ok", requiredVersion:
null}, |
124 {header: "(something)[Adblock]", downloadStatus: "synchronize_ok", requiredVer
sion: null}, | 123 {header: "(something)[Adblock]", downloadStatus: "synchronize_ok", requiredVer
sion: null}, |
(...skipping 16 matching lines...) Expand all Loading... |
141 { | 140 { |
142 test.equal(subscription.downloadStatus, currentTest.downloadStatus, "Downl
oad status"); | 141 test.equal(subscription.downloadStatus, currentTest.downloadStatus, "Downl
oad status"); |
143 test.equal(subscription.requiredVersion, currentTest.requiredVersion, "Req
uired version"); | 142 test.equal(subscription.requiredVersion, currentTest.requiredVersion, "Req
uired version"); |
144 | 143 |
145 if (currentTest.downloadStatus == "synchronize_ok") | 144 if (currentTest.downloadStatus == "synchronize_ok") |
146 { | 145 { |
147 test.deepEqual(subscription.filters, [ | 146 test.deepEqual(subscription.filters, [ |
148 Filter.fromText("foo"), | 147 Filter.fromText("foo"), |
149 Filter.fromText("!bar"), | 148 Filter.fromText("!bar"), |
150 Filter.fromText("@@bas"), | 149 Filter.fromText("@@bas"), |
151 Filter.fromText("#bam"), | 150 Filter.fromText("#bam") |
152 ], "Resulting subscription filters"); | 151 ], "Resulting subscription filters"); |
153 } | 152 } |
154 else | 153 else |
155 { | 154 { |
156 test.deepEqual(subscription.filters, [ | 155 test.deepEqual(subscription.filters, [ |
157 ], "Resulting subscription filters"); | 156 ], "Resulting subscription filters"); |
158 } | 157 } |
159 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 158 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
160 }; | 159 }; |
161 } | 160 } |
162 | 161 |
163 exports.testsDisabledUpdates = function(test) | 162 exports.testsDisabledUpdates = function(test) |
164 { | 163 { |
165 Prefs.subscriptions_autoupdate = false; | 164 Prefs.subscriptions_autoupdate = false; |
166 | 165 |
167 let subscription = Subscription.fromURL("http://example.com/subscription"); | 166 let subscription = Subscription.fromURL("http://example.com/subscription"); |
168 FilterStorage.addSubscription(subscription); | 167 FilterStorage.addSubscription(subscription); |
169 | 168 |
170 let requests = 0; | 169 let requests = 0; |
171 this.registerHandler("/subscription", metadata => | 170 this.registerHandler("/subscription", metadata => |
172 { | 171 { |
173 requests++; | 172 requests++; |
174 throw new Error("Unexpected request"); | 173 throw new Error("Unexpected request"); |
175 }); | 174 }); |
176 | 175 |
177 this.runScheduledTasks(50).then(() => | 176 this.runScheduledTasks(50).then(() => |
178 { | 177 { |
179 test.equal(requests, 0, "Request count"); | 178 test.equal(requests, 0, "Request count"); |
180 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 179 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
181 }; | 180 }; |
182 | 181 |
183 exports.testExpirationTime = {}; | 182 exports.testExpirationTime = {}; |
184 | 183 |
185 for (let currentTest of [ | 184 for (let currentTest of [ |
186 { | 185 { |
187 expiration: "default", | 186 expiration: "default", |
188 randomResult: 0.5, | 187 randomResult: 0.5, |
189 requests: [0 + initialDelay, 5 * 24 + initialDelay] | 188 requests: [0 + initialDelay, 5 * 24 + initialDelay] |
190 }, | 189 }, |
191 { | 190 { |
192 expiration: "1 hours", // Minimal expiration interval | 191 expiration: "1 hours", // Minimal expiration interval |
193 randomResult: 0.5, | 192 randomResult: 0.5, |
194 requests: [0 + initialDelay, 1 + initialDelay, 2 + initialDelay, 3 + initial
Delay] | 193 requests: [0 + initialDelay, 1 + initialDelay, 2 + initialDelay, 3 + initial
Delay] |
195 }, | 194 }, |
196 { | 195 { |
197 expiration: "26 hours", | 196 expiration: "26 hours", |
198 randomResult: 0.5, | 197 randomResult: 0.5, |
199 requests: [0 + initialDelay, 26 + initialDelay] | 198 requests: [0 + initialDelay, 26 + initialDelay] |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 ["Wrong checksum", "[Adblock]\n! Checksum: wrongggny6Fn24b7JHsq/A\nfoo\nbar\n"
, false], | 279 ["Wrong checksum", "[Adblock]\n! Checksum: wrongggny6Fn24b7JHsq/A\nfoo\nbar\n"
, false], |
281 ["Empty lines ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\n\nfoo\
n\nbar\n\n", true], | 280 ["Empty lines ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq/A\n\nfoo\
n\nbar\n\n", true], |
282 ["CR LF line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7
JHsq/A\nfoo\r\nbar\r\n", true], | 281 ["CR LF line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7
JHsq/A\nfoo\r\nbar\r\n", true], |
283 ["CR line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHs
q/A\nfoo\rbar\r", true], | 282 ["CR line breaks treated like LR", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHs
q/A\nfoo\rbar\r", true], |
284 ["Trailing line break not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JH
sq/A\nfoo\nbar", false], | 283 ["Trailing line break not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JH
sq/A\nfoo\nbar", false], |
285 ["Line breaks between lines not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn
24b7JHsq/A\nfoobar", false], | 284 ["Line breaks between lines not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn
24b7JHsq/A\nfoobar", false], |
286 ["Lines with spaces not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq
/A\n \nfoo\n\nbar\n", false], | 285 ["Lines with spaces not ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn24b7JHsq
/A\n \nfoo\n\nbar\n", false], |
287 ["Extra content in checksum line is part of the checksum", "[Adblock]\n! Check
sum: e/JCmqXny6Fn24b7JHsq/A foobar\nfoo\nbar\n", false], | 286 ["Extra content in checksum line is part of the checksum", "[Adblock]\n! Check
sum: e/JCmqXny6Fn24b7JHsq/A foobar\nfoo\nbar\n", false], |
288 ["= symbols after checksum are ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn2
4b7JHsq/A===\nfoo\nbar\n", true], | 287 ["= symbols after checksum are ignored", "[Adblock]\n! Checksum: e/JCmqXny6Fn2
4b7JHsq/A===\nfoo\nbar\n", true], |
289 ["Header line is part of the checksum", "[Adblock Plus]\n! Checksum: e/JCmqXny
6Fn24b7JHsq/A\nfoo\nbar\n", false], | 288 ["Header line is part of the checksum", "[Adblock Plus]\n! Checksum: e/JCmqXny
6Fn24b7JHsq/A\nfoo\nbar\n", false], |
290 ["Special comments are part of the checksum", "[Adblock]\n! Checksum: e/JCmqXn
y6Fn24b7JHsq/A\n! Expires: 1\nfoo\nbar\n", false], | 289 ["Special comments are part of the checksum", "[Adblock]\n! Checksum: e/JCmqXn
y6Fn24b7JHsq/A\n! Expires: 1\nfoo\nbar\n", false] |
291 ]) | 290 ]) |
292 { | 291 { |
293 exports.testChecksumVerification[testName] = function(test) | 292 exports.testChecksumVerification[testName] = function(test) |
294 { | 293 { |
295 let subscription = Subscription.fromURL("http://example.com/subscription"); | 294 let subscription = Subscription.fromURL("http://example.com/subscription"); |
296 FilterStorage.addSubscription(subscription); | 295 FilterStorage.addSubscription(subscription); |
297 | 296 |
298 this.registerHandler("/subscription", metadata => | 297 this.registerHandler("/subscription", metadata => |
299 { | 298 { |
300 return [Cr.NS_OK, 200, subscriptionBody]; | 299 return [Cr.NS_OK, 200, subscriptionBody]; |
(...skipping 11 matching lines...) Expand all Loading... |
312 for (let [comment, check] of [ | 311 for (let [comment, check] of [ |
313 ["! Homepage: http://example.com/", (test, subscription) => | 312 ["! Homepage: http://example.com/", (test, subscription) => |
314 { | 313 { |
315 test.equal(subscription.homepage, "http://example.com/", "Valid homepage com
ment"); | 314 test.equal(subscription.homepage, "http://example.com/", "Valid homepage com
ment"); |
316 }], | 315 }], |
317 ["! Homepage: ssh://example.com/", (test, subscription) => | 316 ["! Homepage: ssh://example.com/", (test, subscription) => |
318 { | 317 { |
319 test.equal(subscription.homepage, null, "Invalid homepage comment"); | 318 test.equal(subscription.homepage, null, "Invalid homepage comment"); |
320 }], | 319 }], |
321 ["! Title: foo", (test, subscription) => | 320 ["! Title: foo", (test, subscription) => |
322 { | 321 { |
323 test.equal(subscription.title, "foo", "Title comment"); | 322 test.equal(subscription.title, "foo", "Title comment"); |
324 test.equal(subscription.fixedTitle, true, "Fixed title"); | 323 test.equal(subscription.fixedTitle, true, "Fixed title"); |
325 }], | 324 }], |
326 ["! Version: 1234", (test, subscription) => | 325 ["! Version: 1234", (test, subscription) => |
327 { | 326 { |
328 test.equal(subscription.version, 1234, "Version comment"); | 327 test.equal(subscription.version, 1234, "Version comment"); |
329 }] | 328 }] |
330 ]) | 329 ]) |
331 { | 330 { |
332 exports.testSpecialComments[comment] = function(test) | 331 exports.testSpecialComments[comment] = function(test) |
333 { | 332 { |
334 let subscription = Subscription.fromURL("http://example.com/subscription"); | 333 let subscription = Subscription.fromURL("http://example.com/subscription"); |
335 FilterStorage.addSubscription(subscription); | 334 FilterStorage.addSubscription(subscription); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 resetSubscription(subscription); | 375 resetSubscription(subscription); |
377 return this.runScheduledTasks(15); | 376 return this.runScheduledTasks(15); |
378 }).then(() => | 377 }).then(() => |
379 { | 378 { |
380 test.equal(FilterStorage.subscriptions[0].url, "http://example.com/redirecte
d", "Redirect followed"); | 379 test.equal(FilterStorage.subscriptions[0].url, "http://example.com/redirecte
d", "Redirect followed"); |
381 test.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resulting re
quests"); | 380 test.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resulting re
quests"); |
382 | 381 |
383 this.registerHandler("/redirected", metadata => | 382 this.registerHandler("/redirected", metadata => |
384 { | 383 { |
385 return [Cr.NS_OK, 200, "[Adblock]\nfoo\n!Redirect: http://example.com/subs
cription\nbar"]; | 384 return [Cr.NS_OK, 200, "[Adblock]\nfoo\n!Redirect: http://example.com/subs
cription\nbar"]; |
386 }) | 385 }); |
387 | 386 |
388 subscription = Subscription.fromURL("http://example.com/subscription"); | 387 subscription = Subscription.fromURL("http://example.com/subscription"); |
389 resetSubscription(subscription); | 388 resetSubscription(subscription); |
390 FilterStorage.removeSubscription(FilterStorage.subscriptions[0]); | 389 FilterStorage.removeSubscription(FilterStorage.subscriptions[0]); |
391 FilterStorage.addSubscription(subscription); | 390 FilterStorage.addSubscription(subscription); |
392 | 391 |
393 return this.runScheduledTasks(2); | 392 return this.runScheduledTasks(2); |
394 }).then(() => | 393 }).then(() => |
395 { | 394 { |
396 test.equal(FilterStorage.subscriptions[0], subscription, "Redirect not follo
wed on redirect loop"); | 395 test.equal(FilterStorage.subscriptions[0], subscription, "Redirect not follo
wed on redirect loop"); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 | 520 |
522 this.registerHandler("/subscription", metadata => | 521 this.registerHandler("/subscription", metadata => |
523 { | 522 { |
524 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 2 hours\nfoo\nbar"]; | 523 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 2 hours\nfoo\nbar"]; |
525 }); | 524 }); |
526 | 525 |
527 let startTime = this.currentTime; | 526 let startTime = this.currentTime; |
528 this.runScheduledTasks(2).then(() => | 527 this.runScheduledTasks(2).then(() => |
529 { | 528 { |
530 test.equal(subscription.downloadStatus, "synchronize_ok", "downloadStatus af
ter successful download"); | 529 test.equal(subscription.downloadStatus, "synchronize_ok", "downloadStatus af
ter successful download"); |
531 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + initia
lDelay * MILLIS_IN_HOUR, "lastDownload after successful download"); | 530 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + initial
Delay * MILLIS_IN_HOUR, "lastDownload after successful download"); |
532 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initial
Delay * MILLIS_IN_HOUR, "lastSuccess after successful download"); | 531 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after successful download"); |
533 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (1 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after successful download"); | 532 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (1 + initi
alDelay) * MILLIS_IN_HOUR, "lastCheck after successful download"); |
534 test.equal(subscription.errors, 0, "errors after successful download"); | 533 test.equal(subscription.errors, 0, "errors after successful download"); |
535 | 534 |
536 this.registerHandler("/subscription", metadata => | 535 this.registerHandler("/subscription", metadata => |
537 { | 536 { |
538 return [Cr.NS_ERROR_FAILURE, 0, ""]; | 537 return [Cr.NS_ERROR_FAILURE, 0, ""]; |
539 }); | 538 }); |
540 | 539 |
541 return this.runScheduledTasks(2); | 540 return this.runScheduledTasks(2); |
542 }).then(() => | 541 }).then(() => |
543 { | 542 { |
544 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after connection error"); | 543 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after connection error"); |
545 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (2 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after connection error"); | 544 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (2 + in
itialDelay) * MILLIS_IN_HOUR, "lastDownload after connection error"); |
546 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after connection error"); | 545 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after connection error"); |
547 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (3 + initi
alDelay) * MILLIS_IN_HOUR, "lastCheck after connection error"); | 546 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (3 + initi
alDelay) * MILLIS_IN_HOUR, "lastCheck after connection error"); |
548 test.equal(subscription.errors, 1, "errors after connection error"); | 547 test.equal(subscription.errors, 1, "errors after connection error"); |
549 | 548 |
550 this.registerHandler("/subscription", metadata => | 549 this.registerHandler("/subscription", metadata => |
551 { | 550 { |
552 return [Cr.NS_OK, 404, ""]; | 551 return [Cr.NS_OK, 404, ""]; |
553 }); | 552 }); |
554 | 553 |
555 return this.runScheduledTasks(24); | 554 return this.runScheduledTasks(24); |
556 }).then(() => | 555 }).then(() => |
557 { | 556 { |
558 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); | 557 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); |
559 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); | 558 test.equal(subscription.lastDownload * MILLIS_IN_SECOND, startTime + (26 + i
nitialDelay) * MILLIS_IN_HOUR, "lastDownload after download error"); |
560 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after download error"); | 559 test.equal(subscription.lastSuccess * MILLIS_IN_SECOND, startTime + initialD
elay * MILLIS_IN_HOUR, "lastSuccess after download error"); |
561 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); | 560 test.equal(subscription.lastCheck * MILLIS_IN_SECOND, startTime + (27 + init
ialDelay) * MILLIS_IN_HOUR, "lastCheck after download error"); |
562 test.equal(subscription.errors, 2, "errors after download error"); | 561 test.equal(subscription.errors, 2, "errors after download error"); |
563 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 562 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
564 }; | 563 }; |
OLD | NEW |