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

Side by Side Diff: test/filterStorage_readwrite.js

Issue 29416573: Issue 5153 - Simplify patterns.ini parsing (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created April 18, 2017, 1:33 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') | 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-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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 exports.testReadAndSaveToFile = function(test) 129 exports.testReadAndSaveToFile = function(test)
130 { 130 {
131 testReadWrite(test, false); 131 testReadWrite(test, false);
132 }; 132 };
133 133
134 exports.testReadAndSaveToFileWithExternalSubscription = function(test) 134 exports.testReadAndSaveToFileWithExternalSubscription = function(test)
135 { 135 {
136 testReadWrite(test, true); 136 testReadWrite(test, true);
137 }; 137 };
138 138
139 exports.testLegacyGroups = {};
140
141 for (let url of ["~wl~", "~fl~", "~eh~"])
142 {
143 exports.testLegacyGroups["read empty " + url] = function(test)
144 {
145 IO._setFileContents(FilterStorage.sourceFile, [
146 "[Subscription]", "url=" + url
147 ]);
148
149 FilterStorage.loadFromDisk().then(() =>
150 {
151 test.equal(FilterStorage.subscriptions.length, 0, "Number of filter subscr iptions");
152 }).catch(unexpectedError.bind(test)).then(() => test.done());
153 };
154
155 exports.testLegacyGroups["read non-empty " + url] = function(test)
156 {
157 IO._setFileContents(FilterStorage.sourceFile, [
158 "[Subscription]", "url=" + url,
159 "[Subscription filters]", "foo"
160 ]);
161
162 FilterStorage.loadFromDisk().then(() =>
163 {
164 test.equal(FilterStorage.subscriptions.length, 1, "Number of filter subscr iptions");
165 if (FilterStorage.subscriptions.length == 1)
166 {
167 let subscription = FilterStorage.subscriptions[0];
168 test.equal(subscription.url, url, "Subscription ID");
169 test.equal(subscription.title, null, "Subscription title");
170 test.deepEqual(subscription.defaults, null, "Default types");
171 test.equal(subscription.filters.length, 1, "Number of subscription filte rs");
172 if (subscription.filters.length == 1)
173 test.equal(subscription.filters[0].text, "foo", "First filter");
174 }
175 }).catch(unexpectedError.bind(test)).then(() => test.done());
176 };
177 }
178
179 exports.testReadLegacyFilters = function(test)
180 {
181 IO._setFileContents(FilterStorage.sourceFile, [
182 "[Subscription]", "url=~user~1234", "title=Foo",
183 "[Subscription filters]",
184 "[User patterns]", "foo", "\\[bar]", "foo#bar"
185 ]);
186
187 FilterStorage.loadFromDisk().then(() =>
188 {
189 test.equal(FilterStorage.subscriptions.length, 1, "Number of filter subscrip tions");
190 if (FilterStorage.subscriptions.length == 1)
191 {
192 let subscription = FilterStorage.subscriptions[0];
193 test.equal(subscription.filters.length, 3, "Number of subscription filters ");
194 if (subscription.filters.length == 3)
195 {
196 test.equal(subscription.filters[0].text, "foo", "First filter");
197 test.equal(subscription.filters[1].text, "[bar]", "Second filter");
198 test.equal(subscription.filters[2].text, "foo#bar", "Third filter");
199 }
200 }
201 }).catch(unexpectedError.bind(test)).then(() => test.done());
202 };
203
204 exports.testImportExport = function(test) 139 exports.testImportExport = function(test)
205 { 140 {
206 testData.then(lines => 141 testData.then(lines =>
207 { 142 {
208 if (lines.length && lines[lines.length - 1] == "") 143 if (lines.length && lines[lines.length - 1] == "")
209 lines.pop(); 144 lines.pop();
210 145
211 let importer = FilterStorage.importData(); 146 let importer = FilterStorage.importData();
212 for (let line of lines) 147 for (let line of lines)
213 importer(line); 148 importer(line);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return FilterStorage.restoreBackup(1); 243 return FilterStorage.restoreBackup(1);
309 }).then(() => 244 }).then(() =>
310 { 245 {
311 test.equal(FilterStorage.subscriptions[0].filters.length, 1, "Filter count a fter restoring backup"); 246 test.equal(FilterStorage.subscriptions[0].filters.length, 1, "Filter count a fter restoring backup");
312 return FilterStorage.loadFromDisk(); 247 return FilterStorage.loadFromDisk();
313 }).then(() => 248 }).then(() =>
314 { 249 {
315 test.equal(FilterStorage.subscriptions[0].filters.length, 1, "Filter count a fter reloading"); 250 test.equal(FilterStorage.subscriptions[0].filters.length, 1, "Filter count a fter reloading");
316 }).catch(unexpectedError.bind(test)).then(() => test.done()); 251 }).catch(unexpectedError.bind(test)).then(() => test.done());
317 }; 252 };
OLDNEW
« no previous file with comments | « test/filterStorage.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld