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