Bug 1257488 - Fix test_gzip_offline.html to work with e10s enabled, r=mayhemer
authorGabriele Svelto <gsvelto@mozilla.com>
Thu, 17 Mar 2016 11:58:14 +0100
changeset 313350 116497ecbdabb62e985e99fc15e9f05814482c94
parent 313349 ab15d48afbb2a88b157b305ff93384f5fe6398d0
child 313351 8279c04272ee46eac5fc60ba52065ed7aefc5b28
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1257488
milestone48.0a1
Bug 1257488 - Fix test_gzip_offline.html to work with e10s enabled, r=mayhemer MozReview-Commit-ID: Fv3ECOAlJ2b
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_gZipOfflineChild.js
browser/base/content/test/general/gZipOfflineChild.html
browser/base/content/test/general/mochitest.ini
browser/base/content/test/general/test_offline_gzip.html
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -346,16 +346,19 @@ skip-if = os == "linux" # Linux: Intermi
 [browser_menuButtonFitts.js]
 skip-if = os != "win" # The Fitts Law menu button is only supported on Windows (bug 969376)
 [browser_middleMouse_noJSPaste.js]
 [browser_minimize.js]
 [browser_mixedcontent_securityflags.js]
 tags = mcb
 [browser_offlineQuotaNotification.js]
 skip-if = buildapp == 'mulet' || e10s # Bug 1093603 - test breaks with PopupNotifications.panel.firstElementChild is null
+[browser_gZipOfflineChild.js]
+skip-if = buildapp == 'mulet' # Bug 1066070 - I don't think either popup notifications nor addon install stuff works?
+support-files = test_offline_gzip.html gZipOfflineChild.cacheManifest gZipOfflineChild.cacheManifest^headers^ gZipOfflineChild.html gZipOfflineChild.html^headers^
 [browser_openPromptInBackgroundTab.js]
 support-files = openPromptOffTimeout.html
 [browser_overflowScroll.js]
 [browser_pageInfo.js]
 skip-if = buildapp == 'mulet'
 [browser_page_style_menu.js]
 [browser_page_style_menu_update.js]
 [browser_parsable_css.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_gZipOfflineChild.js
@@ -0,0 +1,80 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const URL = "http://mochi.test:8888/browser/browser/base/content/test/general/test_offline_gzip.html"
+
+registerCleanupFunction(function() {
+  // Clean up after ourself
+  let uri = Services.io.newURI(URL, null, null);
+  let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {});
+  Services.perms.removeFromPrincipal(principal, "offline-app");
+  Services.prefs.clearUserPref("offline-apps.allow_by_default");
+});
+
+var cacheCount = 0;
+var intervalID = 0;
+
+////
+// Handle "message" events which are posted from the iframe upon
+// offline cache events.
+//
+function handleMessageEvents(event) {
+  cacheCount++;
+  switch (cacheCount) {
+    case 1:
+      // This is the initial caching off offline data.
+      is(event.data, "oncache", "Child was successfully cached.");
+      // Reload the frame; this will generate an error message
+      // in the case of bug 501422.
+      event.source.location.reload();
+      // Use setInterval to repeatedly call a function which
+      // checks that one of two things has occurred:  either
+      // the offline cache is udpated (which means our iframe
+      // successfully reloaded), or the string "error" appears
+      // in the iframe, as in the case of bug 501422.
+      intervalID = setInterval(function() {
+        // Sometimes document.body may not exist, and trying to access
+        // it will throw an exception, so handle this case.
+        try {
+          var bodyInnerHTML = event.source.document.body.innerHTML;
+        }
+        catch (e) {
+          var bodyInnerHTML = "";
+        }
+        if (cacheCount == 2 || bodyInnerHTML.includes("error")) {
+          clearInterval(intervalID);
+          is(cacheCount, 2, "frame not reloaded successfully");
+          if (cacheCount != 2) {
+            finish();
+          }
+        }
+      }, 100);
+      break;
+    case 2:
+      is(event.data, "onupdate", "Child was successfully updated.");
+      clearInterval(intervalID);
+      finish();
+      break;
+    default:
+      // how'd we get here?
+      ok(false, "cacheCount not 1 or 2");
+  }
+}
+
+function test() {
+  waitForExplicitFinish();
+
+  Services.prefs.setBoolPref("offline-apps.allow_by_default", true);
+
+  // Open a new tab.
+  gBrowser.selectedTab = gBrowser.addTab(URL);
+  registerCleanupFunction(() => gBrowser.removeCurrentTab());
+
+  BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
+    let window = gBrowser.selectedBrowser.contentWindow;
+
+    window.addEventListener("message", handleMessageEvents, false);
+  });
+}
index bd2d62ee0d2013c832769a9a5652b85c5172154e..ea2caa12553bc4754c59e9d3007cacd76460a572
GIT binary patch
literal 303
zc$@(*0nq**iwFoCjp|kc17>e;E@*UZYyfqUF;BxV5QTUDiX&5tNTO~?I9WPZEKF?1
zzSLKxwq;)^1@*sUC#}RlCrkJFy}NrSEgwfXDn|n*?yCJeh1X#i$>G-0Xd11w#od)x
zy^t1_=>>p%sB3t$lwhC{A;0@?3IPqU2OUu{g8%C@cdF}b!Neo>vRz&wkH`wNRWV^6
zVd9~FE}fE&6d3p%u&WrqxIL&(wNx_~!{juRcX<Fu$*$6*HKw$NpFG})objh7sECf6
z;1lmMQ+vF9dxGk*TEB>k5GsU`v?^ZPvTozuytaW3ZcSF%_SUGn@+^nTe`@EaU`haY
z^$WjifHC@bUp?bREM&VRk^^g(+X(sL&AFUv)6daouqpUjZp$Tl@eAkxgv$E?007-I
BlHC9R
--- a/browser/base/content/test/general/mochitest.ini
+++ b/browser/base/content/test/general/mochitest.ini
@@ -3,20 +3,16 @@ skip-if = buildapp == 'b2g'
 support-files =
   audio.ogg
   bug364677-data.xml
   bug364677-data.xml^headers^
   bug395533-data.txt
   contextmenu_common.js
   ctxmenu-image.png
   feed_discovery.html
-  gZipOfflineChild.cacheManifest
-  gZipOfflineChild.cacheManifest^headers^
-  gZipOfflineChild.html
-  gZipOfflineChild.html^headers^
   head_plain.js
   offlineByDefault.js
   offlineChild.cacheManifest
   offlineChild.cacheManifest^headers^
   offlineChild.html
   offlineChild2.cacheManifest
   offlineChild2.cacheManifest^headers^
   offlineChild2.html
@@ -27,10 +23,8 @@ support-files =
   video.ogg
 
 [test_bug364677.html]
 [test_bug395533.html]
 [test_feed_discovery.html]
 skip-if = e10s
 [test_offlineNotification.html]
 skip-if = buildapp == 'mulet' || e10s # Bug 1066070 - I don't think either popup notifications nor addon install stuff works?
-[test_offline_gzip.html]
-skip-if = buildapp == 'mulet' || e10s # Bug 1066070 - I don't think either popup notifications nor addon install stuff works?
--- a/browser/base/content/test/general/test_offline_gzip.html
+++ b/browser/base/content/test/general/test_offline_gzip.html
@@ -4,112 +4,18 @@
 https://bugzilla.mozilla.org/show_bug.cgi?id=501422
 
 When content which was transported over the network with
 Content-Type: gzip is added to the offline 
 cache, it can be fetched from the cache successfully.
 -->
 <head>
   <title>Test gzipped offline resources</title>
-  <script type="text/javascript" 
-          src="/MochiKit/MochiKit.js"></script>
-  <script type="text/javascript"
-          src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="offlineByDefault.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <meta charset="utf-8">
 </head>
-<body onload="loaded()">
+<body>
 <p id="display">
 <iframe name="testFrame" src="gZipOfflineChild.html"></iframe>
 
 <div id="content" style="display: none">
 </div>
-<pre id="test">
-<script class="testbody" type="text/javascript">
-
-var cacheCount = 0;
-var intervalID = 0;
-
-window.addEventListener("message", handleMessageEvents, false);
-SimpleTest.waitForExplicitFinish();
-
-function finishTest() {
-  // Clean up after ourselves.
-  var Cc = SpecialPowers.Cc;
-  var pm = Cc["@mozilla.org/permissionmanager;1"].
-           getService(SpecialPowers.Ci.nsIPermissionManager);
-
-  var uri = Cc["@mozilla.org/network/io-service;1"].getService(SpecialPowers.Ci.nsIIOService)
-              .newURI(window.frames[0].location, null, null);
-  var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
-              .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
-  var principal = ssm.createCodebasePrincipal(uri, {});
-
-  pm.removeFromPrincipal(principal, "offline-app");
-
-  window.removeEventListener("message", handleMessageEvents, false);
-
-  offlineByDefault.reset();
-  SimpleTest.finish();  
-}
-
-////
-// Handle "message" events which are posted from the iframe upon
-// offline cache events.
-//
-function handleMessageEvents(event) {
-  cacheCount++;
-  switch (cacheCount) {
-    case 1:
-      // This is the initial caching off offline data.  
-      is(event.data, "oncache", "Child was successfully cached.");
-      // Reload the frame; this will generate an error message
-      // in the case of bug 501422.
-      frames.testFrame.window.location.reload();
-      // Use setInterval to repeatedly call a function which
-      // checks that one of two things has occurred:  either
-      // the offline cache is udpated (which means our iframe
-      // successfully reloaded), or the string "error" appears
-      // in the iframe, as in the case of bug 501422.
-      intervalID = setInterval(function() {
-        // Sometimes document.body may not exist, and trying to access
-        // it will throw an exception, so handle this case.
-        try {
-          var bodyInnerHTML = frames.testFrame.document.body.innerHTML;
-        }
-        catch (e) {
-          var bodyInnerHTML = "";
-        }
-        if (cacheCount == 2 || bodyInnerHTML.includes("error")) {
-          clearInterval(intervalID);
-          is(cacheCount, 2, "frame not reloaded successfully");
-          if (cacheCount != 2) {
-            finishTest();
-          }
-        }
-      }, 100);
-      break;
-    case 2:    
-      is(event.data, "onupdate", "Child was successfully updated.");
-      clearInterval(intervalID);
-      finishTest();
-      break;
-    default:
-      // how'd we get here?
-      ok(false, "cacheCount not 1 or 2");
-  }
-}
-
-function loaded() {
-  // Click the notification panel's "Allow" button.  This should kick
-  // off updates, which will eventually lead to getting messages from
-  // the iframe.
-  var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"].
-           getService(SpecialPowers.Ci.nsIWindowMediator);
-  var win = wm.getMostRecentWindow("navigator:browser");
-  var panel = win.PopupNotifications.panel;
-  panel.firstElementChild.button.click();
-}
-
-</script>
-</pre>
 </body>
 </html>