| LEFT | RIGHT |
| 1 "use strict"; | 1 "use strict"; |
| 2 | 2 |
| 3 { | 3 { |
| 4 const {IndexedDBBackup} = require("../../lib/indexedDBBackup"); | 4 const {IndexedDBBackup} = require("../../lib/indexedDBBackup"); |
| 5 const info = require("info"); | 5 const info = require("info"); |
| 6 const {FilterStorage} = require("../../adblockpluscore/lib/filterStorage"); | 6 const {FilterStorage} = require("../../adblockpluscore/lib/filterStorage"); |
| 7 const {Filter} = require("../../adblockpluscore/lib/filterClasses"); | 7 const {Filter} = require("../../adblockpluscore/lib/filterClasses"); |
| 8 const {Subscription, SpecialSubscription} = | 8 const {Subscription, SpecialSubscription} = |
| 9 require("../../adblockpluscore/lib/subscriptionClasses"); | 9 require("../../adblockpluscore/lib/subscriptionClasses"); |
| 10 | 10 |
| 11 let writeInterval = 100; | 11 let backupDelay = 100; |
| 12 let subscription = Subscription.fromObject({ | 12 let subscription = Subscription.fromObject({ |
| 13 title: "test", | 13 title: "test", |
| 14 url: "test.com", | 14 url: "test.com", |
| 15 homepage: "example.com", | 15 homepage: "example.com", |
| 16 lastSuccess: 8, | 16 lastSuccess: 8, |
| 17 disabled: false, | 17 disabled: false, |
| 18 lastDownload: 12, | 18 lastDownload: 12, |
| 19 lastCheck: 16, | 19 lastCheck: 16, |
| 20 softExpiration: 18, | 20 softExpiration: 18, |
| 21 expires: 20, | 21 expires: 20, |
| 22 downloadStatus: "done", | 22 downloadStatus: "done", |
| 23 errors: 3, | 23 errors: 3, |
| 24 version: 24, | 24 version: 24, |
| 25 downloadCount: 1, | 25 downloadCount: 1, |
| 26 requiredVersion: "0.6" | 26 requiredVersion: "0.6" |
| 27 }); | 27 }); |
| 28 let filter = Filter.fromText("example.com"); | 28 let filter = Filter.fromText("example.com"); |
| 29 let specialSubscription = SpecialSubscription.createForFilter(filter); | 29 let specialSubscription = SpecialSubscription.createForFilter(filter); |
| 30 | 30 |
| 31 let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip; | 31 let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip; |
| 32 | 32 |
| 33 QUnit.module("Microsoft Edge indexedDB backup", { | 33 QUnit.module("Microsoft Edge indexedDB backup", { |
| 34 beforeEach() | 34 beforeEach() |
| 35 { | 35 { |
| 36 this._storageLocalSet = browser.storage.local.set; | 36 this._storageLocalSet = browser.storage.local.set; |
| 37 IndexedDBBackup.setBackupInterval(writeInterval); | 37 IndexedDBBackup.setBackupInterval(backupDelay); |
| 38 }, | 38 }, |
| 39 afterEach() | 39 afterEach() |
| 40 { | 40 { |
| 41 Object.defineProperty( | 41 Object.defineProperty( |
| 42 browser.storage.local, "set", | 42 browser.storage.local, "set", |
| 43 {value: this._storageLocalSet, enumerable: true} | 43 {value: this._storageLocalSet, enumerable: true} |
| 44 ); | 44 ); |
| 45 IndexedDBBackup.setBackupInterval(); | 45 IndexedDBBackup.setBackupInterval(); |
| 46 } | 46 } |
| 47 }); | 47 }); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 68 "[Subscription filters]", | 68 "[Subscription filters]", |
| 69 "example.com", | 69 "example.com", |
| 70 "[Subscription]", | 70 "[Subscription]", |
| 71 "homepage=example.com", | 71 "homepage=example.com", |
| 72 "title=test", | 72 "title=test", |
| 73 "url=test.com", | 73 "url=test.com", |
| 74 "disabled=false" | 74 "disabled=false" |
| 75 ]; | 75 ]; |
| 76 | 76 |
| 77 ok( | 77 ok( |
| 78 saveTimes[0] - start >= writeInterval, | 78 saveTimes[0] - start >= backupDelay, |
| 79 "first write is deferred" | 79 "first write is deferred" |
| 80 ); | 80 ); |
| 81 deepEqual( | 81 deepEqual( |
| 82 data.content, | 82 data.content, |
| 83 expectedFormat, | 83 expectedFormat, |
| 84 "saved data has the correct information" | 84 "saved data has the correct information" |
| 85 ); | 85 ); |
| 86 | 86 |
| 87 FilterStorage.removeSubscription(subscription); | 87 FilterStorage.removeSubscription(subscription); |
| 88 FilterStorage.removeSubscription(specialSubscription); | 88 FilterStorage.removeSubscription(specialSubscription); |
| 89 } | 89 } |
| 90 }, | 90 }, |
| 91 { | 91 { |
| 92 done: assert.async(), | 92 done: assert.async(), |
| 93 check(data) | 93 check(data) |
| 94 { | 94 { |
| 95 ok( | 95 ok( |
| 96 saveTimes[1] - saveTimes[0] >= writeInterval, | 96 saveTimes[1] - saveTimes[0] >= backupDelay, |
| 97 "next changes are saved after the write delay" | 97 "next changes are saved after the write delay" |
| 98 ); | 98 ); |
| 99 deepEqual( | 99 deepEqual( |
| 100 data.content, [], "saved data has the correct information" | 100 data.content, [], "saved data has the correct information" |
| 101 ); | 101 ); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 ]; | 104 ]; |
| 105 let mockSave = data => | 105 let mockSave = data => |
| 106 { | 106 { |
| 107 let step = steps.shift(); | 107 let step = steps.shift(); |
| 108 | 108 |
| 109 saveTimes.push(performance.now()); | 109 saveTimes.push(performance.now()); |
| 110 step.check(data["file:indexedDB-backup"]); | 110 |
| 111 step.done(); | 111 setTimeout(() => |
| 112 { |
| 113 step.check(data["file:indexedDB-backup"]); |
| 114 step.done(); |
| 115 }, 0); |
| 112 }; | 116 }; |
| 113 | 117 |
| 114 Object.defineProperty( | 118 Object.defineProperty( |
| 115 browser.storage.local, "set", | 119 browser.storage.local, "set", |
| 116 {value: mockSave, enumerable: true} | 120 {value: mockSave, enumerable: true} |
| 117 ); | 121 ); |
| 118 | 122 |
| 119 FilterStorage.addSubscription(specialSubscription); | 123 FilterStorage.addSubscription(specialSubscription); |
| 120 FilterStorage.addSubscription(subscription); | 124 FilterStorage.addSubscription(subscription); |
| 121 } | 125 } |
| 122 } | 126 } |
| LEFT | RIGHT |