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

Delta Between Two Patch Sets: test/elemHide.js

Issue 29342884: Issue 4055 - Test ElemHide.getSelectorsFordomain (Closed)
Left Patch Set: Addressed feedback Created May 23, 2016, 1:46 p.m.
Right Patch Set: Simplify filter function and move comment Created May 23, 2016, 6: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 | « package.json ('k') | test/stub-modules/io.js » ('j') | 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 18 matching lines...) Expand all
29 29
30 exports.testGetSelectorsForDomain = function(test) 30 exports.testGetSelectorsForDomain = function(test)
31 { 31 {
32 function fromText(f) 32 function fromText(f)
33 { 33 {
34 return (filterText) => f(Filter.fromText(filterText)); 34 return (filterText) => f(Filter.fromText(filterText));
35 } 35 }
36 let addFilter = fromText(ElemHide.add); 36 let addFilter = fromText(ElemHide.add);
37 let removeFilter = fromText(ElemHide.remove); 37 let removeFilter = fromText(ElemHide.remove);
38 38
39 function selectorsEqual(domain, selectors, specificOnly) 39 function normalizeSelectors(selectors)
40 { 40 {
41 test.deepEqual(ElemHide.getSelectorsForDomain(domain, specificOnly).sort(), 41 // getSelectorsForDomain is currently allowed to return duplicate selectors
42 selectors.sort()); 42 // for performance reasons, so we need to remove duplicates here.
43 return selectors.sort().filter((selector, index, selectors) =>
44 {
45 return index == 0 || selector != selectors[index - 1];
46 });
47 }
48 function selectorsEqual(domain, expectedSelectors, specificOnly)
49 {
50 test.deepEqual(
51 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)),
52 normalizeSelectors(expectedSelectors)
53 );
43 } 54 }
44 55
45 selectorsEqual("", []); 56 selectorsEqual("", []);
46 57
47 addFilter("~foo.example.com,example.com##foo"); 58 addFilter("~foo.example.com,example.com##foo");
48 selectorsEqual("barfoo.example.com", ["foo"]); 59 selectorsEqual("barfoo.example.com", ["foo"]);
49 selectorsEqual("bar.foo.example.com", []); 60 selectorsEqual("bar.foo.example.com", []);
50 selectorsEqual("foo.example.com", []); 61 selectorsEqual("foo.example.com", []);
51 selectorsEqual("example.com", ["foo"]); 62 selectorsEqual("example.com", ["foo"]);
52 selectorsEqual("com", []); 63 selectorsEqual("com", []);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 addFilter("example.com##dupe"); 139 addFilter("example.com##dupe");
129 selectorsEqual("example.com", ["dupe"]); 140 selectorsEqual("example.com", ["dupe"]);
130 removeFilter("example.com##dupe"); 141 removeFilter("example.com##dupe");
131 selectorsEqual("example.com", []); 142 selectorsEqual("example.com", []);
132 removeFilter("example.com##dupe"); 143 removeFilter("example.com##dupe");
133 144
134 addFilter("~foo.example.com,example.com##foo"); 145 addFilter("~foo.example.com,example.com##foo");
135 146
136 addFilter("##foo"); 147 addFilter("##foo");
137 selectorsEqual("foo.example.com", ["foo"]); 148 selectorsEqual("foo.example.com", ["foo"]);
138 selectorsEqual("example.com", ["foo", "foo"]); 149 selectorsEqual("example.com", ["foo"]);
Wladimir Palant 2016/05/23 15:06:47 Here you are cementing what is considerably a bug
kzar 2016/05/23 15:49:19 Done.
139 selectorsEqual("com", ["foo"]); 150 selectorsEqual("com", ["foo"]);
140 selectorsEqual("", ["foo"]); 151 selectorsEqual("", ["foo"]);
141 removeFilter("##foo"); 152 removeFilter("##foo");
142 153
143 addFilter("example.org##foo"); 154 addFilter("example.org##foo");
144 selectorsEqual("foo.example.com", []); 155 selectorsEqual("foo.example.com", []);
145 selectorsEqual("example.com", ["foo"]); 156 selectorsEqual("example.com", ["foo"]);
146 selectorsEqual("com", []); 157 selectorsEqual("com", []);
147 selectorsEqual("", []); 158 selectorsEqual("", []);
148 removeFilter("example.org##foo"); 159 removeFilter("example.org##foo");
149 160
150 addFilter("~example.com##foo"); 161 addFilter("~example.com##foo");
151 selectorsEqual("foo.example.com", []); 162 selectorsEqual("foo.example.com", []);
152 selectorsEqual("example.com", ["foo"]); 163 selectorsEqual("example.com", ["foo"]);
153 selectorsEqual("com", ["foo"]); 164 selectorsEqual("com", ["foo"]);
154 selectorsEqual("", ["foo"]); 165 selectorsEqual("", ["foo"]);
155 removeFilter("example.org##foo"); 166 removeFilter("example.org##foo");
156 167
157 test.done(); 168 test.done();
158 }; 169 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld