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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial