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

Side by Side Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java

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

Powered by Google App Engine
This is Rietveld