blob: 5acfc05be7d45885175927587014103674e1ead9 [file] [log] [blame]
<!doctype html>
<html lang=en>
<meta charset=utf-8>
<title>XMLHttpRequest: upload progress event for cross-origin requests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<div id="log"></div>
<script>
const remote = get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/corsenabled.py",
redirect = "resources/redirect.py?code=307&location=" + remote;
[remote, redirect].forEach(url => {
promise_test(async test => {
const client = new XMLHttpRequest();
const loadFinished = new Promise(resolve => client.onloadend = resolve);
const progressReceived = new Promise(resolve => client.upload.onprogress = resolve);
const loadReceived = new Promise((resolve, reject) => client.onload = () => { reject("load event received") });
const body = "On time: " + url;
client.open("POST", url);
client.send(body);
await Promise.race([progressReceived, loadReceived]);
await loadFinished;
assert_equals(client.getResponseHeader("X-Request-Data"), body, "test body");
}, "Upload events registered on time (" + url + ")");
});
[remote, redirect].forEach(url => {
promise_test(async test => {
const client = new XMLHttpRequest();
const loadFinished = new Promise(resolve => client.onloadend = resolve);
const loadReceived = new Promise(resolve => client.onload = resolve);
const body = "Too late: " + url;
client.open("POST", url);
client.send(body);
const loadstartReceived = new Promise((resolve, reject) => client.upload.onloadstart = () => { reject("loadstart event received") });
const progressReceived = new Promise((resolve, reject) => client.upload.onprogress = () => { reject("progress event received") });
await Promise.race([loadReceived, progressReceived, loadstartReceived]);
await loadFinished;
assert_equals(client.getResponseHeader("X-Request-Data"), body);
}, "Upload events registered too late (" + url + ")");
});
</script>