Home | History | Annotate | Download | only in appcache
      1 <html manifest="resources/fail-on-update.php">
      2 <p>Test that a 404 response for manifest results in cache removal.</p>
      3 <body>
      4 <ul>
      5 <li>Frame 1: Manifest is still available, so a new master resource is added to the cache.
      6 <li>Frame 2: Manifest loading results in 404 response, so the cache group becomes obsolete, and an obsolete event is dispatched (because the document in frame was associated with a cache in the group).
      7 <li>Frame 3: Manifest is still 404 - the document is never associated with a cache.
      8 <li>Frame 4: Manifest is now available, so the document gets associated with a cache in a newly created group; the obsolete cache group is not affected.
      9 </ul>
     10 <p>Should say SUCCESS:</p>
     11 <div id=result></div>
     12 
     13 <script>
     14 if (window.layoutTestController) {
     15     layoutTestController.dumpAsText();
     16     layoutTestController.waitUntilDone();
     17 }
     18 
     19 function log(message)
     20 {
     21     document.getElementById("result").innerHTML += message + "<br>";
     22 }
     23 
     24 function setManifestDeleted(state)
     25 {
     26     var req = new XMLHttpRequest;
     27     req.open("GET", "resources/fail-on-update.php?command=" + (state ? "delete" : "reset"), false);
     28     req.send(null);
     29 }
     30 
     31 function test()
     32 {
     33     clearTimeout(timeoutId);
     34 
     35     // The frame will be associated to a cache, and its main resource will be added to the cache.
     36     var ifr = document.createElement("iframe");
     37     ifr.setAttribute("src", "resources/remove-cache-frame.html");
     38     document.body.appendChild(ifr);
     39     applicationCache.onnoupdate = test2;
     40 }
     41 
     42 function test2()
     43 {
     44     applicationCache.onnoupdate = function() { log("Unexpected noupdate event") }
     45     applicationCache.oncached = function() { log("Unexpected cached event") }
     46 
     47     setManifestDeleted(true);
     48     // The frame will be associated to a cache, but update will obsolete it.
     49     var ifr = document.createElement("iframe");
     50     ifr.setAttribute("src", "resources/remove-cache-frame.html");
     51     document.body.appendChild(ifr);
     52     applicationCache.onobsolete = test3;
     53 }
     54 
     55 function test3()
     56 {
     57     applicationCache.onchecking = function() { log("Unexpected checking event after obsolete event") }
     58     applicationCache.onupdateready = function() { log("Unexpected updateready event after obsolete event") }
     59     applicationCache.onerror = function() { log("Unexpected error event after obsolete event") }
     60     applicationCache.onnoupdate = function() { log("Unexpected noupdate event after obsolete event") }
     61     applicationCache.oncached = function() { log("Unexpected cached event after obsolete event") }
     62 
     63     // The frame will not be associated to a cache.
     64     var ifr = document.createElement("iframe");
     65     ifr.setAttribute("src", "resources/remove-cache-frame.html");
     66     document.body.appendChild(ifr);
     67     window.addEventListener("message", test4, false);
     68 }
     69 
     70 function test4()
     71 {
     72     setManifestDeleted(false);
     73 
     74     window.removeEventListener("message", test4, false);
     75     applicationCache.onupdateready = null;
     76 
     77     // The frame will be associated to a cache.
     78     var ifr = document.createElement("iframe");
     79     ifr.setAttribute("src", "resources/remove-cache-frame-2.html");
     80     document.body.appendChild(ifr);
     81     window.addEventListener("message", test5, false);
     82 }
     83 
     84 function test5()
     85 {
     86     log("SUCCESS");
     87     if (window.layoutTestController)
     88         layoutTestController.notifyDone();
     89 }
     90 
     91 function resetManifest()
     92 {
     93     if (applicationCache.status != applicationCache.UNCACHED && applicationCache.status != applicationCache.OBSOLETE) {
     94         timeoutId = setTimeout(resetManifest, 100);
     95         return;
     96     }
     97 
     98     setManifestDeleted(false);
     99     location.reload();
    100 }
    101 
    102 applicationCache.onupdateready = function() { log("Unexpected updateready event") }
    103 applicationCache.onnoupdate = test;
    104 applicationCache.oncached = test;
    105 
    106 // If the manifest script happened to be in a wrong state, reset it.
    107 var timeoutId = setTimeout(resetManifest, 100);
    108 
    109 </script>
    110 </body>
    111 </html>
    112