Blob-methods-from-detached-frame.html (2435B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Blob methods from detached frame work as expected</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <iframe id="emptyDocumentIframe" src="../support/empty-document.html"></iframe> 8 9 <script> 10 const BlobPrototypeFromDetachedFramePromise = new Promise(resolve => { 11 emptyDocumentIframe.onload = () => { 12 const BlobPrototype = emptyDocumentIframe.contentWindow.Blob.prototype; 13 emptyDocumentIframe.remove(); 14 resolve(BlobPrototype); 15 }; 16 }); 17 18 const charCodeArrayToString = charCodeArray => Array.from(charCodeArray, c => String.fromCharCode(c)).join(""); 19 const charCodeBufferToString = charCodeBuffer => charCodeArrayToString(new Uint8Array(charCodeBuffer)); 20 21 promise_test(async () => { 22 const { slice } = await BlobPrototypeFromDetachedFramePromise; 23 const blob = new Blob(["foobar"]); 24 25 const slicedBlob = slice.call(blob, 1, 3); 26 assert_true(slicedBlob instanceof Blob); 27 28 assert_equals(await slicedBlob.text(), "oo"); 29 assert_equals(charCodeBufferToString(await slicedBlob.arrayBuffer()), "oo"); 30 assert_equals(charCodeArrayToString(await slicedBlob.bytes()), "oo"); 31 32 const reader = slicedBlob.stream().getReader(); 33 const { value } = await reader.read(); 34 assert_equals(charCodeArrayToString(value), "oo"); 35 }, "slice()"); 36 37 promise_test(async () => { 38 const { text } = await BlobPrototypeFromDetachedFramePromise; 39 const blob = new Blob(["foo"]); 40 41 assert_equals(await text.call(blob), "foo"); 42 }, "text()"); 43 44 promise_test(async () => { 45 const { arrayBuffer } = await BlobPrototypeFromDetachedFramePromise; 46 const blob = new Blob(["bar"]); 47 48 const charCodeBuffer = await arrayBuffer.call(blob); 49 assert_equals(charCodeBufferToString(charCodeBuffer), "bar"); 50 }, "arrayBuffer()"); 51 52 promise_test(async () => { 53 const { bytes } = await BlobPrototypeFromDetachedFramePromise; 54 const blob = new Blob(["bar"]); 55 56 const charCodeBytes = await bytes.call(blob); 57 assert_equals(charCodeArrayToString(charCodeBytes), "bar"); 58 }, "bytes()"); 59 60 promise_test(async () => { 61 const { stream } = await BlobPrototypeFromDetachedFramePromise; 62 const blob = new Blob(["baz"]); 63 64 const reader = stream.call(blob).getReader(); 65 const { value } = await reader.read(); 66 assert_equals(charCodeArrayToString(value), "baz"); 67 }, "stream()"); 68 </script>