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

Side by Side Diff: test/filterStorage_readwrite.js

Issue 29934588: Issue 7094 - Encapsulate management of subscription filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Update tests Created Nov. 17, 2018, 11:40 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
« no previous file with comments | « test/filterStorage.js ('k') | test/subscriptionClasses.js » ('j') | 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
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return filterStorage.loadFromDisk(); 101 return filterStorage.loadFromDisk();
102 }).then(() => 102 }).then(() =>
103 { 103 {
104 test.ok(filterStorage.initialized, "Initialize after the first load"); 104 test.ok(filterStorage.initialized, "Initialize after the first load");
105 test.equal(filterStorage.fileProperties.version, filterStorage.formatVersion , "File format version"); 105 test.equal(filterStorage.fileProperties.version, filterStorage.formatVersion , "File format version");
106 106
107 if (withExternal) 107 if (withExternal)
108 { 108 {
109 { 109 {
110 let subscription = new ExternalSubscription("~external~external subscrip tion ID", "External subscription"); 110 let subscription = new ExternalSubscription("~external~external subscrip tion ID", "External subscription");
111 subscription.filters = [Filter.fromText("foo"), Filter.fromText("bar")]; 111 subscription.addFilter(Filter.fromText("foo"));
112 subscription.addFilter(Filter.fromText("bar"));
112 filterStorage.addSubscription(subscription); 113 filterStorage.addSubscription(subscription);
113 } 114 }
114 115
115 let externalSubscriptions = [...filterStorage.subscriptions()].filter(subs cription => subscription instanceof ExternalSubscription); 116 let externalSubscriptions = [...filterStorage.subscriptions()].filter(subs cription => subscription instanceof ExternalSubscription);
116 test.equal(externalSubscriptions.length, 1, "Number of external subscripti ons after updateExternalSubscription"); 117 test.equal(externalSubscriptions.length, 1, "Number of external subscripti ons after updateExternalSubscription");
117 118
118 test.equal(externalSubscriptions[0].url, "~external~external subscription ID", "ID of external subscription"); 119 test.equal(externalSubscriptions[0].url, "~external~external subscription ID", "ID of external subscription");
119 test.equal(externalSubscriptions[0].filters.length, 2, "Number of filters in external subscription"); 120 test.equal(externalSubscriptions[0].filterCount, 2, "Number of filters in external subscription");
120 } 121 }
121 122
122 if (withEmptySpecial) 123 if (withEmptySpecial)
123 { 124 {
124 let specialSubscription = 125 let specialSubscription =
125 SpecialSubscription.createForFilter(Filter.fromText("!foo")); 126 SpecialSubscription.createForFilter(Filter.fromText("!foo"));
126 filterStorage.addSubscription(specialSubscription); 127 filterStorage.addSubscription(specialSubscription);
127 128
128 filterStorage.removeFilter(Filter.fromText("!foo"), specialSubscription); 129 filterStorage.removeFilter(Filter.fromText("!foo"), specialSubscription);
129 130
130 test.equal(specialSubscription.filters.length, 0, 131 test.equal(specialSubscription.filterCount, 0,
131 "No filters in special subscription"); 132 "No filters in special subscription");
132 test.ok(new Set(filterStorage.subscriptions()).has(specialSubscription), 133 test.ok(new Set(filterStorage.subscriptions()).has(specialSubscription),
133 "Empty special subscription still in storage"); 134 "Empty special subscription still in storage");
134 } 135 }
135 136
136 return filterStorage.saveToDisk(); 137 return filterStorage.saveToDisk();
137 }).then(() => testData).then(expected => 138 }).then(() => testData).then(expected =>
138 { 139 {
139 test.deepEqual(canonize(IO._getFileContents(filterStorage.sourceFile)), 140 test.deepEqual(canonize(IO._getFileContents(filterStorage.sourceFile)),
140 canonize(expected), "Read/write result"); 141 canonize(expected), "Read/write result");
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 }).catch(unexpectedError.bind(test)).then(() => test.done()); 244 }).catch(unexpectedError.bind(test)).then(() => test.done());
244 }; 245 };
245 246
246 exports.testRestoringBackup = function(test) 247 exports.testRestoringBackup = function(test)
247 { 248 {
248 Prefs.patternsbackups = 2; 249 Prefs.patternsbackups = 2;
249 Prefs.patternsbackupinterval = 24; 250 Prefs.patternsbackupinterval = 24;
250 251
251 filterStorage.saveToDisk().then(() => 252 filterStorage.saveToDisk().then(() =>
252 { 253 {
253 test.equal([...filterStorage.subscriptions()][0].filters.length, 1, "Initial filter count"); 254 test.equal([...filterStorage.subscriptions()][0].filterCount, 1, "Initial fi lter count");
254 filterStorage.addFilter(Filter.fromText("barfoo")); 255 filterStorage.addFilter(Filter.fromText("barfoo"));
255 test.equal([...filterStorage.subscriptions()][0].filters.length, 2, "Filter count after adding a filter"); 256 test.equal([...filterStorage.subscriptions()][0].filterCount, 2, "Filter cou nt after adding a filter");
256 return filterStorage.saveToDisk(); 257 return filterStorage.saveToDisk();
257 }).then(() => 258 }).then(() =>
258 { 259 {
259 return filterStorage.loadFromDisk(); 260 return filterStorage.loadFromDisk();
260 }).then(() => 261 }).then(() =>
261 { 262 {
262 test.equal([...filterStorage.subscriptions()][0].filters.length, 2, "Filter count after adding filter and reloading"); 263 test.equal([...filterStorage.subscriptions()][0].filterCount, 2, "Filter cou nt after adding filter and reloading");
263 return filterStorage.restoreBackup(1); 264 return filterStorage.restoreBackup(1);
264 }).then(() => 265 }).then(() =>
265 { 266 {
266 test.equal([...filterStorage.subscriptions()][0].filters.length, 1, "Filter count after restoring backup"); 267 test.equal([...filterStorage.subscriptions()][0].filterCount, 1, "Filter cou nt after restoring backup");
267 return filterStorage.loadFromDisk(); 268 return filterStorage.loadFromDisk();
268 }).then(() => 269 }).then(() =>
269 { 270 {
270 test.equal([...filterStorage.subscriptions()][0].filters.length, 1, "Filter count after reloading"); 271 test.equal([...filterStorage.subscriptions()][0].filterCount, 1, "Filter cou nt after reloading");
271 }).catch(unexpectedError.bind(test)).then(() => test.done()); 272 }).catch(unexpectedError.bind(test)).then(() => test.done());
272 }; 273 };
OLDNEW
« no previous file with comments | « test/filterStorage.js ('k') | test/subscriptionClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld