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

Side by Side Diff: test/elemHide.js

Issue 29783618: Issue 6665 - Split out element hiding exceptions into their own module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Emit own elemhideupdate event Created May 17, 2018, 5:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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
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 const {createSandbox} = require("./_common"); 20 const {createSandbox} = require("./_common");
21 21
22 let ElemHide = null; 22 let ElemHide = null;
23 let ElemHideExceptions = null;
23 let Filter = null; 24 let Filter = null;
24 25
25 exports.setUp = function(callback) 26 exports.setUp = function(callback)
26 { 27 {
27 let sandboxedRequire = createSandbox(); 28 let sandboxedRequire = createSandbox();
28 ( 29 (
29 {ElemHide} = sandboxedRequire("../lib/elemHide"), 30 {ElemHide} = sandboxedRequire("../lib/elemHide"),
31 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"),
30 {Filter} = sandboxedRequire("../lib/filterClasses") 32 {Filter} = sandboxedRequire("../lib/filterClasses")
31 ); 33 );
32 34
33 callback(); 35 callback();
34 }; 36 };
35 37
36 function normalizeSelectors(selectors) 38 function normalizeSelectors(selectors)
37 { 39 {
38 // getSelectorsForDomain is currently allowed to return duplicate selectors 40 // getSelectorsForDomain is currently allowed to return duplicate selectors
39 // for performance reasons, so we need to remove duplicates here. 41 // for performance reasons, so we need to remove duplicates here.
(...skipping 10 matching lines...) Expand all
50 test.deepEqual( 52 test.deepEqual(
51 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)), 53 normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)),
52 normalizedExpectedSelectors 54 normalizedExpectedSelectors
53 ); 55 );
54 } 56 }
55 57
56 exports.testGetSelectorsForDomain = function(test) 58 exports.testGetSelectorsForDomain = function(test)
57 { 59 {
58 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); 60 let addFilter = filterText => ElemHide.add(Filter.fromText(filterText));
59 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); 61 let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText));
62 let addException =
Manish Jethani 2018/05/17 05:42:48 We could just add type checks to addFilter and rem
63 filterText => ElemHideExceptions.add(Filter.fromText(filterText));
64 let removeException =
65 filterText => ElemHideExceptions.remove(Filter.fromText(filterText));
60 66
61 testResult(test, "", []); 67 testResult(test, "", []);
62 68
63 addFilter("~foo.example.com,example.com##foo"); 69 addFilter("~foo.example.com,example.com##foo");
64 testResult(test, "barfoo.example.com", ["foo"]); 70 testResult(test, "barfoo.example.com", ["foo"]);
65 testResult(test, "bar.foo.example.com", []); 71 testResult(test, "bar.foo.example.com", []);
66 testResult(test, "foo.example.com", []); 72 testResult(test, "foo.example.com", []);
67 testResult(test, "example.com", ["foo"]); 73 testResult(test, "example.com", ["foo"]);
68 testResult(test, "com", []); 74 testResult(test, "com", []);
69 testResult(test, "", []); 75 testResult(test, "", []);
70 76
71 addFilter("foo.example.com##turnip"); 77 addFilter("foo.example.com##turnip");
72 testResult(test, "foo.example.com", ["turnip"]); 78 testResult(test, "foo.example.com", ["turnip"]);
73 testResult(test, "example.com", ["foo"]); 79 testResult(test, "example.com", ["foo"]);
74 testResult(test, "com", []); 80 testResult(test, "com", []);
75 testResult(test, "", []); 81 testResult(test, "", []);
76 82
77 addFilter("example.com#@#foo"); 83 addException("example.com#@#foo");
78 testResult(test, "foo.example.com", ["turnip"]); 84 testResult(test, "foo.example.com", ["turnip"]);
79 testResult(test, "example.com", []); 85 testResult(test, "example.com", []);
80 testResult(test, "com", []); 86 testResult(test, "com", []);
81 testResult(test, "", []); 87 testResult(test, "", []);
82 88
83 addFilter("com##bar"); 89 addFilter("com##bar");
84 testResult(test, "foo.example.com", ["turnip", "bar"]); 90 testResult(test, "foo.example.com", ["turnip", "bar"]);
85 testResult(test, "example.com", ["bar"]); 91 testResult(test, "example.com", ["bar"]);
86 testResult(test, "com", ["bar"]); 92 testResult(test, "com", ["bar"]);
87 testResult(test, "", []); 93 testResult(test, "", []);
88 94
89 addFilter("example.com#@#bar"); 95 addException("example.com#@#bar");
90 testResult(test, "foo.example.com", ["turnip"]); 96 testResult(test, "foo.example.com", ["turnip"]);
91 testResult(test, "example.com", []); 97 testResult(test, "example.com", []);
92 testResult(test, "com", ["bar"]); 98 testResult(test, "com", ["bar"]);
93 testResult(test, "", []); 99 testResult(test, "", []);
94 100
95 removeFilter("example.com#@#foo"); 101 removeException("example.com#@#foo");
96 testResult(test, "foo.example.com", ["turnip"]); 102 testResult(test, "foo.example.com", ["turnip"]);
97 testResult(test, "example.com", ["foo"]); 103 testResult(test, "example.com", ["foo"]);
98 testResult(test, "com", ["bar"]); 104 testResult(test, "com", ["bar"]);
99 testResult(test, "", []); 105 testResult(test, "", []);
100 106
101 removeFilter("example.com#@#bar"); 107 removeException("example.com#@#bar");
102 testResult(test, "foo.example.com", ["turnip", "bar"]); 108 testResult(test, "foo.example.com", ["turnip", "bar"]);
103 testResult(test, "example.com", ["foo", "bar"]); 109 testResult(test, "example.com", ["foo", "bar"]);
104 testResult(test, "com", ["bar"]); 110 testResult(test, "com", ["bar"]);
105 testResult(test, "", []); 111 testResult(test, "", []);
106 112
107 addFilter("##generic"); 113 addFilter("##generic");
108 testResult(test, "foo.example.com", ["turnip", "bar", "generic"]); 114 testResult(test, "foo.example.com", ["turnip", "bar", "generic"]);
109 testResult(test, "example.com", ["foo", "bar", "generic"]); 115 testResult(test, "example.com", ["foo", "bar", "generic"]);
110 testResult(test, "com", ["bar", "generic"]); 116 testResult(test, "com", ["bar", "generic"]);
111 testResult(test, "", ["generic"]); 117 testResult(test, "", ["generic"]);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 removeFilter("##hello"); 190 removeFilter("##hello");
185 testResult(test, "foo.com", []); 191 testResult(test, "foo.com", []);
186 192
187 addFilter("##hello"); 193 addFilter("##hello");
188 testResult(test, "foo.com", [], true); 194 testResult(test, "foo.com", [], true);
189 testResult(test, "foo.com", ["hello"], false); 195 testResult(test, "foo.com", ["hello"], false);
190 testResult(test, "foo.com", ["hello"]); 196 testResult(test, "foo.com", ["hello"]);
191 testResult(test, "bar.com", [], true); 197 testResult(test, "bar.com", [], true);
192 testResult(test, "bar.com", ["hello"], false); 198 testResult(test, "bar.com", ["hello"], false);
193 testResult(test, "bar.com", ["hello"]); 199 testResult(test, "bar.com", ["hello"]);
194 addFilter("foo.com#@#hello"); 200 addException("foo.com#@#hello");
195 testResult(test, "foo.com", [], true); 201 testResult(test, "foo.com", [], true);
196 testResult(test, "foo.com", [], false); 202 testResult(test, "foo.com", [], false);
197 testResult(test, "foo.com", []); 203 testResult(test, "foo.com", []);
198 testResult(test, "bar.com", [], true); 204 testResult(test, "bar.com", [], true);
199 testResult(test, "bar.com", ["hello"], false); 205 testResult(test, "bar.com", ["hello"], false);
200 testResult(test, "bar.com", ["hello"]); 206 testResult(test, "bar.com", ["hello"]);
201 removeFilter("foo.com#@#hello"); 207 removeException("foo.com#@#hello");
202 testResult(test, "foo.com", [], true); 208 testResult(test, "foo.com", [], true);
203 // Note: We don't take care to track conditional selectors which became 209 // Note: We don't take care to track conditional selectors which became
204 // unconditional when a filter was removed. This was too expensive. 210 // unconditional when a filter was removed. This was too expensive.
205 testResult(test, "foo.com", ["hello"], false); 211 testResult(test, "foo.com", ["hello"], false);
206 testResult(test, "foo.com", ["hello"]); 212 testResult(test, "foo.com", ["hello"]);
207 testResult(test, "bar.com", [], true); 213 testResult(test, "bar.com", [], true);
208 testResult(test, "bar.com", ["hello"], false); 214 testResult(test, "bar.com", ["hello"], false);
209 testResult(test, "bar.com", ["hello"]); 215 testResult(test, "bar.com", ["hello"]);
210 removeFilter("##hello"); 216 removeFilter("##hello");
211 testResult(test, "foo.com", []); 217 testResult(test, "foo.com", []);
(...skipping 14 matching lines...) Expand all
226 testResult(test, "foo.com", ["hello"]); 232 testResult(test, "foo.com", ["hello"]);
227 removeFilter("foo.com##hello"); 233 removeFilter("foo.com##hello");
228 testResult(test, "foo.com", []); 234 testResult(test, "foo.com", []);
229 235
230 test.done(); 236 test.done();
231 }; 237 };
232 238
233 exports.testZeroFilterKey = function(test) 239 exports.testZeroFilterKey = function(test)
234 { 240 {
235 ElemHide.add(Filter.fromText("##test")); 241 ElemHide.add(Filter.fromText("##test"));
236 ElemHide.add(Filter.fromText("foo.com#@#test")); 242 ElemHideExceptions.add(Filter.fromText("foo.com#@#test"));
237 testResult(test, "foo.com", []); 243 testResult(test, "foo.com", []);
238 testResult(test, "bar.com", ["test"]); 244 testResult(test, "bar.com", ["test"]);
239 test.done(); 245 test.done();
240 }; 246 };
OLDNEW

Powered by Google App Engine
This is Rietveld