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