OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>StorageManager API and opaque origins</title> |
| 4 <script src="/resources/testharness.js"></script> |
| 5 <script src="/resources/testharnessreport.js"></script> |
| 6 <script> |
| 7 |
| 8 function load_iframe(src, sandbox) { |
| 9 return new Promise(resolve => { |
| 10 const iframe = document.createElement('iframe'); |
| 11 iframe.onload = () => { resolve(iframe); }; |
| 12 if (sandbox) |
| 13 iframe.sandbox = sandbox; |
| 14 iframe.srcdoc = src; |
| 15 iframe.style.display = 'none'; |
| 16 document.documentElement.appendChild(iframe); |
| 17 }); |
| 18 } |
| 19 |
| 20 function wait_for_message(iframe) { |
| 21 return new Promise(resolve => { |
| 22 self.addEventListener('message', function listener(e) { |
| 23 if (e.source === iframe.contentWindow) { |
| 24 resolve(e.data); |
| 25 self.removeEventListener('message', listener); |
| 26 } |
| 27 }); |
| 28 }); |
| 29 } |
| 30 |
| 31 function make_script(snippet) { |
| 32 return '<script>' + |
| 33 ' window.onmessage = () => {' + |
| 34 ' try {' + |
| 35 ' (' + snippet + ')' + |
| 36 ' .then(' + |
| 37 ' result => {' + |
| 38 ' window.parent.postMessage({result: "no rejection"}, "*");'
+ |
| 39 ' }, ' + |
| 40 ' error => {' + |
| 41 ' window.parent.postMessage({result: error.name}, "*");' + |
| 42 ' });' + |
| 43 ' } catch (ex) {' + |
| 44 // Report if not implemented/exposed, rather than time out. |
| 45 ' window.parent.postMessage({result: ex.message}, "*");' + |
| 46 ' }' + |
| 47 ' };' + |
| 48 '<\/script>'; |
| 49 } |
| 50 |
| 51 ['navigator.storage.persist()', |
| 52 'navigator.storage.persisted()', |
| 53 'navigator.storage.estimate()' |
| 54 ].forEach(snippet => { |
| 55 promise_test(t => { |
| 56 return load_iframe(make_script(snippet)) |
| 57 .then(iframe => { |
| 58 iframe.contentWindow.postMessage({}, '*'); |
| 59 return wait_for_message(iframe); |
| 60 }) |
| 61 .then(message => { |
| 62 assert_equals(message.result, 'no rejection', |
| 63 `${snippet} should not reject`); |
| 64 }); |
| 65 }, `${snippet} in non-sandboxed iframe should not reject`); |
| 66 |
| 67 promise_test(t => { |
| 68 return load_iframe(make_script(snippet), 'allow-scripts') |
| 69 .then(iframe => { |
| 70 iframe.contentWindow.postMessage({}, '*'); |
| 71 return wait_for_message(iframe); |
| 72 }) |
| 73 .then(message => { |
| 74 assert_equals(message.result, 'TypeError', |
| 75 `${snippet} should reject with TypeError`); |
| 76 }); |
| 77 }, `${snippet} in sandboxed iframe should reject with TypeError`); |
| 78 }); |
| 79 </script> |
OLD | NEW |