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

Unified Diff: qunit/tests/ioIndexedDB.js

Issue 29796555: Issue 6621 (Closed)
Patch Set: Fixed tests Created July 4, 2018, 7:59 a.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..c7480617c3af60ac7062304e46ee271f66f62520 100644
--- a/qunit/tests/ioIndexedDB.js
+++ b/qunit/tests/ioIndexedDB.js
@@ -2,6 +2,8 @@
{
const {IO} = require("io");
+ const info = require("info");
+
const testFileNames = {
testData: "testData",
@@ -16,75 +18,104 @@
lastModified: Date.now()
};
- QUnit.module("IO tests", {
+ const isEdge = info.platform == "edgehtml";
kzar 2018/07/04 15:45:58 How about something like this? let testEdge = r
+
+ QUnit.module("Edge filter storage", {
beforeEach()
{
- return prePopulateStorage();
+ if (isEdge)
+ return prePopulateStorage();
},
afterEach()
{
- return clearStorage();
+ if (isEdge)
+ return clearStorage();
}
});
- 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);
+ };
+ });
+ }
+
+ if (isEdge)
{
- const writeCheck = {
- fileName: "file:writeCheck",
- content: [1, 2, 3],
- lastModified: Date.now()
- };
- let done = assert.async();
+ test("statFile", assert => testStatFile(assert));
+ test("readFromFile", assert => testReadFromFile(assert));
+ test("writeToFile", assert => testWriteToFile(assert));
+ test("renameFile", assert => testRenameFile(assert));
+ }
+ else
+ {
+ QUnit.skip("statFile", assert => testStatFile(assert));
+ QUnit.skip("readFromFile", assert => testReadFromFile(assert));
+ QUnit.skip("writeToFile", assert => testWriteToFile(assert));
+ QUnit.skip("renameFile", assert => testRenameFile(assert));
+ }
- 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");
+ function testStatFile(assert)
+ {
+ const noFileMsg = "returns correct value if file doesn't exist";
+ const fileExistsMsg = "returns correct value if file exists";
- deepEqual(
- writeCheck.content,
- result.content,
- "data has the correct content");
- done();
- });
+ ok(IO.statFile(testFileNames.simpleCheck) instanceof Promise,
+ "returns a promise");
+
+ 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 +131,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 +166,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 +226,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 +245,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