1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
<!--
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>
|