LEFT | RIGHT |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
1 "use strict"; | 18 "use strict"; |
2 | 19 |
3 let { | 20 let {createSandbox} = require("./_common"); |
4 Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, | 21 |
5 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, | 22 let Filter = null; |
6 ElemHideException, CSSPropertyFilter | 23 let InvalidFilter = null; |
7 } = require("../lib/filterClasses"); | 24 let CommentFilter = null; |
| 25 let ActiveFilter = null; |
| 26 let RegExpFilter = null; |
| 27 let BlockingFilter = null; |
| 28 let WhitelistFilter = null; |
| 29 let ElemHideBase = null; |
| 30 let ElemHideFilter = null; |
| 31 let ElemHideException = null; |
| 32 let CSSPropertyFilter = null; |
| 33 |
| 34 exports.setUp = function(callback) |
| 35 { |
| 36 let sandboxedRequire = createSandbox(); |
| 37 ( |
| 38 { |
| 39 Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, |
| 40 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, |
| 41 ElemHideException, CSSPropertyFilter |
| 42 } = sandboxedRequire("../lib/filterClassesNew") |
| 43 ); |
| 44 callback(); |
| 45 }; |
8 | 46 |
9 exports.testFromText = function(test) | 47 exports.testFromText = function(test) |
10 { | 48 { |
11 let tests = [ | 49 let tests = [ |
12 ["!asdf", CommentFilter, "comment"], | 50 ["!asdf", CommentFilter, "comment"], |
13 ["asdf", BlockingFilter, "blocking"], | 51 ["asdf", BlockingFilter, "blocking"], |
14 ["asdf$image,~collapse", BlockingFilter, "blocking"], | 52 ["asdf$image,~collapse", BlockingFilter, "blocking"], |
15 ["/asdf/", BlockingFilter, "blocking"], | 53 ["/asdf/", BlockingFilter, "blocking"], |
16 ["/asdf??+/", InvalidFilter, "invalid"], | 54 ["/asdf??+/", InvalidFilter, "invalid"], |
17 ["@@asdf", WhitelistFilter, "whitelist"], | 55 ["@@asdf", WhitelistFilter, "whitelist"], |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 test.ok(!(filter instanceof eval(cls)), | 137 test.ok(!(filter instanceof eval(cls)), |
100 "Filter " + filter.text + " isn't an instance of " + cls); | 138 "Filter " + filter.text + " isn't an instance of " + cls); |
101 } | 139 } |
102 } | 140 } |
103 filter.delete(); | 141 filter.delete(); |
104 } | 142 } |
105 | 143 |
106 test.done(); | 144 test.done(); |
107 }; | 145 }; |
108 | 146 |
109 exports.testGetKnownFilter = function(test) | 147 exports.testGC = function(test) |
110 { | 148 { |
111 let filter1 = Filter.getKnownFilter("someknownfilter"); | 149 let filter1 = Filter.fromText("someknownfilter"); |
112 test.ok(!filter1, "Unknown filter returns null"); | 150 test.equal(filter1.hitCount, 0, "Initial hit count"); |
| 151 |
| 152 filter1.hitCount = 432; |
113 | 153 |
114 let filter2 = Filter.fromText("someknownfilter"); | 154 let filter2 = Filter.fromText("someknownfilter"); |
115 filter1 = Filter.getKnownFilter("someknownfilter"); | 155 test.equal(filter2.hitCount, 432, "Known filter returned"); |
116 test.ok(filter1, "Known filter returned"); | 156 |
117 | 157 filter2.hitCount = 234; |
118 filter2.hitCount = 432; | 158 test.equal(filter1.hitCount, 234, "Changing second wrapper modifies original a
s well"); |
119 test.equal(filter1.hitCount, 432, "Changes on previous instance are reflected
on new instance"); | |
120 | 159 |
121 filter1.delete(); | 160 filter1.delete(); |
122 filter2.delete(); | 161 filter2.delete(); |
| 162 |
| 163 let filter3 = Filter.fromText("someknownfilter"); |
| 164 test.equal(filter3.hitCount, 0, "Filter data has been reset once previous inst
ances have been released"); |
| 165 filter3.delete(); |
123 | 166 |
124 test.done(); | 167 test.done(); |
125 }; | 168 }; |
126 | 169 |
127 exports.testNormalize = function(test) | 170 exports.testNormalize = function(test) |
128 { | 171 { |
129 let tests = [ | 172 let tests = [ |
130 [" ! comment something ", "! comment something"], | 173 [" ! comment something ", "! comment something"], |
131 [" ! \n comment something ", "! comment something"], | 174 [" ! \n comment something ", "! comment something"], |
132 [" foo bar ", "foobar"], | 175 [" foo bar ", "foobar"], |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 { | 384 { |
342 let filter = Filter.fromText(text); | 385 let filter = Filter.fromText(text); |
343 test.equal(filter.regexpString, regexp, "Regular expression of " + text); | 386 test.equal(filter.regexpString, regexp, "Regular expression of " + text); |
344 test.equal(filter.selectorPrefix, prefix, "Selector prefix of " + text); | 387 test.equal(filter.selectorPrefix, prefix, "Selector prefix of " + text); |
345 test.equal(filter.selectorSuffix, suffix, "Selector suffix of " + text); | 388 test.equal(filter.selectorSuffix, suffix, "Selector suffix of " + text); |
346 filter.delete(); | 389 filter.delete(); |
347 } | 390 } |
348 | 391 |
349 test.done(); | 392 test.done(); |
350 }; | 393 }; |
LEFT | RIGHT |