chromium/third_party/blink/web_tests/http/tests/cache/history-only-cached-subresource-loads.html

<!DOCTYPE html>
<html>
<head>
    <title>Test Caching "no-store" For History Only</title>
</head>
<body>
    <p>
        This test checks that a subresource with "Cache-Control: no-store" is not cached.
    </p>
    <pre id="console"></pre>
    <script>
    // Asynchronous test because this requires a new window to perform multiple navigations.
    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
        testRunner.setPopupBlockingEnabled(false);
    }

    // Values to check.
    var originalRandomNumber = 0;
    var backLoadRandomNumber = 0;
    var refreshRandomNumber  = 0;
    var nextLoadRandomNumber = 0;

    // Window we will be controlling.
    var target;

    // Pass messages between windows to control the navigation types.
    var pre = document.getElementById('console');
    window.addEventListener('message', function(event) {

        // First time, record the first number, and tell the target window to trigger a back navigation.
        if (!originalRandomNumber) {
            originalRandomNumber = event.data;
            target.postMessage('go-forward-and-back', '*');
            return;
        }

        // Second time, record the second number. It should be identical. Also tell the target window to reload.
        if (!backLoadRandomNumber) {
            backLoadRandomNumber = event.data;
            var wasCached = (backLoadRandomNumber === originalRandomNumber);
            if (wasCached)
                pre.appendChild(document.createTextNode('FAIL - no-store subresource should have been refetched for a back navigation\n'));
            else
                pre.appendChild(document.createTextNode('PASS - no-store subresource was refetched for a back navigation\n'));
            target.postMessage('reload', '*');
            return;
        }

        // Third time, record the third number. It should not match. Also tell the target window to navigate forward.
        if (!refreshRandomNumber) {
            refreshRandomNumber = event.data;
            var wasCached = (refreshRandomNumber === originalRandomNumber);
            if (wasCached)
                pre.appendChild(document.createTextNode('FAIL - no-store subresource should have been refetched with a reload\n'));
            else
                pre.appendChild(document.createTextNode('PASS - no-store subresource was refetched with a reload\n'));
            target.postMessage('next', '*');
            return;
        }

        // Fourth time, record the fourth number. It should not match any numbers so far.
        if (!nextLoadRandomNumber) {
            nextLoadRandomNumber = event.data;
            var wasCached = (nextLoadRandomNumber === originalRandomNumber || nextLoadRandomNumber === refreshRandomNumber);
            if (wasCached)
                pre.appendChild(document.createTextNode('FAIL - no-store subresource should have been refetched with a normal navigation\n'));
            else
                pre.appendChild(document.createTextNode('PASS - no-store subresource was refetched with a normal navigation\n'));
        }

        // Test completed.
        target.close();
        if (window.testRunner)
            testRunner.notifyDone();

    }, false);

    // Open the target window and it will begin to send us messages.
    target = window.open('resources/no-store-resource.html');
    </script>
</body>
</html>