mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1457166: Fire online / offline events at the window. r=bz
MozReview-Commit-ID: 2v5zNwM9qSh
This commit is contained in:
parent
db4c6f9696
commit
28b9b16ea6
@ -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> 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<EventTarget*>(this),
|
||||
name,
|
||||
false,
|
||||
false);
|
||||
}
|
||||
|
||||
class NotifyIdleObserverRunnable : public Runnable
|
||||
|
@ -16,23 +16,6 @@ function trace(text) {
|
||||
//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
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,34 +29,22 @@ Mozilla Bug 336682 (online/offline events)</a>
|
||||
<![CDATA[
|
||||
addLoadEvent(function() {
|
||||
/** @see test_bug336682.js */
|
||||
MAX_STATE = 4;
|
||||
MAX_STATE = 2;
|
||||
|
||||
function makeWindowHandler(eventName) {
|
||||
return function (aThis, aEvent) {
|
||||
var handler = makeHandler("<body on%1='...'>", eventName, [3,4]);
|
||||
var handler = makeHandler("<body on%1='...'>", 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);
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,18 @@
|
||||
</div>
|
||||
<script>
|
||||
|
||||
function showOnline() {
|
||||
document.getElementById('actualMsg').innerHTML = 'online event is raised.';
|
||||
function showOnline(e) {
|
||||
let msg = 'online 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.';
|
||||
function showOffline(e) {
|
||||
let msg = 'offline event is raised';
|
||||
if (e.target != window)
|
||||
msg += ' (on the WRONG target)';
|
||||
document.getElementById('actualMsg').innerHTML = msg + '.';
|
||||
}
|
||||
|
||||
window.addEventListener("online", showOnline, false);
|
||||
|
Loading…
Reference in New Issue
Block a user