OLD | NEW |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 if (knownSubscriptions) | 65 if (knownSubscriptions) |
66 { | 66 { |
67 test.deepEqual([...Subscription.knownSubscriptions.values()], | 67 test.deepEqual([...Subscription.knownSubscriptions.values()], |
68 knownSubscriptions, testMessage); | 68 knownSubscriptions, testMessage); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 function compareFiltersList(test, testMessage, list) | 72 function compareFiltersList(test, testMessage, list) |
73 { | 73 { |
74 let result = [...filterStorage.subscriptions()].map( | 74 let result = [...filterStorage.subscriptions()].map( |
75 subscription => subscription.filters.map( | 75 subscription => subscription.filters); |
76 filter => filter.text)); | |
77 test.deepEqual(result, list, testMessage); | 76 test.deepEqual(result, list, testMessage); |
78 } | 77 } |
79 | 78 |
80 function compareFilterSubscriptions(test, testMessage, filter, list) | 79 function compareFilterSubscriptions(test, testMessage, filter, list) |
81 { | 80 { |
82 let result = [...filter.subscriptions()].map(subscription => subscription.url)
; | 81 let result = [...filter.subscriptions()].map(subscription => subscription.url)
; |
83 let expected = list.map(subscription => subscription.url); | 82 let expected = list.map(subscription => subscription.url); |
84 test.deepEqual(result, expected, testMessage); | 83 test.deepEqual(result, expected, testMessage); |
85 } | 84 } |
86 | 85 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 filterStorage.addFilter(Filter.fromText("!foobar"), subscription2, 0); | 283 filterStorage.addFilter(Filter.fromText("!foobar"), subscription2, 0); |
285 compareFiltersList(test, "Adding filter to an explicit subscription with posit
ion", [["foo", "foo"], ["!foobar", "@@bar", "foo##bar", "foo#@#bar"], ["!foobar"
, "foo"]]); | 284 compareFiltersList(test, "Adding filter to an explicit subscription with posit
ion", [["foo", "foo"], ["!foobar", "@@bar", "foo##bar", "foo#@#bar"], ["!foobar"
, "foo"]]); |
286 test.deepEqual(changes, ["filter.added !foobar"], "Received changes"); | 285 test.deepEqual(changes, ["filter.added !foobar"], "Received changes"); |
287 | 286 |
288 test.done(); | 287 test.done(); |
289 }; | 288 }; |
290 | 289 |
291 exports.testRemovingFilters = function(test) | 290 exports.testRemovingFilters = function(test) |
292 { | 291 { |
293 let subscription1 = Subscription.fromURL("~foo"); | 292 let subscription1 = Subscription.fromURL("~foo"); |
294 subscription1.filters = [Filter.fromText("foo"), Filter.fromText("foo"), Filte
r.fromText("bar")]; | 293 subscription1.filters = ["foo", "foo", "bar"]; |
295 | 294 |
296 let subscription2 = Subscription.fromURL("~bar"); | 295 let subscription2 = Subscription.fromURL("~bar"); |
297 subscription2.filters = [Filter.fromText("foo"), Filter.fromText("bar"), Filte
r.fromText("foo")]; | 296 subscription2.filters = ["foo", "bar", "foo"]; |
298 | 297 |
299 let subscription3 = Subscription.fromURL("http://test/"); | 298 let subscription3 = Subscription.fromURL("http://test/"); |
300 subscription3.filters = [Filter.fromText("foo"), Filter.fromText("bar")]; | 299 subscription3.filters = ["foo", "bar"]; |
301 | 300 |
302 filterStorage.addSubscription(subscription1); | 301 filterStorage.addSubscription(subscription1); |
303 filterStorage.addSubscription(subscription2); | 302 filterStorage.addSubscription(subscription2); |
304 filterStorage.addSubscription(subscription3); | 303 filterStorage.addSubscription(subscription3); |
305 | 304 |
306 let changes = []; | 305 let changes = []; |
307 function listener(action, filter) | 306 function listener(action, filter) |
308 { | 307 { |
309 if (action.indexOf("filter.") == 0) | 308 if (action.indexOf("filter.") == 0) |
310 changes.push(action + " " + filter.text); | 309 changes.push(action + " " + filter.text); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 filterStorage.removeFilter(Filter.fromText("bar")); | 342 filterStorage.removeFilter(Filter.fromText("bar")); |
344 compareFiltersList(test, "Remove of unknown filter", [[], ["foo"], ["foo", "ba
r"]]); | 343 compareFiltersList(test, "Remove of unknown filter", [[], ["foo"], ["foo", "ba
r"]]); |
345 test.deepEqual(changes, [], "Received changes"); | 344 test.deepEqual(changes, [], "Received changes"); |
346 | 345 |
347 test.done(); | 346 test.done(); |
348 }; | 347 }; |
349 | 348 |
350 exports.testMovingFilters = function(test) | 349 exports.testMovingFilters = function(test) |
351 { | 350 { |
352 let subscription1 = Subscription.fromURL("~foo"); | 351 let subscription1 = Subscription.fromURL("~foo"); |
353 subscription1.filters = [Filter.fromText("foo"), Filter.fromText("bar"), Filte
r.fromText("bas"), Filter.fromText("foo")]; | 352 subscription1.filters = ["foo", "bar", "bas", "foo"]; |
354 | 353 |
355 let subscription2 = Subscription.fromURL("http://test/"); | 354 let subscription2 = Subscription.fromURL("http://test/"); |
356 subscription2.filters = [Filter.fromText("foo"), Filter.fromText("bar")]; | 355 subscription2.filters = ["foo", "bar"]; |
357 | 356 |
358 filterStorage.addSubscription(subscription1); | 357 filterStorage.addSubscription(subscription1); |
359 filterStorage.addSubscription(subscription2); | 358 filterStorage.addSubscription(subscription2); |
360 | 359 |
361 let changes = []; | 360 let changes = []; |
362 function listener(action, filter) | 361 function listener(action, filter) |
363 { | 362 { |
364 if (action.indexOf("filter.") == 0) | 363 if (action.indexOf("filter.") == 0) |
365 changes.push(action + " " + filter.text); | 364 changes.push(action + " " + filter.text); |
366 } | 365 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 test.done(); | 443 test.done(); |
445 }; | 444 }; |
446 | 445 |
447 exports.testFilterSubscriptionRelationship = function(test) | 446 exports.testFilterSubscriptionRelationship = function(test) |
448 { | 447 { |
449 let filter1 = Filter.fromText("filter1"); | 448 let filter1 = Filter.fromText("filter1"); |
450 let filter2 = Filter.fromText("filter2"); | 449 let filter2 = Filter.fromText("filter2"); |
451 let filter3 = Filter.fromText("filter3"); | 450 let filter3 = Filter.fromText("filter3"); |
452 | 451 |
453 let subscription1 = Subscription.fromURL("http://test1/"); | 452 let subscription1 = Subscription.fromURL("http://test1/"); |
454 subscription1.filters = [filter1, filter2]; | 453 subscription1.filters = [filter1.text, filter2.text]; |
455 | 454 |
456 let subscription2 = Subscription.fromURL("http://test2/"); | 455 let subscription2 = Subscription.fromURL("http://test2/"); |
457 subscription2.filters = [filter2, filter3]; | 456 subscription2.filters = [filter2.text, filter3.text]; |
458 | 457 |
459 let subscription3 = Subscription.fromURL("http://test3/"); | 458 let subscription3 = Subscription.fromURL("http://test3/"); |
460 subscription3.filters = [filter1, filter2, filter3]; | 459 subscription3.filters = [filter1.text, filter2.text, filter3.text]; |
461 | 460 |
462 compareFilterSubscriptions(test, "Initial filter1 subscriptions", filter1, [])
; | 461 compareFilterSubscriptions(test, "Initial filter1 subscriptions", filter1, [])
; |
463 compareFilterSubscriptions(test, "Initial filter2 subscriptions", filter2, [])
; | 462 compareFilterSubscriptions(test, "Initial filter2 subscriptions", filter2, [])
; |
464 compareFilterSubscriptions(test, "Initial filter3 subscriptions", filter3, [])
; | 463 compareFilterSubscriptions(test, "Initial filter3 subscriptions", filter3, [])
; |
465 | 464 |
466 filterStorage.addSubscription(subscription1); | 465 filterStorage.addSubscription(subscription1); |
467 | 466 |
468 compareFilterSubscriptions(test, "filter1 subscriptions after adding http://te
st1/", filter1, [subscription1]); | 467 compareFilterSubscriptions(test, "filter1 subscriptions after adding http://te
st1/", filter1, [subscription1]); |
469 compareFilterSubscriptions(test, "filter2 subscriptions after adding http://te
st1/", filter2, [subscription1]); | 468 compareFilterSubscriptions(test, "filter2 subscriptions after adding http://te
st1/", filter2, [subscription1]); |
470 compareFilterSubscriptions(test, "filter3 subscriptions after adding http://te
st1/", filter3, []); | 469 compareFilterSubscriptions(test, "filter3 subscriptions after adding http://te
st1/", filter3, []); |
(...skipping 29 matching lines...) Expand all Loading... |
500 compareFilterSubscriptions(test, "filter3 subscriptions after updating http://
test3/ filters", filter3, [subscription2]); | 499 compareFilterSubscriptions(test, "filter3 subscriptions after updating http://
test3/ filters", filter3, [subscription2]); |
501 | 500 |
502 filterStorage.removeSubscription(subscription3); | 501 filterStorage.removeSubscription(subscription3); |
503 | 502 |
504 compareFilterSubscriptions(test, "filter1 subscriptions after removing http://
test3/", filter1, []); | 503 compareFilterSubscriptions(test, "filter1 subscriptions after removing http://
test3/", filter1, []); |
505 compareFilterSubscriptions(test, "filter2 subscriptions after removing http://
test3/", filter2, [subscription2]); | 504 compareFilterSubscriptions(test, "filter2 subscriptions after removing http://
test3/", filter2, [subscription2]); |
506 compareFilterSubscriptions(test, "filter3 subscriptions after removing http://
test3/", filter3, [subscription2]); | 505 compareFilterSubscriptions(test, "filter3 subscriptions after removing http://
test3/", filter3, [subscription2]); |
507 | 506 |
508 test.done(); | 507 test.done(); |
509 }; | 508 }; |
OLD | NEW |