зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1600619 - Don't focus the content page when closing the console when the tab it was opened for is now inactive. r=ochameau.
This patch checks for window.docShell.isActive to ensure we should indeed restore the focus on the page. A test case is added to make sure it works as expected and that we don't regress. Differential Revision: https://phabricator.services.mozilla.com/D60277 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
ec1ab205e9
Коммит
ccf7c09e21
|
@ -14,7 +14,7 @@ add_task(async function() {
|
||||||
ok(isInputFocused(hud), "input node is focused after console is opened");
|
ok(isInputFocused(hud), "input node is focused after console is opened");
|
||||||
|
|
||||||
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
|
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
|
||||||
this.onFocus = new Promise(resolve => {
|
content.onFocus = new Promise(resolve => {
|
||||||
content.addEventListener("focus", resolve, { once: true });
|
content.addEventListener("focus", resolve, { once: true });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -26,9 +26,74 @@ add_task(async function() {
|
||||||
gBrowser.selectedBrowser,
|
gBrowser.selectedBrowser,
|
||||||
[],
|
[],
|
||||||
async function() {
|
async function() {
|
||||||
await this.onFocus;
|
await content.onFocus;
|
||||||
return Services.focus.focusedWindow == content;
|
return Services.focus.focusedWindow == content;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
ok(isFocused, "content document has focus after closing the console");
|
ok(isFocused, "content document has focus after closing the console");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add_task(async function testSeparateWindowToolbox() {
|
||||||
|
const hud = await openNewTabAndConsole(TEST_URI, true, "window");
|
||||||
|
|
||||||
|
info("Focus after console is opened");
|
||||||
|
ok(isInputFocused(hud), "input node is focused after console is opened");
|
||||||
|
|
||||||
|
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
|
||||||
|
content.onFocus = new Promise(resolve => {
|
||||||
|
content.addEventListener("focus", resolve, { once: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
info("Closing console");
|
||||||
|
await closeConsole();
|
||||||
|
|
||||||
|
const isFocused = await SpecialPowers.spawn(
|
||||||
|
gBrowser.selectedBrowser,
|
||||||
|
[],
|
||||||
|
async function() {
|
||||||
|
await content.onFocus;
|
||||||
|
return Services.focus.focusedWindow == content;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
ok(isFocused, "content document has focus after closing the console");
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(async function testSeparateWindowToolboxInactiveTab() {
|
||||||
|
await openNewTabAndConsole(TEST_URI, true, "window");
|
||||||
|
|
||||||
|
info("Focus after console is opened");
|
||||||
|
const firstTab = gBrowser.selectedTab;
|
||||||
|
await addTab(`data:text/html,<meta charset=utf8>New tab XXX`);
|
||||||
|
|
||||||
|
await SpecialPowers.spawn(firstTab.linkedBrowser, [], async () => {
|
||||||
|
// For some reason, there is no blur event fired on the document
|
||||||
|
await ContentTaskUtils.waitForCondition(
|
||||||
|
() => !docShell.isActive && !content.document.hasFocus(),
|
||||||
|
"Waiting for first tab to become inactive"
|
||||||
|
);
|
||||||
|
content.onFocus = new Promise(resolve => {
|
||||||
|
content.addEventListener("focus", resolve, { once: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
info("Closing console");
|
||||||
|
await closeConsole(firstTab);
|
||||||
|
|
||||||
|
const onFirstTabFocus = SpecialPowers.spawn(
|
||||||
|
firstTab.linkedBrowser,
|
||||||
|
[],
|
||||||
|
async function() {
|
||||||
|
await content.onFocus;
|
||||||
|
return "focused";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const timeoutRes = "time's out";
|
||||||
|
const onTimeout = wait(2000).then(() => timeoutRes);
|
||||||
|
const res = await Promise.race([onFirstTabFocus, onTimeout]);
|
||||||
|
is(
|
||||||
|
res,
|
||||||
|
timeoutRes,
|
||||||
|
"original tab wasn't focused when closing the toolbox window"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
|
@ -74,12 +74,14 @@ registerCleanupFunction(async function() {
|
||||||
* The URL for the tab to be opened.
|
* The URL for the tab to be opened.
|
||||||
* @param Boolean clearJstermHistory
|
* @param Boolean clearJstermHistory
|
||||||
* true (default) if the jsterm history should be cleared.
|
* true (default) if the jsterm history should be cleared.
|
||||||
|
* @param String hostId (optional)
|
||||||
|
* The type of toolbox host to be used.
|
||||||
* @return Promise
|
* @return Promise
|
||||||
* Resolves when the tab has been added, loaded and the toolbox has been opened.
|
* Resolves when the tab has been added, loaded and the toolbox has been opened.
|
||||||
* Resolves to the toolbox.
|
* Resolves to the toolbox.
|
||||||
*/
|
*/
|
||||||
async function openNewTabAndConsole(url, clearJstermHistory = true) {
|
async function openNewTabAndConsole(url, clearJstermHistory = true, hostId) {
|
||||||
const toolbox = await openNewTabAndToolbox(url, "webconsole");
|
const toolbox = await openNewTabAndToolbox(url, "webconsole", hostId);
|
||||||
const hud = toolbox.getCurrentPanel().hud;
|
const hud = toolbox.getCurrentPanel().hud;
|
||||||
|
|
||||||
if (clearJstermHistory) {
|
if (clearJstermHistory) {
|
||||||
|
|
|
@ -1168,7 +1168,8 @@ const browsingContextTargetPrototype = {
|
||||||
this._setCacheDisabled(false);
|
this._setCacheDisabled(false);
|
||||||
this._setServiceWorkersTestingEnabled(false);
|
this._setServiceWorkersTestingEnabled(false);
|
||||||
this._setPaintFlashingEnabled(false);
|
this._setPaintFlashingEnabled(false);
|
||||||
if (this._restoreFocus) {
|
|
||||||
|
if (this._restoreFocus && this.window.docShell.isActive) {
|
||||||
this.window.focus();
|
this.window.focus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Загрузка…
Ссылка в новой задаче