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 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:
View unified diff | Download patch
« no previous file with comments | « metadata.edge ('k') | qunit/tests/ioIndexedDB.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 backupDelay = 100;
12 let subscription = Subscription.fromObject({
13 title: "test",
14 url: "test.com",
15 homepage: "example.com",
16 lastSuccess: 8,
17 disabled: false,
18 lastDownload: 12,
19 lastCheck: 16,
20 softExpiration: 18,
21 expires: 20,
22 downloadStatus: "done",
23 errors: 3,
24 version: 24,
25 downloadCount: 1,
26 requiredVersion: "0.6"
27 });
28 let filter = Filter.fromText("example.com");
29 let specialSubscription = SpecialSubscription.createForFilter(filter);
30
31 let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip;
32
33 QUnit.module("Microsoft Edge indexedDB backup", {
34 beforeEach()
35 {
36 this._storageLocalSet = browser.storage.local.set;
37 IndexedDBBackup.setBackupInterval(backupDelay);
38 },
39 afterEach()
40 {
41 Object.defineProperty(
42 browser.storage.local, "set",
43 {value: this._storageLocalSet, enumerable: true}
44 );
45 IndexedDBBackup.setBackupInterval();
46 }
47 });
48
49 testEdge("Backup creation", assert =>
50 {
51 testSaveSteps(assert);
52 });
53
54 function testSaveSteps(assert)
55 {
56 let start = performance.now();
57 let saveTimes = [];
58
59 let steps = [
60 {
61 done: assert.async(),
62 check(data)
63 {
64 let expectedFormat = [
65 "[Subscription]",
66 `url=${specialSubscription.url}`,
67 "defaults=blocking",
68 "[Subscription filters]",
69 "example.com",
70 "[Subscription]",
71 "homepage=example.com",
72 "title=test",
73 "url=test.com",
74 "disabled=false"
75 ];
76
77 ok(
78 saveTimes[0] - start >= backupDelay,
79 "first write is deferred"
80 );
81 deepEqual(
82 data.content,
83 expectedFormat,
84 "saved data has the correct information"
85 );
86
87 FilterStorage.removeSubscription(subscription);
88 FilterStorage.removeSubscription(specialSubscription);
89 }
90 },
91 {
92 done: assert.async(),
93 check(data)
94 {
95 ok(
96 saveTimes[1] - saveTimes[0] >= backupDelay,
97 "next changes are saved after the write delay"
98 );
99 deepEqual(
100 data.content, [], "saved data has the correct information"
101 );
102 }
103 }
104 ];
105 let mockSave = data =>
106 {
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,
112 {
113 step.check(data["file:indexedDB-backup"]);
114 step.done();
115 }, 0);
116 };
117
118 Object.defineProperty(
119 browser.storage.local, "set",
120 {value: mockSave, enumerable: true}
121 );
122
123 FilterStorage.addSubscription(specialSubscription);
124 FilterStorage.addSubscription(subscription);
125 }
126 }
OLDNEW
« no previous file with comments | « metadata.edge ('k') | qunit/tests/ioIndexedDB.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld