Bug 1843507 - [bidi] Add support for "background" argument to "browsingContext.create" command. r=webdriver-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D184453
This commit is contained in:
Alexandra Borovova 2023-07-27 07:47:54 +00:00
Родитель 60268388ae
Коммит 0717ff9cbf
5 изменённых файлов: 38 добавлений и 40 удалений

Просмотреть файл

@ -29,6 +29,9 @@ export class MobileTabBrowser {
throw new Error("GeckoView only supports a single tab");
}
// At the moment we don't have an API in `GeckoViewTabUtil` to select the tab,
// something might be added in the scope of bug 1845559.
// Synthesize a custom TabSelect event to indicate that a tab has been
// selected even when we don't change it.
const event = this.window.CustomEvent("TabSelect", {

Просмотреть файл

@ -218,9 +218,13 @@ class WindowManager {
await Promise.all([activated, focused, startup]);
// The new window shouldn't get focused. As such set the
// focus back to the opening window.
if (!focus) {
if (focus) {
// Focus the currently selected tab.
const browser = lazy.TabManager.getTabBrowser(win).selectedBrowser;
browser.focus();
} else {
// If the new window shouldn't get focused, set the
// focus back to the opening window.
await this.focusWindow(openerWindow);
}

Просмотреть файл

@ -302,6 +302,9 @@ class BrowsingContextModule extends Module {
* Create a new browsing context using the provided type "tab" or "window".
*
* @param {object=} options
* @param {boolean=} options.background
* Whether the tab/window should be open in the background. Defaults to false,
* which means that the tab/window will be open in the foreground.
* @param {string=} options.referenceContext
* Id of the top-level browsing context to use as reference.
* If options.type is "tab", the new tab will open in the same window as
@ -316,17 +319,28 @@ class BrowsingContextModule extends Module {
* If the browsing context cannot be found.
*/
async create(options = {}) {
const { referenceContext: referenceContextId = null, type } = options;
const {
background = false,
referenceContext: referenceContextId = null,
type,
} = options;
if (type !== CreateType.tab && type !== CreateType.window) {
throw new lazy.error.InvalidArgumentError(
`Expected "type" to be one of ${Object.values(CreateType)}, got ${type}`
);
}
lazy.assert.boolean(
background,
lazy.pprint`Expected "background" to be a boolean, got ${background}`
);
let browser;
switch (type) {
case "window":
let newWindow = await lazy.windowManager.openBrowserWindow();
const newWindow = await lazy.windowManager.openBrowserWindow({
focus: !background,
});
browser = lazy.TabManager.getTabBrowser(newWindow).selectedBrowser;
break;
@ -364,7 +378,7 @@ class BrowsingContextModule extends Module {
}
const tab = await lazy.TabManager.addTab({
focus: false,
focus: !background,
referenceTab,
});
browser = lazy.TabManager.getBrowserForTab(tab);

Просмотреть файл

@ -1,25 +1,17 @@
[background.py]
[test_background_default_false[tab\]]
expected:
if os == "android": PASS
FAIL
[test_background_default_false[window\]]
expected:
if os == "android": FAIL
[test_background[True-tab\]]
expected:
if os == "android": FAIL
[test_background[True-window\]]
expected: FAIL
[test_background[False-tab\]]
expected:
if os == "android": PASS
FAIL
disabled:
if os == "android": Not supported
[test_background[False-window\]]
disabled:
if os == "android": Not supported
[test_background[True-window\]]
disabled:
if os == "android": Not supported
[test_background[True-tab\]]
bug: 1845559
expected:
if os == "android": FAIL

Просмотреть файл

@ -1,15 +0,0 @@
[invalid.py]
[test_params_background_invalid_type[None\]]
expected: FAIL
[test_params_background_invalid_type[\]]
expected: FAIL
[test_params_background_invalid_type[42\]]
expected: FAIL
[test_params_background_invalid_type[value3\]]
expected: FAIL
[test_params_background_invalid_type[value4\]]
expected: FAIL