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

Side by Side Diff: test/subscriptionClasses.js

Issue 29398669: Issue 5063 - [emscripten] Make FilterNotifier calls more efficient (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Added missing files Created April 6, 2017, 8:08 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 | « test/filterClasses.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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 let {createSandbox} = require("./_common"); 20 let {createSandbox} = require("./_common");
21 21
22 let Filter = null; 22 let Filter = null;
23 let Subscription = null; 23 let Subscription = null;
24 let SpecialSubscription = null; 24 let SpecialSubscription = null;
25 let DownloadableSubscription = null; 25 let DownloadableSubscription = null;
26 let RegularSubscription = null; 26 let RegularSubscription = null;
27 let ExternalSubscription = null; 27 let ExternalSubscription = null;
28 let FilterNotifier = null;
28 29
29 exports.setUp = function(callback) 30 exports.setUp = function(callback)
30 { 31 {
31 let sandboxedRequire = createSandbox(); 32 let sandboxedRequire = createSandbox();
32 ({Filter} = sandboxedRequire("../lib/filterClasses")); 33 ({Filter} = sandboxedRequire("../lib/filterClasses"));
33 ( 34 (
34 { 35 {
35 Subscription, SpecialSubscription, DownloadableSubscription 36 Subscription, SpecialSubscription, DownloadableSubscription
36 } = sandboxedRequire("../lib/subscriptionClasses") 37 } = sandboxedRequire("../lib/subscriptionClasses")
37 ); 38 );
39 ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier"));
38 callback(); 40 callback();
39 }; 41 };
40 42
41 function compareSubscription(test, url, expected, postInit) 43 function compareSubscription(test, url, expected, postInit)
42 { 44 {
43 expected.push("[Subscription]") 45 expected.push("[Subscription]")
44 let subscription = Subscription.fromURL(url); 46 let subscription = Subscription.fromURL(url);
45 if (postInit) 47 if (postInit)
46 postInit(subscription) 48 postInit(subscription)
47 let result = subscription.serialize().trim().split("\n"); 49 let result = subscription.serialize().trim().split("\n");
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 249
248 subscription.removeFilterAt(0); 250 subscription.removeFilterAt(0);
249 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\n filter1\n", "One filter removed"); 251 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\n filter1\n", "One filter removed");
250 252
251 subscription.delete(); 253 subscription.delete();
252 filter1.delete(); 254 filter1.delete();
253 filter2.delete(); 255 filter2.delete();
254 256
255 test.done(); 257 test.done();
256 }; 258 };
259
260 exports.testNotifications = function(test)
261 {
262 function checkNotifications(action, expected, message)
263 {
264 let result = null;
265 let listener = (topic, subscription, newValue, oldValue) =>
266 {
267 if (result)
268 test.ok(false, "Got more that one notification - " + message);
269 else
270 result = [topic, subscription.url, newValue, oldValue];
271 };
272 FilterNotifier.addListener(listener);
273 action();
274 FilterNotifier.removeListener(listener);
275 test.deepEqual(result, expected, message);
276 }
277
278 let subscription = Subscription.fromURL("http://example.com/");
279 checkNotifications(() =>
280 {
281 subscription.title = "foobar";
282 }, ["subscription.title", "http://example.com/", "foobar", "http://example.com /"], "Changing subscription title");
283 checkNotifications(() =>
284 {
285 subscription.title = "foobar";
286 }, null, "Setting subscription title to same value");
287 checkNotifications(() =>
288 {
289 subscription.title = null;
290 }, ["subscription.title", "http://example.com/", "", "foobar"], "Resetting sub scription title");
291
292 checkNotifications(() =>
293 {
294 subscription.disabled = true;
295 }, ["subscription.disabled", "http://example.com/", true, false], "Disabling s ubscription");
296 checkNotifications(() =>
297 {
298 subscription.disabled = true;
299 }, null, "Disabling already disabled subscription");
300 checkNotifications(() =>
301 {
302 subscription.disabled = false;
303 }, ["subscription.disabled", "http://example.com/", false, true], "Enabling su bscription");
304
305 checkNotifications(() =>
306 {
307 subscription.fixedTitle = true;
308 }, ["subscription.fixedTitle", "http://example.com/", true, false], "Marking t itle as fixed");
309 checkNotifications(() =>
310 {
311 subscription.fixedTitle = false;
312 }, ["subscription.fixedTitle", "http://example.com/", false, true], "Marking t itle as editable");
313
314 checkNotifications(() =>
315 {
316 subscription.homepage = "http://example.info/";
317 }, ["subscription.homepage", "http://example.com/", "http://example.info/", "" ], "Changing subscription homepage");
318 checkNotifications(() =>
319 {
320 subscription.homepage = null;
321 }, ["subscription.homepage", "http://example.com/", "", "http://example.info/" ], "Resetting subscription homepage");
322
323 checkNotifications(() =>
324 {
325 // Using a large number that will only fit into double but not int
326 subscription.lastCheck = 123456789012345;
327 }, ["subscription.lastCheck", "http://example.com/", 123456789012345, 0], "Cha nging subscription.lastCheck");
328 checkNotifications(() =>
329 {
330 subscription.lastCheck = 123456789012345;
331 }, null, "Setting subscription.lastCheck to same value");
332 checkNotifications(() =>
333 {
334 subscription.lastCheck = 0;
335 }, ["subscription.lastCheck", "http://example.com/", 0, 123456789012345], "Res etting subscription.lastCheck");
336
337 checkNotifications(() =>
338 {
339 // Using a large number that will only fit into double but not int
340 subscription.lastDownload = 543210987654321;
341 }, ["subscription.lastDownload", "http://example.com/", 543210987654321, 0], " Changing subscription.lastDownload");
342 checkNotifications(() =>
343 {
344 subscription.lastDownload = 0;
345 }, ["subscription.lastDownload", "http://example.com/", 0, 543210987654321], " Resetting subscription.lastDownload");
346
347 checkNotifications(() =>
348 {
349 subscription.downloadStatus = "ok";
350 }, ["subscription.downloadStatus", "http://example.com/", "ok", ""], "Changing subscription.downloadStatus");
351 checkNotifications(() =>
352 {
353 subscription.downloadStatus = null;
354 }, ["subscription.downloadStatus", "http://example.com/", "", "ok"], "Resettin g subscription.downloadStatus");
355
356 checkNotifications(() =>
357 {
358 subscription.errors++;
359 }, ["subscription.errors", "http://example.com/", 1, 0], "Increasing subscript ion.errors");
360 checkNotifications(() =>
361 {
362 subscription.errors = 0;
363 }, ["subscription.errors", "http://example.com/", 0, 1], "Resetting subscripti on.erros");
364
365 subscription.delete();
366 test.done();
367 };
OLDNEW
« no previous file with comments | « test/filterClasses.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld