Index: LayoutTests/fast/files/blob-close-revoke.html |
diff --git a/LayoutTests/fast/files/blob-close-revoke.html b/LayoutTests/fast/files/blob-close-revoke.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f1073f41cba2c3cf1f1087f09db2f43331707ed2 |
--- /dev/null |
+++ b/LayoutTests/fast/files/blob-close-revoke.html |
@@ -0,0 +1,123 @@ |
+<!doctype html> |
+<script src="../../resources/js-test.js"></script> |
+<script src="resources/read-common.js"></script> |
+<script> |
+description("Test the Blob.close() method, revoking."); |
+ |
+window.jsTestIsAsync = true; |
+ |
+function base64ToUint8Array(a) |
+{ |
+ var binary = window.atob(a); |
+ var buffer = new Uint8Array(binary.length); |
+ for (var i = 0; i < binary.length; i++) |
+ buffer[i] = binary.charCodeAt(i); |
+ |
+ return buffer; |
+} |
+ |
+var pngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAnklEQVR42u3QMQEAAAgDoGlyo1vBzwciUJlw1ApkyZIlS5YsBbJkyZIlS5YCWbJkyZIlS4EsWbJkyZKlQJYsWbJkyVIgS5YsWbJkKZAlS5YsWbIUyJIlS5YsWQpkyZIlS5YsBbJkyZIlS5YCWbJkyZIlS4EsWbJkyZKlQJYsWbJkyVIgS5YsWbJkKZAlS5YsWbIUyJIlS5YsWQpkyfq2MosBSIeKONMAAAAASUVORK5CYII="; |
+ |
+var blobContents = [base64ToUint8Array(pngBase64)]; |
+ |
+var blob; |
+var blobURL1; |
+var blobURL2; |
+var img; |
+var worker; |
+var blobURLs = []; |
+ |
+function testRevokeAfterCloseWorkers() |
+{ |
+ debug("Test that dereferencing URLs referring to closed Blobs fail, workers."); |
+ blob = new Blob(["postMessage('FAIL');"], {type: "application/javascript"}); |
+ for (var i = 0; i < 10; i++) |
+ blobURLs.push(window.URL.createObjectURL(blob)); |
+ |
+ // First check that the Blob URL can be used by a Worker, |
+ // then close it and verify that the rest cannot. |
+ |
+ function onNonClosedError() { |
+ testFailed("Worker failed to load from Blob."); |
+ blob.close(); |
+ testNextWorker(); |
+ } |
+ function onNonClosedMessage() { |
+ testPassed("Worker loaded."); |
+ blob.close(); |
+ testNextWorker(); |
+ } |
+ function onClosedError() { |
+ testPassed("Error triggered on starting Worker from a closed Blob."); |
+ testNextWorker(); |
+ } |
+ function onClosedMessage() { |
+ testFailed("Worker loaded."); |
+ testNextWorker(); |
+ } |
+ |
+ function testNextWorker(onerror, onmessage) { |
+ var u = blobURLs.shift(); |
+ if (u) { |
+ worker = new Worker(u); |
+ worker.onerror = onerror ? onerror : onClosedError; |
+ worker.onmessage = onmessage ? onmessage : onClosedMessage; |
+ } else { |
+ runNextTest(); |
+ } |
+ } |
+ testNextWorker(onNonClosedError, onNonClosedMessage); |
+} |
+ |
+function testRevokeAfterClose() |
+{ |
+ debug("Test that dereferencing URLs referring to closed Blobs fail."); |
+ blob = new Blob(blobContents, {type: "image/png"}); |
+ img = document.createElement("img"); |
+ img.onerror = function (e) { |
+ testPassed("Error triggered on loading image from closed Blob."); |
+ runNextTest(); |
+ }; |
+ img.onload = function () { |
+ testFailed("Image loaded"); |
+ runNextTest(); |
+ }; |
+ blobURL1 = window.URL.createObjectURL(blob); |
+ // create some more Blob URLs. |
+ for (var i = 0; i < 10; i++) |
+ window.URL.createObjectURL(blob); |
+ // Make them all inaccessible. |
+ blob.close(); |
+ img.src = blobURL1; |
+} |
+ |
+function testRegisterAfterClose() |
+{ |
+ debug("Test creating object URLs on closed Blobs"); |
+ blob = new Blob(["body{background: green}"], {type: "text/css"}); |
+ blobURL1 = window.URL.createObjectURL(blob); |
+ blob.close(); |
+ // Verifies createObjectURL() still works and returns a valid (non-empty) URL |
+ // without throwing an error. See http://crbug.com/344820 for this requirement. |
+ blobURL2 = window.URL.createObjectURL(blob); |
+ shouldBeTrue("blobURL1 !== blobURL2"); |
+ shouldBeTrue("blobURL2.length > 0"); |
+ runNextTest(); |
+} |
+ |
+var tests = [ |
+ testRevokeAfterClose, |
+ testRevokeAfterCloseWorkers, |
+ testRegisterAfterClose ]; |
+ |
+function runNextTest() |
+{ |
+ if (!tests.length) { |
+ finishJSTest(); |
+ return; |
+ } |
+ tests.shift()(); |
+} |
+</script> |
+<body onload="runNextTest()"> |
+</body> |