<!DOCTYPE html>
<html>
<head>
    <script src="../../resources/js-test-pre.js"></script>
    <script>
        description('This tests that the XMLHttpRequest responseType attribute is modifiable in the HEADERS_RECEIVED state.');
        window.jsTestIsAsync = true;

        var xhr = new XMLHttpRequest();
        xhr.open('GET', window.location.href);
        xhr.onload = function() {
            shouldBeTrue('xhr.response === xhr.responseXML');
            shouldBeEqualToString('xhr.responseType', 'document');
            finishJSTest();
        };
        xhr.onerror = function() {
            testFailed('An error occurred while loading the document "' + window.location.href + '".');
            finishJSTest();
        };
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 2) {
                // HEADERS_RECEIVED state, set the responseType now
                evalAndLog("xhr.responseType = 'document';");
            } else if (xhr.readyState > 2) {
                // LOADING or DONE, so we should get an exception when trying to set responseType
                shouldThrow("xhr.responseType = 'text';");
            }
        };
        xhr.send(null);
    </script>
    <script src="../../resources/js-test-post.js"></script>
</head>
<body>
    <div id="description"></div>
    <div id="console"></div>
</body>
</html>
