Backed out changeset b543167ab064 (bug 1457166) for mochitest failures on test_bug336682_1.html CLOSED TREE
authorBrindusan Cristian <cbrindusan@mozilla.com>
Fri, 27 Apr 2018 15:44:00 +0300
changeset 472130 faf594a73b96eddc467938ec537c6f29265f31ef
parent 472129 cdd70d25704ec2791fe02cd26104b8fd7b45df34
child 472131 29afe33cb61d1819fcd0a61a6545bf439712b40e
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1457166
milestone61.0a1
backs outb543167ab064bc66d789e54711243fda677a453f
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset b543167ab064 (bug 1457166) for mochitest failures on test_bug336682_1.html CLOSED TREE
dom/base/nsGlobalWindowInner.cpp
dom/events/test/test_bug336682.js
dom/events/test/test_bug336682_2.xul
testing/web-platform/tests/html/browsers/offline/browser-state/navigator_online_event-manual.https.html
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -5199,21 +5199,30 @@ nsGlobalWindowInner::FireOfflineStatusEv
   mWasOffline = !mWasOffline;
 
   nsAutoString name;
   if (mWasOffline) {
     name.AssignLiteral("offline");
   } else {
     name.AssignLiteral("online");
   }
-  nsContentUtils::DispatchTrustedEvent(mDoc,
-                                       static_cast<EventTarget*>(this),
-                                       name,
-                                       false,
-                                       false);
+  // The event is fired at the body element, or if there is no body element,
+  // at the document.
+  nsCOMPtr<EventTarget> eventTarget = mDoc.get();
+  if (mDoc->IsHTMLOrXHTML()) {
+    if (Element* body = mDoc->GetBody()) {
+      eventTarget = body;
+    }
+  } else {
+    Element* documentElement = mDoc->GetDocumentElement();
+    if (documentElement) {
+      eventTarget = documentElement;
+    }
+  }
+  nsContentUtils::DispatchTrustedEvent(mDoc, eventTarget, name, true, false);
 }
 
 class NotifyIdleObserverRunnable : public Runnable
 {
 public:
   NotifyIdleObserverRunnable(nsIIdleObserver* aIdleObserver,
                              uint32_t aTimeInS,
                              bool aCallOnidle,
--- a/dom/events/test/test_bug336682.js
+++ b/dom/events/test/test_bug336682.js
@@ -11,16 +11,33 @@ var gState = 0;
  */
 var MAX_STATE;
 
 function trace(text) {
   var t = text.replace(/&/g, "&" + "amp;").replace(/</g, "&" + "lt;") + "<br>";
   //document.getElementById("display").innerHTML += t;
 }
 
+// window.ononline and window.onclick shouldn't work
+// Right now, <body ononline=...> sets window.ononline (bug 380618)
+// When these start passing, be sure to uncomment the code inside if(0) below.
+todo(typeof window.ononline == "undefined",
+     "window.ononline should be undefined at this point");
+todo(typeof window.onoffline == "undefined",
+     "window.onoffline should be undefined at this point");
+
+if (0) {
+  window.ononline = function() {
+    ok(false, "window.ononline shouldn't be called");
+  }
+  window.onoffline = function() {
+    ok(false, "window.onclick shouldn't be called");
+  }
+}
+
 /**
  * Returns a handler function for an online/offline event. The returned handler
  * ensures the passed event object has expected properties and that the handler
  * is called at the right moment (according to the gState variable).
  * @param nameTemplate The string identifying the hanlder. '%1' in that
  *                     string will be replaced with the event name.
  * @param eventName 'online' or 'offline'
  * @param expectedStates an array listing the possible values of gState at the
@@ -33,19 +50,21 @@ function makeHandler(nameTemplate, event
     var name = nameTemplate.replace(/%1/, eventName);
     ++gState;
     trace(name + ": gState=" + gState);
     ok(expectedStates.includes(gState),
        "handlers called in the right order: " + name + " is called, " + 
        "gState=" + gState + ", expectedStates=" + expectedStates);
     ok(e.constructor == Event, "event should be an Event");
     ok(e.type == eventName, "event type should be " + eventName);
-    ok(!e.bubbles, "event should not bubble");
+    ok(e.bubbles, "event should bubble");
     ok(!e.cancelable, "event should not be cancelable");
-    ok(e.target == window, "target should be the window");
+    ok(e.target == (document instanceof HTMLDocument
+                    ? document.body : document.documentElement),
+       "the event target should be the body element");
   }
 }
 
 function doTest() {
   var iosvc = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
                            .getService(SpecialPowers.Ci.nsIIOService);
   iosvc.manageOfflineStatus = false;
   iosvc.offline = false;
--- a/dom/events/test/test_bug336682_2.xul
+++ b/dom/events/test/test_bug336682_2.xul
@@ -24,32 +24,44 @@ Mozilla Bug 336682 (online/offline event
 </div>
 </body>
 
 <script type="text/javascript" src="test_bug336682.js"/>
 <script class="testbody" type="text/javascript">
 <![CDATA[
 addLoadEvent(function() {
   /** @see test_bug336682.js */
-  MAX_STATE = 2;
+  MAX_STATE = 4;
 
   function makeWindowHandler(eventName) {
     return function (aThis, aEvent) {
-      var handler = makeHandler("<body on%1='...'>", eventName, [1]);
+      var handler = makeHandler("<body on%1='...'>", eventName, [3,4]);
       handler(aEvent);
     }
   }
 
   for (var event of ["online", "offline"]) {
+    document.documentElement.addEventListener(
+      event,
+      makeHandler("document.body.addEventListener('%1', ..., false)",
+                  event, [1]),
+      false);
+
+    document.addEventListener(
+      event,
+      makeHandler("document.addEventListener('%1', ..., false)",
+                  event, [2]),
+      false);
+
     window["windowOn" + event] = makeWindowHandler(event);
 
     window.addEventListener(
       event,
       makeHandler("window.addEventListener('%1', ..., false)",
-                  event, [2]),
+                  event, [3,4]),
       false);
   }
 
   doTest();
   SimpleTest.finish();
 });
 
 SimpleTest.waitForExplicitFinish();
--- a/testing/web-platform/tests/html/browsers/offline/browser-state/navigator_online_event-manual.https.html
+++ b/testing/web-platform/tests/html/browsers/offline/browser-state/navigator_online_event-manual.https.html
@@ -20,27 +20,21 @@
   </div>
 
   <h2>Expected Result</h2>
   <div id="expectedResult">
     <span id="expectedMsg">apply 'work offline': offline event is raised.<p>release 'work offline': online event is raised.</span>
   </div>
   <script>
 
-  function showOnline(e) {
-    let msg = 'online event is raised';
-    if (e.target != window)
-      msg += ' (on the WRONG target)';
-    document.getElementById('actualMsg').innerHTML = msg + '.';
+  function showOnline() {
+    document.getElementById('actualMsg').innerHTML = 'online event is raised.';
   }
 
-  function showOffline(e) {
-    let msg = 'offline event is raised';
-    if (e.target != window)
-      msg += ' (on the WRONG target)';
-    document.getElementById('actualMsg').innerHTML = msg + '.';
+  function showOffline() {
+    document.getElementById('actualMsg').innerHTML = 'offline event is raised.';
   }
 
   window.addEventListener("online", showOnline, false);
   window.addEventListener("offline", showOffline, false);
   </script>
  </body>
 </html>