Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / cache / history-only-cached-subresource-loads.html
blobcf218b1a4731392c6dc887b8d085c26b507e20f3
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Test Caching "no-store" For History Only</title>
5 </head>
6 <body>
7 <p>
8 This test checks that loading a subresource with "Cache-Control: no-store" is
9 cached and reused in back navigation when the page is not in the page cache.
10 </p>
11 <p>
12 We then test that loading the same subresource is refetched when used in
13 non-stale loads such as refreshes or normal navigation.
14 </p>
15 <pre id="console"></pre>
16 <script>
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();
24 // Values to check.
25 var originalRandomNumber = 0;
26 var backLoadRandomNumber = 0;
27 var refreshRandomNumber = 0;
28 var nextLoadRandomNumber = 0;
30 // Window we will be controlling.
31 var target;
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', '*');
41 return;
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);
48 if (wasCached)
49 pre.appendChild(document.createTextNode('PASS - no-store subresource was cached and used for a back navigation\n'));
50 else
51 pre.appendChild(document.createTextNode('FAIL - no-store subresource should have been cached and used in a back navigation\n'));
52 target.postMessage('reload', '*');
53 return;
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);
60 if (wasCached)
61 pre.appendChild(document.createTextNode('FAIL - no-store subresource should have been refetched with a reload\n'));
62 else
63 pre.appendChild(document.createTextNode('PASS - no-store subresource was refetched with a reload\n'));
64 target.postMessage('next', '*');
65 return;
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);
72 if (wasCached)
73 pre.appendChild(document.createTextNode('FAIL - no-store subresource should have been refetched with a normal navigation\n'));
74 else
75 pre.appendChild(document.createTextNode('PASS - no-store subresource was refetched with a normal navigation\n'));
78 // Test completed.
79 target.close();
80 if (window.testRunner)
81 window.testRunner.notifyDone();
83 }, false);
85 // Open the target window and it will begin to send us messages.
86 target = window.open('resources/no-store-resource.html');
87 </script>
88 </body>
89 </html>