2015-09-09 14:15:05 +03:00
|
|
|
<!--
|
|
|
|
Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
-->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Indexed Database Property Test</title>
|
|
|
|
|
2019-04-16 07:01:46 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js">
|
2015-09-09 14:15:05 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
|
2017-02-23 00:10:07 +03:00
|
|
|
<script type="text/javascript">
|
2016-12-01 12:11:32 +03:00
|
|
|
function* testSteps()
|
2015-09-09 14:15:05 +03:00
|
|
|
{
|
|
|
|
const databaseName = window.location.pathname;
|
|
|
|
const databaseVersion = 1;
|
|
|
|
const objectStoreName = "foo";
|
|
|
|
const mutableFileName = "bar";
|
|
|
|
const mutableFileKey = 42;
|
|
|
|
|
|
|
|
info("opening database");
|
|
|
|
|
|
|
|
let request = indexedDB.open(databaseName, databaseVersion);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
|
|
request.onsuccess = unexpectedSuccessHandler;
|
|
|
|
let event = yield undefined;
|
|
|
|
|
|
|
|
info("creating object store");
|
|
|
|
|
|
|
|
let db = event.target.result;
|
|
|
|
db.onerror = errorHandler;
|
|
|
|
db.onversionchange = function(event) {
|
|
|
|
is(event.oldVersion, databaseVersion, "got correct oldVersion");
|
|
|
|
is(event.newVersion, null, "got correct newVersion");
|
|
|
|
db.close();
|
|
|
|
};
|
|
|
|
|
|
|
|
let objectStore = db.createObjectStore(objectStoreName,
|
|
|
|
{ autoIncrement: true });
|
|
|
|
|
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
info("creating mutable file");
|
|
|
|
|
|
|
|
request = db.createMutableFile(mutableFileName);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
let mutableFile = event.target.result;
|
|
|
|
|
|
|
|
verifyMutableFile(mutableFile, getFile(mutableFileName, "", ""));
|
|
|
|
yield undefined;
|
|
|
|
|
|
|
|
objectStore = db.transaction([objectStoreName], "readwrite")
|
|
|
|
.objectStore(objectStoreName);
|
|
|
|
|
|
|
|
info("adding mutable file");
|
|
|
|
|
|
|
|
request = objectStore.add(mutableFile, mutableFileKey);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
info("getting mutable file");
|
|
|
|
|
|
|
|
request = objectStore.get(mutableFileKey);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
verifyMutableFile(event.target.result,
|
|
|
|
getFile(mutableFileName, "", ""));
|
|
|
|
yield undefined;
|
|
|
|
|
|
|
|
info("opening database");
|
|
|
|
|
|
|
|
request = indexedDB.open(databaseName, databaseVersion);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
let db2 = event.target.result;
|
|
|
|
db2.onerror = errorHandler;
|
|
|
|
db2.onversionchange = function(event) {
|
|
|
|
is(event.oldVersion, databaseVersion, "got correct oldVersion");
|
|
|
|
is(event.newVersion, null, "got correct newVersion");
|
|
|
|
db2.close();
|
|
|
|
};
|
|
|
|
|
|
|
|
objectStore = db2.transaction([objectStoreName], "readwrite")
|
|
|
|
.objectStore(objectStoreName);
|
|
|
|
|
|
|
|
info("adding mutable file");
|
|
|
|
|
|
|
|
request = objectStore.add(mutableFile);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
info("getting mutable file");
|
|
|
|
|
|
|
|
request = objectStore.get(event.target.result);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
verifyMutableFile(event.target.result,
|
|
|
|
getFile(mutableFileName, "", ""));
|
|
|
|
yield undefined;
|
|
|
|
|
|
|
|
info("setting file handle pref");
|
|
|
|
|
|
|
|
SpecialPowers.pushPrefEnv({ set: [["dom.fileHandle.enabled", false]] },
|
|
|
|
continueToNextStep);
|
|
|
|
yield undefined;
|
|
|
|
|
|
|
|
info("opening database");
|
|
|
|
|
|
|
|
request = indexedDB.open(databaseName, databaseVersion);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = unexpectedSuccessHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
let db3 = event.target.result;
|
|
|
|
db3.onerror = errorHandler;
|
|
|
|
db3.onversionchange = function(event) {
|
|
|
|
is(event.oldVersion, databaseVersion, "got correct oldVersion");
|
|
|
|
is(event.newVersion, null, "got correct newVersion");
|
|
|
|
db3.close();
|
|
|
|
};
|
|
|
|
|
|
|
|
info("creating mutable file");
|
|
|
|
|
|
|
|
try {
|
|
|
|
db3.createMutableFile(mutableFileName);
|
|
|
|
ok(false, "Should have thrown!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(e instanceof DOMException, "Got exception.");
|
|
|
|
is(e.name, "InvalidStateError", "Good error.");
|
|
|
|
is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
|
|
|
|
}
|
|
|
|
|
|
|
|
objectStore = db3.transaction([objectStoreName], "readwrite")
|
|
|
|
.objectStore(objectStoreName);
|
|
|
|
|
|
|
|
info("adding mutable file");
|
|
|
|
|
|
|
|
try {
|
|
|
|
objectStore.add(mutableFile);
|
|
|
|
ok(false, "Should have thrown!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(e instanceof DOMException, "Got exception.");
|
|
|
|
is(e.name, "DataCloneError", "Good error.");
|
|
|
|
is(e.code, DOMException.DATA_CLONE_ERR, "Good error code.");
|
|
|
|
}
|
|
|
|
|
|
|
|
info("getting mutable file");
|
|
|
|
|
|
|
|
request = objectStore.get(mutableFileKey);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
try {
|
2017-05-10 19:28:55 +03:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2015-09-09 14:15:05 +03:00
|
|
|
let result = request.result;
|
|
|
|
ok(false, "Should have thrown!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(e instanceof DOMException, "Got exception.");
|
|
|
|
is(e.name, "InvalidStateError", "Good error.");
|
|
|
|
is(e.code, DOMException.INVALID_STATE_ERR, "Good error code.");
|
|
|
|
}
|
|
|
|
|
|
|
|
info("deleting database");
|
|
|
|
|
|
|
|
request = indexedDB.deleteDatabase(databaseName);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
|
|
|
|
event = yield undefined;
|
|
|
|
|
|
|
|
info("resetting file handle pref");
|
|
|
|
|
|
|
|
SpecialPowers.popPrefEnv(continueToNextStep);
|
|
|
|
yield undefined;
|
|
|
|
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2017-02-23 00:10:07 +03:00
|
|
|
<script type="text/javascript" src="helpers.js"></script>
|
|
|
|
<script type="text/javascript" src="file.js"></script>
|
2015-09-09 14:15:05 +03:00
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|