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

Powered by Google App Engine
This is Rietveld