2012-06-03 20:33:52 +04:00
|
|
|
<!--
|
|
|
|
Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
-->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Indexed Database Property Test</title>
|
|
|
|
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
|
|
|
2017-02-23 00:10:07 +03:00
|
|
|
<script type="text/javascript">
|
2017-05-10 19:05:18 +03:00
|
|
|
/* import-globals-from file.js */
|
|
|
|
/* import-globals-from helpers.js */
|
2016-12-01 12:11:32 +03:00
|
|
|
function* testSteps()
|
2012-06-03 20:33:52 +04:00
|
|
|
{
|
2013-07-29 21:12:21 +04:00
|
|
|
const READ_WRITE = "readwrite";
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
const name = window.location.pathname;
|
|
|
|
|
|
|
|
const objectStoreName = "Blobs";
|
|
|
|
|
|
|
|
const testFile = getRandomFile("random.bin", 100000);
|
|
|
|
|
2012-07-13 09:37:28 +04:00
|
|
|
let request = indexedDB.open(name, 1);
|
2012-06-03 20:33:52 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
let event = yield undefined;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
is(event.type, "upgradeneeded", "Got correct event type");
|
|
|
|
|
|
|
|
let db = event.target.result;
|
|
|
|
db.onerror = errorHandler;
|
|
|
|
|
|
|
|
let objectStore = db.createObjectStore(objectStoreName, { });
|
|
|
|
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
is(event.type, "success", "Got correct event type");
|
|
|
|
|
2014-06-12 07:35:29 +04:00
|
|
|
request = db.createMutableFile("random.bin", "binary/random");
|
2012-06-03 20:33:52 +04:00
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2014-06-12 07:35:29 +04:00
|
|
|
let mutableFile = event.target.result;
|
|
|
|
mutableFile.onerror = errorHandler;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2014-06-12 07:35:29 +04:00
|
|
|
let fileHandle = mutableFile.open("readwrite");
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2014-06-12 07:35:29 +04:00
|
|
|
is(getFileId(mutableFile), 1, "Correct file id");
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2014-06-12 07:35:29 +04:00
|
|
|
request = fileHandle.write(testFile);
|
2012-06-03 20:33:52 +04:00
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2014-06-12 07:35:29 +04:00
|
|
|
request = mutableFile.getFile();
|
2012-06-03 20:33:52 +04:00
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
let file = event.target.result;
|
|
|
|
|
|
|
|
let trans = db.transaction([objectStoreName], READ_WRITE);
|
2014-09-16 03:30:47 +04:00
|
|
|
objectStore = trans.objectStore(objectStoreName);
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
request = objectStore.add(file, 42);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2012-07-10 09:07:01 +04:00
|
|
|
// At this moment, the file should not be readable anymore.
|
|
|
|
let reader = new FileReader();
|
|
|
|
try {
|
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
|
ok(false, "Should have thrown!");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(e instanceof DOMException, "Got exception.");
|
2014-06-12 07:35:29 +04:00
|
|
|
is(e.name, "FileHandleInactiveError", "Good error.");
|
2012-07-10 09:07:01 +04:00
|
|
|
is(e.code, 0, "Good error code.");
|
|
|
|
}
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
request = objectStore.get(42);
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
2013-07-11 01:52:35 +04:00
|
|
|
event = yield undefined;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
verifyBlob(event.target.result, testFile, 2);
|
2013-07-11 01:52:35 +04:00
|
|
|
yield undefined;
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
</script>
|
2017-02-23 00:10:07 +03:00
|
|
|
<script type="text/javascript" src="file.js"></script>
|
|
|
|
<script type="text/javascript" src="helpers.js"></script>
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|