| LEFT | RIGHT |
| (no file at all) | |
| 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 21 matching lines...) Expand all Loading... |
| 32 ( | 32 ( |
| 33 {Filter} = sandboxedRequire("../lib/filterClasses"), | 33 {Filter} = sandboxedRequire("../lib/filterClasses"), |
| 34 {FilterNotifier} = sandboxedRequire("../lib/filterNotifier"), | 34 {FilterNotifier} = sandboxedRequire("../lib/filterNotifier"), |
| 35 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), | 35 {FilterStorage} = sandboxedRequire("../lib/filterStorage"), |
| 36 {Subscription} = sandboxedRequire("../lib/subscriptionClasses") | 36 {Subscription} = sandboxedRequire("../lib/subscriptionClasses") |
| 37 ); | 37 ); |
| 38 | 38 |
| 39 callback(); | 39 callback(); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 function compareSubscriptionList(test, testMessage, list) | 42 function compareSubscriptionList(test, testMessage, list, |
| 43 knownSubscriptions = null) |
| 43 { | 44 { |
| 44 let result = FilterStorage.subscriptions.map(subscription => subscription.url)
; | 45 let result = FilterStorage.subscriptions.map(subscription => subscription.url)
; |
| 45 let expected = list.map(subscription => subscription.url); | 46 let expected = list.map(subscription => subscription.url); |
| 46 test.deepEqual(result, expected, testMessage); | 47 test.deepEqual(result, expected, testMessage); |
| 48 |
| 49 if (knownSubscriptions) |
| 50 { |
| 51 test.deepEqual([...Subscription.knownSubscriptions.values()], |
| 52 knownSubscriptions, testMessage); |
| 53 } |
| 47 } | 54 } |
| 48 | 55 |
| 49 function compareFiltersList(test, testMessage, list) | 56 function compareFiltersList(test, testMessage, list) |
| 50 { | 57 { |
| 51 let result = FilterStorage.subscriptions.map( | 58 let result = FilterStorage.subscriptions.map( |
| 52 subscription => subscription.filters.map( | 59 subscription => subscription.filters.map( |
| 53 filter => filter.text)); | 60 filter => filter.text)); |
| 54 test.deepEqual(result, list, testMessage); | 61 test.deepEqual(result, list, testMessage); |
| 55 } | 62 } |
| 56 | 63 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 compareSubscriptionList(test, "Re-adding previously removed subscription", [su
bscription2, subscription1]); | 107 compareSubscriptionList(test, "Re-adding previously removed subscription", [su
bscription2, subscription1]); |
| 101 test.deepEqual(changes, ["subscription.added http://test1/"], "Received change
s"); | 108 test.deepEqual(changes, ["subscription.added http://test1/"], "Received change
s"); |
| 102 | 109 |
| 103 test.done(); | 110 test.done(); |
| 104 }; | 111 }; |
| 105 | 112 |
| 106 exports.testRemovingSubscriptions = function(test) | 113 exports.testRemovingSubscriptions = function(test) |
| 107 { | 114 { |
| 108 let subscription1 = Subscription.fromURL("http://test1/"); | 115 let subscription1 = Subscription.fromURL("http://test1/"); |
| 109 let subscription2 = Subscription.fromURL("http://test2/"); | 116 let subscription2 = Subscription.fromURL("http://test2/"); |
| 117 |
| 118 test.equal(Subscription.fromURL(subscription1.url), subscription1, |
| 119 "Subscription known before addition"); |
| 120 |
| 110 FilterStorage.addSubscription(subscription1); | 121 FilterStorage.addSubscription(subscription1); |
| 111 FilterStorage.addSubscription(subscription2); | 122 FilterStorage.addSubscription(subscription2); |
| 112 | 123 |
| 113 let changes = []; | 124 let changes = []; |
| 114 function listener(action, subscription) | 125 function listener(action, subscription) |
| 115 { | 126 { |
| 116 if (action.indexOf("subscription.") == 0) | 127 if (action.indexOf("subscription.") == 0) |
| 117 changes.push(action + " " + subscription.url); | 128 changes.push(action + " " + subscription.url); |
| 118 } | 129 } |
| 119 FilterNotifier.addListener(listener); | 130 FilterNotifier.addListener(listener); |
| 120 | 131 |
| 121 compareSubscriptionList(test, "Initial state", [subscription1, subscription2])
; | 132 compareSubscriptionList(test, "Initial state", [subscription1, subscription2], |
| 122 test.deepEqual(changes, [], "Received changes"); | 133 [subscription1, subscription2]); |
| 134 test.deepEqual(changes, [], "Received changes"); |
| 135 |
| 136 test.equal(Subscription.fromURL(subscription1.url), subscription1, |
| 137 "Subscription known after addition"); |
| 123 | 138 |
| 124 changes = []; | 139 changes = []; |
| 125 FilterStorage.removeSubscription(subscription1); | 140 FilterStorage.removeSubscription(subscription1); |
| 126 compareSubscriptionList(test, "Removing first subscription", [subscription2]); | 141 compareSubscriptionList(test, "Removing first subscription", [subscription2], |
| 142 [subscription2]); |
| 127 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan
ges"); | 143 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan
ges"); |
| 128 | 144 |
| 145 // Once a subscription has been removed, it is forgotten; a new object is |
| 146 // created for the previously known subscription URL. |
| 147 test.notEqual(Subscription.fromURL(subscription1.url), subscription1, |
| 148 "Subscription forgotten upon removal"); |
| 149 Subscription.knownSubscriptions.delete(subscription1.url); |
| 150 |
| 129 changes = []; | 151 changes = []; |
| 130 FilterStorage.removeSubscription(subscription1); | 152 FilterStorage.removeSubscription(subscription1); |
| 131 compareSubscriptionList(test, "Removing already removed subscription", [subscr
iption2]); | 153 compareSubscriptionList(test, "Removing already removed subscription", [subscr
iption2], |
| 154 [subscription2]); |
| 132 test.deepEqual(changes, [], "Received changes"); | 155 test.deepEqual(changes, [], "Received changes"); |
| 133 | 156 |
| 134 changes = []; | 157 changes = []; |
| 135 FilterStorage.removeSubscription(subscription2); | 158 FilterStorage.removeSubscription(subscription2); |
| 136 compareSubscriptionList(test, "Removing remaining subscription", []); | 159 compareSubscriptionList(test, "Removing remaining subscription", [], []); |
| 137 test.deepEqual(changes, ["subscription.removed http://test2/"], "Received chan
ges"); | 160 test.deepEqual(changes, ["subscription.removed http://test2/"], "Received chan
ges"); |
| 138 | 161 |
| 139 FilterStorage.addSubscription(subscription1); | 162 FilterStorage.addSubscription(subscription1); |
| 140 compareSubscriptionList(test, "Add", [subscription1]); | 163 compareSubscriptionList(test, "Add", [subscription1], []); |
| 141 | 164 |
| 142 changes = []; | 165 changes = []; |
| 143 FilterStorage.removeSubscription(subscription1); | 166 FilterStorage.removeSubscription(subscription1); |
| 144 compareSubscriptionList(test, "Re-removing previously added subscription", [])
; | 167 compareSubscriptionList(test, "Re-removing previously added subscription", [],
[]); |
| 145 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan
ges"); | 168 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan
ges"); |
| 146 | 169 |
| 147 test.done(); | 170 test.done(); |
| 148 }; | 171 }; |
| 149 | 172 |
| 150 exports.testMovingSubscriptions = function(test) | 173 exports.testMovingSubscriptions = function(test) |
| 151 { | 174 { |
| 152 let subscription1 = Subscription.fromURL("http://test1/"); | 175 let subscription1 = Subscription.fromURL("http://test1/"); |
| 153 let subscription2 = Subscription.fromURL("http://test2/"); | 176 let subscription2 = Subscription.fromURL("http://test2/"); |
| 154 let subscription3 = Subscription.fromURL("http://test3/"); | 177 let subscription3 = Subscription.fromURL("http://test3/"); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 compareFilterSubscriptions(test, "filter3 subscriptions after updating http://
test3/ filters", filter3, [subscription2]); | 514 compareFilterSubscriptions(test, "filter3 subscriptions after updating http://
test3/ filters", filter3, [subscription2]); |
| 492 | 515 |
| 493 FilterStorage.removeSubscription(subscription3); | 516 FilterStorage.removeSubscription(subscription3); |
| 494 | 517 |
| 495 compareFilterSubscriptions(test, "filter1 subscriptions after removing http://
test3/", filter1, []); | 518 compareFilterSubscriptions(test, "filter1 subscriptions after removing http://
test3/", filter1, []); |
| 496 compareFilterSubscriptions(test, "filter2 subscriptions after removing http://
test3/", filter2, [subscription2]); | 519 compareFilterSubscriptions(test, "filter2 subscriptions after removing http://
test3/", filter2, [subscription2]); |
| 497 compareFilterSubscriptions(test, "filter3 subscriptions after removing http://
test3/", filter3, [subscription2]); | 520 compareFilterSubscriptions(test, "filter3 subscriptions after removing http://
test3/", filter3, [subscription2]); |
| 498 | 521 |
| 499 test.done(); | 522 test.done(); |
| 500 }; | 523 }; |
| LEFT | RIGHT |