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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: qunit/tests/indexedDBBackup.js
diff --git a/qunit/tests/indexedDBBackup.js b/qunit/tests/indexedDBBackup.js
new file mode 100644
index 0000000000000000000000000000000000000000..3bd493bbce71fac4833a81bbcb5d95f8d32d3613
--- /dev/null
+++ b/qunit/tests/indexedDBBackup.js
@@ -0,0 +1,120 @@
+"use strict";
+
+{
+ const {IndexedDBBackup} = require("../../lib/indexedDBBackup");
+ const info = require("info");
+ const {Filter} = require("../../adblockpluscore/lib/filterClasses");
+ const {Subscription, SpecialSubscription} =
+ require("../../adblockpluscore/lib/subscriptionClasses");
+
+ let writeTime = 0;
+ let writeInterval = 100;
+
+ let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip;
+
+ QUnit.module("Microsoft Edge indexedDB backup", {
+ afterEach()
+ {
+ IndexedDBBackup.init();
+ }
+ });
+
+ testEdge("Data serialization", () =>
+ {
+ let subscription = Subscription.fromObject({
+ title: "test",
+ url: "test.com",
+ homepage: "example.com",
+ disabled: false,
+ lastSuccess: 8,
+ lastDownload: 12,
+ lastCheck: 16,
+ softExpiration: 18,
+ expires: 20,
+ downloadStatus: "done",
+ errors: 3,
+ version: 24,
+ downloadCount: 1,
+ requiredVersion: "0.6"
+ });
+ let filter = Filter.fromText("example.com");
+ let specialSubscription = SpecialSubscription.createForFilter(filter);
+
+ let expectedFormat = [
+ "",
+ "[Subscription]",
+ `homepage=${subscription.homepage}`,
+ `title=${subscription.title}`,
+ `url=${subscription.url}`,
+ `disabled=${subscription.disabled}`,
+ "",
+ "[Subscription]",
+ `url=${specialSubscription.url}`,
+ "defaults=blocking",
+ "",
+ "[Subscription filters]",
+ "example.com"
+ ];
+ let actualFormat = IndexedDBBackup.serialize([
+ subscription,
+ specialSubscription
+ ]);
+ 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.
+ });
+
+ testEdge("Write time smaller than backup interval", assert =>
+ {
+ writeTime = 10;
+ testSaveSteps(assert);
+ });
+
+ testEdge("Write time greater than backup interval", assert =>
+ {
+ writeTime = 150;
+ testSaveSteps(assert);
+ });
+
+ function testSaveSteps(assert)
+ {
+ let start = performance.now();
+ let saveTimes = [];
+ let steps = [
+ {
+ done: assert.async(),
+ check()
+ {
+ ok(start - saveTimes[0].start < writeInterval,
+ "first change is proccessed imediatelly");
+ }
+ },
+ {
+ done: assert.async(),
+ check()
+ {
+ ok(saveTimes[1].start - saveTimes[0].end >= writeInterval,
+ "next change is after the time limit");
+ }
+ }
+ ];
+ let mockSave = () =>
+ {
+ saveTimes.push({start: performance.now()});
+ return new Promise(resolve =>
+ {
+ setTimeout(() =>
+ {
+ saveTimes[saveTimes.length - 1].end = performance.now();
+ let step = steps.shift();
+ step.check();
+ step.done();
+ resolve();
+ }, writeTime);
+ });
+ };
+
+ IndexedDBBackup.init(writeInterval, mockSave);
+ IndexedDBBackup.scheduleBackup();
+ setTimeout(IndexedDBBackup.scheduleBackup, writeTime / 2);
+ setTimeout(IndexedDBBackup.scheduleBackup, writeInterval);
+ }
+}
« metadata.edge ('K') | « metadata.edge ('k') | qunit/tests/ioIndexedDB.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld