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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 package org.adblockplus.libadblockplus.tests; | 18 package org.adblockplus.libadblockplus.tests; |
19 | 19 |
20 import org.adblockplus.libadblockplus.Filter; | 20 import org.adblockplus.libadblockplus.Filter; |
21 import org.adblockplus.libadblockplus.FilterEngine; | 21 import org.adblockplus.libadblockplus.FilterEngine; |
| 22 import org.adblockplus.libadblockplus.LazyWebRequest; |
22 import org.adblockplus.libadblockplus.MockFilterChangeCallback; | 23 import org.adblockplus.libadblockplus.MockFilterChangeCallback; |
23 import org.adblockplus.libadblockplus.Subscription; | 24 import org.adblockplus.libadblockplus.Subscription; |
24 | 25 |
25 import org.junit.Test; | 26 import org.junit.Test; |
26 | 27 |
27 public class FilterEngineTest extends FilterEngineGenericTest | 28 public class FilterEngineTest extends FilterEngineGenericTest |
28 { | 29 { |
29 @Test | 30 @Test |
30 public void testFilterCreation() | 31 public void testFilterCreation() |
| 32 { |
| 33 Filter filter1 = filterEngine.getFilter("foo"); |
| 34 assertEquals(Filter.Type.BLOCKING, filter1.getType()); |
| 35 Filter filter2 = filterEngine.getFilter("@@foo"); |
| 36 assertEquals(Filter.Type.EXCEPTION, filter2.getType()); |
| 37 Filter filter3 = filterEngine.getFilter("example.com##foo"); |
| 38 assertEquals(Filter.Type.ELEMHIDE, filter3.getType()); |
| 39 Filter filter4 = filterEngine.getFilter("example.com#@#foo"); |
| 40 assertEquals(Filter.Type.ELEMHIDE_EXCEPTION, filter4.getType()); |
| 41 Filter filter5 = filterEngine.getFilter(" foo "); |
| 42 assertEquals(filter1, filter5); |
| 43 } |
| 44 |
| 45 @Test |
| 46 public void testAddRemoveFilters() |
| 47 { |
| 48 while (filterEngine.getListedFilters().size() > 0) |
31 { | 49 { |
32 Filter filter1 = filterEngine.getFilter("foo"); | 50 filterEngine.getListedFilters().get(0).removeFromList(); |
33 assertEquals(Filter.Type.BLOCKING, filter1.getType()); | |
34 Filter filter2 = filterEngine.getFilter("@@foo"); | |
35 assertEquals(Filter.Type.EXCEPTION, filter2.getType()); | |
36 Filter filter3 = filterEngine.getFilter("example.com##foo"); | |
37 assertEquals(Filter.Type.ELEMHIDE, filter3.getType()); | |
38 Filter filter4 = filterEngine.getFilter("example.com#@#foo"); | |
39 assertEquals(Filter.Type.ELEMHIDE_EXCEPTION, filter4.getType()); | |
40 Filter filter5 = filterEngine.getFilter(" foo "); | |
41 assertEquals(filter1, filter5); | |
42 } | 51 } |
43 | 52 |
44 @Test | 53 assertEquals(0, filterEngine.getListedFilters().size()); |
45 public void testAddRemoveFilters() | 54 Filter filter = filterEngine.getFilter("foo"); |
| 55 assertEquals(0, filterEngine.getListedFilters().size()); |
| 56 assertFalse(filter.isListed()); |
| 57 |
| 58 filter.addToList(); |
| 59 assertEquals(1, filterEngine.getListedFilters().size()); |
| 60 assertEquals(filter, filterEngine.getListedFilters().get(0)); |
| 61 assertTrue(filter.isListed()); |
| 62 |
| 63 filter.addToList(); |
| 64 assertEquals(1, filterEngine.getListedFilters().size()); |
| 65 assertEquals(filter, filterEngine.getListedFilters().get(0)); |
| 66 assertTrue(filter.isListed()); |
| 67 |
| 68 filter.removeFromList(); |
| 69 assertEquals(0, filterEngine.getListedFilters().size()); |
| 70 assertFalse(filter.isListed()); |
| 71 |
| 72 filter.removeFromList(); |
| 73 assertEquals(0, filterEngine.getListedFilters().size()); |
| 74 assertFalse(filter.isListed()); |
| 75 } |
| 76 |
| 77 @Test |
| 78 public void testAddRemoveSubscriptions() |
| 79 { |
| 80 while (filterEngine.getListedSubscriptions().size() > 0) |
46 { | 81 { |
47 assertEquals(0, filterEngine.getListedFilters().size()); | 82 filterEngine.getListedSubscriptions().get(0).removeFromList(); |
48 Filter filter = filterEngine.getFilter("foo"); | |
49 assertEquals(0, filterEngine.getListedFilters().size()); | |
50 assertFalse(filter.isListed()); | |
51 | |
52 filter.addToList(); | |
53 assertEquals(1, filterEngine.getListedFilters().size()); | |
54 assertEquals(filter, filterEngine.getListedFilters().get(0)); | |
55 assertTrue(filter.isListed()); | |
56 | |
57 filter.addToList(); | |
58 assertEquals(1, filterEngine.getListedFilters().size()); | |
59 assertEquals(filter, filterEngine.getListedFilters().get(0)); | |
60 assertTrue(filter.isListed()); | |
61 | |
62 filter.removeFromList(); | |
63 assertEquals(0, filterEngine.getListedFilters().size()); | |
64 assertFalse(filter.isListed()); | |
65 | |
66 filter.removeFromList(); | |
67 assertEquals(0, filterEngine.getListedFilters().size()); | |
68 assertFalse(filter.isListed()); | |
69 } | 83 } |
70 | 84 |
71 @Test | 85 assertEquals(0, filterEngine.getListedSubscriptions().size()); |
72 public void testAddRemoveSubscriptions() | 86 Subscription subscription = filterEngine.getSubscription("foo"); |
73 { | 87 assertEquals(0, filterEngine.getListedSubscriptions().size()); |
74 assertEquals(0, filterEngine.getListedSubscriptions().size()); | 88 assertFalse(subscription.isListed()); |
75 Subscription subscription = filterEngine.getSubscription("foo"); | 89 subscription.addToList(); |
76 assertEquals(0, filterEngine.getListedSubscriptions().size()); | 90 assertEquals(1, filterEngine.getListedSubscriptions().size()); |
77 assertFalse(subscription.isListed()); | 91 assertEquals(subscription, filterEngine.getListedSubscriptions().get(0)); |
78 subscription.addToList(); | 92 assertTrue(subscription.isListed()); |
79 assertEquals(1, filterEngine.getListedSubscriptions().size()); | 93 subscription.addToList(); |
80 assertEquals(subscription, filterEngine.getListedSubscriptions().get(0))
; | 94 assertEquals(1, filterEngine.getListedSubscriptions().size()); |
81 assertTrue(subscription.isListed()); | 95 assertEquals(subscription, filterEngine.getListedSubscriptions().get(0)); |
82 subscription.addToList(); | 96 assertTrue(subscription.isListed()); |
83 assertEquals(1, filterEngine.getListedSubscriptions().size()); | 97 subscription.removeFromList(); |
84 assertEquals(subscription, filterEngine.getListedSubscriptions().get(0))
; | 98 assertEquals(0, filterEngine.getListedSubscriptions().size()); |
85 assertTrue(subscription.isListed()); | 99 assertFalse(subscription.isListed()); |
86 subscription.removeFromList(); | 100 subscription.removeFromList(); |
87 assertEquals(0, filterEngine.getListedSubscriptions().size()); | 101 assertEquals(0, filterEngine.getListedSubscriptions().size()); |
88 assertFalse(subscription.isListed()); | 102 assertFalse(subscription.isListed()); |
89 subscription.removeFromList(); | 103 } |
90 assertEquals(0, filterEngine.getListedSubscriptions().size()); | 104 |
91 assertFalse(subscription.isListed()); | 105 @Test |
92 } | 106 public void testSubscriptionUpdates() |
93 | 107 { |
94 @Test | 108 Subscription subscription = filterEngine.getSubscription("foo"); |
95 public void testSubscriptionUpdates() | 109 assertFalse(subscription.isUpdating()); |
96 { | 110 subscription.updateFilters(); |
97 Subscription subscription = filterEngine.getSubscription("foo"); | 111 } |
98 assertFalse(subscription.isUpdating()); | 112 |
99 subscription.updateFilters(); | 113 @Test |
100 } | 114 public void testMatches() |
101 | 115 { |
102 @Test | 116 filterEngine.getFilter("adbanner.gif").addToList(); |
103 public void testMatches() | 117 filterEngine.getFilter("@@notbanner.gif").addToList(); |
104 { | 118 filterEngine.getFilter("tpbanner.gif$third-party").addToList(); |
105 filterEngine.getFilter("adbanner.gif").addToList(); | 119 filterEngine.getFilter("fpbanner.gif$~third-party").addToList(); |
106 filterEngine.getFilter("@@notbanner.gif").addToList(); | 120 filterEngine.getFilter("combanner.gif$domain=example.com").addToList(); |
107 filterEngine.getFilter("tpbanner.gif$third-party").addToList(); | 121 filterEngine.getFilter("orgbanner.gif$domain=~example.com").addToList(); |
108 filterEngine.getFilter("fpbanner.gif$~third-party").addToList(); | 122 |
109 filterEngine.getFilter("combanner.gif$domain=example.com").addToList(); | 123 Filter match1 = filterEngine.matches( |
110 filterEngine.getFilter("orgbanner.gif$domain=~example.com").addToList(); | 124 "http://example.org/foobar.gif", |
111 | 125 FilterEngine.ContentType.IMAGE, |
112 Filter match1 = filterEngine.matches( | 126 ""); |
113 "http://example.org/foobar.gif", | 127 assertNull(match1); |
114 FilterEngine.ContentType.IMAGE, | 128 |
115 ""); | 129 Filter match2 = filterEngine.matches( |
116 assertNull(match1); | 130 "http://example.org/adbanner.gif", |
117 | 131 FilterEngine.ContentType.IMAGE, |
118 Filter match2 = filterEngine.matches( | 132 ""); |
119 "http://example.org/adbanner.gif", | 133 assertNotNull(match2); |
120 FilterEngine.ContentType.IMAGE, | 134 assertEquals(Filter.Type.BLOCKING, match2.getType()); |
121 ""); | 135 |
122 assertNotNull(match2); | 136 Filter match3 = filterEngine.matches( |
123 assertEquals(Filter.Type.BLOCKING, match2.getType()); | 137 "http://example.org/notbanner.gif", |
124 | 138 FilterEngine.ContentType.IMAGE, |
125 Filter match3 = filterEngine.matches( | 139 ""); |
126 "http://example.org/notbanner.gif", | 140 assertNotNull(match3); |
127 FilterEngine.ContentType.IMAGE, | 141 assertEquals(Filter.Type.EXCEPTION, match3.getType()); |
128 ""); | 142 |
129 assertNotNull(match3); | 143 Filter match4 = filterEngine.matches( |
130 assertEquals(Filter.Type.EXCEPTION, match3.getType()); | 144 "http://example.org/notbanner.gif", |
131 | 145 FilterEngine.ContentType.IMAGE, ""); |
132 Filter match4 = filterEngine.matches( | 146 assertNotNull(match4); |
133 "http://example.org/notbanner.gif", | 147 assertEquals(Filter.Type.EXCEPTION, match4.getType()); |
134 FilterEngine.ContentType.IMAGE, ""); | 148 |
135 assertNotNull(match4); | 149 Filter match5 = filterEngine.matches( |
136 assertEquals(Filter.Type.EXCEPTION, match4.getType()); | 150 "http://example.org/tpbanner.gif", |
137 | 151 FilterEngine.ContentType.IMAGE, |
138 Filter match5 = filterEngine.matches( | 152 "http://example.org/"); |
139 "http://example.org/tpbanner.gif", | 153 assertNull(match5); |
140 FilterEngine.ContentType.IMAGE, | 154 |
141 "http://example.org/"); | 155 Filter match6 = filterEngine.matches( |
142 assertNull(match5); | 156 "http://example.org/fpbanner.gif", |
143 | 157 FilterEngine.ContentType.IMAGE, |
144 Filter match6 = filterEngine.matches( | 158 "http://example.org/"); |
145 "http://example.org/fpbanner.gif", | 159 assertNotNull(match6); |
146 FilterEngine.ContentType.IMAGE, | 160 assertEquals(Filter.Type.BLOCKING, match6.getType()); |
147 "http://example.org/"); | 161 |
148 assertNotNull(match6); | 162 Filter match7 = filterEngine.matches( |
149 assertEquals(Filter.Type.BLOCKING, match6.getType()); | 163 "http://example.org/tpbanner.gif", |
150 | 164 FilterEngine.ContentType.IMAGE, |
151 Filter match7 = filterEngine.matches( | 165 "http://example.com/"); |
152 "http://example.org/tpbanner.gif", | 166 assertNotNull(match7); |
153 FilterEngine.ContentType.IMAGE, | 167 assertEquals(Filter.Type.BLOCKING, match7.getType()); |
154 "http://example.com/"); | 168 |
155 assertNotNull(match7); | 169 Filter match8 = filterEngine.matches( |
156 assertEquals(Filter.Type.BLOCKING, match7.getType()); | 170 "http://example.org/fpbanner.gif", |
157 | 171 FilterEngine.ContentType.IMAGE, |
158 Filter match8 = filterEngine.matches( | 172 "http://example.com/"); |
159 "http://example.org/fpbanner.gif", | 173 assertNull(match8); |
160 FilterEngine.ContentType.IMAGE, | 174 |
161 "http://example.com/"); | 175 Filter match9 = filterEngine.matches( |
162 assertNull(match8); | 176 "http://example.org/combanner.gif", |
163 | 177 FilterEngine.ContentType.IMAGE, |
164 Filter match9 = filterEngine.matches( | 178 "http://example.com/"); |
165 "http://example.org/combanner.gif", | 179 assertNotNull(match9); |
166 FilterEngine.ContentType.IMAGE, | 180 assertEquals(Filter.Type.BLOCKING, match9.getType()); |
167 "http://example.com/"); | 181 |
168 assertNotNull(match9); | 182 Filter match10 = filterEngine.matches( |
169 assertEquals(Filter.Type.BLOCKING, match9.getType()); | 183 "http://example.org/combanner.gif", |
170 | 184 FilterEngine.ContentType.IMAGE, |
171 Filter match10 = filterEngine.matches( | 185 "http://example.org/"); |
172 "http://example.org/combanner.gif", | 186 assertNull(match10); |
173 FilterEngine.ContentType.IMAGE, | 187 |
174 "http://example.org/"); | 188 Filter match11 = filterEngine.matches( |
175 assertNull(match10); | 189 "http://example.org/orgbanner.gif", |
176 | 190 FilterEngine.ContentType.IMAGE, |
177 Filter match11 = filterEngine.matches( | 191 "http://example.com/"); |
178 "http://example.org/orgbanner.gif", | 192 assertNull(match11); |
179 FilterEngine.ContentType.IMAGE, | 193 |
180 "http://example.com/"); | 194 Filter match12 = filterEngine.matches( |
181 assertNull(match11); | 195 "http://example.org/orgbanner.gif", |
182 | 196 FilterEngine.ContentType.IMAGE, |
183 Filter match12 = filterEngine.matches( | 197 "http://example.org/"); |
184 "http://example.org/orgbanner.gif", | 198 assertNotNull(match12); |
185 FilterEngine.ContentType.IMAGE, | 199 assertEquals(Filter.Type.BLOCKING, match12.getType()); |
186 "http://example.org/"); | 200 } |
187 assertNotNull(match12); | 201 |
188 assertEquals(Filter.Type.BLOCKING, match12.getType()); | 202 @Test |
189 } | 203 public void testMatchesOnWhitelistedDomain() |
190 | 204 { |
191 @Test | 205 filterEngine.getFilter("adbanner.gif").addToList(); |
192 public void testMatchesOnWhitelistedDomain() | 206 filterEngine.getFilter("@@||example.org^$document").addToList(); |
193 { | 207 |
194 filterEngine.getFilter("adbanner.gif").addToList(); | 208 Filter match1 = filterEngine.matches( |
195 filterEngine.getFilter("@@||example.org^$document").addToList(); | 209 "http://ads.com/adbanner.gif", |
196 | 210 FilterEngine.ContentType.IMAGE, |
197 Filter match1 = filterEngine.matches( | 211 "http://example.com/"); |
198 "http://ads.com/adbanner.gif", | 212 assertNotNull(match1); |
199 FilterEngine.ContentType.IMAGE, | 213 assertEquals(Filter.Type.BLOCKING, match1.getType()); |
200 "http://example.com/"); | 214 |
201 assertNotNull(match1); | 215 Filter match2 = filterEngine.matches( |
202 assertEquals(Filter.Type.BLOCKING, match1.getType()); | 216 "http://ads.com/adbanner.gif", |
203 | 217 FilterEngine.ContentType.IMAGE, |
204 Filter match2 = filterEngine.matches( | 218 "http://example.org/"); |
205 "http://ads.com/adbanner.gif", | 219 assertNotNull(match2); |
206 FilterEngine.ContentType.IMAGE, | 220 assertEquals(Filter.Type.EXCEPTION, match2.getType()); |
207 "http://example.org/"); | 221 } |
208 assertNotNull(match2); | 222 |
209 assertEquals(Filter.Type.EXCEPTION, match2.getType()); | 223 @Test |
210 } | 224 public void testMatchesNestedFrameRequest() |
211 | 225 { |
212 @Test | 226 filterEngine.getFilter("adbanner.gif").addToList(); |
213 public void testMatchesNestedFrameRequest() | 227 filterEngine.getFilter("@@adbanner.gif$domain=example.org").addToList(); |
214 { | 228 |
215 filterEngine.getFilter("adbanner.gif").addToList(); | 229 Filter match1 = filterEngine.matches( |
216 filterEngine.getFilter("@@adbanner.gif$domain=example.org").addToList(); | 230 "http://ads.com/adbanner.gif", |
217 | 231 FilterEngine.ContentType.IMAGE, |
218 Filter match1 = filterEngine.matches( | 232 new String[] |
219 "http://ads.com/adbanner.gif", | 233 { |
220 FilterEngine.ContentType.IMAGE, | 234 "http://ads.com/frame/", |
221 new String[] | 235 "http://example.com/" |
222 { | 236 }); |
223 "http://ads.com/frame/", | 237 assertNotNull(match1); |
224 "http://example.com/" | 238 assertEquals(Filter.Type.BLOCKING, match1.getType()); |
225 }); | 239 |
226 assertNotNull(match1); | 240 Filter match2 = filterEngine.matches( |
227 assertEquals(Filter.Type.BLOCKING, match1.getType()); | 241 "http://ads.com/adbanner.gif", |
228 | 242 FilterEngine.ContentType.IMAGE, |
229 Filter match2 = filterEngine.matches( | 243 new String[] |
230 "http://ads.com/adbanner.gif", | 244 { |
231 FilterEngine.ContentType.IMAGE, | 245 "http://ads.com/frame/", |
232 new String[] | 246 "http://example.org/" |
233 { | 247 }); |
234 "http://ads.com/frame/", | 248 assertNotNull(match2); |
235 "http://example.org/" | 249 assertEquals(Filter.Type.EXCEPTION, match2.getType()); |
236 }); | 250 |
237 assertNotNull(match2); | 251 Filter match3 = filterEngine.matches( |
238 assertEquals(Filter.Type.EXCEPTION, match2.getType()); | 252 "http://ads.com/adbanner.gif", |
239 | 253 FilterEngine.ContentType.IMAGE, |
240 Filter match3 = filterEngine.matches( | 254 new String[] |
241 "http://ads.com/adbanner.gif", | 255 { |
242 FilterEngine.ContentType.IMAGE, | 256 "http://example.org/", |
243 new String[] | 257 "http://ads.com/frame/" |
244 { | 258 }); |
245 "http://example.org/", | 259 assertNotNull(match3); |
246 "http://ads.com/frame/" | 260 assertEquals(Filter.Type.BLOCKING, match3.getType()); |
247 }); | 261 } |
248 assertNotNull(match3); | 262 |
249 assertEquals(Filter.Type.BLOCKING, match3.getType()); | 263 @Test |
250 } | 264 public void testMatchesNestedFrameOnWhitelistedDomain() |
251 | 265 { |
252 @Test | 266 filterEngine.getFilter("adbanner.gif").addToList(); |
253 public void testMatchesNestedFrameOnWhitelistedDomain() | 267 filterEngine.getFilter("@@||example.org^$document,domain=ads.com").addToList
(); |
254 { | 268 |
255 filterEngine.getFilter("adbanner.gif").addToList(); | 269 Filter match1 = filterEngine.matches( |
256 filterEngine.getFilter("@@||example.org^$document,domain=ads.com").addTo
List(); | 270 "http://ads.com/adbanner.gif", |
257 | 271 FilterEngine.ContentType.IMAGE, |
258 Filter match1 = filterEngine.matches( | 272 new String[] |
259 "http://ads.com/adbanner.gif", | 273 { |
260 FilterEngine.ContentType.IMAGE, | 274 "http://ads.com/frame/", |
261 new String[] | 275 "http://example.com/" |
262 { | 276 }); |
263 "http://ads.com/frame/", | 277 assertNotNull(match1); |
264 "http://example.com/" | 278 assertEquals(Filter.Type.BLOCKING, match1.getType()); |
265 }); | 279 |
266 assertNotNull(match1); | 280 Filter match2 = filterEngine.matches( |
267 assertEquals(Filter.Type.BLOCKING, match1.getType()); | 281 "http://ads.com/adbanner.gif", |
268 | 282 FilterEngine.ContentType.IMAGE, |
269 Filter match2 = filterEngine.matches( | 283 new String[] |
270 "http://ads.com/adbanner.gif", | 284 { |
271 FilterEngine.ContentType.IMAGE, | 285 "http://ads.com/frame/", |
272 new String[] | 286 "http://example.org/" |
273 { | 287 }); |
274 "http://ads.com/frame/", | 288 assertNotNull(match2); |
275 "http://example.org/" | 289 assertEquals(Filter.Type.EXCEPTION, match2.getType()); |
276 }); | 290 |
277 assertNotNull(match2); | 291 Filter match3 = filterEngine.matches( |
278 assertEquals(Filter.Type.EXCEPTION, match2.getType()); | 292 "http://ads.com/adbanner.gif", |
279 | 293 FilterEngine.ContentType.IMAGE, |
280 Filter match3 = filterEngine.matches( | 294 new String[] |
281 "http://ads.com/adbanner.gif", | 295 { |
282 FilterEngine.ContentType.IMAGE, | 296 "http://example.org/" |
283 new String[] | 297 }); |
284 { | 298 assertNotNull(match3); |
285 "http://example.org/" | 299 assertEquals(Filter.Type.BLOCKING, match3.getType()); |
286 }); | 300 |
287 assertNotNull(match3); | 301 Filter match4 = filterEngine.matches( |
288 assertEquals(Filter.Type.BLOCKING, match3.getType()); | 302 "http://ads.com/adbanner.gif", |
289 | 303 FilterEngine.ContentType.IMAGE, |
290 Filter match4 = filterEngine.matches( | 304 new String[] |
291 "http://ads.com/adbanner.gif", | 305 { |
292 FilterEngine.ContentType.IMAGE, | 306 "http://example.org/", |
293 new String[] | 307 "http://ads.com/frame/" |
294 { | 308 }); |
295 "http://example.org/", | 309 assertNotNull(match4); |
296 "http://ads.com/frame/" | 310 assertEquals(Filter.Type.BLOCKING, match4.getType()); |
297 }); | 311 |
298 assertNotNull(match4); | 312 Filter match5 = filterEngine.matches( |
299 assertEquals(Filter.Type.BLOCKING, match4.getType()); | 313 "http://ads.com/adbanner.gif", |
300 | 314 FilterEngine.ContentType.IMAGE, |
301 Filter match5 = filterEngine.matches( | 315 new String[] |
302 "http://ads.com/adbanner.gif", | 316 { |
303 FilterEngine.ContentType.IMAGE, | 317 "http://ads.com/frame/", |
304 new String[] | 318 "http://example.org/", |
305 { | 319 "http://example.com/" |
306 "http://ads.com/frame/", | 320 }); |
307 "http://example.org/", | 321 assertNotNull(match5); |
308 "http://example.com/" | 322 assertEquals(Filter.Type.EXCEPTION, match5.getType()); |
309 }); | 323 } |
310 assertNotNull(match5); | 324 |
311 assertEquals(Filter.Type.EXCEPTION, match5.getType()); | 325 @Test |
312 } | 326 public void testFirstRunFlag() |
313 | 327 { |
314 @Test | 328 jsEngine.setWebRequest(new LazyWebRequest()); |
315 public void testFirstRunFlag() | 329 jsEngine.setDefaultLogSystem(); |
316 { | 330 |
317 assertFalse(filterEngine.isFirstRun()); | 331 LazyFileSystem lazyFileSystem = new LazyFileSystem(); |
318 } | 332 lazyFileSystem.setPatternsIniExists(false); |
319 | 333 jsEngine.setFileSystem(lazyFileSystem); |
320 @Test | 334 |
321 public void testSetRemoveFilterChangeCallback() | 335 filterEngine = new FilterEngine(jsEngine); |
322 { | 336 assertTrue(filterEngine.isFirstRun()); |
323 MockFilterChangeCallback mockFilterChangeCallback = new MockFilterChange
Callback(0); | 337 } |
324 | 338 |
325 filterEngine.setFilterChangeCallback(mockFilterChangeCallback); | 339 @Test |
326 filterEngine.getFilter("foo").addToList(); | 340 public void testSetRemoveFilterChangeCallback() |
327 assertEquals(1, mockFilterChangeCallback.getTimesCalled()); | 341 { |
328 | 342 MockFilterChangeCallback mockFilterChangeCallback = new MockFilterChangeCall
back(0); |
329 filterEngine.removeFilterChangeCallback(); | 343 |
330 filterEngine.getFilter("foo").removeFromList(); | 344 filterEngine.setFilterChangeCallback(mockFilterChangeCallback); |
331 assertEquals(1, mockFilterChangeCallback.getTimesCalled()); | 345 filterEngine.getFilter("foo").addToList(); |
332 } | 346 assertEquals(1, mockFilterChangeCallback.getTimesCalled()); |
333 | 347 |
334 @Test | 348 filterEngine.removeFilterChangeCallback(); |
335 public void testDocumentWhitelisting() | 349 filterEngine.getFilter("foo").removeFromList(); |
336 { | 350 assertEquals(1, mockFilterChangeCallback.getTimesCalled()); |
337 filterEngine.getFilter("@@||example.org^$document").addToList(); | 351 } |
338 filterEngine.getFilter("@@||example.com^$document,domain=example.de").ad
dToList(); | 352 |
339 | 353 @Test |
340 String[] emptyArray = new String[] | 354 public void testDocumentWhitelisting() |
341 { | 355 { |
342 }; | 356 filterEngine.getFilter("@@||example.org^$document").addToList(); |
343 | 357 filterEngine.getFilter("@@||example.com^$document,domain=example.de").addToL
ist(); |
344 assertTrue(filterEngine.isDocumentWhitelisted("http://example.org", empt
yArray)); | 358 |
345 assertFalse(filterEngine.isDocumentWhitelisted("http://example.co.uk", e
mptyArray)); | 359 String[] emptyArray = new String[] |
346 assertFalse(filterEngine.isDocumentWhitelisted("http://example.com", emp
tyArray)); | 360 { |
347 | 361 }; |
348 String[] documentUrls1 = new String[] | 362 |
349 { | 363 assertTrue(filterEngine.isDocumentWhitelisted("http://example.org", emptyArr
ay)); |
350 "http://example.de" | 364 assertFalse(filterEngine.isDocumentWhitelisted("http://example.co.uk", empty
Array)); |
351 }; | 365 assertFalse(filterEngine.isDocumentWhitelisted("http://example.com", emptyAr
ray)); |
352 assertTrue(filterEngine.isDocumentWhitelisted("http://example.com", docu
mentUrls1)); | 366 |
353 assertFalse(filterEngine.isDocumentWhitelisted("http://example.co.uk", d
ocumentUrls1)); | 367 String[] documentUrls1 = new String[] |
354 } | 368 { |
355 | 369 "http://example.de" |
356 @Test | 370 }; |
357 public void testElemhideWhitelisting() | 371 assertTrue(filterEngine.isDocumentWhitelisted("http://example.com", document
Urls1)); |
358 { | 372 assertFalse(filterEngine.isDocumentWhitelisted("http://example.co.uk", docum
entUrls1)); |
359 filterEngine.getFilter("@@||example.org^$elemhide").addToList(); | 373 } |
360 filterEngine.getFilter("@@||example.com^$elemhide,domain=example.de").ad
dToList(); | 374 |
361 | 375 @Test |
362 String[] emptyArray = new String[] | 376 public void testElemhideWhitelisting() |
363 { | 377 { |
364 }; | 378 filterEngine.getFilter("@@||example.org^$elemhide").addToList(); |
365 | 379 filterEngine.getFilter("@@||example.com^$elemhide,domain=example.de").addToL
ist(); |
366 assertTrue(filterEngine.isElemhideWhitelisted("http://example.org", empt
yArray)); | 380 |
367 assertFalse(filterEngine.isElemhideWhitelisted("http://example.co.uk", e
mptyArray)); | 381 String[] emptyArray = new String[] |
368 assertFalse(filterEngine.isElemhideWhitelisted("http://example.com", emp
tyArray)); | 382 { |
369 | 383 }; |
370 String[] documentUrls1 = new String[] | 384 |
371 { | 385 assertTrue(filterEngine.isElemhideWhitelisted("http://example.org", emptyArr
ay)); |
372 "http://example.de" | 386 assertFalse(filterEngine.isElemhideWhitelisted("http://example.co.uk", empty
Array)); |
373 }; | 387 assertFalse(filterEngine.isElemhideWhitelisted("http://example.com", emptyAr
ray)); |
374 assertTrue(filterEngine.isElemhideWhitelisted("http://example.com", docu
mentUrls1)); | 388 |
375 assertFalse(filterEngine.isElemhideWhitelisted("http://example.co.uk", d
ocumentUrls1)); | 389 String[] documentUrls1 = new String[] |
376 } | 390 { |
| 391 "http://example.de" |
| 392 }; |
| 393 assertTrue(filterEngine.isElemhideWhitelisted("http://example.com", document
Urls1)); |
| 394 assertFalse(filterEngine.isElemhideWhitelisted("http://example.co.uk", docum
entUrls1)); |
| 395 } |
377 } | 396 } |
LEFT | RIGHT |