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

Powered by Google App Engine
This is Rietveld