| LEFT | RIGHT |
| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 test.equal(selectors.selectorAt(1), ".foo"); | 80 test.equal(selectors.selectorAt(1), ".foo"); |
| 81 test.equal(selectors.filterKeyAt(1), "example.com##.foo"); | 81 test.equal(selectors.filterKeyAt(1), "example.com##.foo"); |
| 82 })(elemHide.getSelectorsForDomain("example.com", 0)); | 82 })(elemHide.getSelectorsForDomain("example.com", 0)); |
| 83 | 83 |
| 84 withNAD(0, filter3 => | 84 withNAD(0, filter3 => |
| 85 { | 85 { |
| 86 elemHide.add(filter3); | 86 elemHide.add(filter3); |
| 87 | 87 |
| 88 withNAD( | 88 withNAD( |
| 89 0, selectors => | 89 0, selectors => |
| 90 test.equal(selectors.selectorCount, 3))( | 90 { |
| 91 test.equal(selectors.selectorCount, 3); |
| 92 test.equal(selectors.selectorAt(0), "#ads"); |
| 93 test.equal(selectors.selectorAt(1), ".message"); |
| 94 test.equal(selectors.selectorAt(2), ".foo"); |
| 95 })( |
| 91 elemHide.getSelectorsForDomain("example.com", 0)); | 96 elemHide.getSelectorsForDomain("example.com", 0)); |
| 92 | 97 |
| 93 withNAD( | 98 withNAD( |
| 94 0, selectors => | 99 0, selectors => |
| 95 test.equal(selectors.selectorCount, 3))( | 100 { |
| 101 test.equal(selectors.selectorCount, 3); |
| 102 test.equal(selectors.selectorAt(0), "#ads"); |
| 103 test.equal(selectors.selectorAt(1), ".message"); |
| 104 test.equal(selectors.selectorAt(2), ".foo"); |
| 105 })( |
| 96 elemHide.getSelectorsForDomain("mail.example.com", 0)); | 106 elemHide.getSelectorsForDomain("mail.example.com", 0)); |
| 97 | 107 |
| 98 withNAD(0, filter4 => | 108 withNAD(0, filter4 => |
| 99 { | 109 { |
| 100 elemHide.add(filter4); | 110 elemHide.add(filter4); |
| 101 withNAD( | 111 withNAD( |
| 102 0, selectors => | 112 0, selectors => |
| 103 test.equal(selectors.selectorCount, 3))( | 113 { |
| 114 test.equal(selectors.selectorCount, 3); |
| 115 test.equal(selectors.selectorAt(0), "#ads"); |
| 116 test.equal(selectors.selectorAt(1), ".message"); |
| 117 test.equal(selectors.selectorAt(2), ".foo"); |
| 118 })( |
| 104 elemHide.getSelectorsForDomain("example.com", 0)); | 119 elemHide.getSelectorsForDomain("example.com", 0)); |
| 105 | 120 |
| 106 withNAD( | 121 withNAD( |
| 107 0, selectors => | 122 0, selectors => |
| 108 test.equal(selectors.selectorCount, 2))( | 123 { |
| 124 test.equal(selectors.selectorCount, 2); |
| 125 test.equal(selectors.selectorAt(0), "#ads"); |
| 126 test.equal(selectors.selectorAt(1), ".foo"); |
| 127 })( |
| 109 elemHide.getSelectorsForDomain("mail.example.com", 0)); | 128 elemHide.getSelectorsForDomain("mail.example.com", 0)); |
| 110 | 129 |
| 111 withNAD( | 130 withNAD( |
| 112 0, | 131 0, |
| 113 unconditionals => | 132 unconditionals => |
| 114 test.equal(unconditionals.selectorCount, 1))(elemHide.getUncondition
alSelectors()); | 133 { |
| 134 test.equal(unconditionals.selectorCount, 1); |
| 135 test.equal(unconditionals.selectorAt(0), "#ads"); |
| 136 })(elemHide.getUnconditionalSelectors()); |
| 115 | 137 |
| 116 elemHide.remove(filter4); | 138 elemHide.remove(filter4); |
| 117 })(Filter.fromText("mail.example.com#@#.message")); | 139 })(Filter.fromText("mail.example.com#@#.message")); |
| 118 | 140 |
| 119 withNAD( | 141 withNAD( |
| 120 0, selectors => | 142 0, selectors => |
| 121 test.equal(selectors.selectorCount, 3))( | 143 { |
| 122 elemHide.getSelectorsForDomain("example.com", 0)); | 144 test.equal(selectors.selectorCount, 3); |
| 145 test.equal(selectors.selectorAt(0), "#ads"); |
| 146 test.equal(selectors.selectorAt(1), ".message"); |
| 147 test.equal(selectors.selectorAt(2), ".foo"); |
| 148 })(elemHide.getSelectorsForDomain("example.com", 0)); |
| 123 | 149 |
| 124 withNAD( | 150 withNAD( |
| 125 0, selectors => | 151 0, selectors => |
| 126 test.equal(selectors.selectorCount, 3))( | 152 { |
| 127 elemHide.getSelectorsForDomain("mail.example.com", 0)); | 153 test.equal(selectors.selectorCount, 3); |
| 154 test.equal(selectors.selectorAt(0), "#ads"); |
| 155 test.equal(selectors.selectorAt(1), ".message"); |
| 156 test.equal(selectors.selectorAt(2), ".foo"); |
| 157 })(elemHide.getSelectorsForDomain("mail.example.com", 0)); |
| 128 | 158 |
| 129 elemHide.remove(filter3); | 159 elemHide.remove(filter3); |
| 130 })(Filter.fromText("example.com##.message")); | 160 })(Filter.fromText("example.com##.message")); |
| 131 | 161 |
| 132 withNAD( | 162 withNAD( |
| 133 0, selectors => | 163 0, selectors => |
| 134 test.equal(selectors.selectorCount, 2))( | 164 test.equal(selectors.selectorCount, 2))( |
| 135 elemHide.getSelectorsForDomain("example.com", 0)); | 165 elemHide.getSelectorsForDomain("example.com", 0)); |
| 136 })(ElemHide.create()); | 166 })(ElemHide.create()); |
| 137 | 167 |
| 138 test.done(); | 168 test.done(); |
| 139 }; | 169 }; |
| 140 | 170 |
| 141 exports.testSyntaxConversion = function(test) | 171 exports.testSyntaxConversion = function(test) |
| 142 { | 172 { |
| 143 function checkConvertedFilter(old, converted) | 173 function checkConvertedFilter(old, converted) |
| 144 { | 174 { |
| 145 withNAD( | 175 withNAD( |
| 146 0, filter => test.equal(filter.text, converted))(Filter.fromText(old)); | 176 0, filter => test.equal(filter.text, converted))(Filter.fromText(old)); |
| 147 } | 177 } |
| 148 | 178 |
| 149 checkConvertedFilter("example.com#?#foo[-abp-properties='something']bar", "exa
mple.com#?#foo:-abp-properties(something)bar"); | 179 checkConvertedFilter("example.com##foo[-abp-properties='something']bar", "exam
ple.com#?#foo:-abp-properties(something)bar"); |
| 150 checkConvertedFilter("example.com#@#foo[-abp-properties='something']bar", "exa
mple.com#@#foo:-abp-properties(something)bar"); | 180 checkConvertedFilter("example.com#@#foo[-abp-properties='something']bar", "exa
mple.com#@#foo:-abp-properties(something)bar"); |
| 151 checkConvertedFilter("example.com#?#[-abp-properties=\"something\"]", "example
.com#?#:-abp-properties(something)"); | 181 checkConvertedFilter("example.com##[-abp-properties=\"something\"]", "example.
com#?#:-abp-properties(something)"); |
| 152 checkConvertedFilter("example.com#?#[-abp-properties=(something)]", "example.c
om#?#:-abp-properties((something))"); | 182 checkConvertedFilter("example.com##[-abp-properties='(something)']", "example.
com#?#:-abp-properties((something))"); |
| 153 | 183 |
| 154 test.done(); | 184 test.done(); |
| 155 }; | 185 }; |
| 156 | 186 |
| 157 exports.testDomainRestrictions = function(test) | 187 exports.testDomainRestrictions = function(test) |
| 158 { | 188 { |
| 159 function testSelectorMatches(description, filters, domain, expectedMatches) | 189 function testSelectorMatches(description, filters, domain, expectedMatches) |
| 160 { | 190 { |
| 161 withNAD([0, 1], (elemHide, elemHideEmulation) => | 191 withNAD([0, 1], (elemHide, elemHideEmulation) => |
| 162 { | 192 { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 "www.example.com", | 306 "www.example.com", |
| 277 [] | 307 [] |
| 278 ); | 308 ); |
| 279 })(Filter.fromText("example.com##filter1"), | 309 })(Filter.fromText("example.com##filter1"), |
| 280 Filter.fromText("www.example.com##filter2"), | 310 Filter.fromText("www.example.com##filter2"), |
| 281 Filter.fromText("other.example.com##filter3")); | 311 Filter.fromText("other.example.com##filter3")); |
| 282 })(ElemHide.create(), ElemHideEmulation.create()); | 312 })(ElemHide.create(), ElemHideEmulation.create()); |
| 283 | 313 |
| 284 test.done(); | 314 test.done(); |
| 285 }; | 315 }; |
| LEFT | RIGHT |