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 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 FilterStorage.addSubscription(subscription2); | 118 FilterStorage.addSubscription(subscription2); |
112 | 119 |
113 let changes = []; | 120 let changes = []; |
114 function listener(action, subscription) | 121 function listener(action, subscription) |
115 { | 122 { |
116 if (action.indexOf("subscription.") == 0) | 123 if (action.indexOf("subscription.") == 0) |
117 changes.push(action + " " + subscription.url); | 124 changes.push(action + " " + subscription.url); |
118 } | 125 } |
119 FilterNotifier.addListener(listener); | 126 FilterNotifier.addListener(listener); |
120 | 127 |
121 compareSubscriptionList(test, "Initial state", [subscription1, subscription2])
; | 128 compareSubscriptionList(test, "Initial state", [subscription1, subscription2], |
| 129 [subscription1, subscription2]); |
122 test.deepEqual(changes, [], "Received changes"); | 130 test.deepEqual(changes, [], "Received changes"); |
123 | 131 |
124 changes = []; | 132 changes = []; |
125 FilterStorage.removeSubscription(subscription1); | 133 FilterStorage.removeSubscription(subscription1); |
126 compareSubscriptionList(test, "Removing first subscription", [subscription2]); | 134 compareSubscriptionList(test, "Removing first subscription", [subscription2], |
| 135 [subscription2]); |
127 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan
ges"); | 136 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan
ges"); |
128 | 137 |
129 changes = []; | 138 changes = []; |
130 FilterStorage.removeSubscription(subscription1); | 139 FilterStorage.removeSubscription(subscription1); |
131 compareSubscriptionList(test, "Removing already removed subscription", [subscr
iption2]); | 140 compareSubscriptionList(test, "Removing already removed subscription", [subscr
iption2], |
| 141 [subscription2]); |
132 test.deepEqual(changes, [], "Received changes"); | 142 test.deepEqual(changes, [], "Received changes"); |
133 | 143 |
134 changes = []; | 144 changes = []; |
135 FilterStorage.removeSubscription(subscription2); | 145 FilterStorage.removeSubscription(subscription2); |
136 compareSubscriptionList(test, "Removing remaining subscription", []); | 146 compareSubscriptionList(test, "Removing remaining subscription", [], []); |
137 test.deepEqual(changes, ["subscription.removed http://test2/"], "Received chan
ges"); | 147 test.deepEqual(changes, ["subscription.removed http://test2/"], "Received chan
ges"); |
138 | 148 |
| 149 // Compare references to make sure that a new object is created for the same |
| 150 // subscription URL. |
| 151 test.notEqual(Subscription.fromURL(subscription2.url), subscription2, |
| 152 "Subscription forgotten"); |
| 153 |
| 154 // Adding a removed Subscription object back still works but is not |
| 155 // recommended. |
139 FilterStorage.addSubscription(subscription1); | 156 FilterStorage.addSubscription(subscription1); |
140 compareSubscriptionList(test, "Add", [subscription1]); | 157 compareSubscriptionList(test, "Add", [subscription1]); |
141 | 158 |
142 changes = []; | 159 changes = []; |
143 FilterStorage.removeSubscription(subscription1); | 160 FilterStorage.removeSubscription(subscription1); |
144 compareSubscriptionList(test, "Re-removing previously added subscription", [])
; | 161 compareSubscriptionList(test, "Re-removing previously added subscription", [])
; |
145 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan
ges"); | 162 test.deepEqual(changes, ["subscription.removed http://test1/"], "Received chan
ges"); |
146 | 163 |
147 test.done(); | 164 test.done(); |
148 }; | 165 }; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 compareFilterSubscriptions(test, "filter3 subscriptions after updating http://
test3/ filters", filter3, [subscription2]); | 508 compareFilterSubscriptions(test, "filter3 subscriptions after updating http://
test3/ filters", filter3, [subscription2]); |
492 | 509 |
493 FilterStorage.removeSubscription(subscription3); | 510 FilterStorage.removeSubscription(subscription3); |
494 | 511 |
495 compareFilterSubscriptions(test, "filter1 subscriptions after removing http://
test3/", filter1, []); | 512 compareFilterSubscriptions(test, "filter1 subscriptions after removing http://
test3/", filter1, []); |
496 compareFilterSubscriptions(test, "filter2 subscriptions after removing http://
test3/", filter2, [subscription2]); | 513 compareFilterSubscriptions(test, "filter2 subscriptions after removing http://
test3/", filter2, [subscription2]); |
497 compareFilterSubscriptions(test, "filter3 subscriptions after removing http://
test3/", filter3, [subscription2]); | 514 compareFilterSubscriptions(test, "filter3 subscriptions after removing http://
test3/", filter3, [subscription2]); |
498 | 515 |
499 test.done(); | 516 test.done(); |
500 }; | 517 }; |
OLD | NEW |