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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 subscription1.delete(); | 158 subscription1.delete(); |
159 subscription2.delete(); | 159 subscription2.delete(); |
160 | 160 |
161 let subscription3 = Subscription.fromURL("http://example.com/"); | 161 let subscription3 = Subscription.fromURL("http://example.com/"); |
162 test.equal(subscription3.lastDownload, 0, "Subscription data has been reset on
ce previous instances have been released"); | 162 test.equal(subscription3.lastDownload, 0, "Subscription data has been reset on
ce previous instances have been released"); |
163 subscription3.delete(); | 163 subscription3.delete(); |
164 | 164 |
165 test.done(); | 165 test.done(); |
166 }; | 166 }; |
| 167 |
| 168 exports.testDownloadableSubscriptionFilters = function(test) |
| 169 { |
| 170 let filter = Filter.fromText("test"); |
| 171 |
| 172 let subscription = Subscription.fromURL("http://example.com/"); |
| 173 test.equal(subscription.filterCount, 0, "Initial filter count"); |
| 174 test.equal(subscription.filterAt(0), null, "Retrieving non-existent filter"); |
| 175 test.equal(subscription.indexOfFilter(filter), -1, "Index of non-existent filt
er"); |
| 176 |
| 177 subscription.delete(); |
| 178 filter.delete(); |
| 179 |
| 180 test.done(); |
| 181 }; |
| 182 |
| 183 exports.testSpecialSubscriptionFilters = function(test) |
| 184 { |
| 185 let filter1 = Filter.fromText("filter1"); |
| 186 let filter2 = Filter.fromText("filter2"); |
| 187 let subscription = Subscription.fromURL("~user~12345"); |
| 188 |
| 189 function checkFilterAt(pos, expected, message) |
| 190 { |
| 191 let filter = subscription.filterAt(pos); |
| 192 test.equal(filter && filter.text, expected, message); |
| 193 if (filter) |
| 194 filter.delete(); |
| 195 } |
| 196 |
| 197 test.equal(subscription.filterCount, 0, "Initial filter count"); |
| 198 checkFilterAt(0, null, "Retrieving non-existent filter"); |
| 199 test.equal(subscription.indexOfFilter(filter1), -1, "Index of non-existent fil
ter"); |
| 200 |
| 201 subscription.insertFilterAt(filter1, 0); |
| 202 test.equal(subscription.filterCount, 1, "Filter count after insert"); |
| 203 checkFilterAt(0, filter1.text, "First filter after insert"); |
| 204 checkFilterAt(1, null, "Retrieving non-existent filter"); |
| 205 test.equal(subscription.indexOfFilter(filter1), 0, "Index of existent filter")
; |
| 206 test.equal(subscription.indexOfFilter(filter2), -1, "Index of non-existent fil
ter"); |
| 207 |
| 208 subscription.insertFilterAt(filter2, 0); |
| 209 test.equal(subscription.filterCount, 2, "Filter count after second insert"); |
| 210 checkFilterAt(0, filter2.text, "First filter after second insert"); |
| 211 checkFilterAt(1, filter1.text, "Second filter after second insert"); |
| 212 test.equal(subscription.indexOfFilter(filter1), 1, "Index of first filter"); |
| 213 test.equal(subscription.indexOfFilter(filter2), 0, "Index of second filter"); |
| 214 |
| 215 subscription.insertFilterAt(filter1, 1); |
| 216 test.equal(subscription.filterCount, 3, "Filter count after inserting duplicat
e filter"); |
| 217 checkFilterAt(0, filter2.text, "First filter after inserting duplicate filter"
); |
| 218 checkFilterAt(1, filter1.text, "Second filter after inserting duplicate filter
"); |
| 219 checkFilterAt(2, filter1.text, "Third filter after inserting duplicate filter"
); |
| 220 test.equal(subscription.indexOfFilter(filter1), 1, "Index of first filter"); |
| 221 |
| 222 subscription.removeFilterAt(1); |
| 223 test.equal(subscription.filterCount, 2, "Filter count after remove"); |
| 224 checkFilterAt(0, filter2.text, "First filter after remove"); |
| 225 checkFilterAt(1, filter1.text, "Second filter after remove"); |
| 226 test.equal(subscription.indexOfFilter(filter1), 1, "Index of first filter"); |
| 227 |
| 228 filter1.delete(); |
| 229 filter2.delete(); |
| 230 Filter.fromText("dummy overwriting some released memory").delete(); |
| 231 checkFilterAt(0, "filter2", "First filter after releasing filter references"); |
| 232 checkFilterAt(1, "filter1", "Second filter after releasing filter references")
; |
| 233 |
| 234 subscription.delete(); |
| 235 |
| 236 test.done(); |
| 237 }; |
| 238 |
| 239 exports.testFilterSerialization = function(test) |
| 240 { |
| 241 let filter1 = Filter.fromText("filter1"); |
| 242 let filter2 = Filter.fromText("filter2"); |
| 243 |
| 244 let subscription = Subscription.fromURL("~user~12345"); |
| 245 test.equal(subscription.serializeFilters(), "", "No filters added"); |
| 246 |
| 247 subscription.insertFilterAt(filter1, 0); |
| 248 subscription.insertFilterAt(filter1, 1); |
| 249 subscription.insertFilterAt(filter2, 1); |
| 250 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter1\n
filter2\nfilter1\n", "Three filters added"); |
| 251 |
| 252 subscription.removeFilterAt(0); |
| 253 test.equal(subscription.serializeFilters(), "[Subscription filters]\nfilter2\n
filter1\n", "One filter removed"); |
| 254 |
| 255 subscription.delete(); |
| 256 filter1.delete(); |
| 257 filter2.delete(); |
| 258 |
| 259 test.done(); |
| 260 }; |
OLD | NEW |