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