4 <title>Test Caching
"max-age" For History Only
</title>
8 This test checks that loading a subresource with
"Cache-Control: max-age=0" is
9 cached and reused in back navigation when the page is not in the page cache.
12 We then test that loading the same subresource is refetched when used in
13 non-stale loads such as refreshes or normal navigation.
15 <pre id=
"console"></pre>
17 // Asynchronous test because this requires a new window to perform multiple navigations.
18 if (window
.testRunner
) {
19 testRunner
.dumpAsText();
20 testRunner
.waitUntilDone();
21 testRunner
.setCanOpenWindows();
25 var originalRandomNumber
= 0;
26 var backLoadRandomNumber
= 0;
27 var refreshRandomNumber
= 0;
28 var nextLoadRandomNumber
= 0;
30 // Window we will be controlling.
33 // Pass messages between windows to control the navigation types.
34 var pre
= document
.getElementById('console');
35 window
.addEventListener('message', function(event
) {
37 // First time, record the first number, and tell the target window to trigger a back navigation.
38 if (!originalRandomNumber
) {
39 originalRandomNumber
= event
.data
;
40 target
.postMessage('go-forward-and-back', '*');
44 // Second time, record the second number. It should be identical. Also tell the target window to reload.
45 if (!backLoadRandomNumber
) {
46 backLoadRandomNumber
= event
.data
;
47 var wasCached
= (backLoadRandomNumber
=== originalRandomNumber
);
49 pre
.appendChild(document
.createTextNode('PASS - max-age subresource was cached and used for a back navigation\n'));
51 pre
.appendChild(document
.createTextNode('FAIL - max-age subresource should have been cached and used in a back navigation\n'));
52 target
.postMessage('reload', '*');
56 // Third time, record the third number. It should not match. Also tell the target window to navigate forward.
57 if (!refreshRandomNumber
) {
58 refreshRandomNumber
= event
.data
;
59 var wasCached
= (refreshRandomNumber
=== originalRandomNumber
);
61 pre
.appendChild(document
.createTextNode('FAIL - max-age subresource should have been refetched with a reload\n'));
63 pre
.appendChild(document
.createTextNode('PASS - max-age subresource was refetched with a reload\n'));
64 target
.postMessage('next', '*');
68 // Fourth time, record the fourth number. It should not match any numbers so far.
69 if (!nextLoadRandomNumber
) {
70 nextLoadRandomNumber
= event
.data
;
71 var wasCached
= (nextLoadRandomNumber
=== originalRandomNumber
|| nextLoadRandomNumber
=== refreshRandomNumber
);
73 pre
.appendChild(document
.createTextNode('FAIL - max-age subresource should have been refetched with a normal navigation\n'));
75 pre
.appendChild(document
.createTextNode('PASS - max-age subresource was refetched with a normal navigation\n'));
80 if (window
.testRunner
)
81 window
.testRunner
.notifyDone();
85 // Open the target window and it will begin to send us messages.
86 target
= window
.open('https://127.0.0.1:8443/cache/resources/max-age-resource.html');