2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
7 <title>Indexed Database Property Test
</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
12 <script type=
"text/javascript">
14 * Create a composite/multi-file Blob on the worker, then post it as an XHR
15 * payload and ensure that we don't hang/generate an assertion/etc. but
16 * instead generate the expected 404. This test is basically the same as
17 * test_blob_worker_xhr_post.html except for the composite Blob.
21 const BLOB_DATA
= ["fun ", "times ", "all ", "around!"];
22 const BLOB_TYPE
= "text/plain";
23 const BLOB_SIZE
= BLOB_DATA
.join("").length
;
27 let request
= indexedDB
.open(window
.location
.pathname
, 1);
28 request
.onerror
= errorHandler
;
29 request
.onupgradeneeded
= grabEventAndContinueHandler
;
30 request
.onsuccess
= unexpectedSuccessHandler
;
31 let event
= yield undefined;
33 let db
= event
.target
.result
;
34 db
.onerror
= errorHandler
;
36 ok(db
, "Created database");
38 info("Creating objectStore");
40 let objectStore
= db
.createObjectStore("foo", { autoIncrement
: true });
42 request
.onupgradeneeded
= unexpectedSuccessHandler
;
43 request
.onsuccess
= grabEventAndContinueHandler
;
44 event
= yield undefined;
46 ok(true, "Opened database");
48 let blob
= new Blob(BLOB_DATA
, { type
: BLOB_TYPE
});
50 info("Adding blob to database");
52 objectStore
= db
.transaction("foo", "readwrite").objectStore("foo");
53 objectStore
.add(blob
).onsuccess
= grabEventAndContinueHandler
;
54 event
= yield undefined;
56 let blobKey
= event
.target
.result
;
57 ok(blobKey
, "Got a key for the blob");
59 info("Getting blob from the database");
61 objectStore
= db
.transaction("foo").objectStore("foo");
62 objectStore
.get(blobKey
).onsuccess
= grabEventAndContinueHandler
;
63 event
= yield undefined;
65 blob
= event
.target
.result
;
67 ok(blob
instanceof Blob
, "Got a blob");
68 is(blob
.size
, BLOB_SIZE
, "Correct size");
69 is(blob
.type
, BLOB_TYPE
, "Correct type");
71 function workerScript() {
72 /* eslint-env worker */
73 onmessage = function(event
) {
74 var blob
= event
.data
;
75 var compositeBlob
= new Blob(["preceding string. ", blob
],
76 { type
: "text/plain" });
77 var xhr
= new XMLHttpRequest();
78 // We just want to make sure the error case doesn't fire; it's fine for
79 // us to just want a 404.
80 xhr
.open("POST", "http://mochi.test:8888/does-not-exist", true);
81 xhr
.onload = function() {
82 postMessage({ status
: xhr
.status
});
84 xhr
.onerror = function() {
85 postMessage({ status
: "error" });
87 xhr
.send(compositeBlob
);
92 URL
.createObjectURL(new Blob(["(", workerScript
.toString(), ")()"]));
94 let xhrWorker
= new Worker(workerScriptUrl
);
95 xhrWorker
.postMessage(blob
);
96 xhrWorker
.onmessage
= grabEventAndContinueHandler
;
97 event
= yield undefined;
99 is(event
.data
.status
, 404, "XHR generated the expected 404");
100 xhrWorker
.terminate();
102 URL
.revokeObjectURL(workerScriptUrl
);
107 <script type=
"text/javascript" src=
"helpers.js"></script>
111 <body onload=
"runTest();"></body>