Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java

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

Powered by Google App Engine
This is Rietveld