chromium/third_party/blink/web_tests/http/tests/xmlhttprequest/ontimeout-event-override.html

<!doctype html>
<html>
<head>
<title>Verify that a timeout ProgressEvent is dispatched and have the expected values.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<div id="logEvent"></div>
<script type="text/javascript">
var didTimeout = false;

function timeoutEvent(e) {
    didTimeout = true;
}

function unexpectedProgressEvent(e) {
    assert_unreached("'" + e.type + "' event should not be dispatched, expected 'timeout'");
}

var testOnTimeoutEvent = async_test("Check that 'timeout' events are delivered and have expected values.");
testOnTimeoutEvent.step(function () {
    var xhr = new XMLHttpRequest();
    xhr.ontimeout = testOnTimeoutEvent.step_func(timeoutEvent);
    xhr.onabort = testOnTimeoutEvent.step_func(unexpectedProgressEvent);
    xhr.onerror = testOnTimeoutEvent.step_func(unexpectedProgressEvent);
    xhr.onload = testOnTimeoutEvent.step_func(unexpectedProgressEvent);
    xhr.onloadend = testOnTimeoutEvent.step_func(function(e) {
        assert_true(didTimeout, "'timeout' event should be dispatched after 400ms");
        testOnTimeoutEvent.done();
    });
    xhr.timeout = 100000;
    xhr.open("GET", "../resources/load-and-stall.php?name=test.mp4&stallAt=0&stallFor=1000&mimeType=video/mp4", true);
    xhr.send();
    // Defer overriding timeout
    setTimeout(function() {
        xhr.timeout = 400;
    }, 200);
});
</script>
</body>
</html>