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

Side by Side Diff: test/elemHide.js

Issue 29886555: Issue 6957 - Add generateStyleSheetForDomain function to ElemHide module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
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:
View unified diff | Download patch
« no previous file with comments | « lib/elemHide.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-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.sort().filter((selector, index, sortedSelectors) => 50 return selectors.slice().sort().filter((selector, index, sortedSelectors) =>
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 59
60 test.deepEqual( 60 let {code, selectors} =
61 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)), 61 ElemHide.generateStyleSheetForDomain(domain, specificOnly);
62 normalizedExpectedSelectors 62
63 ); 63 test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors);
64
65 // Make sure each expected selector is in the actual CSS code.
66 for (let selector of normalizedExpectedSelectors)
67 {
68 test.ok(code.includes(selector + ", ") ||
69 code.includes(selector + " {display: none !important;}\n"));
70 }
64 } 71 }
65 72
66 exports.testGetSelectorsForDomain = function(test) 73 exports.testGenerateStyleSheetForDomain = function(test)
67 { 74 {
68 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); 75 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText));
69 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); 76 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText));
70 let addException = 77 let addException =
71 filterText => ElemHideExceptions.add(Filter.fromText(filterText)); 78 filterText => ElemHideExceptions.add(Filter.fromText(filterText));
72 let removeException = 79 let removeException =
73 filterText => ElemHideExceptions.remove(Filter.fromText(filterText)); 80 filterText => ElemHideExceptions.remove(Filter.fromText(filterText));
74 81
75 testResult(test, "", []); 82 testResult(test, "", []);
76 83
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 298
292 let selectors = new Array(50000).map((element, index) => ".s" + index); 299 let selectors = new Array(50000).map((element, index) => ".s" + index);
293 300
294 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length, 301 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length,
295 Math.ceil(50000 / selectorGroupSize), 302 Math.ceil(50000 / selectorGroupSize),
296 "Style sheet should be split up into rules with at most " + 303 "Style sheet should be split up into rules with at most " +
297 selectorGroupSize + " selectors each"); 304 selectorGroupSize + " selectors each");
298 305
299 test.done(); 306 test.done();
300 }; 307 };
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld