chromium/third_party/blink/web_tests/http/tests/security/link-crossorigin-preload-anonymous.html

<!DOCTYPE HTML>
<html>
<head>
    <script src="../resources/testharness.js"></script>
    <script src="../resources/testharnessreport.js"></script>
</head>
<body>
<script>
    var t = async_test("Test that a preload with a crossorigin=anonymous loads a CORS enabled resource.");
    var anonymousMarkupLoad = false;
    var credentialsMarkupLoad = false;
    var anonymousDynamicLoad = false;
    var credentialsDynamicLoad = false;
</script>
<link crossorigin="anonymous" rel="preload" as="fetch" href="http://localhost:8080/security/resources/abe-allow-star.php" onload="anonymousMarkupLoad = true;">
<link crossorigin="anonymous" rel="preload" as="fetch" href="http://localhost:8080/security/resources/abe-allow-credentials.php" onload="credentialsMarkupLoad = true;">
<script>
    // Test that dynamically inserted <link> elements are handled the same way.
    var link = document.createElement("link");
    link.rel = "preload";
    link.as = "fetch";
    link.crossOrigin = "anonymous";
    link.addEventListener("load", function() { anonymousDynamicLoad = true; });
    link.href = "http://localhost:8080/security/resources/abe-allow-star.php?1";
    document.body.appendChild(link);

    link = document.createElement("link");
    link.rel = "preload";
    link.as = "fetch";
    link.crossOrigin = "anonymous";
    link.addEventListener("load", function() { credentialsDynamicLoad = true; });
    link.href = "http://localhost:8080/security/resources/abe-allow-credentials.php?1";
    document.body.appendChild(link);
</script>
<script src="../resources/slow-script.pl?delay=500"></script>
<script>
    window.onload = t.step(function(){
        assert_true(anonymousMarkupLoad, "anonymous markup resource triggered load event");
        assert_true(credentialsMarkupLoad, "use-credentials markup resource triggered load event");
        assert_true(anonymousDynamicLoad, "anonymous dynamic resource triggered load event");
        assert_true(credentialsDynamicLoad, "use-credentials dynamic resource triggered load event");
        t.done();
    });
</script>
</body>
</html>