<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function addElement() {
    document.documentElement.appendChild(document.createTextNode('X'));
}
document.addEventListener("DOMContentLoaded", addElement, false);
window.onload = addElement;

var xhr = new XMLHttpRequest;
function sendXHR()
{
    console.log('Sending XHR');
    xhr.open("GET", "", true);
    try {
        xhr.send();
    }
    catch(e) {
        // In case of reentrant call, the call to "open" will be aborted by reentrant call.
        // The call to "send" following the "open" aborted call will throw an exception (XHR not in open mode)
        if (e.name != "InvalidStateError") {
            console.log("FAILED: Was expecting an InvalidStateError exception");
        }
        testRunner.notifyDone();
    }
}
window.addEventListener("DOMSubtreeModified", sendXHR);
addElement();
window.addEventListener('load', () => setTimeout(() => {
    if (window.testRunner)
        testRunner.notifyDone();
}, 0));
</script>
This tests that when we re-entrantly create and cancel XHRs, we don't try to disconnect the same CachedResourceClient
multiple times from its CachedResource. We pass if we don't crash.
