1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/test_offline_gzip.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=501422 1.8 + 1.9 +When content which was transported over the network with 1.10 +Content-Type: gzip is added to the offline 1.11 +cache, it can be fetched from the cache successfully. 1.12 +--> 1.13 +<head> 1.14 + <title>Test gzipped offline resources</title> 1.15 + <script type="text/javascript" 1.16 + src="/MochiKit/MochiKit.js"></script> 1.17 + <script type="text/javascript" 1.18 + src="/tests/SimpleTest/SimpleTest.js"></script> 1.19 + <script type="text/javascript" src="offlineByDefault.js"></script> 1.20 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.21 +</head> 1.22 +<body onload="loaded()"> 1.23 +<p id="display"> 1.24 +<iframe name="testFrame" src="gZipOfflineChild.html"></iframe> 1.25 + 1.26 +<div id="content" style="display: none"> 1.27 +</div> 1.28 +<pre id="test"> 1.29 +<script class="testbody" type="text/javascript"> 1.30 + 1.31 +var cacheCount = 0; 1.32 +var intervalID = 0; 1.33 + 1.34 +window.addEventListener("message", handleMessageEvents, false); 1.35 +SimpleTest.waitForExplicitFinish(); 1.36 + 1.37 +function finishTest() { 1.38 + // Clean up after ourselves. 1.39 + var Cc = SpecialPowers.Cc; 1.40 + var pm = Cc["@mozilla.org/permissionmanager;1"]. 1.41 + getService(SpecialPowers.Ci.nsIPermissionManager); 1.42 + 1.43 + var uri = Cc["@mozilla.org/network/io-service;1"].getService(SpecialPowers.Ci.nsIIOService) 1.44 + .newURI(window.frames[0].location, null, null); 1.45 + var principal = Cc["@mozilla.org/scriptsecuritymanager;1"] 1.46 + .getService(SpecialPowers.Ci.nsIScriptSecurityManager) 1.47 + .getNoAppCodebasePrincipal(uri); 1.48 + 1.49 + pm.removeFromPrincipal(principal, "offline-app"); 1.50 + 1.51 + window.removeEventListener("message", handleMessageEvents, false); 1.52 + 1.53 + offlineByDefault.reset(); 1.54 + SimpleTest.finish(); 1.55 +} 1.56 + 1.57 +//// 1.58 +// Handle "message" events which are posted from the iframe upon 1.59 +// offline cache events. 1.60 +// 1.61 +function handleMessageEvents(event) { 1.62 + cacheCount++; 1.63 + switch (cacheCount) { 1.64 + case 1: 1.65 + // This is the initial caching off offline data. 1.66 + is(event.data, "oncache", "Child was successfully cached."); 1.67 + // Reload the frame; this will generate an error message 1.68 + // in the case of bug 501422. 1.69 + frames.testFrame.window.location.reload(); 1.70 + // Use setInterval to repeatedly call a function which 1.71 + // checks that one of two things has occurred: either 1.72 + // the offline cache is udpated (which means our iframe 1.73 + // successfully reloaded), or the string "error" appears 1.74 + // in the iframe, as in the case of bug 501422. 1.75 + intervalID = setInterval(function() { 1.76 + // Sometimes document.body may not exist, and trying to access 1.77 + // it will throw an exception, so handle this case. 1.78 + try { 1.79 + var bodyInnerHTML = frames.testFrame.document.body.innerHTML; 1.80 + } 1.81 + catch (e) { 1.82 + var bodyInnerHTML = ""; 1.83 + } 1.84 + if (cacheCount == 2 || bodyInnerHTML.contains("error")) { 1.85 + clearInterval(intervalID); 1.86 + is(cacheCount, 2, "frame not reloaded successfully"); 1.87 + if (cacheCount != 2) { 1.88 + finishTest(); 1.89 + } 1.90 + } 1.91 + }, 100); 1.92 + break; 1.93 + case 2: 1.94 + is(event.data, "onupdate", "Child was successfully updated."); 1.95 + finishTest(); 1.96 + break; 1.97 + default: 1.98 + // how'd we get here? 1.99 + ok(false, "cacheCount not 1 or 2"); 1.100 + } 1.101 +} 1.102 + 1.103 +function loaded() { 1.104 + // Click the notification panel's "Allow" button. This should kick 1.105 + // off updates, which will eventually lead to getting messages from 1.106 + // the iframe. 1.107 + var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"]. 1.108 + getService(SpecialPowers.Ci.nsIWindowMediator); 1.109 + var win = wm.getMostRecentWindow("navigator:browser"); 1.110 + var panel = win.PopupNotifications.panel; 1.111 + panel.firstElementChild.button.click(); 1.112 +} 1.113 + 1.114 +</script> 1.115 +</pre> 1.116 +</body> 1.117 +</html>