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