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 { |
| 44 let filter = Filter.fromText("###ads"); |
| 45 ElemHide.add(filter); |
| 46 |
| 47 test.equal(filter.selectorDomain, ""); |
| 48 let unconditionals = ElemHide.getUnconditionalSelectors(); |
| 49 test.equal(unconditionals.selectorCount, 1); |
| 50 test.equal(unconditionals.selectorAt(0), "#ads"); |
| 51 test.equal(unconditionals.filterKeyAt(0), "###ads"); |
| 52 filter.delete(); |
| 53 } |
| 54 |
| 55 { |
| 56 let filter2 = Filter.fromText("example.com##.foo"); |
| 57 ElemHide.add(filter2); |
| 58 test.equal(filter2.selectorDomain, "example.com"); |
| 59 filter2.delete(); |
| 60 } |
| 61 |
| 62 let unconditionals = ElemHide.getUnconditionalSelectors(); |
| 63 test.equal(unconditionals.selectorCount, 1); |
| 64 |
| 65 let selectors = ElemHide.getSelectorsForDomain("example.com", 1); |
| 66 test.equal(selectors.selectorCount, 1); |
| 67 test.equal(selectors.selectorAt(0), ".foo"); |
| 68 test.equal(selectors.filterKeyAt(0), "example.com##.foo"); |
| 69 |
| 70 selectors = ElemHide.getSelectorsForDomain("example.com", 0); |
| 71 test.equal(selectors.selectorCount, 2); |
| 72 test.equal(selectors.selectorAt(0), "#ads"); |
| 73 test.equal(selectors.filterKeyAt(0), "###ads"); |
| 74 test.equal(selectors.selectorAt(1), ".foo"); |
| 75 test.equal(selectors.filterKeyAt(1), "example.com##.foo"); |
| 76 |
| 77 let filter3 = Filter.fromText("example.com##.message"); |
| 78 ElemHide.add(filter3); |
| 79 selectors = ElemHide.getSelectorsForDomain("example.com", 0); |
| 80 test.equal(selectors.selectorCount, 3); |
| 81 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0); |
| 82 test.equal(selectors.selectorCount, 3); |
| 83 |
| 84 let filter4 = Filter.fromText("mail.example.com#@#.message"); |
| 85 ElemHide.add(filter4); |
| 86 selectors = ElemHide.getSelectorsForDomain("example.com", 0); |
| 87 test.equal(selectors.selectorCount, 3); |
| 88 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0); |
| 89 test.equal(selectors.selectorCount, 2); |
| 90 |
| 91 unconditionals = ElemHide.getUnconditionalSelectors(); |
| 92 test.equal(unconditionals.selectorCount, 1); |
| 93 |
| 94 ElemHide.remove(filter4); |
| 95 filter4.delete(); |
| 96 selectors = ElemHide.getSelectorsForDomain("example.com", 0); |
| 97 test.equal(selectors.selectorCount, 3); |
| 98 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0); |
| 99 test.equal(selectors.selectorCount, 3); |
| 100 |
| 101 ElemHide.remove(filter3); |
| 102 filter3.delete(); |
| 103 selectors = ElemHide.getSelectorsForDomain("example.com", 0); |
| 104 test.equal(selectors.selectorCount, 2); |
| 105 |
| 106 test.done(); |
| 107 }; |
| 108 |
40 exports.testDomainRestrictions = function(test) | 109 exports.testDomainRestrictions = function(test) |
41 { | 110 { |
42 function testSelectorMatches(description, filters, domain, expectedMatches) | 111 function testSelectorMatches(description, filters, domain, expectedMatches) |
43 { | 112 { |
44 for (let filter of filters) | 113 for (let text of filters) |
45 { | 114 { |
46 filter = Filter.fromText(filter); | 115 let filter = Filter.fromText(text); |
47 if (filter instanceof ElemHideEmulationFilter) | 116 if (filter instanceof ElemHideEmulationFilter) |
48 ElemHideEmulation.add(filter); | 117 ElemHideEmulation.add(filter); |
49 else | 118 else |
50 ElemHide.add(filter); | 119 ElemHide.add(filter); |
| 120 filter.delete(); |
51 } | 121 } |
52 | |
53 let matches = ElemHideEmulation.getRulesForDomain(domain) | 122 let matches = ElemHideEmulation.getRulesForDomain(domain) |
54 .map(filter => filter.text); | 123 .map(filter => filter.text); |
55 test.deepEqual(matches.sort(), expectedMatches.sort(), description); | 124 test.deepEqual(matches.sort(), expectedMatches.sort(), description); |
56 | 125 |
57 ElemHideEmulation.clear(); | 126 ElemHideEmulation.clear(); |
58 ElemHide.clear(); | 127 ElemHide.clear(); |
59 } | 128 } |
60 | 129 |
61 testSelectorMatches( | 130 testSelectorMatches( |
62 "Ignore generic filters", | 131 "Ignore generic filters", |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 208 |
140 ElemHideEmulation.clear(); | 209 ElemHideEmulation.clear(); |
141 compareRules( | 210 compareRules( |
142 "Return no filters after clearing", | 211 "Return no filters after clearing", |
143 "www.example.com", | 212 "www.example.com", |
144 [] | 213 [] |
145 ); | 214 ); |
146 | 215 |
147 test.done(); | 216 test.done(); |
148 }; | 217 }; |
OLD | NEW |