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