chromium/third_party/blink/web_tests/http/tests/xmlhttprequest/withCredentials-after-send.html

<!doctype html>
<html>
<head>
<title>XMLHttpRequest: setting withCredentials while sending data</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<script>
var testAsync = async_test("Setting withCredentials, post-send() (async)");
testAsync.step(() => {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "resources/delay.php?iteration=1&delay=1000");
    xhr.onloadstart = testAsync.step_func(() => {
        assert_equals(xhr.readyState, XMLHttpRequest.OPENED);
        assert_throws_dom('InvalidStateError', () => { xhr.withCredentials = true; });
    });
    xhr.onloadend = testAsync.step_func(() => {
        assert_equals(xhr.readyState, XMLHttpRequest.DONE);
        testAsync.done();
    });
    xhr.send();
});

var testSync = async_test("Setting withCredentials, post-send() (sync)");
testSync.step(() => {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "resources/delay.php?iteration=1&delay=1000", false);
    xhr.onprogress = testSync.step_func(() => {
        assert_throws_dom('InvalidStateError', () => { xhr.withCredentials = true });
    });
    xhr.onloadend = testSync.step_func(() => {
        assert_equals(xhr.readyState, XMLHttpRequest.DONE);
        testSync.done();
    });
    xhr.send();
});
</script>
</body>
</html>