OLD | NEW |
1 <script src="/common/get-host-info.sub.js"></script> | 1 <script src="/common/get-host-info.sub.js"></script> |
2 <script src="test-helpers.sub.js?pipe=sub"></script> | 2 <script src="test-helpers.sub.js?pipe=sub"></script> |
3 <script> | 3 <script> |
4 var host_info = get_host_info(); | 4 var host_info = get_host_info(); |
5 | 5 |
6 function xhr_send(method, data) { | 6 function xhr_send(method, data) { |
7 return new Promise(function(resolve, reject) { | 7 return new Promise(function(resolve, reject) { |
8 var xhr = new XMLHttpRequest(); | 8 var xhr = new XMLHttpRequest(); |
9 xhr.onload = function() { | 9 xhr.onload = function() { |
10 resolve(xhr); | 10 resolve(xhr); |
11 }; | 11 }; |
12 xhr.onerror = function() { | 12 xhr.onerror = function() { |
13 reject('XHR should succeed.'); | 13 reject('XHR should succeed.'); |
14 }; | 14 }; |
15 xhr.responseType = 'text'; | 15 xhr.responseType = 'text'; |
16 xhr.open(method, './dummy?test', true); | 16 xhr.open(method, './dummy?test', true); |
17 xhr.send(data); | 17 xhr.send(data); |
18 }); | 18 }); |
19 } | 19 } |
20 | 20 |
21 function coalesce_headers_test() { | 21 function coalesce_headers_test() { |
22 return xhr_send('POST', 'test string') | 22 return xhr_send('POST', 'test string') |
23 .then(function(xhr) { | 23 .then(function(xhr) { |
24 window.parent.postMessage({results: xhr.getResponseHeader('foo')}, | 24 window.parent.postMessage({results: xhr.getResponseHeader('foo')}, |
25 host_info['HTTPS_ORIGIN']); | 25 host_info['HTTPS_ORIGIN']); |
| 26 |
| 27 return new Promise(function(resolve) { |
| 28 window.addEventListener('message', function handle(evt) { |
| 29 if (event.data !== 'ACK') { |
| 30 return; |
| 31 } |
| 32 |
| 33 window.removeEventListener('message', handle); |
| 34 resolve(); |
| 35 }); |
| 36 }); |
26 }); | 37 }); |
27 } | 38 } |
28 | 39 |
29 window.addEventListener('message', function(evt) { | 40 window.addEventListener('message', function(evt) { |
30 var port = evt.ports[0]; | 41 var port; |
| 42 |
| 43 if (event.data !== 'START') { |
| 44 return; |
| 45 } |
| 46 |
| 47 port = evt.ports[0]; |
| 48 |
31 coalesce_headers_test() | 49 coalesce_headers_test() |
32 .then(function() { port.postMessage({results: 'finish'}); }) | 50 .then(function() { port.postMessage({results: 'finish'}); }) |
33 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); | 51 .catch(function(e) { port.postMessage({results: 'failure:' + e}); }); |
34 }); | 52 }); |
35 </script> | 53 </script> |
OLD | NEW |