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

Unified Diff: qunit/tests/ioIndexedDB.js

Issue 29823569: fixed ioIndexedDB tests (Closed)
Patch Set: Created July 9, 2018, 2:04 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: qunit/tests/ioIndexedDB.js
diff --git a/qunit/tests/ioIndexedDB.js b/qunit/tests/ioIndexedDB.js
index 58defadc4d6e9624370d50d85f7c80067e5f65fb..6ed3d76f436432212ea1e7445f4b1dc0015cd8a8 100644
--- a/qunit/tests/ioIndexedDB.js
+++ b/qunit/tests/ioIndexedDB.js
@@ -2,6 +2,7 @@
{
const {IO} = require("io");
+ const info = require("info");
const testFileNames = {
testData: "testData",
@@ -16,7 +17,9 @@
lastModified: Date.now()
};
- QUnit.module("IO tests", {
+ let testEdge = info.platform == "edgehtml" ? QUnit.test : QUnit.skip;
+
+ QUnit.module("Edge filter storage", {
beforeEach()
{
return prePopulateStorage();
@@ -27,64 +30,79 @@
}
});
- test("statFile", assert =>
+ function prePopulateStorage()
{
- const noFileMsg = "returns correct value if file doesn't exist";
- const fileExistsMsg = "returns correct value if file exists";
-
- ok(IO.statFile(testFileNames.simpleCheck) instanceof Promise,
- "returns a promise");
+ return new Promise(resolve =>
+ {
+ let db;
+ let req = indexedDB.open("adblockplus", 1);
- asyncReadHelper(
- IO.statFile,
- testFileNames.testData,
- {exists: true, lastModified: testData.lastModified},
- fileExistsMsg,
- assert);
+ req.onsuccess = event =>
+ {
+ db = event.currentTarget.result;
+ let store = db
+ .transaction(["file"], "readwrite")
+ .objectStore("file");
- asyncReadHelper(
- IO.statFile,
- testFileNames.simpleCheck,
- {exists: false},
- noFileMsg,
- assert);
- });
+ store.put(testData).onsuccess = () => resolve();
+ };
+ });
+ }
- test("writeToFile", assert =>
+ function clearStorage()
{
- ok(IO.writeToFile(testFileNames.simpleCheck, ["test"]) instanceof Promise,
- "returns a promise");
+ return new Promise(resolve =>
+ {
+ let db;
+ let req = indexedDB.open("adblockplus", 1);
- writesCorrectValue(assert);
- });
+ req.onsuccess = event =>
+ {
+ db = event.currentTarget.result;
+ let files = Object.values(testFileNames)
+ .map(fileName => new Promise((resolveFile, reject) =>
+ {
+ let store = db
+ .transaction(["file"], "readwrite")
+ .objectStore("file");
- function writesCorrectValue(assert)
+ store.delete("file:" + fileName).onsuccess = resolveFile;
+ }));
+
+ Promise.all(files).then(resolve);
+ };
+ });
+ }
+
+ testEdge("statFile", assert => testStatFile(assert));
+ testEdge("readFromFile", assert => testReadFromFile(assert));
+ testEdge("writeToFile", assert => testWriteToFile(assert));
+ testEdge("renameFile", assert => testRenameFile(assert));
+
+ function testStatFile(assert)
{
- const writeCheck = {
- fileName: "file:writeCheck",
- content: [1, 2, 3],
- lastModified: Date.now()
- };
- let done = assert.async();
+ const noFileMsg = "returns correct value if file doesn't exist";
+ const fileExistsMsg = "returns correct value if file exists";
- IO.writeToFile(testFileNames.write, writeCheck.content)
- .then(() => readFromStorage(writeCheck.fileName))
- .then(result =>
- {
- deepEqual(
- Object.keys(writeCheck),
- Object.keys(result),
- "data is written in the correct format");
+ ok(IO.statFile(testFileNames.simpleCheck) instanceof Promise,
+ "returns a promise");
- deepEqual(
- writeCheck.content,
- result.content,
- "data has the correct content");
- done();
- });
+ asyncReadHelper(
+ IO.statFile,
+ testFileNames.testData,
+ {exists: true, lastModified: testData.lastModified},
+ fileExistsMsg,
+ assert);
+
+ asyncReadHelper(
+ IO.statFile,
+ testFileNames.simpleCheck,
+ {exists: false},
+ noFileMsg,
+ assert);
}
- test("readFromFile", assert =>
+ function testReadFromFile(assert)
{
const noFileMsg = "returns correct value if file doesn't exist";
@@ -100,14 +118,31 @@
);
callsListeners(assert);
- });
+ }
+
+ function asyncReadHelper(method, fileName, expectedValue, description, assert)
+ {
+ let done = assert.async();
+
+ method(fileName)
+ .then(result =>
+ {
+ deepEqual(result, expectedValue, description);
+ done();
+ })
+ .catch(error =>
+ {
+ deepEqual(error, expectedValue, description);
+ done();
+ });
+ }
function callsListeners(assert)
{
let done = assert.async();
let called = [];
- IO.readFromFile(testFileNames.testData, (entry) => called.push(entry))
+ IO.readFromFile(testFileNames.testData, entry => called.push(entry))
.then(() =>
{
deepEqual(
@@ -118,13 +153,47 @@
});
}
- test("renameFile", assert =>
+ function testWriteToFile(assert)
+ {
+ ok(IO.writeToFile(testFileNames.simpleCheck, ["test"]) instanceof Promise,
+ "returns a promise");
+
+ writesCorrectValue(assert);
+ }
+
+ function writesCorrectValue(assert)
+ {
+ const writeCheck = {
+ fileName: "file:writeCheck",
+ content: [1, 2, 3],
+ lastModified: Date.now()
+ };
+ let done = assert.async();
+
+ IO.writeToFile(testFileNames.write, writeCheck.content)
+ .then(() => readFromStorage(writeCheck.fileName))
+ .then(result =>
+ {
+ deepEqual(
+ Object.keys(writeCheck),
+ Object.keys(result),
+ "data is written in the correct format");
+
+ deepEqual(
+ writeCheck.content,
+ result.content,
+ "data has the correct content");
+ done();
+ });
+ }
+
+ function testRenameFile(assert)
{
ok(IO.renameFile(testFileNames.simpleCheck) instanceof Promise,
- "returns a promise");
+ "returns a promise");
checkRename(assert);
- });
+ }
function checkRename(assert)
{
@@ -144,29 +213,13 @@
});
}
- function asyncReadHelper(method, fileName, expectedValue, description, assert)
- {
- let done = assert.async();
- method(fileName)
- .then(result =>
- {
- deepEqual(result, expectedValue, description);
- done();
- })
- .catch(error =>
- {
- deepEqual(error, expectedValue, description);
- done();
- });
- }
-
function readFromStorage(fileName)
{
return new Promise(resolve =>
{
let db;
let req = indexedDB.open("adblockplus", 1);
- req.onsuccess = (event) =>
+ req.onsuccess = event =>
{
db = event.currentTarget.result;
let store = db
@@ -179,49 +232,4 @@
};
});
}
-
- function prePopulateStorage()
- {
- return new Promise(resolve =>
- {
- let db;
- let req = indexedDB.open("adblockplus", 1);
-
- req.onsuccess = (event) =>
- {
- db = event.currentTarget.result;
- let store = db
- .transaction(["file"], "readwrite")
- .objectStore("file");
-
- store.put(testData).onsuccess = resolve;
- };
- });
- }
-
- function clearStorage()
- {
- return new Promise(resolve =>
- {
- let db;
- let req = indexedDB.open("adblockplus", 1);
-
- req.onsuccess = (event) =>
- {
- db = event.currentTarget.result;
- let files = Object.keys(testFileNames)
- .map(fileName => new Promise((resolveFile, reject) =>
- {
- let store = db
- .transaction(["file"], "readwrite")
- .objectStore("file");
-
- store.delete("file:" + fileName).onsuccess = resolveFile;
- }));
-
- Promise.all(files).then(resolve);
- };
- });
- }
}
-
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld