<!DOCTYPE html>
<script>
    if (window.testRunner) {
        testRunner.dumpAsText()
        testRunner.waitUntilDone();
    }
</script>
<script src="/js-test-resources/js-test.js"></script>
<script>
    var scriptLoaded = false;
    var styleLoaded = false;
    var imageLoaded = false;
    var fontLoaded = false;
    var mediaLoaded = false;
    var trackLoaded = false;
    var gibberishLoaded = false;
    var gibberishErrored = false;
    var xsltLoaded = false;
    var xsltErrored = false;
    var noTypeLoaded = false;
    var emptyTypeLoaded = false;
    var fetchLoaded = false;
    var counter = 0;
    function count() {
        ++window.counter;
    };
</script>
<link rel=preload href="../resources/dummy.js" as=script onload="count(); scriptLoaded = true;" onerror="count()">
<link rel=preload href="../resources/dummy.css" as=style onload="count(); styleLoaded = true;" onerror="count()">
<link rel=preload href="../resources/square100.png" as=image onload="count(); imageLoaded = true;" onerror="count()">
<link rel=preload href="../resources/Ahem.woff" as=font crossorigin onload="count(); fontLoaded = true;" onerror="count()">
<link rel=preload href="../resources/test.ogv" as=video onload="count(); mediaLoaded = true;" onerror="count()">
<link rel=preload href="../security/resources/captions.vtt" as=track onload="count(); trackLoaded = true;" onerror="count();">
<link rel=preload href="../resources/dummy.xml?foobarxmlthing" as=foobarxmlthing onload="count(); gibberishLoaded = true;" onerror="count(); gibberishErrored = true;">
<link rel=preload href="../resources/dummy.xslt" as=xslt onload="count(); xsltLoaded = true;" onerror="count(); xsltErrored = true;">
<link rel=preload href="../resources/dummy.xml" onload="count(); noTypeLoaded = true;" onerror="count()">
<link rel=preload href="../resources/dummy.xml?empty" as onload="count(); emptyTypeLoaded = true;" onerror="count()">
<link rel=preload href="../resources/dummy.xml?fetch" as=fetch onload="count(); fetchLoaded = true;" onerror="count()">
<script>
    function test() {
        shouldBeTrue("styleLoaded");
        shouldBeTrue("scriptLoaded");
        shouldBeTrue("imageLoaded");
        shouldBeTrue("fontLoaded");
        shouldBeTrue("mediaLoaded");
        shouldBeTrue("trackLoaded");
        shouldBeFalse("gibberishLoaded");
        shouldBeFalse("gibberishErrored");
        shouldBeFalse("xsltLoaded");
        shouldBeFalse("xsltErrored");
        shouldBeFalse("noTypeLoaded");
        shouldBeFalse("emptyTypeLoaded");
        shouldBeTrue("fetchLoaded");
        if (window.testRunner)
            testRunner.notifyDone();
    }
    document.write('<script src="../resources/dummy.js"></scr' + 'ipt>' +
                   '<link rel=stylesheet href="../resources/dummy.css">' +
                   '<img src="../resources/square.png">' +
                   '<video><source src="test.mp4">' +
                   '<track kind=subtitles src="../../security/resources/captions.vtt" srclang=en>' +
                   '</video>' +
                   '<style>' +
                   '    @font-face { font-family:ahem; src: url(../../w3c/webperf/resources/Ahem.ttf); }' +
                   '    span { font-family: ahem, Arial; }' +
                   '</style>' +
                   '<span>This test makes sure that link preload events are fired</span>');
    var xhr = new XMLHttpRequest();
    xhr.open("GET", "../resources/dummy.xml");
    xhr.send();
    var xhr2 = new XMLHttpRequest();
    xhr2.open("GET", "../resources/dummy.xml?badvalue");
    xhr2.send();
    addEventListener("load", function(){
        setInterval(function() {
            if (window.counter >= 7)
                test();
        }, 100);
    });
</script>

