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 Sept. 5, 2018, 3:53 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
« no previous file with comments | « metadata.edge ('k') | qunit/tests/ioIndexedDB.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: qunit/tests/indexedDBBackup.js
diff --git a/qunit/tests/indexedDBBackup.js b/qunit/tests/indexedDBBackup.js
new file mode 100644
index 0000000000000000000000000000000000000000..379e83e911ecfae375357f8f684d41f351d659fc
--- /dev/null
+++ b/qunit/tests/indexedDBBackup.js
@@ -0,0 +1,126 @@
+"use strict";
+
+{
+ const {IndexedDBBackup} = require("../../lib/indexedDBBackup");
+ const info = require("info");
+ const {FilterStorage} = require("../../adblockpluscore/lib/filterStorage");
+ const {Filter} = require("../../adblockpluscore/lib/filterClasses");
+ const {Subscription, SpecialSubscription} =
+ require("../../adblockpluscore/lib/subscriptionClasses");
+
+ let backupDelay = 100;
+ let subscription = Subscription.fromObject({
+ title: "test",
+ url: "test.com",
+ homepage: "example.com",
+ lastSuccess: 8,
+ disabled: false,
+ 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 testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip;
+
+ QUnit.module("Microsoft Edge indexedDB backup", {
+ beforeEach()
+ {
+ this._storageLocalSet = browser.storage.local.set;
+ IndexedDBBackup.setBackupInterval(backupDelay);
+ },
+ afterEach()
+ {
+ Object.defineProperty(
+ browser.storage.local, "set",
+ {value: this._storageLocalSet, enumerable: true}
+ );
+ IndexedDBBackup.setBackupInterval();
+ }
+ });
+
+ testEdge("Backup creation", assert =>
+ {
+ testSaveSteps(assert);
+ });
+
+ function testSaveSteps(assert)
+ {
+ let start = performance.now();
+ let saveTimes = [];
+
+ let steps = [
+ {
+ done: assert.async(),
+ check(data)
+ {
+ let expectedFormat = [
+ "[Subscription]",
+ `url=${specialSubscription.url}`,
+ "defaults=blocking",
+ "[Subscription filters]",
+ "example.com",
+ "[Subscription]",
+ "homepage=example.com",
+ "title=test",
+ "url=test.com",
+ "disabled=false"
+ ];
+
+ ok(
+ saveTimes[0] - start >= backupDelay,
+ "first write is deferred"
+ );
+ deepEqual(
+ data.content,
+ expectedFormat,
+ "saved data has the correct information"
+ );
+
+ FilterStorage.removeSubscription(subscription);
+ FilterStorage.removeSubscription(specialSubscription);
+ }
+ },
+ {
+ done: assert.async(),
+ check(data)
+ {
+ ok(
+ saveTimes[1] - saveTimes[0] >= backupDelay,
+ "next changes are saved after the write delay"
+ );
+ deepEqual(
+ data.content, [], "saved data has the correct information"
+ );
+ }
+ }
+ ];
+ let mockSave = data =>
+ {
+ let step = steps.shift();
+
+ saveTimes.push(performance.now());
+
+ setTimeout(() =>
geo 2018/09/05 15:59:08 I've reintroduced this timeout because without it,
+ {
+ step.check(data["file:indexedDB-backup"]);
+ step.done();
+ }, 0);
+ };
+
+ Object.defineProperty(
+ browser.storage.local, "set",
+ {value: mockSave, enumerable: true}
+ );
+
+ FilterStorage.addSubscription(specialSubscription);
+ FilterStorage.addSubscription(subscription);
+ }
+}
« 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