OLD | NEW |
1 <script src="test-helpers.sub.js?pipe=sub"></script> | 1 <script src="test-helpers.sub.js"></script> |
2 <script> | 2 <script> |
3 | 3 |
4 function xhr_send(method, data) { | 4 function xhr_send(method, data) { |
5 return new Promise(function(resolve, reject) { | 5 return new Promise(function(resolve, reject) { |
6 var xhr = new XMLHttpRequest(); | 6 var xhr = new XMLHttpRequest(); |
7 xhr.onload = function() { | 7 xhr.onload = function() { |
8 if (xhr.getResponseHeader('Content-Type') !== null) { | 8 if (xhr.getResponseHeader('Content-Type') !== null) { |
9 reject('Content-Type must be null.'); | 9 reject('Content-Type must be null.'); |
10 } | 10 } |
11 resolve(); | 11 resolve(); |
12 }; | 12 }; |
13 xhr.onerror = function() { | 13 xhr.onerror = function() { |
14 reject('XHR must succeed.'); | 14 reject('XHR must succeed.'); |
15 }; | 15 }; |
16 xhr.responseType = 'text'; | 16 xhr.responseType = 'text'; |
17 xhr.open(method, './dummy?test', true); | 17 xhr.open(method, './dummy?test', true); |
18 xhr.send(data); | 18 xhr.send(data); |
19 }); | 19 }); |
20 } | 20 } |
21 | 21 |
22 | 22 |
23 window.addEventListener('message', function(evt) { | 23 window.addEventListener('message', function(evt) { |
24 var port = evt.ports[0]; | 24 var port = evt.ports[0]; |
25 xhr_send('POST', 'test string') | 25 xhr_send('POST', 'test string') |
26 .then(function() { port.postMessage({results: 'finish'}); }) | 26 .then(function() { port.postMessage({results: 'finish'}); }) |
27 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); | 27 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); |
28 }); | 28 }); |
29 </script> | 29 </script> |
OLD | NEW |