Bug 967873 - browser_onbeforeunload_navigation.js fix for e10s (r=Gijs)
authorBill McCloskey <billm@mozilla.com>
Tue, 29 Sep 2015 14:07:15 -0700
changeset 298316 0bf4a906901280034b0dbc09091b337a79f0cf07
parent 298315 c7715a504b005084819a23f8bd5ddd94a2ffc659
child 298317 c98a08ab12b358ec2843e1ea08659c93e475f90e
push id6068
push userkcambridge@mozilla.com
push dateFri, 02 Oct 2015 20:37:20 +0000
reviewersGijs
bugs967873
milestone44.0a1
Bug 967873 - browser_onbeforeunload_navigation.js fix for e10s (r=Gijs)
docshell/test/browser/browser.ini
docshell/test/browser/browser_onbeforeunload_navigation.js
docshell/test/browser/file_bug1046022.html
--- a/docshell/test/browser/browser.ini
+++ b/docshell/test/browser/browser.ini
@@ -98,15 +98,14 @@ skip-if = e10s # Bug ?????? - event hand
 skip-if = e10s # Bug ?????? - event handler checks event.target is the content document and test e10s-utils doesn't do that.
 [browser_uriFixupIntegration.js]
 [browser_loadDisallowInherit.js]
 skip-if = e10s
 [browser_loadURI.js]
 skip-if = e10s # Bug ?????? - event handler checks event.target is the content document and test e10s-utils doesn't do that.
 [browser_multiple_pushState.js]
 [browser_onbeforeunload_navigation.js]
-skip-if = e10s
 [browser_search_notification.js]
 [browser_timelineMarkers-01.js]
 [browser_timelineMarkers-02.js]
 [browser_timelineMarkers-03.js]
 [browser_timelineMarkers-04.js]
 [browser_timelineMarkers-05.js]
--- a/docshell/test/browser/browser_onbeforeunload_navigation.js
+++ b/docshell/test/browser/browser_onbeforeunload_navigation.js
@@ -5,16 +5,17 @@ var stayingOnPage = true;
 
 var TEST_PAGE = "http://mochi.test:8888/browser/docshell/test/browser/file_bug1046022.html";
 var TARGETED_PAGE = "data:text/html," + encodeURIComponent("<body>Shouldn't be seeing this</body>");
 
 SpecialPowers.pushPrefEnv({"set": [["dom.require_user_interaction_for_beforeunload", false]]});
 
 var loadExpected = TEST_PAGE;
 var testTab;
+var testsLength;
 
 var loadStarted = false;
 var tabStateListener = {
   onStateChange: function(webprogress, request, stateFlags, status) {
     let startDocumentFlags = Ci.nsIWebProgressListener.STATE_START |
                              Ci.nsIWebProgressListener.STATE_IS_DOCUMENT;
     if ((stateFlags & startDocumentFlags) == startDocumentFlags) {
       loadStarted = true;
@@ -35,16 +36,20 @@ function onTabLoaded(event) {
     return;
   }
 
   if (!loadExpected) {
     ok(false, "Expected no page loads, but loaded " + loadedPage + " instead!");
     return;
   }
 
+  if (!testsLength) {
+    testsLength = testTab.linkedBrowser.contentWindow.wrappedJSObject.testFns.length;
+  }
+
   is(loadedPage, loadExpected, "Loaded the expected page");
   if (contentWindow) {
     is(contentWindow.document, event.target, "Same doc");
   }
   if (onAfterPageLoad) {
     onAfterPageLoad();
   }
 }
@@ -97,57 +102,19 @@ function onTabModalDialogLoaded(node) {
   // ... and then actually make the dialog go away
   info("Clicking button: " + button.label);
   EventUtils.synthesizeMouseAtCenter(button, {});
 }
 
 // Listen for the dialog being created
 Services.obs.addObserver(onTabModalDialogLoaded, "tabmodal-dialog-loaded", false);
 
-var testFns = [
-  function(e) {
-    e.target.location.href = 'otherpage-href-set.html';
-    return "stop";
-  },
-  function(e) {
-    e.target.location.reload();
-    return "stop";
-  },
-  function(e) {
-    e.target.location.replace('otherpage-location-replaced.html');
-    return "stop";
-  },
-  function(e) {
-    var link = e.target.createElement('a');
-    link.href = "otherpage.html";
-    e.target.body.appendChild(link);
-    link.click();
-    return "stop";
-  },
-  function(e) {
-    var link = e.target.createElement('a');
-    link.href = "otherpage.html";
-    link.setAttribute("target", "_blank");
-    e.target.body.appendChild(link);
-    link.click();
-    return "stop";
-  },
-  function(e) {
-    var link = e.target.createElement('a');
-    link.href = e.target.location.href;
-    e.target.body.appendChild(link);
-    link.setAttribute("target", "somearbitrarywindow");
-    link.click();
-    return "stop";
-  },
-];
-
 function runNextTest() {
   currentTest++;
-  if (currentTest >= testFns.length) {
+  if (currentTest >= testsLength) {
     if (!stayingOnPage) {
       finish();
       return;
     }
     // Run the same tests again, but this time let the navigation happen:
     stayingOnPage = false;
     currentTest = 0;
   }
@@ -166,20 +133,20 @@ function runNextTest() {
 
 function runCurrentTest() {
   // Reset things so we're sure the previous tests failings don't influence this one:
   contentWindow = testTab.linkedBrowser.contentWindow;
   contentWindow.mySuperSpecialMark = 42;
   contentWindow.dialogWasInvoked = false;
   originalLocation = contentWindow.location.href;
   // And run this test:
-  info("Running test with onbeforeunload " + testFns[currentTest].toSource());
-  contentWindow.onbeforeunload = testFns[currentTest];
+  info("Running test with onbeforeunload " + contentWindow.wrappedJSObject.testFns[currentTest].toSource());
+  contentWindow.onbeforeunload = contentWindow.wrappedJSObject.testFns[currentTest];
   loadStarted = false;
-  contentWindow.location.href = TARGETED_PAGE;
+  testTab.linkedBrowser.loadURI(TARGETED_PAGE);
 }
 
 var onAfterPageLoad = runNextTest;
 
 function test() {
   waitForExplicitFinish();
   gBrowser.addProgressListener(tabStateListener);
 
--- a/docshell/test/browser/file_bug1046022.html
+++ b/docshell/test/browser/file_bug1046022.html
@@ -2,9 +2,49 @@
 <html>
   <head>
     <meta charset="utf-8">
     <title>Bug 1046022 - test navigating inside onbeforeunload</title>
   </head>
   <body>
     Waiting for onbeforeunload to hit...
   </body>
+
+  <script>
+var testFns = [
+  function(e) {
+    e.target.location.href = 'otherpage-href-set.html';
+    return "stop";
+  },
+  function(e) {
+    e.target.location.reload();
+    return "stop";
+  },
+  function(e) {
+    e.target.location.replace('otherpage-location-replaced.html');
+    return "stop";
+  },
+  function(e) {
+    var link = e.target.createElement('a');
+    link.href = "otherpage.html";
+    e.target.body.appendChild(link);
+    link.click();
+    return "stop";
+  },
+  function(e) {
+    var link = e.target.createElement('a');
+    link.href = "otherpage.html";
+    link.setAttribute("target", "_blank");
+    e.target.body.appendChild(link);
+    link.click();
+    return "stop";
+  },
+  function(e) {
+    var link = e.target.createElement('a');
+    link.href = e.target.location.href;
+    e.target.body.appendChild(link);
+    link.setAttribute("target", "somearbitrarywindow");
+    link.click();
+    return "stop";
+  },
+];
+  </script>
 </html>