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

Side by Side Diff: test/subscriptionClasses.js

Issue 29385742: Issue 4127 - [emscripten] Convert subscription classes to C++ - Part 2 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Use iterators syntax Created April 6, 2017, 8:05 a.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 | « compiled/subscription/UserDefinedSubscription.cpp ('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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 subscription1.delete(); 154 subscription1.delete();
155 subscription2.delete(); 155 subscription2.delete();
156 156
157 let subscription3 = Subscription.fromURL("http://example.com/"); 157 let subscription3 = Subscription.fromURL("http://example.com/");
158 test.equal(subscription3.lastDownload, 0, "Subscription data has been reset on ce previous instances have been released"); 158 test.equal(subscription3.lastDownload, 0, "Subscription data has been reset on ce previous instances have been released");
159 subscription3.delete(); 159 subscription3.delete();
160 160
161 test.done(); 161 test.done();
162 }; 162 };
163
164 exports.testDownloadableSubscriptionFilters = function(test)
165 {
166 let filter = Filter.fromText("test");
167
168 let subscription = Subscription.fromURL("http://example.com/");
169 test.equal(subscription.filterCount, 0, "Initial filter count");
170 test.equal(subscription.filterAt(0), null, "Retrieving non-existent filter");
171 test.equal(subscription.indexOfFilter(filter), -1, "Index of non-existent filt er");
172
173 subscription.delete();
174 filter.delete();
175
176 test.done();
177 };
178
179 exports.testSpecialSubscriptionFilters = function(test)
180 {
181 let filter1 = Filter.fromText("filter1");
182 let filter2 = Filter.fromText("filter2");
183 let subscription = Subscription.fromURL("~user~12345");
184
185 function checkFilterAt(pos, expected, message)
186 {
187 let filter = subscription.filterAt(pos);
188 test.equal(filter && filter.text, expected, message);
189 if (filter)
190 filter.delete();
191 }
192
193 test.equal(subscription.filterCount, 0, "Initial filter count");
194 checkFilterAt(0, null, "Retrieving non-existent filter");
195 test.equal(subscription.indexOfFilter(filter1), -1, "Index of non-existent fil ter");
196
197 subscription.insertFilterAt(filter1, 0);
198 test.equal(subscription.filterCount, 1, "Filter count after insert");
199 checkFilterAt(0, filter1.text, "First filter after insert");
200 checkFilterAt(1, null, "Retrieving non-existent filter");
201 test.equal(subscription.indexOfFilter(filter1), 0, "Index of existent filter") ;
202 test.equal(subscription.indexOfFilter(filter2), -1, "Index of non-existent fil ter");
203
204 subscription.insertFilterAt(filter2, 0);
205 test.equal(subscription.filterCount, 2, "Filter count after second insert");
206 checkFilterAt(0, filter2.text, "First filter after second insert");
207 checkFilterAt(1, filter1.text, "Second filter after second insert");
208 test.equal(subscription.indexOfFilter(filter1), 1, "Index of first filter");
209 test.equal(subscription.indexOfFilter(filter2), 0, "Index of second filter");
210
211 subscription.insertFilterAt(filter1, 1);
212 test.equal(subscription.filterCount, 3, "Filter count after inserting duplicat e filter");
213 checkFilterAt(0, filter2.text, "First filter after inserting duplicate filter" );
214 checkFilterAt(1, filter1.text, "Second filter after inserting duplicate filter ");
215 checkFilterAt(2, filter1.text, "Third filter after inserting duplicate filter" );
216 test.equal(subscription.indexOfFilter(filter1), 1, "Index of first filter");
217
218 subscription.removeFilterAt(1);
219 test.equal(subscription.filterCount, 2, "Filter count after remove");
220 checkFilterAt(0, filter2.text, "First filter after remove");
221 checkFilterAt(1, filter1.text, "Second filter after remove");
222 test.equal(subscription.indexOfFilter(filter1), 1, "Index of first filter");
223
224 filter1.delete();
225 filter2.delete();
226 Filter.fromText("dummy overwriting some released memory").delete();
227 checkFilterAt(0, "filter2", "First filter after releasing filter references");
228 checkFilterAt(1, "filter1", "Second filter after releasing filter references") ;
229
230 subscription.delete();
231
232 test.done();
233 };
234
235 exports.testFilterSerialization = function(test)
236 {
237 let filter1 = Filter.fromText("filter1");
238 let filter2 = Filter.fromText("filter2");
239
240 let subscription = Subscription.fromURL("~user~12345");
241 test.equal(subscription.serializeFilters(), "", "No filters added");
242
243 subscription.insertFilterAt(filter1, 0);
244 subscription.insertFilterAt(filter1, 1);
245 subscription.insertFilterAt(filter2, 1);
246 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter1\n filter2\nfilter1\n", "Three filters added");
247
248 subscription.removeFilterAt(0);
249 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\n filter1\n", "One filter removed");
250
251 subscription.delete();
252 filter1.delete();
253 filter2.delete();
254
255 test.done();
256 };
OLDNEW
« no previous file with comments | « compiled/subscription/UserDefinedSubscription.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld