Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / cache / post-with-cached-subresources.php
bloba9cc043e42df1d1495c426f6330c5f90cb665503
1 <?php
2 require_once '../resources/portabilityLayer.php';
4 // This test loads an uncacheable main resource and a cacheable image subresource.
5 // We request this page as a GET, then reload this page with a POST.
6 // On the post request, the image should be loaded from the cache and no HTTP
7 // request should be sent. The image resource will return 404 if it receives
8 // a second request, which will cause us to FAIL.
9 // See https://bugs.webkit.org/show_bug.cgi?id=38690
10 header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
11 header('Pragma: no-cache');
12 header('Expires: ' . gmdate(DATE_RFC1123, time()-1));
14 <html>
15 <body>
16 <div id="result"></div>
17 <script>
18 if (window.testRunner) {
19 testRunner.dumpAsText();
20 testRunner.waitUntilDone();
23 function logAndFinish(message)
25 document.getElementById("result").appendChild(document.createTextNode(message));
26 var xhr = new XMLHttpRequest;
27 xhr.open("GET", "../resources/reset-temp-file.php?filename=post.tmp", false);
28 xhr.send(null);
29 if (window.testRunner)
30 testRunner.notifyDone();
32 </script>
33 <?php
34 clearstatcache();
35 if ($_POST["submit"] == "finish") {
36 // The initial load of the image might have been done from the cache. In that case, touch the
37 // state file to indicate a load has already occurred.
38 if (!file_exists(sys_get_temp_dir() . "/post.tmp")) {
39 echo "<script>";
40 echo "xhr = new XMLHttpRequest;";
41 echo "xhr.open('GET', '../resources/touch-temp-file.php?filename=post.tmp', false);";
42 echo "xhr.send(null);";
43 echo "</script>";
45 // Evict resources in memory cache before re-posting. Otherwise, it will
46 // always PASS.
47 echo "<script>";
48 echo "if (window.internals)";
49 echo " window.internals.evictAllResources();";
50 echo "</script>";
51 echo "<img src='resources/post-image-to-verify.php' onload=\"logAndFinish('PASS');\" onerror=\"logAndFinish('FAIL');\"></img>";
52 } else {
53 echo "<form action='post-with-cached-subresources.php' method='post'>";
54 echo "<input type='submit' id='submit' name='submit' value='finish'>";
55 echo "</form>";
56 echo "<img src='resources/post-image-to-verify.php' onload=\"document.getElementById('submit').click();\" onerror=\"logAndFinish('FAIL on initial load');\"></img>";
59 </body>
60 </html>