blob: 8f0e6baca1757cfc18c929438b72750920303343 (
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
|
<script src="test-helpers.sub.js"></script>
<script>
function xhr_send(method, data) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
reject('XHR must fail.');
};
xhr.onerror = function() {
resolve();
};
xhr.responseType = 'text';
xhr.open(method, './sample?test', true);
xhr.send(data);
});
}
window.addEventListener('message', function(evt) {
var port = evt.ports[0];
xhr_send('POST', 'test string')
.then(function() { port.postMessage({results: 'finish'}); })
.catch(function(e) { port.postMessage({results: 'failure:' + e}); });
});
</script>
|