diff options
Diffstat (limited to '')
-rw-r--r-- | remote/webdriver-bidi/modules/root/browsingContext.sys.mjs | 128 |
1 files changed, 102 insertions, 26 deletions
diff --git a/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs b/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs index 8424bebf4a..649e801175 100644 --- a/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs +++ b/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs @@ -85,6 +85,7 @@ const CreateType = { * @enum {LocatorType} */ export const LocatorType = { + accessibility: "accessibility", css: "css", innerText: "innerText", xpath: "xpath", @@ -545,7 +546,7 @@ class BrowsingContextModule extends Module { // On Android there is only a single window allowed. As such fallback to // open a new tab instead. const type = lazy.AppInfo.isAndroid ? "tab" : typeHint; - + let waitForVisibilityChangePromise; switch (type) { case "window": { const newWindow = await lazy.windowManager.openBrowserWindow({ @@ -572,8 +573,6 @@ class BrowsingContextModule extends Module { window = lazy.TabManager.getWindowForTab(referenceTab); } - const promises = []; - if (!background && !lazy.AppInfo.isAndroid) { // When opening a new foreground tab we need to wait until the // "document.visibilityState" of the currently selected tab in this @@ -581,32 +580,32 @@ class BrowsingContextModule extends Module { // // Bug 1884142: It's not supported on Android for the TestRunner package. const selectedTab = lazy.TabManager.getTabBrowser(window).selectedTab; - promises.push( - this.#waitForVisibilityChange( - lazy.TabManager.getBrowserForTab(selectedTab).browsingContext - ) + + // Create the promise immediately, but await it later in parallel with + // waitForInitialNavigationCompleted. + waitForVisibilityChangePromise = this.#waitForVisibilityChange( + lazy.TabManager.getBrowserForTab(selectedTab).browsingContext ); } - promises.unshift( - lazy.TabManager.addTab({ - focus: !background, - referenceTab, - userContextId: userContext, - }) - ); - - const [tab] = await Promise.all(promises); + const tab = await lazy.TabManager.addTab({ + focus: !background, + referenceTab, + userContextId: userContext, + }); browser = lazy.TabManager.getBrowserForTab(tab); } } - await lazy.waitForInitialNavigationCompleted( - browser.browsingContext.webProgress, - { - unloadTimeout: 5000, - } - ); + await Promise.all([ + lazy.waitForInitialNavigationCompleted( + browser.browsingContext.webProgress, + { + unloadTimeout: 5000, + } + ), + waitForVisibilityChangePromise, + ]); // The tab on Android is always opened in the foreground, // so we need to select the previous tab, @@ -805,13 +804,33 @@ class BrowsingContextModule extends Module { /** * Used as an argument for browsingContext.locateNodes command, as one of the available variants - * {CssLocator}, {InnerTextLocator} or {XPathLocator}, to represent a way of how lookup of nodes + * {AccessibilityLocator}, {CssLocator}, {InnerTextLocator} or {XPathLocator}, to represent a way of how lookup of nodes * is going to be performed. * * @typedef Locator */ /** + * Used as a value argument for browsingContext.locateNodes command + * in case of a lookup by accessibility attributes. + * + * @typedef AccessibilityLocatorValue + * + * @property {string=} name + * @property {string=} role + */ + + /** + * Used as an argument for browsingContext.locateNodes command + * to represent a lookup by accessibility attributes. + * + * @typedef AccessibilityLocator + * + * @property {LocatorType} [type=LocatorType.accessibility] + * @property {AccessibilityLocatorValue} value + */ + + /** * Used as an argument for browsingContext.locateNodes command * to represent a lookup by css selector. * @@ -900,7 +919,42 @@ class BrowsingContextModule extends Module { `Expected "locator.type" to be one of ${locatorTypes}, got ${locator.type}` )(locator.type); - if (![LocatorType.css, LocatorType.xpath].includes(locator.type)) { + if ( + [LocatorType.css, LocatorType.innerText, LocatorType.xpath].includes( + locator.type + ) + ) { + lazy.assert.string( + locator.value, + `Expected "locator.value" of "locator.type" "${locator.type}" to be a string, got ${locator.value}` + ); + } + if (locator.type == LocatorType.accessibility) { + lazy.assert.object( + locator.value, + `Expected "locator.value" of "locator.type" "${locator.type}" to be an object, got ${locator.value}` + ); + + const { name = null, role = null } = locator.value; + if (name !== null) { + lazy.assert.string( + locator.value.name, + `Expected "locator.value.name" of "locator.type" "${locator.type}" to be a string, got ${name}` + ); + } + if (role !== null) { + lazy.assert.string( + locator.value.role, + `Expected "locator.value.role" of "locator.type" "${locator.type}" to be a string, got ${role}` + ); + } + } + + if ( + ![LocatorType.accessibility, LocatorType.css, LocatorType.xpath].includes( + locator.type + ) + ) { throw new lazy.error.UnsupportedOperationError( `"locator.type" argument with value: ${locator.type} is not supported yet.` ); @@ -1249,7 +1303,11 @@ class BrowsingContextModule extends Module { * @param {object=} options * @param {string} options.context * Id of the browsing context. - * @param {Viewport|null} options.viewport + * @param {(number|null)=} options.devicePixelRatio + * A value to override device pixel ratio, or `null` to reset it to + * the original value. Different values will not cause the rendering to change, + * only image srcsets and media queries will be applied as if DPR is redefined. + * @param {(Viewport|null)=} options.viewport * Dimensions to set the viewport to, or `null` to reset it * to the original dimensions. * @@ -1259,7 +1317,7 @@ class BrowsingContextModule extends Module { * Raised when the command is called on Android. */ async setViewport(options = {}) { - const { context: contextId, viewport } = options; + const { context: contextId, devicePixelRatio, viewport } = options; if (lazy.AppInfo.isAndroid) { // Bug 1840084: Add Android support for modifying the viewport. @@ -1322,6 +1380,24 @@ class BrowsingContextModule extends Module { browser.style.setProperty("width", targetWidth + "px"); } + if (devicePixelRatio !== undefined) { + if (devicePixelRatio !== null) { + lazy.assert.number( + devicePixelRatio, + `Expected "devicePixelRatio" to be a number or null, got ${devicePixelRatio}` + ); + lazy.assert.that( + devicePixelRatio => devicePixelRatio > 0, + `Expected "devicePixelRatio" to be greater than 0, got ${devicePixelRatio}` + )(devicePixelRatio); + + context.overrideDPPX = devicePixelRatio; + } else { + // Will reset to use the global default scaling factor. + context.overrideDPPX = 0; + } + } + if (targetHeight !== currentHeight || targetWidth !== currentWidth) { // Wait until the viewport has been resized await this.messageHandler.forwardCommand({ |