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. 21, 2018, 4:40 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 {Filter} = require("../../adblockpluscore/lib/filterClasses");
7 const {Subscription, SpecialSubscription} =
8 require("../../adblockpluscore/lib/subscriptionClasses");
9
10 let writeTime = 0;
11 let writeInterval = 100;
12
13 let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip;
14
15 QUnit.module("Microsoft Edge indexedDB backup", {
16 afterEach()
17 {
18 IndexedDBBackup.init();
19 }
20 });
21
22 testEdge("Data serialization", () =>
23 {
24 let subscription = Subscription.fromObject({
25 title: "test",
26 url: "test.com",
27 homepage: "example.com",
28 disabled: false,
29 lastSuccess: 8,
30 lastDownload: 12,
31 lastCheck: 16,
32 softExpiration: 18,
33 expires: 20,
34 downloadStatus: "done",
35 errors: 3,
36 version: 24,
37 downloadCount: 1,
38 requiredVersion: "0.6"
39 });
40 let filter = Filter.fromText("example.com");
41 let specialSubscription = SpecialSubscription.createForFilter(filter);
42
43 let expectedFormat = [
44 "",
45 "[Subscription]",
46 `homepage=${subscription.homepage}`,
47 `title=${subscription.title}`,
48 `url=${subscription.url}`,
49 `disabled=${subscription.disabled}`,
50 "",
51 "[Subscription]",
52 `url=${specialSubscription.url}`,
53 "defaults=blocking",
54 "",
55 "[Subscription filters]",
56 "example.com"
57 ];
58 let actualFormat = IndexedDBBackup.serialize([
59 subscription,
60 specialSubscription
61 ]);
62 deepEqual(actualFormat, expectedFormat, "formates the data correctly");
Sebastian Noack 2018/08/21 20:26:25 Maybe we should test the serialization as part of
geo 2018/08/31 15:49:25 Done.
63 });
64
65 testEdge("Write time smaller than backup interval", assert =>
66 {
67 writeTime = 10;
68 testSaveSteps(assert);
69 });
70
71 testEdge("Write time greater than backup interval", assert =>
72 {
73 writeTime = 150;
74 testSaveSteps(assert);
75 });
76
77 function testSaveSteps(assert)
78 {
79 let start = performance.now();
80 let saveTimes = [];
81 let steps = [
82 {
83 done: assert.async(),
84 check()
85 {
86 ok(start - saveTimes[0].start < writeInterval,
87 "first change is proccessed imediatelly");
88 }
89 },
90 {
91 done: assert.async(),
92 check()
93 {
94 ok(saveTimes[1].start - saveTimes[0].end >= writeInterval,
95 "next change is after the time limit");
96 }
97 }
98 ];
99 let mockSave = () =>
100 {
101 saveTimes.push({start: performance.now()});
102 return new Promise(resolve =>
103 {
104 setTimeout(() =>
105 {
106 saveTimes[saveTimes.length - 1].end = performance.now();
107 let step = steps.shift();
108 step.check();
109 step.done();
110 resolve();
111 }, writeTime);
112 });
113 };
114
115 IndexedDBBackup.init(writeInterval, mockSave);
116 IndexedDBBackup.scheduleBackup();
117 setTimeout(IndexedDBBackup.scheduleBackup, writeTime / 2);
118 setTimeout(IndexedDBBackup.scheduleBackup, writeInterval);
119 }
120 }
OLDNEW
« metadata.edge ('K') | « metadata.edge ('k') | qunit/tests/ioIndexedDB.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld