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

Delta Between Two Patch Sets: test/elemHide.js

Issue 29886555: Issue 6957 - Add generateStyleSheetForDomain function to ElemHide module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Sept. 20, 2018, 12:22 p.m.
Right Patch Set: Rebase, remove getSelectorsForDomain Created Sept. 27, 2018, 3:55 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/elemHide.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 27 matching lines...) Expand all
38 sandboxedRequire("../lib/elemHide"), 38 sandboxedRequire("../lib/elemHide"),
39 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), 39 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"),
40 {Filter} = sandboxedRequire("../lib/filterClasses") 40 {Filter} = sandboxedRequire("../lib/filterClasses")
41 ); 41 );
42 42
43 callback(); 43 callback();
44 }; 44 };
45 45
46 function normalizeSelectors(selectors) 46 function normalizeSelectors(selectors)
47 { 47 {
48 // getSelectorsForDomain is currently allowed to return duplicate selectors 48 // generateStyleSheetForDomain is currently allowed to return duplicate
49 // for performance reasons, so we need to remove duplicates here. 49 // selectors for performance reasons, so we need to remove duplicates here.
50 return selectors.slice().sort().filter((selector, index, sortedSelectors) => 50 return selectors.slice().sort().filter((selector, index, sortedSelectors) =>
Manish Jethani 2018/09/20 12:27:24 Somewhat unrelated, but we should make a copy and
Jon Sonesen 2018/09/20 20:10:20 Acknowledged. Just curious, since slice returns a
Manish Jethani 2018/09/21 10:53:05 The selectors themselves are immutable string obje
Jon Sonesen 2018/09/23 18:01:59 Yeah I figured since it is test code the importanc
51 { 51 {
52 return index == 0 || selector != sortedSelectors[index - 1]; 52 return index == 0 || selector != sortedSelectors[index - 1];
53 }); 53 });
54 } 54 }
55 55
56 function testResult(test, domain, expectedSelectors, specificOnly) 56 function testResult(test, domain, expectedSelectors, specificOnly)
57 { 57 {
58 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors); 58 let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors);
59
60 test.deepEqual(
61 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)),
62 normalizedExpectedSelectors
63 );
64 59
65 let {code, selectors} = 60 let {code, selectors} =
66 ElemHide.generateStyleSheetForDomain(domain, specificOnly); 61 ElemHide.generateStyleSheetForDomain(domain, specificOnly);
67 62
68 test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors); 63 test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors);
69 64
70 // Make sure each expected selector is in the actual CSS code. 65 // Make sure each expected selector is in the actual CSS code.
71 for (let selector of normalizedExpectedSelectors) 66 for (let selector of normalizedExpectedSelectors)
72 { 67 {
73 test.ok(code.includes(selector + ", ") || 68 test.ok(code.includes(selector + ", ") ||
74 code.includes(selector + " {display: none !important;}\n")); 69 code.includes(selector + " {display: none !important;}\n"));
75 } 70 }
Jon Sonesen 2018/09/20 20:10:20 I am sort of confused by the set literal `{code, s
Manish Jethani 2018/09/21 10:53:05 This is called a destructuring assignment [1] [1]
Jon Sonesen 2018/09/23 18:01:59 I do think the convention is helpful tbh so I was
76 } 71 }
77 72
78 exports.testGetSelectorsForDomain = function(test) 73 exports.testGenerateStyleSheetForDomain = function(test)
79 { 74 {
80 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); 75 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText));
81 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); 76 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText));
82 let addException = 77 let addException =
83 filterText => ElemHideExceptions.add(Filter.fromText(filterText)); 78 filterText => ElemHideExceptions.add(Filter.fromText(filterText));
84 let removeException = 79 let removeException =
85 filterText => ElemHideExceptions.remove(Filter.fromText(filterText)); 80 filterText => ElemHideExceptions.remove(Filter.fromText(filterText));
86 81
87 testResult(test, "", []); 82 testResult(test, "", []);
88 83
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 298
304 let selectors = new Array(50000).map((element, index) => ".s" + index); 299 let selectors = new Array(50000).map((element, index) => ".s" + index);
305 300
306 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length, 301 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length,
307 Math.ceil(50000 / selectorGroupSize), 302 Math.ceil(50000 / selectorGroupSize),
308 "Style sheet should be split up into rules with at most " + 303 "Style sheet should be split up into rules with at most " +
309 selectorGroupSize + " selectors each"); 304 selectorGroupSize + " selectors each");
310 305
311 test.done(); 306 test.done();
312 }; 307 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld