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

Side by Side Diff: qunit/tests/indexedDBBackup.js

Issue 29860578: Issue 6775 - Work around filter data stored in IndexedDB getting lost on Microsoft Edge (Closed)
Patch Set: Created Aug. 31, 2018, 3:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(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.init(writeInterval);
39 },
40 afterEach()
41 {
42 Object.defineProperty(
43 browser.storage.local, "set",
44 {value: this._storageLocalSet, enumerable: true});
45 IndexedDBBackup.init();
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 ok(start - data.lastModified < writeInterval,
79 "first change is proccessed immediately");
80 deepEqual(
81 data.content, expectedFormat, "data is formatted correctly");
82 }
83 },
84 {
85 done: assert.async(),
86 check(data)
87 {
88 let expectedFormat = [
89 "[Subscription]",
90 `url=${specialSubscription.url}`,
91 "defaults=blocking",
92 "[Subscription filters]",
93 "example.com",
94 "[Subscription]",
95 "homepage=example.com",
96 "title=test",
97 "url=test.com",
98 "disabled=false"
99 ];
100 ok(data.lastModified - saveTimes[0] >= writeInterval,
101 "next change is after the time limit");
102 deepEqual(
103 data.content, expectedFormat, "data is formatted correctly");
104
105 FilterStorage.removeSubscription(subscription);
106 FilterStorage.removeSubscription(specialSubscription);
107 }
108 },
109 {
110 done: assert.async(),
111 check(data)
112 {
113 deepEqual(
114 data.content, [], "multiple changes are treated in one write");
115 }
116 }
117 ];
118 let mockSave = (data) =>
119 {
120 return new Promise(resolve =>
121 {
122 setTimeout(() =>
123 {
124 saveTimes.push(performance.now());
125 let step = steps.shift();
126 step.check(data["file:indexedDB-backup"]);
127 step.done();
128 resolve();
129 }, writeTime);
130 });
131 };
132
133 Object.defineProperty(
134 browser.storage.local, "set",
135 {value: mockSave, enumerable: true});
136
137 FilterStorage.addSubscription(specialSubscription);
138 FilterStorage.addSubscription(subscription);
139 }
140 }
OLDNEW
« lib/ioIndexedDB.js ('K') | « metadata.edge ('k') | qunit/tests/ioIndexedDB.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld