Skip to content

Commit

Permalink
Delay logging for focus event on toplevel window in order to ignore t…
Browse files Browse the repository at this point in the history
…he inital focus event

I didn't aware there is any spec that ensure the order of load event and initial
focus event. It could be possible that the initial focus event comes after load
event and cause test failures. But I didn't figure out a way to detect whether
we should wait for the initial focus event, so just delay logging for focus
event a bit to ignore the initial one.

Differential Revision: https://phabricator.services.mozilla.com/D150002

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1775118
gecko-commit: 57af2ae1491a9bc2ec8f102d2d765c932ce88aed
gecko-reviewers: hsivonen
  • Loading branch information
EdgarChen authored and moz-wptsync-bot committed Jun 23, 2022
1 parent fd8aeb1 commit b4a0914
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 33 deletions.
5 changes: 5 additions & 0 deletions focus/activeelement-after-calling-window-focus.sub.html
Expand Up @@ -16,6 +16,10 @@
});
}

function start(w) {
w.postMessage("start", "*");
}

function focusInnerInput(w) {
w.postMessage("focusinnerinput", "*");
}
Expand Down Expand Up @@ -51,6 +55,7 @@
let w = window.open(url);
t.add_cleanup(() => { w.close(); });
await waitForEvent(window, "message", e => e.data === "ready");
start(w);
// Calling input.focus() on inner iframe should move its document.activeElement to INPUT.
focusInnerInput(w);
assert_equals(await getLog(w), 'outerlog:windowblur,middlelog:innerlog:windowfocus,INPUT,');
Expand Down
5 changes: 5 additions & 0 deletions focus/focus-event-after-focusing-iframes.html
Expand Up @@ -15,6 +15,10 @@
});
}

function start(w) {
w.postMessage("start", "*");
}

function focusIframe(w) {
w.postMessage("focus", "*");
}
Expand All @@ -38,6 +42,7 @@
let w = window.open(url);
t.add_cleanup(() => { w.close(); });
await waitForEvent(window, "message", e => e.data === "ready");
start(w);
focusIframe(w);
assert_equals(await getLog(w), 'outerlog:willfocusiframe,windowblur,didfocusiframe,innerlog:windowfocus,');
focusIframe(w);
Expand Down
5 changes: 5 additions & 0 deletions focus/focus-event-after-iframe-gets-focus.html
Expand Up @@ -15,6 +15,10 @@
});
}

function start(w) {
w.postMessage("start", "*");
}

function focusIframe(w) {
w.postMessage("focus", "*");
}
Expand All @@ -38,6 +42,7 @@
let w = window.open(url);
t.add_cleanup(() => { w.close(); });
await waitForEvent(window, "message", e => e.data === "ready");
start(w);
focusIframe(w);
assert_equals(await getLog(w), expectResult);
}
Expand Down
Expand Up @@ -7,8 +7,12 @@

let iframe = document.querySelector("iframe");
window.onmessage = function(e) {
if (e.data == "ready") {
if (e.data == "ready") {
opener.postMessage(e.data, "*");
} else if (e.data == "start") {
window.onfocus = function() {
outerlog += "windowfocus,";
};
} else if (e.data == "focusinnerinput" || e.data == "focusinner" || e.data == "focusmiddle" || e.data == "getlog") {
iframe.contentWindow.postMessage(e.data, "*");
} else if (e.data == "focusouter") {
Expand Down
Expand Up @@ -7,8 +7,12 @@

let iframe = document.querySelector("iframe");
window.onmessage = function(e) {
if (e.data == "ready") {
if (e.data == "ready") {
opener.postMessage(e.data, "*");
} else if (e.data == "start") {
window.onfocus = function() {
outerlog += "windowfocus,";
};
} else if (e.data == "focusinnerinput" || e.data == "focusinner" || e.data == "focusmiddle" || e.data == "getlog") {
iframe.contentWindow.postMessage(e.data, "*");
} else if (e.data == "focusouter") {
Expand All @@ -19,12 +23,6 @@
}
};

window.onload = function() {
window.onfocus = function() {
outerlog += "windowfocus,";
};
};

window.onblur = function() {
outerlog += "windowblur,";
};
Expand Down
Expand Up @@ -7,7 +7,11 @@

let iframe = document.querySelector("iframe");
window.onmessage = function(e) {
if (e.data == "focus") {
if (e.data == "start") {
window.onfocus = function() {
outerlog += "windowfocus,";
};
} else if (e.data == "focus") {
iframe.contentWindow.postMessage("focus", "*");
} else if (e.data == "getlog") {
iframe.contentWindow.postMessage("getlog", "*");
Expand All @@ -17,10 +21,6 @@
};

window.onload = function() {
window.onfocus = function() {
outerlog += "windowfocus,";
};

window.onblur = function() {
outerlog += "windowblur,";
};
Expand Down
Expand Up @@ -7,7 +7,11 @@

let iframe = document.querySelector("iframe");
window.onmessage = function(e) {
if (e.data == "focus") {
if (e.data == "start") {
window.onfocus = function() {
outerlog += "windowfocus,";
};
} else if (e.data == "focus") {
outerlog += "willfocusiframe,";
iframe.focus();
outerlog += "didfocusiframe,";
Expand All @@ -19,10 +23,6 @@
};

window.onload = function() {
window.onfocus = function() {
outerlog += "windowfocus,";
};

window.onblur = function() {
outerlog += "windowblur,";
};
Expand Down
Expand Up @@ -7,7 +7,11 @@

let iframe = document.querySelector("iframe");
window.onmessage = function(e) {
if (e.data == "focus") {
if (e.data == "start") {
window.onfocus = function() {
outerlog += "windowfocus,";
};
} else if (e.data == "focus") {
outerlog += "willfocusiframe,";
document.querySelector("iframe").focus();
outerlog += "didfocusiframe,";
Expand All @@ -19,10 +23,6 @@
};

window.onload = function() {
window.onfocus = function() {
outerlog += "windowfocus,";
};

window.onblur = function() {
outerlog += "windowblur,";
};
Expand Down
Expand Up @@ -7,7 +7,11 @@

let iframe = document.querySelector("iframe");
window.onmessage = function(e) {
if (e.data == "focus") {
if (e.data == "start") {
window.onfocus = function() {
outerlog += "windowfocus,";
};
} else if (e.data == "focus") {
iframe.contentWindow.postMessage("focus", "*");
} else if (e.data == "getlog") {
iframe.contentWindow.postMessage("getlog", "*");
Expand All @@ -17,10 +21,6 @@
};

window.onload = function() {
window.onfocus = function() {
outerlog += "windowfocus,";
};

window.onblur = function() {
outerlog += "windowblur,";
};
Expand Down
Expand Up @@ -7,7 +7,11 @@

let iframe = document.querySelector("iframe");
window.onmessage = function(e) {
if (e.data == "focus") {
if (e.data == "start") {
window.onfocus = function() {
outerlog += "windowfocus,";
};
} else if (e.data == "focus") {
iframe.contentWindow.postMessage("focus", "*");
} else if (e.data == "getlog") {
iframe.contentWindow.postMessage("getlog", "*");
Expand All @@ -17,10 +21,6 @@
};

window.onload = function() {
window.onfocus = function() {
outerlog += "windowfocus,";
};

window.onblur = function() {
outerlog += "windowblur,";
};
Expand Down

0 comments on commit b4a0914

Please sign in to comment.