| OLD | NEW |
| (Empty) | |
| 1 <!doctype html> |
| 2 <meta charset="utf-8"> |
| 3 <title>FileAPI Test: Creating Blob URL with Blob</title> |
| 4 <link rel="author" title="Victor Costan" href="mailto:pwnall@chromium.org"> |
| 5 <link rel="help" href="https://w3c.github.io/FileAPI/#originOfBlobURL"> |
| 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/browsers.html#conc
ept-origin"> |
| 7 <link rel="help" href="https://url.spec.whatwg.org/#url-parsing"> |
| 8 <link rel="help" href="https://fetch.spec.whatwg.org/#main-fetch"> |
| 9 <script src="/resources/testharness.js"></script> |
| 10 <script src="/resources/testharnessreport.js"></script> |
| 11 |
| 12 <style> |
| 13 iframe { width: 10px; height: 10px; } |
| 14 </style> |
| 15 |
| 16 <iframe id="unconstrained-iframe"></iframe> |
| 17 <iframe id="sandboxed-iframe" sandbox="allow-scripts"></iframe> |
| 18 |
| 19 <script id="iframe-srcdoc" language="text/html"> |
| 20 <!doctype html> |
| 21 <script> |
| 22 'use strict'; |
| 23 |
| 24 window.onload = () => { |
| 25 const blob = new Blob(['Hello world!']); |
| 26 const blobUrl = URL.createObjectURL(blob); |
| 27 |
| 28 fetch(blobUrl).then(response => response.text()).then(text => { |
| 29 window.parent.postMessage({ blobUrl, text }, '*'); |
| 30 }); |
| 31 }; |
| 32 // The script tag is closed in readBlobFromUrl(). |
| 33 </script> |
| 34 |
| 35 <script> |
| 36 |
| 37 // Carries out the test of minting a Blob URL in an iframe, and reading it back. |
| 38 // |
| 39 // Returns a promise resolved with an object with properties blobUrl and text |
| 40 // (the text read back from the Blob URL). |
| 41 function readBlobFromUrl(t, iframeSelector) { |
| 42 return new Promise((resolve, reject) => { |
| 43 window.onmessage = t.step_func((message) => { resolve(message.data); }); |
| 44 |
| 45 const frame = document.querySelector(iframeSelector); |
| 46 const html = document.querySelector('#iframe-srcdoc').textContent + |
| 47 '<' + '/script>'; |
| 48 frame.setAttribute('srcdoc', html); |
| 49 }); |
| 50 } |
| 51 |
| 52 promise_test(t => readBlobFromUrl(t, '#unconstrained-iframe').then(data => { |
| 53 assert_true(data.blobUrl.startsWith('blob:'), |
| 54 "The Blob's URL should use the blob: scheme"); |
| 55 assert_equals(data.text, 'Hello world!', |
| 56 "The result of reading the Blob's URL should be the Blob's contents"); |
| 57 }), 'reading a Blob URL in an unconstrained iframe'); |
| 58 |
| 59 promise_test(t => readBlobFromUrl(t, '#sandboxed-iframe').then(data => { |
| 60 assert_true(data.blobUrl.startsWith('blob:'), |
| 61 "The Blob's URL should use the blob: scheme"); |
| 62 assert_equals(data.text, 'Hello world!', |
| 63 "The result of reading the Blob's URL should be the Blob's contents"); |
| 64 }), 'reading a Blob URL in a sandboxed iframe without the same-origin flag'); |
| 65 |
| 66 </script> |
| OLD | NEW |