Home | History | Annotate | Download | only in appcache
      1 <html manifest=resources/online-fallback-layering.manifest>
      2 <head>
      3 <script>
      4 
      5 if (window.layoutTestController) {
      6     layoutTestController.dumpAsText();
      7     layoutTestController.waitUntilDone();
      8 }
      9 
     10 function log(message) {
     11     document.getElementById("log").innerHTML += message + "<br>";
     12 }
     13 
     14 function testComplete(result) {
     15     log(result);
     16     if (window.layoutTestController)
     17        layoutTestController.notifyDone();
     18 }
     19 
     20 function syncGet(url) {
     21     var xhr = new XMLHttpRequest();
     22     xhr.open("GET", url, false);
     23     xhr.send();
     24     if (xhr.status == 200)
     25         return xhr.responseText;
     26     if (xhr.status == 404)
     27         return "404 not found";
     28     log ("unexpected status code");
     29     return "";
     30 }
     31 
     32 applicationCache.oncached = function() { setTimeout(startTest, 0); }
     33 applicationCache.onnoupdate = function() { setTimeout(startTest, 0); }
     34 applicationCache.onupdateready = function() { log('onupdateready'); location.reload(); }
     35 applicationCache.onerror = function() { testComplete('FAIL - onerror'); }
     36 applicationCache.onobsolete = function() { testComplete('FAIL - onobsolete'); }
     37 
     38 function startTest() {
     39     applicationCache.oncached = null;
     40     applicationCache.onnoupdate = null;
     41 
     42     var response;
     43 
     44     log('Sanity check the presence of the fallback namespace, should get the fallback resource.');
     45     response = syncGet('resources/fallbacknamespace-nonexisting-resource');
     46     if (!response.match('fallback resource'))
     47         return testComplete('FAIL - did not get the fallback resource');
     48 
     49     log('Getting a network namespace resource that exists on the server, should succeed.');
     50     response = syncGet('resources/fallbacknamespace-networknamespace-existing-resource.html');
     51     if (!response.match('hello'))
     52         return testComplete('FAIL - did not get the existing resource');
     53 
     54     log('Getting a network namespace resource that does not exist on the server, should get a 404.');
     55     response = syncGet('resources/fallbacknamespace-networknamespace-nonexisting-resource');
     56     if (response != "404 not found")
     57         return testComplete('FAIL - did not get a 404 for the nonexisting resource');
     58 
     59     log('Creating two iframes for an existing and non-existing page, one should say "hello" the other should 404.');
     60     createFrame('resources/fallbacknamespace-networknamespace-existing-resource.html');
     61     createFrame('resources/fallbacknamespace-networknamespace-nonexisting-resource');
     62 }
     63 
     64 function createFrame(src) {
     65     var frame = document.createElement("iframe");
     66     frame.setAttribute("src", src);
     67     document.body.appendChild(frame);
     68 }
     69  
     70 function frameCreated() {
     71     log('- hello heard');
     72     setTimeout(waitFor404, 0);
     73 }
     74 
     75 function waitFor404() {
     76   try {
     77       var frameContent = frames[1].document.documentElement.innerHTML;
     78       if (frameContent.match("Not Found")) {
     79           log('- 404 detected');
     80           testComplete('PASS');
     81       } else if (frameContent.match("fallback resource"))
     82           testComplete('FAIL - subframe was loaded with the fallback resource.');
     83       else
     84           throw "Try again";
     85   } catch (ex) {
     86       setTimeout(waitFor404, 100);
     87   }
     88 }
     89 
     90 </script>
     91 </head>
     92 
     93 <body>
     94 <p>Test that a network namespace trumps a fallback namespace where they overlap.</p>
     95 <div id=log></div> 
     96 </body>
     97 </html>
     98