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