| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 52   filterNotifier.on("filter.removed", makeWrapper("filter.removed")); | 52   filterNotifier.on("filter.removed", makeWrapper("filter.removed")); | 
| 53   filterNotifier.on("filter.moved", makeWrapper("filter.moved")); | 53   filterNotifier.on("filter.moved", makeWrapper("filter.moved")); | 
| 54 | 54 | 
| 55   filterNotifier.on("filter.hitCount", makeWrapper("filter.hitCount")); | 55   filterNotifier.on("filter.hitCount", makeWrapper("filter.hitCount")); | 
| 56   filterNotifier.on("filter.lastHit", makeWrapper("filter.lastHit")); | 56   filterNotifier.on("filter.lastHit", makeWrapper("filter.lastHit")); | 
| 57 } | 57 } | 
| 58 | 58 | 
| 59 function compareSubscriptionList(test, testMessage, list, | 59 function compareSubscriptionList(test, testMessage, list, | 
| 60                                  knownSubscriptions = null) | 60                                  knownSubscriptions = null) | 
| 61 { | 61 { | 
| 62   let result = FilterStorage.subscriptions.map(subscription => subscription.url)
     ; | 62   let result = [...FilterStorage.knownSubscriptions.keys()]; | 
| 63   let expected = list.map(subscription => subscription.url); | 63   let expected = list.map(subscription => subscription.url); | 
| 64   test.deepEqual(result, expected, testMessage); | 64   test.deepEqual(result, expected, testMessage); | 
| 65 | 65 | 
| 66   if (knownSubscriptions) | 66   if (knownSubscriptions) | 
| 67   { | 67   { | 
| 68     test.deepEqual([...Subscription.knownSubscriptions.values()], | 68     test.deepEqual([...Subscription.knownSubscriptions.values()], | 
| 69                    knownSubscriptions, testMessage); | 69                    knownSubscriptions, testMessage); | 
| 70   } | 70   } | 
| 71 } | 71 } | 
| 72 | 72 | 
| 73 function compareFiltersList(test, testMessage, list) | 73 function compareFiltersList(test, testMessage, list) | 
| 74 { | 74 { | 
| 75   let result = FilterStorage.subscriptions.map( | 75   let result = [...FilterStorage.subscriptions()].map( | 
| 76     subscription => subscription.filters.map( | 76     subscription => subscription.filters.map( | 
| 77       filter => filter.text)); | 77       filter => filter.text)); | 
| 78   test.deepEqual(result, list, testMessage); | 78   test.deepEqual(result, list, testMessage); | 
| 79 } | 79 } | 
| 80 | 80 | 
| 81 function compareFilterSubscriptions(test, testMessage, filter, list) | 81 function compareFilterSubscriptions(test, testMessage, filter, list) | 
| 82 { | 82 { | 
| 83   let result = [...filter.subscriptions()].map(subscription => subscription.url)
     ; | 83   let result = [...filter.subscriptions()].map(subscription => subscription.url)
     ; | 
| 84   let expected = list.map(subscription => subscription.url); | 84   let expected = list.map(subscription => subscription.url); | 
| 85   test.deepEqual(result, expected, testMessage); | 85   test.deepEqual(result, expected, testMessage); | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 201   function listener(action, subscription) | 201   function listener(action, subscription) | 
| 202   { | 202   { | 
| 203     if (action.indexOf("subscription.") == 0) | 203     if (action.indexOf("subscription.") == 0) | 
| 204       changes.push(action + " " + subscription.url); | 204       changes.push(action + " " + subscription.url); | 
| 205   } | 205   } | 
| 206   addListener(listener); | 206   addListener(listener); | 
| 207 | 207 | 
| 208   compareSubscriptionList(test, "Initial state", [subscription1, subscription2, 
     subscription3]); | 208   compareSubscriptionList(test, "Initial state", [subscription1, subscription2, 
     subscription3]); | 
| 209   test.deepEqual(changes, [], "Received changes"); | 209   test.deepEqual(changes, [], "Received changes"); | 
| 210 | 210 | 
| 211   changes = []; |  | 
| 212   FilterStorage.moveSubscription(subscription1); |  | 
| 213   compareSubscriptionList(test, "Move without explicit position", [subscription2
     , subscription3, subscription1]); |  | 
| 214   test.deepEqual(changes, ["subscription.moved http://test1/"], "Received change
     s"); |  | 
| 215 |  | 
| 216   changes = []; |  | 
| 217   FilterStorage.moveSubscription(subscription1); |  | 
| 218   compareSubscriptionList(test, "Move without explicit position (subscription al
     ready last)", [subscription2, subscription3, subscription1]); |  | 
| 219   test.deepEqual(changes, [], "Received changes"); |  | 
| 220 |  | 
| 221   changes = []; |  | 
| 222   FilterStorage.moveSubscription(subscription2, subscription1); |  | 
| 223   compareSubscriptionList(test, "Move with explicit position", [subscription3, s
     ubscription2, subscription1]); |  | 
| 224   test.deepEqual(changes, ["subscription.moved http://test2/"], "Received change
     s"); |  | 
| 225 |  | 
| 226   changes = []; |  | 
| 227   FilterStorage.moveSubscription(subscription3, subscription2); |  | 
| 228   compareSubscriptionList(test, "Move without explicit position (subscription al
     ready at position)", [subscription3, subscription2, subscription1]); |  | 
| 229   test.deepEqual(changes, [], "Received changes"); |  | 
| 230 |  | 
| 231   FilterStorage.removeSubscription(subscription2); | 211   FilterStorage.removeSubscription(subscription2); | 
| 232   compareSubscriptionList(test, "Remove", [subscription3, subscription1]); | 212   compareSubscriptionList(test, "Remove", [subscription1, subscription3]); | 
| 233 |  | 
| 234   changes = []; |  | 
| 235   FilterStorage.moveSubscription(subscription3, subscription2); |  | 
| 236   compareSubscriptionList(test, "Move before removed subscription", [subscriptio
     n1, subscription3]); |  | 
| 237   test.deepEqual(changes, ["subscription.moved http://test3/"], "Received change
     s"); |  | 
| 238 |  | 
| 239   changes = []; |  | 
| 240   FilterStorage.moveSubscription(subscription2); |  | 
| 241   compareSubscriptionList(test, "Move of removed subscription", [subscription1, 
     subscription3]); |  | 
| 242   test.deepEqual(changes, [], "Received changes"); |  | 
| 243 | 213 | 
| 244   test.done(); | 214   test.done(); | 
| 245 }; | 215 }; | 
| 246 | 216 | 
| 247 exports.testAddingFilters = function(test) | 217 exports.testAddingFilters = function(test) | 
| 248 { | 218 { | 
| 249   let subscription1 = Subscription.fromURL("~blocking"); | 219   let subscription1 = Subscription.fromURL("~blocking"); | 
| 250   subscription1.defaults = ["blocking"]; | 220   subscription1.defaults = ["blocking"]; | 
| 251 | 221 | 
| 252   let subscription2 = Subscription.fromURL("~exceptions"); | 222   let subscription2 = Subscription.fromURL("~exceptions"); | 
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 531   compareFilterSubscriptions(test, "filter3 subscriptions after updating http://
     test3/ filters", filter3, [subscription2]); | 501   compareFilterSubscriptions(test, "filter3 subscriptions after updating http://
     test3/ filters", filter3, [subscription2]); | 
| 532 | 502 | 
| 533   FilterStorage.removeSubscription(subscription3); | 503   FilterStorage.removeSubscription(subscription3); | 
| 534 | 504 | 
| 535   compareFilterSubscriptions(test, "filter1 subscriptions after removing http://
     test3/", filter1, []); | 505   compareFilterSubscriptions(test, "filter1 subscriptions after removing http://
     test3/", filter1, []); | 
| 536   compareFilterSubscriptions(test, "filter2 subscriptions after removing http://
     test3/", filter2, [subscription2]); | 506   compareFilterSubscriptions(test, "filter2 subscriptions after removing http://
     test3/", filter2, [subscription2]); | 
| 537   compareFilterSubscriptions(test, "filter3 subscriptions after removing http://
     test3/", filter3, [subscription2]); | 507   compareFilterSubscriptions(test, "filter3 subscriptions after removing http://
     test3/", filter3, [subscription2]); | 
| 538 | 508 | 
| 539   test.done(); | 509   test.done(); | 
| 540 }; | 510 }; | 
| OLD | NEW | 
|---|