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