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

Side by Side Diff: test/synchronizer.js

Issue 29934588: Issue 7094 - Encapsulate management of subscription filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Remove hasFilter and related code Created Nov. 18, 2018, 10:21 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
« lib/subscriptionClasses.js ('K') | « test/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-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
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
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 { 529 {
537 // To test allowing unknown special comments like `! :`, `!!@#$%^&*() : `, a nd `! Some Unknown Comment : ` 530 // To test allowing unknown special comments like `! :`, `!!@#$%^&*() : `, a nd `! Some Unknown Comment : `
538 return [Cr.NS_OK, 200, "[Adblock]\n! :\n! !@#$%^&*() :\n! Some Unknown Comme nt :\n! Title: foobar\nfoo\nbar"]; 531 return [Cr.NS_OK, 200, "[Adblock]\n! :\n! !@#$%^&*() :\n! Some Unknown Comme nt :\n! Title: foobar\nfoo\nbar"];
539 }); 532 });
540 533
541 this.runScheduledTasks(1).then(() => 534 this.runScheduledTasks(1).then(() =>
542 { 535 {
543 test.equal(subscription.title, "foobar", "make sure title was found"); 536 test.equal(subscription.title, "foobar", "make sure title was found");
544 }).catch(unexpectedError.bind(test)).then(() => test.done()); 537 }).catch(unexpectedError.bind(test)).then(() => test.done());
545 }; 538 };
OLDNEW
« lib/subscriptionClasses.js ('K') | « test/subscriptionClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld