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: Add lib/elemHideExceptions.js Created Aug. 7, 2018, 2:18 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/filterListener.js ('k') | test/elemHideEmulation.js » ('j') | 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
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 =
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 removeFilter("##hello"); 192 removeFilter("##hello");
187 testResult(test, "foo.com", []); 193 testResult(test, "foo.com", []);
188 194
189 addFilter("##hello"); 195 addFilter("##hello");
190 testResult(test, "foo.com", [], true); 196 testResult(test, "foo.com", [], true);
191 testResult(test, "foo.com", ["hello"], false); 197 testResult(test, "foo.com", ["hello"], false);
192 testResult(test, "foo.com", ["hello"]); 198 testResult(test, "foo.com", ["hello"]);
193 testResult(test, "bar.com", [], true); 199 testResult(test, "bar.com", [], true);
194 testResult(test, "bar.com", ["hello"], false); 200 testResult(test, "bar.com", ["hello"], false);
195 testResult(test, "bar.com", ["hello"]); 201 testResult(test, "bar.com", ["hello"]);
196 addFilter("foo.com#@#hello"); 202 addException("foo.com#@#hello");
197 testResult(test, "foo.com", [], true); 203 testResult(test, "foo.com", [], true);
198 testResult(test, "foo.com", [], false); 204 testResult(test, "foo.com", [], false);
199 testResult(test, "foo.com", []); 205 testResult(test, "foo.com", []);
200 testResult(test, "bar.com", [], true); 206 testResult(test, "bar.com", [], true);
201 testResult(test, "bar.com", ["hello"], false); 207 testResult(test, "bar.com", ["hello"], false);
202 testResult(test, "bar.com", ["hello"]); 208 testResult(test, "bar.com", ["hello"]);
203 removeFilter("foo.com#@#hello"); 209 removeException("foo.com#@#hello");
204 testResult(test, "foo.com", [], true); 210 testResult(test, "foo.com", [], true);
205 // Note: We don't take care to track conditional selectors which became 211 // Note: We don't take care to track conditional selectors which became
206 // unconditional when a filter was removed. This was too expensive. 212 // unconditional when a filter was removed. This was too expensive.
207 testResult(test, "foo.com", ["hello"], false); 213 testResult(test, "foo.com", ["hello"], false);
208 testResult(test, "foo.com", ["hello"]); 214 testResult(test, "foo.com", ["hello"]);
209 testResult(test, "bar.com", [], true); 215 testResult(test, "bar.com", [], true);
210 testResult(test, "bar.com", ["hello"], false); 216 testResult(test, "bar.com", ["hello"], false);
211 testResult(test, "bar.com", ["hello"]); 217 testResult(test, "bar.com", ["hello"]);
212 removeFilter("##hello"); 218 removeFilter("##hello");
213 testResult(test, "foo.com", []); 219 testResult(test, "foo.com", []);
(...skipping 14 matching lines...) Expand all
228 testResult(test, "foo.com", ["hello"]); 234 testResult(test, "foo.com", ["hello"]);
229 removeFilter("foo.com##hello"); 235 removeFilter("foo.com##hello");
230 testResult(test, "foo.com", []); 236 testResult(test, "foo.com", []);
231 237
232 test.done(); 238 test.done();
233 }; 239 };
234 240
235 exports.testZeroFilterKey = function(test) 241 exports.testZeroFilterKey = function(test)
236 { 242 {
237 ElemHide.add(Filter.fromText("##test")); 243 ElemHide.add(Filter.fromText("##test"));
238 ElemHide.add(Filter.fromText("foo.com#@#test")); 244 ElemHideExceptions.add(Filter.fromText("foo.com#@#test"));
239 testResult(test, "foo.com", []); 245 testResult(test, "foo.com", []);
240 testResult(test, "bar.com", ["test"]); 246 testResult(test, "bar.com", ["test"]);
241 test.done(); 247 test.done();
242 }; 248 };
OLDNEW
« no previous file with comments | « lib/filterListener.js ('k') | test/elemHideEmulation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld