browser/base/content/test/general/test_offline_gzip.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=501422
     6 When content which was transported over the network with
     7 Content-Type: gzip is added to the offline 
     8 cache, it can be fetched from the cache successfully.
     9 -->
    10 <head>
    11   <title>Test gzipped offline resources</title>
    12   <script type="text/javascript" 
    13           src="/MochiKit/MochiKit.js"></script>
    14   <script type="text/javascript"
    15           src="/tests/SimpleTest/SimpleTest.js"></script>
    16   <script type="text/javascript" src="offlineByDefault.js"></script>
    17   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    18 </head>
    19 <body onload="loaded()">
    20 <p id="display">
    21 <iframe name="testFrame" src="gZipOfflineChild.html"></iframe>
    23 <div id="content" style="display: none">
    24 </div>
    25 <pre id="test">
    26 <script class="testbody" type="text/javascript">
    28 var cacheCount = 0;
    29 var intervalID = 0;
    31 window.addEventListener("message", handleMessageEvents, false);
    32 SimpleTest.waitForExplicitFinish();
    34 function finishTest() {
    35   // Clean up after ourselves.
    36   var Cc = SpecialPowers.Cc;
    37   var pm = Cc["@mozilla.org/permissionmanager;1"].
    38            getService(SpecialPowers.Ci.nsIPermissionManager);
    40   var uri = Cc["@mozilla.org/network/io-service;1"].getService(SpecialPowers.Ci.nsIIOService)
    41               .newURI(window.frames[0].location, null, null);
    42   var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
    43                    .getService(SpecialPowers.Ci.nsIScriptSecurityManager)
    44                    .getNoAppCodebasePrincipal(uri);
    46   pm.removeFromPrincipal(principal, "offline-app");
    48   window.removeEventListener("message", handleMessageEvents, false);
    50   offlineByDefault.reset();
    51   SimpleTest.finish();  
    52 }
    54 ////
    55 // Handle "message" events which are posted from the iframe upon
    56 // offline cache events.
    57 //
    58 function handleMessageEvents(event) {
    59   cacheCount++;
    60   switch (cacheCount) {
    61     case 1:
    62       // This is the initial caching off offline data.  
    63       is(event.data, "oncache", "Child was successfully cached.");
    64       // Reload the frame; this will generate an error message
    65       // in the case of bug 501422.
    66       frames.testFrame.window.location.reload();
    67       // Use setInterval to repeatedly call a function which
    68       // checks that one of two things has occurred:  either
    69       // the offline cache is udpated (which means our iframe
    70       // successfully reloaded), or the string "error" appears
    71       // in the iframe, as in the case of bug 501422.
    72       intervalID = setInterval(function() {
    73         // Sometimes document.body may not exist, and trying to access
    74         // it will throw an exception, so handle this case.
    75         try {
    76           var bodyInnerHTML = frames.testFrame.document.body.innerHTML;
    77         }
    78         catch (e) {
    79           var bodyInnerHTML = "";
    80         }
    81         if (cacheCount == 2 || bodyInnerHTML.contains("error")) {
    82           clearInterval(intervalID);
    83           is(cacheCount, 2, "frame not reloaded successfully");
    84           if (cacheCount != 2) {
    85             finishTest();
    86           }
    87         }
    88       }, 100);
    89       break;
    90     case 2:    
    91       is(event.data, "onupdate", "Child was successfully updated.");
    92       finishTest();
    93       break;
    94     default:
    95       // how'd we get here?
    96       ok(false, "cacheCount not 1 or 2");
    97   }
    98 }
   100 function loaded() {
   101   // Click the notification panel's "Allow" button.  This should kick
   102   // off updates, which will eventually lead to getting messages from
   103   // the iframe.
   104   var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"].
   105            getService(SpecialPowers.Ci.nsIWindowMediator);
   106   var win = wm.getMostRecentWindow("navigator:browser");
   107   var panel = win.PopupNotifications.panel;
   108   panel.firstElementChild.button.click();
   109 }
   111 </script>
   112 </pre>
   113 </body>
   114 </html>

mercurial