shared-storage-writable-fetch-request-fallback-to-network-iframe.https.html (1781B)
1 <!doctype html> 2 <body> 3 <script src=/resources/testharness.js></script> 4 <script> 5 function loadImage(url, hasSharedStorageWritableAttribute) { 6 return new Promise(function(resolve, reject) { 7 var img = document.createElement('img'); 8 document.body.appendChild(img); 9 img.onload = function() { 10 resolve(img); 11 }; 12 img.onerror = function() { 13 reject(new Error('Image load failed')); 14 }; 15 if (hasSharedStorageWritableAttribute) { 16 img.sharedStorageWritable = true; 17 } 18 img.src = url; 19 }); 20 } 21 22 function loadFrame(url, hasSharedStorageWritableAttribute) { 23 return new Promise(function(resolve, reject) { 24 var frame = document.createElement('iframe'); 25 document.body.appendChild(frame); 26 frame.onload = function() { 27 window.parent.postMessage({msg: 'iframe loaded'}, "*"); 28 resolve(frame); 29 }; 30 frame.onerror = function() { 31 reject(new Error('Nested iframe load failed')); 32 }; 33 if (hasSharedStorageWritableAttribute) { 34 frame.sharedStorageWritable = true; 35 } 36 frame.src = url; 37 }); 38 } 39 40 function fetchUrl(url, hasSharedStorageWritableAttribute) { 41 return new Promise(function(resolve, reject) { 42 fetch(url, {sharedStorageWritable: 43 hasSharedStorageWritableAttribute}) 44 .then(response => { 45 if (!response.ok) { 46 throw new Error('Failed to fetch ' + url + '; ' 47 + String(response.status) + ' ' + response.statusText); 48 } 49 resolve(response); 50 }).catch(error => { 51 reject(error); 52 }); 53 }); 54 } 55 </script> 56 </body>