| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 "use strict"; | |
| 2 | |
| 3 { | |
| 4 const {IndexedDBBackup} = require("../../lib/indexedDBBackup"); | |
| 5 const info = require("info"); | |
| 6 const {FilterStorage} = require("../../adblockpluscore/lib/filterStorage"); | |
| 7 const {Filter} = require("../../adblockpluscore/lib/filterClasses"); | |
| 8 const {Subscription, SpecialSubscription} = | |
| 9 require("../../adblockpluscore/lib/subscriptionClasses"); | |
| 10 | |
| 11 let writeTime = 0; | |
| 12 let writeInterval = 100; | |
| 13 let subscription = Subscription.fromObject({ | |
| 14 title: "test", | |
| 15 url: "test.com", | |
| 16 homepage: "example.com", | |
| 17 lastSuccess: 8, | |
| 18 disabled: false, | |
| 19 lastDownload: 12, | |
| 20 lastCheck: 16, | |
| 21 softExpiration: 18, | |
| 22 expires: 20, | |
| 23 downloadStatus: "done", | |
| 24 errors: 3, | |
| 25 version: 24, | |
| 26 downloadCount: 1, | |
| 27 requiredVersion: "0.6" | |
| 28 }); | |
| 29 let filter = Filter.fromText("example.com"); | |
| 30 let specialSubscription = SpecialSubscription.createForFilter(filter); | |
| 31 | |
| 32 let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip; | |
| 33 | |
| 34 QUnit.module("Microsoft Edge indexedDB backup", { | |
| 35 beforeEach() | |
| 36 { | |
| 37 this._storageLocalSet = browser.storage.local.set; | |
| 38 IndexedDBBackup.setBackupInterval(writeInterval); | |
| 39 }, | |
| 40 afterEach() | |
| 41 { | |
| 42 Object.defineProperty( | |
| 43 browser.storage.local, "set", | |
| 44 {value: this._storageLocalSet, enumerable: true}); | |
|
Sebastian Noack
2018/09/04 21:00:01
Nit: See previous comment(s) about wrapping argume
geo
2018/09/05 14:04:34
Done.
| |
| 45 IndexedDBBackup.setBackupInterval(); | |
| 46 } | |
| 47 }); | |
| 48 | |
| 49 testEdge("Write time smaller than backup interval", assert => | |
| 50 { | |
| 51 writeTime = 10; | |
| 52 testSaveSteps(assert); | |
| 53 }); | |
| 54 | |
| 55 testEdge("Write time greater than backup interval", assert => | |
| 56 { | |
| 57 writeTime = 150; | |
| 58 testSaveSteps(assert); | |
| 59 }); | |
| 60 | |
| 61 function testSaveSteps(assert) | |
| 62 { | |
| 63 let start = performance.now(); | |
| 64 let saveTimes = []; | |
| 65 | |
| 66 let steps = [ | |
| 67 { | |
| 68 done: assert.async(), | |
| 69 check(data) | |
| 70 { | |
| 71 let expectedFormat = [ | |
| 72 "[Subscription]", | |
| 73 `url=${specialSubscription.url}`, | |
| 74 "defaults=blocking", | |
| 75 "[Subscription filters]", | |
| 76 "example.com" | |
| 77 ]; | |
| 78 | |
| 79 ok(start - data.lastModified < writeInterval, | |
| 80 "first change is proccessed immediately"); | |
| 81 deepEqual( | |
| 82 data.content, expectedFormat, "data is formatted correctly"); | |
| 83 | |
| 84 FilterStorage.addSubscription(subscription); | |
| 85 } | |
| 86 }, | |
| 87 { | |
| 88 done: assert.async(), | |
| 89 check(data) | |
| 90 { | |
| 91 let expectedFormat = [ | |
| 92 "[Subscription]", | |
| 93 `url=${specialSubscription.url}`, | |
| 94 "defaults=blocking", | |
| 95 "[Subscription filters]", | |
| 96 "example.com", | |
| 97 "[Subscription]", | |
| 98 "homepage=example.com", | |
| 99 "title=test", | |
| 100 "url=test.com", | |
| 101 "disabled=false" | |
| 102 ]; | |
| 103 ok(data.lastModified - saveTimes[0] >= writeInterval, | |
| 104 "next change is after the time limit"); | |
| 105 deepEqual( | |
| 106 data.content, expectedFormat, "data is formatted correctly"); | |
| 107 | |
| 108 FilterStorage.removeSubscription(subscription); | |
| 109 FilterStorage.removeSubscription(specialSubscription); | |
| 110 } | |
| 111 }, | |
| 112 { | |
| 113 done: assert.async(), | |
| 114 check(data) | |
| 115 { | |
| 116 deepEqual( | |
| 117 data.content, [], "multiple changes are treated in one write"); | |
| 118 } | |
| 119 } | |
| 120 ]; | |
| 121 let mockSave = (data) => | |
| 122 { | |
| 123 return new Promise(resolve => | |
| 124 { | |
| 125 setTimeout(() => | |
| 126 { | |
| 127 let step = steps.shift(); | |
| 128 saveTimes.push(performance.now()); | |
| 129 step.check(data["file:indexedDB-backup"]); | |
| 130 step.done(); | |
| 131 resolve(); | |
| 132 }, writeTime); | |
| 133 }); | |
| 134 }; | |
| 135 | |
| 136 Object.defineProperty( | |
| 137 browser.storage.local, "set", | |
| 138 {value: mockSave, enumerable: true}); | |
| 139 | |
| 140 FilterStorage.addSubscription(specialSubscription); | |
| 141 } | |
| 142 } | |
| OLD | NEW |