OLD | NEW |
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 19 matching lines...) Expand all Loading... |
30 ( | 30 ( |
31 {Filter, | 31 {Filter, |
32 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"), | 32 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"), |
33 {ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"), | 33 {ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"), |
34 {ElemHide} = sandboxedRequire("../lib/elemHide") | 34 {ElemHide} = sandboxedRequire("../lib/elemHide") |
35 ); | 35 ); |
36 | 36 |
37 callback(); | 37 callback(); |
38 }; | 38 }; |
39 | 39 |
| 40 |
| 41 exports.testElemHideAPI = function(test) |
| 42 { |
| 43 let filter = Filter.fromText("###ads"); |
| 44 ElemHide.add(filter); |
| 45 |
| 46 test.equal(filter.selectorDomain, ""); |
| 47 let unconditionals = ElemHide.getUnconditionalSelectors(); |
| 48 test.equal(unconditionals.selectorCount, 1); |
| 49 test.equal(unconditionals.selectorAt(0), "#ads"); |
| 50 test.equal(unconditionals.filterKeyAt(0), "###ads"); |
| 51 |
| 52 let filter2 = Filter.fromText("example.com##.foo"); |
| 53 ElemHide.add(filter2); |
| 54 test.equal(filter2.selectorDomain, "example.com"); |
| 55 |
| 56 unconditionals = ElemHide.getUnconditionalSelectors(); |
| 57 test.equal(unconditionals.selectorCount, 1); |
| 58 |
| 59 let selectors = ElemHide.getSelectorsForDomain("example.com", 1); |
| 60 test.equal(selectors.selectorCount, 1); |
| 61 test.equal(selectors.selectorAt(0), ".foo"); |
| 62 test.equal(selectors.filterKeyAt(0), "example.com##.foo"); |
| 63 |
| 64 selectors = ElemHide.getSelectorsForDomain("example.com", 0); |
| 65 test.equal(selectors.selectorCount, 2); |
| 66 |
| 67 test.equal(selectors.selectorAt(0), "#ads"); |
| 68 test.equal(selectors.filterKeyAt(0), "###ads"); |
| 69 |
| 70 test.equal(selectors.selectorAt(1), ".foo"); |
| 71 test.equal(selectors.filterKeyAt(1), "example.com##.foo"); |
| 72 |
| 73 test.done(); |
| 74 }; |
| 75 |
40 exports.testDomainRestrictions = function(test) | 76 exports.testDomainRestrictions = function(test) |
41 { | 77 { |
42 function testSelectorMatches(description, filters, domain, expectedMatches) | 78 function testSelectorMatches(description, filters, domain, expectedMatches) |
43 { | 79 { |
44 for (let filter of filters) | 80 for (let text of filters) |
45 { | 81 { |
46 filter = Filter.fromText(filter); | 82 let filter = Filter.fromText(text); |
47 if (filter instanceof ElemHideEmulationFilter) | 83 if (filter instanceof ElemHideEmulationFilter) |
48 ElemHideEmulation.add(filter); | 84 ElemHideEmulation.add(filter); |
49 else | 85 else |
50 ElemHide.add(filter); | 86 ElemHide.add(filter); |
51 } | 87 } |
52 | |
53 let matches = ElemHideEmulation.getRulesForDomain(domain) | 88 let matches = ElemHideEmulation.getRulesForDomain(domain) |
54 .map(filter => filter.text); | 89 .map(filter => filter.text); |
55 test.deepEqual(matches.sort(), expectedMatches.sort(), description); | 90 test.deepEqual(matches.sort(), expectedMatches.sort(), description); |
56 | 91 |
57 ElemHideEmulation.clear(); | 92 ElemHideEmulation.clear(); |
58 ElemHide.clear(); | 93 ElemHide.clear(); |
59 } | 94 } |
60 | 95 |
61 testSelectorMatches( | 96 testSelectorMatches( |
62 "Ignore generic filters", | 97 "Ignore generic filters", |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 174 |
140 ElemHideEmulation.clear(); | 175 ElemHideEmulation.clear(); |
141 compareRules( | 176 compareRules( |
142 "Return no filters after clearing", | 177 "Return no filters after clearing", |
143 "www.example.com", | 178 "www.example.com", |
144 [] | 179 [] |
145 ); | 180 ); |
146 | 181 |
147 test.done(); | 182 test.done(); |
148 }; | 183 }; |
OLD | NEW |