fetch-response-xhr-iframe.https.html (1412B)
1 <script src="/common/get-host-info.sub.js"></script> 2 <script src="test-helpers.sub.js?pipe=sub"></script> 3 <script> 4 var host_info = get_host_info(); 5 6 function xhr_send(method, data) { 7 return new Promise(function(resolve, reject) { 8 var xhr = new XMLHttpRequest(); 9 xhr.onload = function() { 10 resolve(xhr); 11 }; 12 xhr.onerror = function() { 13 reject('XHR should succeed.'); 14 }; 15 xhr.responseType = 'text'; 16 xhr.open(method, './sample?test', true); 17 xhr.send(data); 18 }); 19 } 20 21 function coalesce_headers_test() { 22 return xhr_send('POST', 'test string') 23 .then(function(xhr) { 24 window.parent.postMessage({results: xhr.getResponseHeader('foo')}, 25 host_info['HTTPS_ORIGIN']); 26 27 return new Promise(function(resolve) { 28 window.addEventListener('message', function handle(evt) { 29 if (evt.data !== 'ACK') { 30 return; 31 } 32 33 window.removeEventListener('message', handle); 34 resolve(); 35 }); 36 }); 37 }); 38 } 39 40 window.addEventListener('message', function(evt) { 41 var port; 42 43 if (evt.data !== 'START') { 44 return; 45 } 46 47 port = evt.ports[0]; 48 49 coalesce_headers_test() 50 .then(function() { port.postMessage({results: 'finish'}); }) 51 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); 52 }); 53 </script>