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; | 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 | 29 |
30 exports.setUp = function(callback) | 30 exports.setUp = function(callback) |
31 { | 31 { |
32 let globals = Object.assign({}, setupTimerAndXMLHttp.call(this), | 32 let globals = Object.assign({}, setupTimerAndXMLHttp.call(this), |
33 setupRandomResult.call(this)); | 33 setupRandomResult.call(this)); |
34 | 34 |
35 let sandboxedRequire = createSandbox({globals}); | 35 let sandboxedRequire = createSandbox({globals}); |
36 ( | 36 ( |
37 {Filter} = sandboxedRequire("../lib/filterClasses"), | 37 {Filter} = sandboxedRequire("../lib/filterClasses"), |
38 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), | 38 {filterStorage} = sandboxedRequire("../lib/filterStorage"), |
39 {Prefs} = sandboxedRequire("./stub-modules/prefs"), | 39 {Prefs} = sandboxedRequire("./stub-modules/prefs"), |
40 {Subscription} = sandboxedRequire("../lib/subscriptionClasses"), | 40 {Subscription} = sandboxedRequire("../lib/subscriptionClasses"), |
41 sandboxedRequire("../lib/synchronizer") | 41 sandboxedRequire("../lib/synchronizer") |
42 ); | 42 ); |
43 | 43 |
44 callback(); | 44 callback(); |
45 }; | 45 }; |
46 | 46 |
47 function resetSubscription(subscription) | 47 function resetSubscription(subscription) |
48 { | 48 { |
49 FilterStorage.updateSubscriptionFilters(subscription, []); | 49 filterStorage.updateSubscriptionFilters(subscription, []); |
50 subscription.lastCheck = subscription.lastDownload = | 50 subscription.lastCheck = subscription.lastDownload = |
51 subscription.version = subscription.lastSuccess = | 51 subscription.version = subscription.lastSuccess = |
52 subscription.expires = subscription.softExpiration = 0; | 52 subscription.expires = subscription.softExpiration = 0; |
53 subscription.title = ""; | 53 subscription.title = ""; |
54 subscription.homepage = null; | 54 subscription.homepage = null; |
55 subscription.errors = 0; | 55 subscription.errors = 0; |
56 subscription.downloadStatus = null; | 56 subscription.downloadStatus = null; |
57 subscription.requiredVersion = null; | 57 subscription.requiredVersion = null; |
58 } | 58 } |
59 | 59 |
60 let initialDelay = 1 / 60; | 60 let initialDelay = 1 / 60; |
61 | 61 |
62 exports.testOneSubscriptionDownloads = function(test) | 62 exports.testOneSubscriptionDownloads = function(test) |
63 { | 63 { |
64 let subscription = Subscription.fromURL("http://example.com/subscription"); | 64 let subscription = Subscription.fromURL("http://example.com/subscription"); |
65 FilterStorage.addSubscription(subscription); | 65 filterStorage.addSubscription(subscription); |
66 | 66 |
67 let requests = []; | 67 let requests = []; |
68 this.registerHandler("/subscription", metadata => | 68 this.registerHandler("/subscription", metadata => |
69 { | 69 { |
70 requests.push([this.getTimeOffset(), metadata.method, metadata.path]); | 70 requests.push([this.getTimeOffset(), metadata.method, metadata.path]); |
71 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; | 71 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; |
72 }); | 72 }); |
73 | 73 |
74 this.runScheduledTasks(50).then(() => | 74 this.runScheduledTasks(50).then(() => |
75 { | 75 { |
76 test.deepEqual(requests, [ | 76 test.deepEqual(requests, [ |
77 [0 + initialDelay, "GET", "/subscription"], | 77 [0 + initialDelay, "GET", "/subscription"], |
78 [24 + initialDelay, "GET", "/subscription"], | 78 [24 + initialDelay, "GET", "/subscription"], |
79 [48 + initialDelay, "GET", "/subscription"] | 79 [48 + initialDelay, "GET", "/subscription"] |
80 ], "Requests after 50 hours"); | 80 ], "Requests after 50 hours"); |
81 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 81 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
82 }; | 82 }; |
83 | 83 |
84 exports.testTwoSubscriptionsDownloads = function(test) | 84 exports.testTwoSubscriptionsDownloads = function(test) |
85 { | 85 { |
86 let subscription1 = Subscription.fromURL("http://example.com/subscription1"); | 86 let subscription1 = Subscription.fromURL("http://example.com/subscription1"); |
87 FilterStorage.addSubscription(subscription1); | 87 filterStorage.addSubscription(subscription1); |
88 | 88 |
89 let subscription2 = Subscription.fromURL("http://example.com/subscription2"); | 89 let subscription2 = Subscription.fromURL("http://example.com/subscription2"); |
90 subscription2.expires = | 90 subscription2.expires = |
91 subscription2.softExpiration = | 91 subscription2.softExpiration = |
92 (this.currentTime + 2 * MILLIS_IN_HOUR) / MILLIS_IN_SECOND; | 92 (this.currentTime + 2 * MILLIS_IN_HOUR) / MILLIS_IN_SECOND; |
93 FilterStorage.addSubscription(subscription2); | 93 filterStorage.addSubscription(subscription2); |
94 | 94 |
95 let requests = []; | 95 let requests = []; |
96 let handler = metadata => | 96 let handler = metadata => |
97 { | 97 { |
98 requests.push([this.getTimeOffset(), metadata.method, metadata.path]); | 98 requests.push([this.getTimeOffset(), metadata.method, metadata.path]); |
99 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; | 99 return [Cr.NS_OK, 200, "[Adblock]\n! ExPiREs: 1day\nfoo\nbar"]; |
100 }; | 100 }; |
101 | 101 |
102 this.registerHandler("/subscription1", handler); | 102 this.registerHandler("/subscription1", handler); |
103 this.registerHandler("/subscription2", handler); | 103 this.registerHandler("/subscription2", handler); |
(...skipping 18 matching lines...) Expand all Loading... |
122 {header: "[Adblock Plus]", downloadStatus: "synchronize_ok", requiredVersion:
null}, | 122 {header: "[Adblock Plus]", downloadStatus: "synchronize_ok", requiredVersion:
null}, |
123 {header: "(something)[Adblock]", downloadStatus: "synchronize_ok", requiredVer
sion: null}, | 123 {header: "(something)[Adblock]", downloadStatus: "synchronize_ok", requiredVer
sion: null}, |
124 {header: "[Adblock Plus 0.0.1]", downloadStatus: "synchronize_ok", requiredVer
sion: "0.0.1"}, | 124 {header: "[Adblock Plus 0.0.1]", downloadStatus: "synchronize_ok", requiredVer
sion: "0.0.1"}, |
125 {header: "[Adblock Plus 99.9]", downloadStatus: "synchronize_ok", requiredVers
ion: "99.9"}, | 125 {header: "[Adblock Plus 99.9]", downloadStatus: "synchronize_ok", requiredVers
ion: "99.9"}, |
126 {header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVersion:
null} | 126 {header: "[Foo]", downloadStatus: "synchronize_invalid_data", requiredVersion:
null} |
127 ]) | 127 ]) |
128 { | 128 { |
129 exports.testSubscriptionHeaders[currentTest.header] = function(test) | 129 exports.testSubscriptionHeaders[currentTest.header] = function(test) |
130 { | 130 { |
131 let subscription = Subscription.fromURL("http://example.com/subscription"); | 131 let subscription = Subscription.fromURL("http://example.com/subscription"); |
132 FilterStorage.addSubscription(subscription); | 132 filterStorage.addSubscription(subscription); |
133 | 133 |
134 this.registerHandler("/subscription", metadata => | 134 this.registerHandler("/subscription", metadata => |
135 { | 135 { |
136 return [Cr.NS_OK, 200, currentTest.header + "\n!Expires: 8 hours\nfoo\n!ba
r\n\n@@bas\n#bam"]; | 136 return [Cr.NS_OK, 200, currentTest.header + "\n!Expires: 8 hours\nfoo\n!ba
r\n\n@@bas\n#bam"]; |
137 }); | 137 }); |
138 | 138 |
139 this.runScheduledTasks(2).then(() => | 139 this.runScheduledTasks(2).then(() => |
140 { | 140 { |
141 test.equal(subscription.downloadStatus, currentTest.downloadStatus, "Downl
oad status"); | 141 test.equal(subscription.downloadStatus, currentTest.downloadStatus, "Downl
oad status"); |
142 test.equal(subscription.requiredVersion, currentTest.requiredVersion, "Req
uired version"); | 142 test.equal(subscription.requiredVersion, currentTest.requiredVersion, "Req
uired version"); |
(...skipping 14 matching lines...) Expand all Loading... |
157 } | 157 } |
158 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 158 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
159 }; | 159 }; |
160 } | 160 } |
161 | 161 |
162 exports.testsDisabledUpdates = function(test) | 162 exports.testsDisabledUpdates = function(test) |
163 { | 163 { |
164 Prefs.subscriptions_autoupdate = false; | 164 Prefs.subscriptions_autoupdate = false; |
165 | 165 |
166 let subscription = Subscription.fromURL("http://example.com/subscription"); | 166 let subscription = Subscription.fromURL("http://example.com/subscription"); |
167 FilterStorage.addSubscription(subscription); | 167 filterStorage.addSubscription(subscription); |
168 | 168 |
169 let requests = 0; | 169 let requests = 0; |
170 this.registerHandler("/subscription", metadata => | 170 this.registerHandler("/subscription", metadata => |
171 { | 171 { |
172 requests++; | 172 requests++; |
173 throw new Error("Unexpected request"); | 173 throw new Error("Unexpected request"); |
174 }); | 174 }); |
175 | 175 |
176 this.runScheduledTasks(50).then(() => | 176 this.runScheduledTasks(50).then(() => |
177 { | 177 { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 ]) | 246 ]) |
247 { | 247 { |
248 let testId = `"${currentTest.expiration}"`; | 248 let testId = `"${currentTest.expiration}"`; |
249 if (currentTest.randomResult != 0.5) | 249 if (currentTest.randomResult != 0.5) |
250 testId += " with Math.random() returning " + currentTest.randomResult; | 250 testId += " with Math.random() returning " + currentTest.randomResult; |
251 if (currentTest.skip) | 251 if (currentTest.skip) |
252 testId += " skipping " + currentTest.skip + " hours after " + currentTest.sk
ipAfter + " hours"; | 252 testId += " skipping " + currentTest.skip + " hours after " + currentTest.sk
ipAfter + " hours"; |
253 exports.testExpirationTime[testId] = function(test) | 253 exports.testExpirationTime[testId] = function(test) |
254 { | 254 { |
255 let subscription = Subscription.fromURL("http://example.com/subscription"); | 255 let subscription = Subscription.fromURL("http://example.com/subscription"); |
256 FilterStorage.addSubscription(subscription); | 256 filterStorage.addSubscription(subscription); |
257 | 257 |
258 let requests = []; | 258 let requests = []; |
259 this.registerHandler("/subscription", metadata => | 259 this.registerHandler("/subscription", metadata => |
260 { | 260 { |
261 requests.push(this.getTimeOffset()); | 261 requests.push(this.getTimeOffset()); |
262 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: " + currentTest.expiration +
"\nbar"]; | 262 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: " + currentTest.expiration +
"\nbar"]; |
263 }); | 263 }); |
264 | 264 |
265 this.randomResult = currentTest.randomResult; | 265 this.randomResult = currentTest.randomResult; |
266 | 266 |
(...skipping 23 matching lines...) Expand all Loading... |
290 }], | 290 }], |
291 ["! Version: 1234", (test, subscription) => | 291 ["! Version: 1234", (test, subscription) => |
292 { | 292 { |
293 test.equal(subscription.version, 1234, "Version comment"); | 293 test.equal(subscription.version, 1234, "Version comment"); |
294 }] | 294 }] |
295 ]) | 295 ]) |
296 { | 296 { |
297 exports.testSpecialComments[comment] = function(test) | 297 exports.testSpecialComments[comment] = function(test) |
298 { | 298 { |
299 let subscription = Subscription.fromURL("http://example.com/subscription"); | 299 let subscription = Subscription.fromURL("http://example.com/subscription"); |
300 FilterStorage.addSubscription(subscription); | 300 filterStorage.addSubscription(subscription); |
301 | 301 |
302 this.registerHandler("/subscription", metadata => | 302 this.registerHandler("/subscription", metadata => |
303 { | 303 { |
304 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"]; | 304 return [Cr.NS_OK, 200, "[Adblock]\n" + comment + "\nfoo\nbar"]; |
305 }); | 305 }); |
306 | 306 |
307 this.runScheduledTasks(2).then(() => | 307 this.runScheduledTasks(2).then(() => |
308 { | 308 { |
309 check(test, subscription); | 309 check(test, subscription); |
310 test.deepEqual(subscription.filters, [Filter.fromText("foo"), Filter.fromT
ext("bar")], "Special comment not added to filters"); | 310 test.deepEqual(subscription.filters, [Filter.fromText("foo"), Filter.fromT
ext("bar")], "Special comment not added to filters"); |
311 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 311 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
312 }; | 312 }; |
313 } | 313 } |
314 | 314 |
315 exports.testRedirects = function(test) | 315 exports.testRedirects = function(test) |
316 { | 316 { |
317 let subscription = Subscription.fromURL("http://example.com/subscription"); | 317 let subscription = Subscription.fromURL("http://example.com/subscription"); |
318 FilterStorage.addSubscription(subscription); | 318 filterStorage.addSubscription(subscription); |
319 | 319 |
320 this.registerHandler("/subscription", metadata => | 320 this.registerHandler("/subscription", metadata => |
321 { | 321 { |
322 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/redirected\
nbar"]; | 322 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/redirected\
nbar"]; |
323 }); | 323 }); |
324 | 324 |
325 let requests; | 325 let requests; |
326 | 326 |
327 this.runScheduledTasks(30).then(() => | 327 this.runScheduledTasks(30).then(() => |
328 { | 328 { |
329 test.equal([...FilterStorage.subscriptions()][0], subscription, "Invalid red
irect ignored"); | 329 test.equal([...filterStorage.subscriptions()][0], subscription, "Invalid red
irect ignored"); |
330 test.equal(subscription.downloadStatus, "synchronize_connection_error", "Con
nection error recorded"); | 330 test.equal(subscription.downloadStatus, "synchronize_connection_error", "Con
nection error recorded"); |
331 test.equal(subscription.errors, 2, "Number of download errors"); | 331 test.equal(subscription.errors, 2, "Number of download errors"); |
332 | 332 |
333 requests = []; | 333 requests = []; |
334 | 334 |
335 this.registerHandler("/redirected", metadata => | 335 this.registerHandler("/redirected", metadata => |
336 { | 336 { |
337 requests.push(this.getTimeOffset()); | 337 requests.push(this.getTimeOffset()); |
338 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 8 hours\nbar"]; | 338 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 8 hours\nbar"]; |
339 }); | 339 }); |
340 | 340 |
341 resetSubscription(subscription); | 341 resetSubscription(subscription); |
342 return this.runScheduledTasks(15); | 342 return this.runScheduledTasks(15); |
343 }).then(() => | 343 }).then(() => |
344 { | 344 { |
345 test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/re
directed", "Redirect followed"); | 345 test.equal([...filterStorage.subscriptions()][0].url, "http://example.com/re
directed", "Redirect followed"); |
346 test.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resulting re
quests"); | 346 test.deepEqual(requests, [0 + initialDelay, 8 + initialDelay], "Resulting re
quests"); |
347 | 347 |
348 this.registerHandler("/redirected", metadata => | 348 this.registerHandler("/redirected", metadata => |
349 { | 349 { |
350 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/subscript
ion\nbar"]; | 350 return [Cr.NS_OK, 200, "[Adblock]\n!Redirect: http://example.com/subscript
ion\nbar"]; |
351 }); | 351 }); |
352 | 352 |
353 subscription = Subscription.fromURL("http://example.com/subscription"); | 353 subscription = Subscription.fromURL("http://example.com/subscription"); |
354 resetSubscription(subscription); | 354 resetSubscription(subscription); |
355 FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]); | 355 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]); |
356 FilterStorage.addSubscription(subscription); | 356 filterStorage.addSubscription(subscription); |
357 | 357 |
358 return this.runScheduledTasks(2); | 358 return this.runScheduledTasks(2); |
359 }).then(() => | 359 }).then(() => |
360 { | 360 { |
361 test.equal([...FilterStorage.subscriptions()][0], subscription, "Redirect no
t followed on redirect loop"); | 361 test.equal([...filterStorage.subscriptions()][0], subscription, "Redirect no
t followed on redirect loop"); |
362 test.equal(subscription.downloadStatus, "synchronize_connection_error", "Dow
nload status after redirect loop"); | 362 test.equal(subscription.downloadStatus, "synchronize_connection_error", "Dow
nload status after redirect loop"); |
363 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 363 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
364 }; | 364 }; |
365 | 365 |
366 exports.testFallback = function(test) | 366 exports.testFallback = function(test) |
367 { | 367 { |
368 Prefs.subscriptions_fallbackerrors = 3; | 368 Prefs.subscriptions_fallbackerrors = 3; |
369 Prefs.subscriptions_fallbackurl = "http://example.com/fallback?%SUBSCRIPTION%&
%CHANNELSTATUS%&%RESPONSESTATUS%"; | 369 Prefs.subscriptions_fallbackurl = "http://example.com/fallback?%SUBSCRIPTION%&
%CHANNELSTATUS%&%RESPONSESTATUS%"; |
370 | 370 |
371 let subscription = Subscription.fromURL("http://example.com/subscription"); | 371 let subscription = Subscription.fromURL("http://example.com/subscription"); |
372 FilterStorage.addSubscription(subscription); | 372 filterStorage.addSubscription(subscription); |
373 | 373 |
374 // No valid response from fallback | 374 // No valid response from fallback |
375 | 375 |
376 let requests = []; | 376 let requests = []; |
377 let fallbackParams; | 377 let fallbackParams; |
378 let redirectedRequests; | 378 let redirectedRequests; |
379 this.registerHandler("/subscription", metadata => | 379 this.registerHandler("/subscription", metadata => |
380 { | 380 { |
381 requests.push(this.getTimeOffset()); | 381 requests.push(this.getTimeOffset()); |
382 return [Cr.NS_OK, 404, ""]; | 382 return [Cr.NS_OK, 404, ""]; |
(...skipping 17 matching lines...) Expand all Loading... |
400 return this.runScheduledTasks(100); | 400 return this.runScheduledTasks(100); |
401 }).then(() => | 401 }).then(() => |
402 { | 402 { |
403 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay], "Stop trying if the fallback responds with Gone"); | 403 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay], "Stop trying if the fallback responds with Gone"); |
404 test.equal(fallbackParams, "http://example.com/subscription&0&404", "Fallbac
k arguments"); | 404 test.equal(fallbackParams, "http://example.com/subscription&0&404", "Fallbac
k arguments"); |
405 | 405 |
406 // Fallback redirecting to a missing file | 406 // Fallback redirecting to a missing file |
407 | 407 |
408 subscription = Subscription.fromURL("http://example.com/subscription"); | 408 subscription = Subscription.fromURL("http://example.com/subscription"); |
409 resetSubscription(subscription); | 409 resetSubscription(subscription); |
410 FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]); | 410 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]); |
411 FilterStorage.addSubscription(subscription); | 411 filterStorage.addSubscription(subscription); |
412 requests = []; | 412 requests = []; |
413 | 413 |
414 this.registerHandler("/fallback", metadata => | 414 this.registerHandler("/fallback", metadata => |
415 { | 415 { |
416 return [Cr.NS_OK, 200, "301 http://example.com/redirected"]; | 416 return [Cr.NS_OK, 200, "301 http://example.com/redirected"]; |
417 }); | 417 }); |
418 return this.runScheduledTasks(100); | 418 return this.runScheduledTasks(100); |
419 }).then(() => | 419 }).then(() => |
420 { | 420 { |
421 test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/su
bscription", "Ignore invalid redirect from fallback"); | 421 test.equal([...filterStorage.subscriptions()][0].url, "http://example.com/su
bscription", "Ignore invalid redirect from fallback"); |
422 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay, 72 + initialDelay, 96 + initialDelay], "Requests not affected by invalid r
edirect"); | 422 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay, 72 + initialDelay, 96 + initialDelay], "Requests not affected by invalid r
edirect"); |
423 | 423 |
424 // Fallback redirecting to an existing file | 424 // Fallback redirecting to an existing file |
425 | 425 |
426 resetSubscription(subscription); | 426 resetSubscription(subscription); |
427 requests = []; | 427 requests = []; |
428 redirectedRequests = []; | 428 redirectedRequests = []; |
429 this.registerHandler("/redirected", metadata => | 429 this.registerHandler("/redirected", metadata => |
430 { | 430 { |
431 redirectedRequests.push(this.getTimeOffset()); | 431 redirectedRequests.push(this.getTimeOffset()); |
432 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"]; | 432 return [Cr.NS_OK, 200, "[Adblock]\n!Expires: 1day\nfoo\nbar"]; |
433 }); | 433 }); |
434 | 434 |
435 return this.runScheduledTasks(100); | 435 return this.runScheduledTasks(100); |
436 }).then(() => | 436 }).then(() => |
437 { | 437 { |
438 test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/re
directed", "Valid redirect from fallback is followed"); | 438 test.equal([...filterStorage.subscriptions()][0].url, "http://example.com/re
directed", "Valid redirect from fallback is followed"); |
439 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay], "Stop polling original URL after a valid redirect from fallback"); | 439 test.deepEqual(requests, [0 + initialDelay, 24 + initialDelay, 48 + initialD
elay], "Stop polling original URL after a valid redirect from fallback"); |
440 test.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay, 96
+ initialDelay], "Request new URL after a valid redirect from fallback"); | 440 test.deepEqual(redirectedRequests, [48 + initialDelay, 72 + initialDelay, 96
+ initialDelay], "Request new URL after a valid redirect from fallback"); |
441 | 441 |
442 // Redirect loop | 442 // Redirect loop |
443 | 443 |
444 this.registerHandler("/subscription", metadata => | 444 this.registerHandler("/subscription", metadata => |
445 { | 445 { |
446 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion2"]; | 446 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion2"]; |
447 }); | 447 }); |
448 this.registerHandler("/subscription2", metadata => | 448 this.registerHandler("/subscription2", metadata => |
449 { | 449 { |
450 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion"]; | 450 return [Cr.NS_OK, 200, "[Adblock]\n! Redirect: http://example.com/subscrip
tion"]; |
451 }); | 451 }); |
452 | 452 |
453 subscription = Subscription.fromURL("http://example.com/subscription"); | 453 subscription = Subscription.fromURL("http://example.com/subscription"); |
454 resetSubscription(subscription); | 454 resetSubscription(subscription); |
455 FilterStorage.removeSubscription([...FilterStorage.subscriptions()][0]); | 455 filterStorage.removeSubscription([...filterStorage.subscriptions()][0]); |
456 FilterStorage.addSubscription(subscription); | 456 filterStorage.addSubscription(subscription); |
457 | 457 |
458 return this.runScheduledTasks(100); | 458 return this.runScheduledTasks(100); |
459 }).then(() => | 459 }).then(() => |
460 { | 460 { |
461 test.equal([...FilterStorage.subscriptions()][0].url, "http://example.com/re
directed", "Fallback can still redirect even after a redirect loop"); | 461 test.equal([...filterStorage.subscriptions()][0].url, "http://example.com/re
directed", "Fallback can still redirect even after a redirect loop"); |
462 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 462 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
463 }; | 463 }; |
464 | 464 |
465 exports.testStateFields = function(test) | 465 exports.testStateFields = function(test) |
466 { | 466 { |
467 let subscription = Subscription.fromURL("http://example.com/subscription"); | 467 let subscription = Subscription.fromURL("http://example.com/subscription"); |
468 FilterStorage.addSubscription(subscription); | 468 filterStorage.addSubscription(subscription); |
469 | 469 |
470 this.registerHandler("/subscription", metadata => | 470 this.registerHandler("/subscription", metadata => |
471 { | 471 { |
472 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 2 hours\nfoo\nbar"]; | 472 return [Cr.NS_OK, 200, "[Adblock]\n! Expires: 2 hours\nfoo\nbar"]; |
473 }); | 473 }); |
474 | 474 |
475 let startTime = this.currentTime; | 475 let startTime = this.currentTime; |
476 this.runScheduledTasks(2).then(() => | 476 this.runScheduledTasks(2).then(() => |
477 { | 477 { |
478 test.equal(subscription.downloadStatus, "synchronize_ok", "downloadStatus af
ter successful download"); | 478 test.equal(subscription.downloadStatus, "synchronize_ok", "downloadStatus af
ter successful download"); |
(...skipping 24 matching lines...) Expand all Loading... |
503 return this.runScheduledTasks(24); | 503 return this.runScheduledTasks(24); |
504 }).then(() => | 504 }).then(() => |
505 { | 505 { |
506 test.equal(subscription.downloadStatus, "synchronize_connection_error", "dow
nloadStatus after download error"); | 506 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"); | 507 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"); | 508 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"); | 509 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"); | 510 test.equal(subscription.errors, 2, "errors after download error"); |
511 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 511 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
512 }; | 512 }; |
OLD | NEW |