diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /dom/indexedDB/test/test_blob_worker_xhr_post.html | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/indexedDB/test/test_blob_worker_xhr_post.html')
-rw-r--r-- | dom/indexedDB/test/test_blob_worker_xhr_post.html | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/dom/indexedDB/test/test_blob_worker_xhr_post.html b/dom/indexedDB/test/test_blob_worker_xhr_post.html new file mode 100644 index 0000000000..5c53e080f5 --- /dev/null +++ b/dom/indexedDB/test/test_blob_worker_xhr_post.html @@ -0,0 +1,113 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<html> +<head> + <title>Indexed Database Property Test</title> + + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> + + <script type="text/javascript"> + function* testSteps() + { + const BLOB_DATA = ["fun ", "times ", "all ", "around!"]; + const BLOB_TYPE = "text/plain"; + const BLOB_SIZE = BLOB_DATA.join("").length; + + info("Setting up"); + + let request = indexedDB.open(window.location.pathname, 1); + request.onerror = errorHandler; + request.onupgradeneeded = grabEventAndContinueHandler; + request.onsuccess = unexpectedSuccessHandler; + let event = yield undefined; + + let db = event.target.result; + db.onerror = errorHandler; + + ok(db, "Created database"); + + info("Creating objectStore"); + + let objectStore = db.createObjectStore("foo", { autoIncrement: true }); + + request.onupgradeneeded = unexpectedSuccessHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + + ok(true, "Opened database"); + + let blob = new Blob(BLOB_DATA, { type: BLOB_TYPE }); + + info("Adding blob to database"); + + objectStore = db.transaction("foo", "readwrite").objectStore("foo"); + objectStore.add(blob).onsuccess = grabEventAndContinueHandler; + event = yield undefined; + + let blobKey = event.target.result; + ok(blobKey, "Got a key for the blob"); + + info("Getting blob from the database"); + + objectStore = db.transaction("foo").objectStore("foo"); + objectStore.get(blobKey).onsuccess = grabEventAndContinueHandler; + event = yield undefined; + + blob = event.target.result; + + ok(blob instanceof Blob, "Got a blob"); + is(blob.size, BLOB_SIZE, "Correct size"); + is(blob.type, BLOB_TYPE, "Correct type"); + + let slice = blob.slice(0, BLOB_DATA[0].length, BLOB_TYPE); + + ok(slice instanceof Blob, "Slice returned a blob"); + is(slice.size, BLOB_DATA[0].length, "Correct size for slice"); + is(slice.type, BLOB_TYPE, "Correct type for slice"); + + info("Sending slice to a worker"); + + function workerScript() { + /* eslint-env worker */ + onmessage = function(event) { + var blob = event.data; + var xhr = new XMLHttpRequest(); + // We just want to make sure the error case doesn't fire; it's fine for + // us to just want a 404. + xhr.open("POST", "http://mochi.test:8888/does-not-exist", true); + xhr.onload = function() { + postMessage({ status: xhr.status }); + }; + xhr.onerror = function() { + postMessage({ status: "error" }); + }; + xhr.send(blob); + }; + } + + let workerScriptUrl = + URL.createObjectURL(new Blob(["(", workerScript.toString(), ")()"])); + + let xhrWorker = new Worker(workerScriptUrl); + xhrWorker.postMessage(slice); + xhrWorker.onmessage = grabEventAndContinueHandler; + event = yield undefined; + + is(event.data.status, 404, "XHR generated the expected 404"); + xhrWorker.terminate(); + + URL.revokeObjectURL(workerScriptUrl); + + finishTest(); + } + </script> + <script type="text/javascript" src="helpers.js"></script> + +</head> + +<body onload="runTest();"></body> + +</html> |