Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: qunit/tests/indexedDBBackup.js

Issue 29860578: Issue 6775 - Work around filter data stored in IndexedDB getting lost on Microsoft Edge (Closed)
Left Patch Set: Created Sept. 4, 2018, 4:07 p.m.
Right Patch Set: Created Sept. 5, 2018, 3:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « metadata.edge ('k') | qunit/tests/ioIndexedDB.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 writeTime = 0; 11 let backupDelay = 100;
12 let writeInterval = 100;
13 let subscription = Subscription.fromObject({ 12 let subscription = Subscription.fromObject({
14 title: "test", 13 title: "test",
15 url: "test.com", 14 url: "test.com",
16 homepage: "example.com", 15 homepage: "example.com",
17 lastSuccess: 8, 16 lastSuccess: 8,
18 disabled: false, 17 disabled: false,
19 lastDownload: 12, 18 lastDownload: 12,
20 lastCheck: 16, 19 lastCheck: 16,
21 softExpiration: 18, 20 softExpiration: 18,
22 expires: 20, 21 expires: 20,
23 downloadStatus: "done", 22 downloadStatus: "done",
24 errors: 3, 23 errors: 3,
25 version: 24, 24 version: 24,
26 downloadCount: 1, 25 downloadCount: 1,
27 requiredVersion: "0.6" 26 requiredVersion: "0.6"
28 }); 27 });
29 let filter = Filter.fromText("example.com"); 28 let filter = Filter.fromText("example.com");
30 let specialSubscription = SpecialSubscription.createForFilter(filter); 29 let specialSubscription = SpecialSubscription.createForFilter(filter);
31 30
32 let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip; 31 let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip;
33 32
34 QUnit.module("Microsoft Edge indexedDB backup", { 33 QUnit.module("Microsoft Edge indexedDB backup", {
35 beforeEach() 34 beforeEach()
36 { 35 {
37 this._storageLocalSet = browser.storage.local.set; 36 this._storageLocalSet = browser.storage.local.set;
38 IndexedDBBackup.setBackupInterval(writeInterval); 37 IndexedDBBackup.setBackupInterval(backupDelay);
39 }, 38 },
40 afterEach() 39 afterEach()
41 { 40 {
42 Object.defineProperty( 41 Object.defineProperty(
43 browser.storage.local, "set", 42 browser.storage.local, "set",
44 {value: this._storageLocalSet, enumerable: true}); 43 {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.
44 );
45 IndexedDBBackup.setBackupInterval(); 45 IndexedDBBackup.setBackupInterval();
46 } 46 }
47 }); 47 });
48 48
49 testEdge("Write time smaller than backup interval", assert => 49 testEdge("Backup creation", assert =>
50 { 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); 51 testSaveSteps(assert);
59 }); 52 });
60 53
61 function testSaveSteps(assert) 54 function testSaveSteps(assert)
62 { 55 {
63 let start = performance.now(); 56 let start = performance.now();
64 let saveTimes = []; 57 let saveTimes = [];
65 58
66 let steps = [ 59 let steps = [
67 { 60 {
68 done: assert.async(), 61 done: assert.async(),
69 check(data) 62 check(data)
70 { 63 {
71 let expectedFormat = [ 64 let expectedFormat = [
72 "[Subscription]", 65 "[Subscription]",
73 `url=${specialSubscription.url}`, 66 `url=${specialSubscription.url}`,
74 "defaults=blocking", 67 "defaults=blocking",
75 "[Subscription filters]", 68 "[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", 69 "example.com",
97 "[Subscription]", 70 "[Subscription]",
98 "homepage=example.com", 71 "homepage=example.com",
99 "title=test", 72 "title=test",
100 "url=test.com", 73 "url=test.com",
101 "disabled=false" 74 "disabled=false"
102 ]; 75 ];
103 ok(data.lastModified - saveTimes[0] >= writeInterval, 76
104 "next change is after the time limit"); 77 ok(
78 saveTimes[0] - start >= backupDelay,
79 "first write is deferred"
80 );
105 deepEqual( 81 deepEqual(
106 data.content, expectedFormat, "data is formatted correctly"); 82 data.content,
83 expectedFormat,
84 "saved data has the correct information"
85 );
107 86
108 FilterStorage.removeSubscription(subscription); 87 FilterStorage.removeSubscription(subscription);
109 FilterStorage.removeSubscription(specialSubscription); 88 FilterStorage.removeSubscription(specialSubscription);
110 } 89 }
111 }, 90 },
112 { 91 {
113 done: assert.async(), 92 done: assert.async(),
114 check(data) 93 check(data)
115 { 94 {
95 ok(
96 saveTimes[1] - saveTimes[0] >= backupDelay,
97 "next changes are saved after the write delay"
98 );
116 deepEqual( 99 deepEqual(
117 data.content, [], "multiple changes are treated in one write"); 100 data.content, [], "saved data has the correct information"
101 );
118 } 102 }
119 } 103 }
120 ]; 104 ];
121 let mockSave = (data) => 105 let mockSave = data =>
122 { 106 {
123 return new Promise(resolve => 107 let step = steps.shift();
108
109 saveTimes.push(performance.now());
110
111 setTimeout(() =>
geo 2018/09/05 15:59:08 I've reintroduced this timeout because without it,
124 { 112 {
125 setTimeout(() => 113 step.check(data["file:indexedDB-backup"]);
126 { 114 step.done();
127 let step = steps.shift(); 115 }, 0);
128 saveTimes.push(performance.now());
129 step.check(data["file:indexedDB-backup"]);
130 step.done();
131 resolve();
132 }, writeTime);
133 });
134 }; 116 };
135 117
136 Object.defineProperty( 118 Object.defineProperty(
137 browser.storage.local, "set", 119 browser.storage.local, "set",
138 {value: mockSave, enumerable: true}); 120 {value: mockSave, enumerable: true}
121 );
139 122
140 FilterStorage.addSubscription(specialSubscription); 123 FilterStorage.addSubscription(specialSubscription);
124 FilterStorage.addSubscription(subscription);
141 } 125 }
142 } 126 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld