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

Delta Between Two Patch Sets: test/filterStorage_readwrite.js

Issue 29402576: Issue 5052 - Adjust filter storage unit tests for API changes (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Created April 4, 2017, 12:06 p.m.
Right Patch Set: Removed unused variable Created April 5, 2017, 7:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 23 matching lines...) Expand all
34 ( 34 (
35 {Filter} = sandboxedRequire("../lib/filterClasses"), 35 {Filter} = sandboxedRequire("../lib/filterClasses"),
36 {FilterNotifier} = sandboxedRequire("../lib/filterNotifier"), 36 {FilterNotifier} = sandboxedRequire("../lib/filterNotifier"),
37 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), 37 {FilterStorage} = sandboxedRequire("../lib/filterStorage"),
38 {IO} = sandboxedRequire("./stub-modules/io"), 38 {IO} = sandboxedRequire("./stub-modules/io"),
39 {Prefs} = sandboxedRequire("./stub-modules/prefs"), 39 {Prefs} = sandboxedRequire("./stub-modules/prefs"),
40 {Subscription, ExternalSubscription} = sandboxedRequire("../lib/subscription Classes") 40 {Subscription, ExternalSubscription} = sandboxedRequire("../lib/subscription Classes")
41 ); 41 );
42 42
43 Prefs.patternsfile = "patterns.ini"; 43 Prefs.patternsfile = "patterns.ini";
44 dataFile = IO.resolveFilePath(Prefs.patternsfile); 44 dataFile = IO.resolveFilePath(Prefs.patternsfile);
kzar 2017/04/05 04:00:15 Shouldn't dataFile be assigned inside the setUp fu
Wladimir Palant 2017/04/05 07:14:24 Isn't it? We are still inside setUp.
kzar 2017/04/05 10:08:58 Argh sorry, so it is.
45 45
46 FilterStorage.addFilter(Filter.fromText("foobar")); 46 FilterStorage.addFilter(Filter.fromText("foobar"));
Wladimir Palant 2017/04/04 12:11:16 Calling FilterStorage.addFilter() has essentially
kzar 2017/04/05 04:00:15 Acknowledged.
47 callback(); 47 callback();
48 }; 48 };
49 49
50 let testData = new Promise((resolve, reject) => 50 let testData = new Promise((resolve, reject) =>
51 { 51 {
52 const fs = require("fs"); 52 const fs = require("fs");
53 const path = require("path"); 53 const path = require("path");
54 let datapath = path.resolve(__dirname, "data", "patterns.ini"); 54 let datapath = path.resolve(__dirname, "data", "patterns.ini");
55 55
56 fs.readFile(datapath, "utf-8", (error, data) => 56 fs.readFile(datapath, "utf-8", (error, data) =>
(...skipping 10 matching lines...) Expand all
67 FilterStorage.loadFromDisk(); 67 FilterStorage.loadFromDisk();
68 return FilterNotifier.once("load"); 68 return FilterNotifier.once("load");
69 } 69 }
70 70
71 function saveFilters() 71 function saveFilters()
72 { 72 {
73 FilterStorage.saveToDisk(); 73 FilterStorage.saveToDisk();
74 return FilterNotifier.once("save"); 74 return FilterNotifier.once("save");
75 } 75 }
76 76
77 function canonize(data) 77 function canonize(data)
Wladimir Palant 2017/04/04 12:11:16 This function was merely moved so that it can be u
kzar 2017/04/05 04:00:15 Acknowledged.
78 { 78 {
79 let curSection = null; 79 let curSection = null;
80 let sections = []; 80 let sections = [];
81 for (let line of (data + "\n[end]").split(/[\r\n]+/)) 81 for (let line of (data + "\n[end]").split(/[\r\n]+/))
82 { 82 {
83 if (/^\[.*\]$/.test(line)) 83 if (/^\[.*\]$/.test(line))
84 { 84 {
85 if (curSection) 85 if (curSection)
86 sections.push(curSection); 86 sections.push(curSection);
87 87
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 300
301 test.ok(!backupFile3.exists(), "Third backup not created with patternsbackup s = 2"); 301 test.ok(!backupFile3.exists(), "Third backup not created with patternsbackup s = 2");
302 }).catch(unexpectedError.bind(test)).then(() => test.done()); 302 }).catch(unexpectedError.bind(test)).then(() => test.done());
303 }; 303 };
304 304
305 exports.testRestoringBackup = function(test) 305 exports.testRestoringBackup = function(test)
306 { 306 {
307 Prefs.patternsbackups = 2; 307 Prefs.patternsbackups = 2;
308 Prefs.patternsbackupinterval = 24; 308 Prefs.patternsbackupinterval = 24;
309 309
310 let backupFile = dataFile.clone();
311 backupFile.leafName = backupFile.leafName.replace(/\.ini$/, "-backup1.ini");
Wladimir Palant 2017/04/04 12:11:16 This variable is unused - I already removed it loc
kzar 2017/04/05 04:00:15 If the variable's unused I don't mind it if you de
312
313 saveFilters().then(() => 310 saveFilters().then(() =>
314 { 311 {
315 test.equal(FilterStorage.subscriptions.length, 1, "Initial subscription coun t"); 312 test.equal(FilterStorage.subscriptions.length, 1, "Initial subscription coun t");
316 FilterStorage.removeSubscription(FilterStorage.subscriptions[0]); 313 FilterStorage.removeSubscription(FilterStorage.subscriptions[0]);
317 return saveFilters(); 314 return saveFilters();
318 }).then(() => 315 }).then(() =>
319 { 316 {
320 return loadFilters(); 317 return loadFilters();
321 }).then(() => 318 }).then(() =>
322 { 319 {
323 test.equal(FilterStorage.subscriptions.length, 0, "Subscription count after removing subscriptions and reloading"); 320 test.equal(FilterStorage.subscriptions.length, 0, "Subscription count after removing subscriptions and reloading");
324 return FilterStorage.restoreBackup(1); 321 return FilterStorage.restoreBackup(1);
325 }).then(() => 322 }).then(() =>
326 { 323 {
327 test.equal(FilterStorage.subscriptions.length, 1, "Subscription count after restoring backup"); 324 test.equal(FilterStorage.subscriptions.length, 1, "Subscription count after restoring backup");
328 return loadFilters(); 325 return loadFilters();
329 }).then(() => 326 }).then(() =>
330 { 327 {
331 test.equal(FilterStorage.subscriptions.length, 1, "Subscription count after reloading"); 328 test.equal(FilterStorage.subscriptions.length, 1, "Subscription count after reloading");
332 }).catch(unexpectedError.bind(test)).then(() => test.done()); 329 }).catch(unexpectedError.bind(test)).then(() => test.done());
333 }; 330 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld