123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <!--
- 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 worker1 = new Worker(url);
- try {
- worker1.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.")
- }
- 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;
- let worker2 = new Worker(url);
- URL.revokeObjectURL(url);
- try {
- worker2.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.")
- }
- 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(), ")()"]));
- let worker3 = new Worker(url);
- URL.revokeObjectURL(url);
- worker3.postMessage(name);
- worker3.onmessage = grabEventAndContinueHandler;
- event = yield undefined;
- is(event.data, "success", "Good response.");
- todo(false, "Terminate all workers at the end of the test to work around bug 1340941.");
- worker1.terminate();
- worker2.terminate();
- worker3.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>
|