LEFT | RIGHT |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.filters = [Filter.fromText("foo"), Filter.fromText("bar")]; |
112 FilterStorage.addSubscription(subscription); | 112 FilterStorage.addSubscription(subscription); |
113 } | 113 } |
114 | 114 |
115 let externalSubscriptions = FilterStorage.subscriptions.filter(subscriptio
n => subscription instanceof ExternalSubscription); | 115 let externalSubscriptions = [...FilterStorage.subscriptions()].filter(subs
cription => subscription instanceof ExternalSubscription); |
116 test.equal(externalSubscriptions.length, 1, "Number of external subscripti
ons after updateExternalSubscription"); | 116 test.equal(externalSubscriptions.length, 1, "Number of external subscripti
ons after updateExternalSubscription"); |
117 | 117 |
118 test.equal(externalSubscriptions[0].url, "~external~external subscription
ID", "ID of external subscription"); | 118 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"); | 119 test.equal(externalSubscriptions[0].filters.length, 2, "Number of filters
in external subscription"); |
120 } | 120 } |
121 | 121 |
122 if (withEmptySpecial) | 122 if (withEmptySpecial) |
123 { | 123 { |
124 let specialSubscription = | 124 let specialSubscription = |
125 SpecialSubscription.createForFilter(Filter.fromText("!foo")); | 125 SpecialSubscription.createForFilter(Filter.fromText("!foo")); |
126 FilterStorage.addSubscription(specialSubscription); | 126 FilterStorage.addSubscription(specialSubscription); |
127 | 127 |
128 FilterStorage.removeFilter(Filter.fromText("!foo"), specialSubscription); | 128 FilterStorage.removeFilter(Filter.fromText("!foo"), specialSubscription); |
129 | 129 |
130 test.equal(specialSubscription.filters.length, 0, | 130 test.equal(specialSubscription.filters.length, 0, |
131 "No filters in special subscription"); | 131 "No filters in special subscription"); |
132 test.ok(FilterStorage.subscriptions.indexOf(specialSubscription) != -1, | 132 test.ok(new Set(FilterStorage.subscriptions()).has(specialSubscription), |
133 "Empty special subscription still in storage"); | 133 "Empty special subscription still in storage"); |
134 } | 134 } |
135 | 135 |
136 return FilterStorage.saveToDisk(); | 136 return FilterStorage.saveToDisk(); |
137 }).then(() => testData).then(expected => | 137 }).then(() => testData).then(expected => |
138 { | 138 { |
139 test.deepEqual(canonize(IO._getFileContents(FilterStorage.sourceFile)), | 139 test.deepEqual(canonize(IO._getFileContents(FilterStorage.sourceFile)), |
140 canonize(expected), "Read/write result"); | 140 canonize(expected), "Read/write result"); |
141 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 141 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
142 } | 142 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 243 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
244 }; | 244 }; |
245 | 245 |
246 exports.testRestoringBackup = function(test) | 246 exports.testRestoringBackup = function(test) |
247 { | 247 { |
248 Prefs.patternsbackups = 2; | 248 Prefs.patternsbackups = 2; |
249 Prefs.patternsbackupinterval = 24; | 249 Prefs.patternsbackupinterval = 24; |
250 | 250 |
251 FilterStorage.saveToDisk().then(() => | 251 FilterStorage.saveToDisk().then(() => |
252 { | 252 { |
253 test.equal(FilterStorage.subscriptions[0].filters.length, 1, "Initial filter
count"); | 253 test.equal([...FilterStorage.subscriptions()][0].filters.length, 1, "Initial
filter count"); |
254 FilterStorage.addFilter(Filter.fromText("barfoo")); | 254 FilterStorage.addFilter(Filter.fromText("barfoo")); |
255 test.equal(FilterStorage.subscriptions[0].filters.length, 2, "Filter count a
fter adding a filter"); | 255 test.equal([...FilterStorage.subscriptions()][0].filters.length, 2, "Filter
count after adding a filter"); |
256 return FilterStorage.saveToDisk(); | 256 return FilterStorage.saveToDisk(); |
257 }).then(() => | 257 }).then(() => |
258 { | 258 { |
259 return FilterStorage.loadFromDisk(); | 259 return FilterStorage.loadFromDisk(); |
260 }).then(() => | 260 }).then(() => |
261 { | 261 { |
262 test.equal(FilterStorage.subscriptions[0].filters.length, 2, "Filter count a
fter adding filter and reloading"); | 262 test.equal([...FilterStorage.subscriptions()][0].filters.length, 2, "Filter
count after adding filter and reloading"); |
263 return FilterStorage.restoreBackup(1); | 263 return FilterStorage.restoreBackup(1); |
264 }).then(() => | 264 }).then(() => |
265 { | 265 { |
266 test.equal(FilterStorage.subscriptions[0].filters.length, 1, "Filter count a
fter restoring backup"); | 266 test.equal([...FilterStorage.subscriptions()][0].filters.length, 1, "Filter
count after restoring backup"); |
267 return FilterStorage.loadFromDisk(); | 267 return FilterStorage.loadFromDisk(); |
268 }).then(() => | 268 }).then(() => |
269 { | 269 { |
270 test.equal(FilterStorage.subscriptions[0].filters.length, 1, "Filter count a
fter reloading"); | 270 test.equal([...FilterStorage.subscriptions()][0].filters.length, 1, "Filter
count after reloading"); |
271 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 271 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
272 }; | 272 }; |
LEFT | RIGHT |