Bug 1801168, only expect the full screen exited event when the inDOMFullscreen attribute is set and select the url only in this case, r=dao

Differential Revision: https://phabricator.services.mozilla.com/D162857
This commit is contained in:
Neil Deakin 2022-11-25 10:36:00 +00:00
parent a5837fc8fa
commit 6f0485ce50
2 changed files with 38 additions and 8 deletions

View File

@ -1412,20 +1412,22 @@
} }
}; };
if (!window.fullScreen) { // This inDOMFullscreen attribute indicates that the page has something
selectURL(); // such as a video in fullscreen mode. Opening a new tab will cancel
return; // fullscreen mode, so we need to wait for that to happen and then
} // select the url field.
if (window.document.documentElement.hasAttribute("inDOMFullscreen")) {
if (newTab.isEmpty) {
// Wait until fullscreen has exited since it will
// change the selection.
window.addEventListener("MozDOMFullscreen:Exited", selectURL, { window.addEventListener("MozDOMFullscreen:Exited", selectURL, {
once: true, once: true,
wantsUntrusted: false, wantsUntrusted: false,
}); });
return; return;
} }
if (!window.fullScreen || newTab.isEmpty) {
selectURL();
return;
}
} }
// Focus the find bar if it was previously focused for that tab. // Focus the find bar if it was previously focused for that tab.

View File

@ -30,6 +30,34 @@ add_task(async function() {
is(gURLBar.selectionStart, 0, "url is selected"); is(gURLBar.selectionStart, 0, "url is selected");
is(gURLBar.selectionEnd, 22, "url is selected"); is(gURLBar.selectionEnd, 22, "url is selected");
// Now check that the url bar is focused when a new tab is opened while in fullscreen.
let fullScreenEntered = TestUtils.waitForCondition(
() => document.documentElement.getAttribute("sizemode") == "fullscreen"
);
BrowserFullScreen();
await fullScreenEntered;
tab2.linkedBrowser.focus();
// Open a new tab
focusPromise = BrowserTestUtils.waitForEvent(
gURLBar.inputField,
"focus",
true
);
EventUtils.synthesizeKey("T", { accelKey: true });
await focusPromise;
is(document.activeElement, gURLBar.inputField, "urlbar is focused");
let fullScreenExited = TestUtils.waitForCondition(
() => document.documentElement.getAttribute("sizemode") != "fullscreen"
);
BrowserFullScreen();
await fullScreenExited;
BrowserTestUtils.removeTab(gBrowser.selectedTab);
BrowserTestUtils.removeTab(tab1); BrowserTestUtils.removeTab(tab1);
BrowserTestUtils.removeTab(tab2); BrowserTestUtils.removeTab(tab2);
}); });