mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
150 lines
4.1 KiB
HTML
150 lines
4.1 KiB
HTML
<!--
|
|
Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
-->
|
|
<html>
|
|
<head>
|
|
<title>File Handle Test</title>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
<script type="text/javascript;version=1.7">
|
|
function testSteps()
|
|
{
|
|
const name = window.location.pathname;
|
|
|
|
let testBuffer = getRandomBuffer(100000);
|
|
|
|
let request = indexedDB.open(name, 1);
|
|
request.onerror = errorHandler;
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
|
request.onsuccess = errorHandler;
|
|
let event = yield undefined;
|
|
|
|
is(event.type, "upgradeneeded", "Got correct event type");
|
|
|
|
let db = event.target.result;
|
|
db.onerror = errorHandler;
|
|
|
|
db.createObjectStore("Foo", { });
|
|
|
|
request.onupgradeneeded = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield undefined;
|
|
|
|
is(event.type, "success", "Got correct event type");
|
|
|
|
request = db.createMutableFile("test.txt");
|
|
request.onerror = errorHandler;
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield undefined;
|
|
|
|
let mutableFile = event.target.result;
|
|
|
|
function dummyWorkerScript() {
|
|
onmessage = function(event) {
|
|
throw("Shouldn't be called!");
|
|
}
|
|
}
|
|
|
|
let url =
|
|
URL.createObjectURL(new Blob(["(", dummyWorkerScript.toSource(), ")()"]));
|
|
|
|
let worker = new Worker(url);
|
|
try {
|
|
worker.postMessage(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.")
|
|
}
|
|
worker.terminate();
|
|
|
|
mutableFile.onerror = errorHandler;
|
|
|
|
let fileHandle = mutableFile.open("readwrite");
|
|
|
|
request = fileHandle.write(testBuffer);
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield undefined;
|
|
|
|
request = mutableFile.getFile();
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield undefined;
|
|
|
|
let file = event.target.result;
|
|
|
|
worker = new Worker(url);
|
|
URL.revokeObjectURL(url);
|
|
try {
|
|
worker.postMessage(file);
|
|
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.")
|
|
}
|
|
worker.terminate();
|
|
|
|
let objectStore =
|
|
db.transaction("Foo", "readwrite").objectStore("Foo");
|
|
|
|
request = objectStore.add(mutableFile, 42);
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
event = yield undefined;
|
|
|
|
function workerScript() {
|
|
onmessage = function(event) {
|
|
var name = event.data;
|
|
var request = indexedDB.open(name, 1);
|
|
request.onsuccess = function(event) {
|
|
var db = event.target.result;
|
|
let objectStore = db.transaction("Foo").objectStore("Foo");
|
|
request = objectStore.get(42);
|
|
request.onsuccess = function(event) {
|
|
try {
|
|
let result = request.result;
|
|
postMessage("error");
|
|
}
|
|
catch (e) {
|
|
postMessage("success");
|
|
}
|
|
}
|
|
request.onerror = function(event) {
|
|
postMessage("error");
|
|
}
|
|
}
|
|
request.onerror = function(event) {
|
|
postMessage("error");
|
|
}
|
|
}
|
|
}
|
|
|
|
url = URL.createObjectURL(new Blob(["(", workerScript.toSource(), ")()"]));
|
|
|
|
worker = new Worker(url);
|
|
URL.revokeObjectURL(url);
|
|
worker.postMessage(name);
|
|
worker.onmessage = grabEventAndContinueHandler;
|
|
event = yield undefined;
|
|
|
|
is(event.data, "success", "Good response.");
|
|
worker.terminate();
|
|
|
|
finishTest();
|
|
yield undefined;
|
|
}
|
|
</script>
|
|
<script type="text/javascript;version=1.7" src="file.js"></script>
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
</html>
|