diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index f65eed5c902c..988270e1f97f 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -5204,20 +5204,11 @@ nsGlobalWindowInner::FireOfflineStatusEventIfChanged() } else { name.AssignLiteral("online"); } - // The event is fired at the body element, or if there is no body element, - // at the document. - nsCOMPtr 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); + nsContentUtils::DispatchTrustedEvent(mDoc, + static_cast(this), + name, + false, + false); } class NotifyIdleObserverRunnable : public Runnable diff --git a/dom/events/test/test_bug336682.js b/dom/events/test/test_bug336682.js index 1fb8c2199af7..fa2383fda3ae 100644 --- a/dom/events/test/test_bug336682.js +++ b/dom/events/test/test_bug336682.js @@ -16,23 +16,6 @@ function trace(text) { //document.getElementById("display").innerHTML += t; } -// window.ononline and window.onclick shouldn't work -// Right now, 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 @@ -55,11 +38,9 @@ function makeHandler(nameTemplate, eventName, expectedStates) { "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 bubble"); + ok(!e.bubbles, "event should not bubble"); ok(!e.cancelable, "event should not be cancelable"); - ok(e.target == (document instanceof HTMLDocument - ? document.body : document.documentElement), - "the event target should be the body element"); + ok(e.target == window, "target should be the window"); } } diff --git a/dom/events/test/test_bug336682_2.xul b/dom/events/test/test_bug336682_2.xul index 303348c2ec5a..0a66a8afaaba 100644 --- a/dom/events/test/test_bug336682_2.xul +++ b/dom/events/test/test_bug336682_2.xul @@ -29,34 +29,22 @@ Mozilla Bug 336682 (online/offline events) ", eventName, [3,4]); + var handler = makeHandler("", eventName, [1]); 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, [3,4]), + event, [2]), false); } diff --git 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 index b100f177eb19..81cad4f4fe2d 100644 --- 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 @@ -25,12 +25,18 @@