<!DOCTYPE html>
<html>
<body>
<script src="/js-test-resources/js-test.js"></script>
<script>
description("Tests that we do not crash when XHR reuses a cached resource that contains a simple cross origin redirect.");
jsTestIsAsync = true;

const url = "/cache/resources/cache-control-redirect.py?code=302&cache_control=public,max-age=1000&url=http%3A%2F%2Flocalhost%3A8000%2Fsecurity%2Fresources%2Fallow-if-origin.py%3FallowCache%26allowCredentials%26origin%3Dhttp%253A%252F%252F127.0.0.1%253A8000";

xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.onload = function() {
    xhr = new XMLHttpRequest();
    xhr.withCredentials = true;
    xhr.onload = function() {
        shouldBeEqualToString("internals.xhrResponseSource(xhr)", "Memory cache");
        finishJSTest();
    };
    xhr.open("GET", url);
    xhr.send();
};
xhr.open("GET", url);
xhr.send();
</script>
</body>
</html>
