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: Rebased Created April 13, 2017, 1:07 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/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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 253
252 subscription.removeFilterAt(0); 254 subscription.removeFilterAt(0);
253 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\n filter1\n", "One filter removed"); 255 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\n filter1\n", "One filter removed");
254 256
255 subscription.delete(); 257 subscription.delete();
256 filter1.delete(); 258 filter1.delete();
257 filter2.delete(); 259 filter2.delete();
258 260
259 test.done(); 261 test.done();
260 }; 262 };
263
264 exports.testNotifications = function(test)
265 {
266 function checkNotifications(action, expected, message)
267 {
268 let result = null;
269 let listener = (topic, subscription, newValue, oldValue) =>
270 {
271 if (result)
272 test.ok(false, "Got more that one notification - " + message);
273 else
274 result = [topic, subscription.url, newValue, oldValue];
275 };
276 FilterNotifier.addListener(listener);
277 action();
278 FilterNotifier.removeListener(listener);
279 test.deepEqual(result, expected, message);
280 }
281
282 let subscription = Subscription.fromURL("http://example.com/");
283 checkNotifications(() =>
284 {
285 subscription.title = "foobar";
286 }, ["subscription.title", "http://example.com/", "foobar", "http://example.com /"], "Changing subscription title");
287 checkNotifications(() =>
288 {
289 subscription.title = "foobar";
290 }, null, "Setting subscription title to same value");
291 checkNotifications(() =>
292 {
293 subscription.title = null;
294 }, ["subscription.title", "http://example.com/", "", "foobar"], "Resetting sub scription title");
295
296 checkNotifications(() =>
297 {
298 subscription.disabled = true;
299 }, ["subscription.disabled", "http://example.com/", true, false], "Disabling s ubscription");
300 checkNotifications(() =>
301 {
302 subscription.disabled = true;
303 }, null, "Disabling already disabled subscription");
304 checkNotifications(() =>
305 {
306 subscription.disabled = false;
307 }, ["subscription.disabled", "http://example.com/", false, true], "Enabling su bscription");
308
309 checkNotifications(() =>
310 {
311 subscription.fixedTitle = true;
312 }, ["subscription.fixedTitle", "http://example.com/", true, false], "Marking t itle as fixed");
313 checkNotifications(() =>
314 {
315 subscription.fixedTitle = false;
316 }, ["subscription.fixedTitle", "http://example.com/", false, true], "Marking t itle as editable");
317
318 checkNotifications(() =>
319 {
320 subscription.homepage = "http://example.info/";
321 }, ["subscription.homepage", "http://example.com/", "http://example.info/", "" ], "Changing subscription homepage");
322 checkNotifications(() =>
323 {
324 subscription.homepage = null;
325 }, ["subscription.homepage", "http://example.com/", "", "http://example.info/" ], "Resetting subscription homepage");
326
327 checkNotifications(() =>
328 {
329 // Using a large number that will only fit into double but not int
330 subscription.lastCheck = 123456789012345;
331 }, ["subscription.lastCheck", "http://example.com/", 123456789012345, 0], "Cha nging subscription.lastCheck");
332 checkNotifications(() =>
333 {
334 subscription.lastCheck = 123456789012345;
335 }, null, "Setting subscription.lastCheck to same value");
336 checkNotifications(() =>
337 {
338 subscription.lastCheck = 0;
339 }, ["subscription.lastCheck", "http://example.com/", 0, 123456789012345], "Res etting subscription.lastCheck");
340
341 checkNotifications(() =>
342 {
343 // Using a large number that will only fit into double but not int
344 subscription.lastDownload = 543210987654321;
345 }, ["subscription.lastDownload", "http://example.com/", 543210987654321, 0], " Changing subscription.lastDownload");
346 checkNotifications(() =>
347 {
348 subscription.lastDownload = 0;
349 }, ["subscription.lastDownload", "http://example.com/", 0, 543210987654321], " Resetting subscription.lastDownload");
350
351 checkNotifications(() =>
352 {
353 subscription.downloadStatus = "ok";
354 }, ["subscription.downloadStatus", "http://example.com/", "ok", ""], "Changing subscription.downloadStatus");
355 checkNotifications(() =>
356 {
357 subscription.downloadStatus = null;
358 }, ["subscription.downloadStatus", "http://example.com/", "", "ok"], "Resettin g subscription.downloadStatus");
359
360 checkNotifications(() =>
361 {
362 subscription.errors++;
363 }, ["subscription.errors", "http://example.com/", 1, 0], "Increasing subscript ion.errors");
364 checkNotifications(() =>
365 {
366 subscription.errors = 0;
367 }, ["subscription.errors", "http://example.com/", 0, 1], "Resetting subscripti on.erros");
368
369 subscription.delete();
370 test.done();
371 };
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