chromium/third_party/blink/web_tests/fast/files/script-tests/xhr-response-blob.js

description("Test that XHR.responseType = 'blob' gives you back a Blob.");

if (window.testRunner)
    testRunner.waitUntilDone();

function testBlob(blobURL, blobType, doneFunction) {
    window.xhr = new XMLHttpRequest();
    xhr.open("GET", blobURL);
    xhr.responseType = "blob";
    shouldBeEqualToString("xhr.responseType", "blob");
    xhr.send();
    xhr.onreadystatechange = function() {
        if (xhr.readyState != 4) {
            shouldBeNull("xhr.response");
            return;
        }
        shouldBeTrue("xhr.response instanceof Blob");
        // This is checking a value determined by MIME sniffing
        shouldBeEqualToString("xhr.response.type", blobType);
        doneFunction();
    }
}

testBlob("resources/UTF8.txt", "text/plain", function() {
    testBlob("resources/does_not_exist.txt", "", function() {
        testBlob("resources/empty-file", "text/plain", function() {
            if (window.testRunner)
                testRunner.notifyDone();
        })
    })
});