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

Delta Between Two Patch Sets: test/elemHide.js

Issue 29882558: Issue 6955 - Avoid making copies of common selector list (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Cache common selector list Created Sept. 17, 2018, 9:20 a.m.
Right Patch Set: Keep track of exceptions per domain Created Sept. 17, 2018, 12:15 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/elemHideExceptions.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 26 matching lines...) Expand all
37 {Filter} = sandboxedRequire("../lib/filterClasses") 37 {Filter} = sandboxedRequire("../lib/filterClasses")
38 ); 38 );
39 39
40 callback(); 40 callback();
41 }; 41 };
42 42
43 function normalizeSelectors(selectors) 43 function normalizeSelectors(selectors)
44 { 44 {
45 // getSelectorsForDomain is currently allowed to return duplicate selectors 45 // getSelectorsForDomain is currently allowed to return duplicate selectors
46 // for performance reasons, so we need to remove duplicates here. 46 // for performance reasons, so we need to remove duplicates here.
47 return selectors.slice().sort().filter((selector, index, sortedSelectors) => 47 return selectors.slice().sort().filter((selector, index, sortedSelectors) =>
Manish Jethani 2018/09/17 09:28:43 Need to make a copy now because the return value o
48 { 48 {
49 return index == 0 || selector != sortedSelectors[index - 1]; 49 return index == 0 || selector != sortedSelectors[index - 1];
50 }); 50 });
51 } 51 }
52 52
53 function testResult(test, domain, expectedSelectors, specificOnly) 53 function testResult(test, domain, expectedSelectors, specificOnly)
54 { 54 {
55 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors); 55 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors);
56 56
57 test.deepEqual( 57 test.deepEqual(
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
268 ElemHide.remove(Filter.fromText("example.com##test")); 268 ElemHide.remove(Filter.fromText("example.com##test"));
269 test.equal(filtersByDomain.size, 2); 269 test.equal(filtersByDomain.size, 2);
270 270
271 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test")); 271 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test"));
272 test.equal(filtersByDomain.size, 0); 272 test.equal(filtersByDomain.size, 0);
273 273
274 test.done(); 274 test.done();
275 }; 275 };
276 276
277 exports.testCommonSelectorsDedup = function(test) 277 exports.testCommonSelectorsDedup = function(test)
Manish Jethani 2018/09/17 09:28:43 Read this first.
278 { 278 {
279 // Here we compare references to verify that the selector lookup function 279 // Here we compare references to verify that the selector lookup function
280 // returns the same object for the common case. 280 // returns the same object for the common case.
281 281
282 ElemHide.add(Filter.fromText("##test1")); 282 ElemHide.add(Filter.fromText("##test1"));
283 ElemHide.add(Filter.fromText("##test2")); 283 ElemHide.add(Filter.fromText("##test2"));
284 ElemHide.add(Filter.fromText("##test3")); 284 ElemHide.add(Filter.fromText("##test3"));
285 285
286 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 286 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"),
287 ElemHide.getSelectorsForDomain("bar.example.com")); 287 ElemHide.getSelectorsForDomain("bar.example.com"));
(...skipping 16 matching lines...) Expand all
304 ElemHide.getSelectorsForDomain("bar.example.com")); 304 ElemHide.getSelectorsForDomain("bar.example.com"));
305 305
306 ElemHide.remove(Filter.fromText("~foo.example.com##test4")); 306 ElemHide.remove(Filter.fromText("~foo.example.com##test4"));
307 307
308 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 308 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"),
309 ElemHide.getSelectorsForDomain("bar.example.com")); 309 ElemHide.getSelectorsForDomain("bar.example.com"));
310 310
311 // Domain-specific exception. 311 // Domain-specific exception.
312 ElemHideExceptions.add(Filter.fromText("foo.example.com#@#test4")); 312 ElemHideExceptions.add(Filter.fromText("foo.example.com#@#test4"));
313 313
314 // Since the exception does not apply to any filters yet, the objects 314 // Even though the exception does not apply to any filters yet, the objects
315 // returned for foo.example.com and bar.example.com are one and the same. 315 // returned for foo.example.com and bar.example.com are not one and the same.
316 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 316 test.notEqual(ElemHide.getSelectorsForDomain("foo.example.com"),
317 ElemHide.getSelectorsForDomain("bar.example.com")); 317 ElemHide.getSelectorsForDomain("bar.example.com"));
318 318
319 ElemHide.add(Filter.fromText("##test4")); 319 ElemHide.add(Filter.fromText("##test4"));
320 320
321 test.notEqual(ElemHide.getSelectorsForDomain("foo.example.com"), 321 test.notEqual(ElemHide.getSelectorsForDomain("foo.example.com"),
322 ElemHide.getSelectorsForDomain("bar.example.com")); 322 ElemHide.getSelectorsForDomain("bar.example.com"));
323 323
324 ElemHide.remove(Filter.fromText("##test4")); 324 ElemHide.remove(Filter.fromText("##test4"));
325 ElemHideExceptions.remove(Filter.fromText("foo.example.com#@#test4")); 325 ElemHideExceptions.remove(Filter.fromText("foo.example.com#@#test4"));
326 326
327 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 327 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"),
328 ElemHide.getSelectorsForDomain("bar.example.com")); 328 ElemHide.getSelectorsForDomain("bar.example.com"));
329 329
330 // Generic exception with domain excluded. 330 // Generic exception with domain excluded.
331 ElemHideExceptions.add(Filter.fromText("~foo.example.com#@#test4")); 331 ElemHideExceptions.add(Filter.fromText("~foo.example.com#@#test4"));
332 332
333 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 333 // Even though the exception does not apply to any filters yet, the objects
334 ElemHide.getSelectorsForDomain("bar.example.com")); 334 // returned for foo.example.com and bar.example.com are not one and the same.
335 test.notEqual(ElemHide.getSelectorsForDomain("foo.example.com"),
336 ElemHide.getSelectorsForDomain("bar.example.com"));
335 337
336 ElemHide.add(Filter.fromText("##test4")); 338 ElemHide.add(Filter.fromText("##test4"));
337 339
338 test.notEqual(ElemHide.getSelectorsForDomain("foo.example.com"), 340 test.notEqual(ElemHide.getSelectorsForDomain("foo.example.com"),
339 ElemHide.getSelectorsForDomain("bar.example.com")); 341 ElemHide.getSelectorsForDomain("bar.example.com"));
340 342
341 ElemHide.remove(Filter.fromText("##test4")); 343 ElemHide.remove(Filter.fromText("##test4"));
342 ElemHideExceptions.remove(Filter.fromText("~foo.example.com#@#test4")); 344 ElemHideExceptions.remove(Filter.fromText("~foo.example.com#@#test4"));
343 345
344 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 346 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"),
345 ElemHide.getSelectorsForDomain("bar.example.com")); 347 ElemHide.getSelectorsForDomain("bar.example.com"));
346 348
347 // Generic exception. 349 // Generic exception.
348 ElemHide.add(Filter.fromText("##test4")); 350 ElemHide.add(Filter.fromText("##test4"));
349 ElemHideExceptions.add(Filter.fromText("#@#test4")); 351 ElemHideExceptions.add(Filter.fromText("#@#test4"));
350 352
351 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 353 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"),
352 ElemHide.getSelectorsForDomain("bar.example.com")); 354 ElemHide.getSelectorsForDomain("bar.example.com"));
353 355
354 ElemHideExceptions.add(Filter.fromText("example.com#@#test4")); 356 ElemHideExceptions.add(Filter.fromText("example.com#@#test4"));
355 357
356 // In this case, even though the exception applies to both domains, we get 358 // In this case, even though the exception applies to both domains, we get
357 // different objects. 359 // different objects.
358 test.notEqual(ElemHide.getSelectorsForDomain("foo.example.com"), 360 test.notEqual(ElemHide.getSelectorsForDomain("foo.example.com"),
359 ElemHide.getSelectorsForDomain("bar.example.com")); 361 ElemHide.getSelectorsForDomain("bar.example.com"));
360 test.deepEqual(ElemHide.getSelectorsForDomain("foo.example.com"), 362 test.deepEqual(ElemHide.getSelectorsForDomain("foo.example.com"),
361 ElemHide.getSelectorsForDomain("bar.example.com")); 363 ElemHide.getSelectorsForDomain("bar.example.com"));
362 364
363 ElemHideExceptions.remove(Filter.fromText("example.com#@#test4")); 365 ElemHideExceptions.remove(Filter.fromText("example.com#@#test4"));
366
367 // Generic exception with unrelated domain excluded.
Manish Jethani 2018/09/17 12:21:15 This particular test would not pass with Patch Set
368 ElemHideExceptions.add(Filter.fromText("~x4aabd7c0ddcd.com#@#test4"));
369
370 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"),
371 ElemHide.getSelectorsForDomain("bar.example.com"));
372
373 ElemHideExceptions.remove(Filter.fromText("~x4aabd7c0ddcd.com#@#test4"));
364 ElemHideExceptions.remove(Filter.fromText("#@#test4")); 374 ElemHideExceptions.remove(Filter.fromText("#@#test4"));
365 ElemHide.remove(Filter.fromText("##test4")); 375 ElemHide.remove(Filter.fromText("##test4"));
366 376
367 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 377 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"),
368 ElemHide.getSelectorsForDomain("bar.example.com")); 378 ElemHide.getSelectorsForDomain("bar.example.com"));
369 379
370 ElemHide.remove(Filter.fromText("##test1")); 380 ElemHide.remove(Filter.fromText("##test1"));
371 ElemHide.remove(Filter.fromText("##test2")); 381 ElemHide.remove(Filter.fromText("##test2"));
372 ElemHide.remove(Filter.fromText("##test3")); 382 ElemHide.remove(Filter.fromText("##test3"));
373 383
374 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"), 384 test.equal(ElemHide.getSelectorsForDomain("foo.example.com"),
375 ElemHide.getSelectorsForDomain("bar.example.com")); 385 ElemHide.getSelectorsForDomain("bar.example.com"));
376 386
377 test.done(); 387 test.done();
378 }; 388 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld