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 reject('XHR must fail.'); | 8 reject('XHR must fail.'); |
9 }; | 9 }; |
10 xhr.onerror = function() { | 10 xhr.onerror = function() { |
11 resolve(); | 11 resolve(); |
12 }; | 12 }; |
13 xhr.responseType = 'text'; | 13 xhr.responseType = 'text'; |
14 xhr.open(method, './dummy?test', true); | 14 xhr.open(method, './dummy?test', true); |
15 xhr.send(data); | 15 xhr.send(data); |
16 }); | 16 }); |
17 } | 17 } |
18 | 18 |
19 | 19 |
20 window.addEventListener('message', function(evt) { | 20 window.addEventListener('message', function(evt) { |
21 var port = evt.ports[0]; | 21 var port = evt.ports[0]; |
22 xhr_send('POST', 'test string') | 22 xhr_send('POST', 'test string') |
23 .then(function() { port.postMessage({results: 'finish'}); }) | 23 .then(function() { port.postMessage({results: 'finish'}); }) |
24 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); | 24 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); |
25 }); | 25 }); |
26 </script> | 26 </script> |
OLD | NEW |