commit 7174cf83a2d34b222992ee9cfed2ab403ddce634
parent b2bd21bacb368aa1c2b776dac08b3979486e1f17
Author: Alexandra Borovova <aborovova@mozilla.com>
Date: Wed, 7 Jan 2026 13:44:41 +0000
Bug 1998732 - [webdriver-bidi] Update "emulation.setGeolocationOverride" command reset behavior. r=jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D277973
Diffstat:
2 files changed, 66 insertions(+), 45 deletions(-)
diff --git a/remote/webdriver-bidi/modules/root/emulation.sys.mjs b/remote/webdriver-bidi/modules/root/emulation.sys.mjs
@@ -218,34 +218,16 @@ class EmulationModule extends RootBiDiModule {
userContextIds
);
- const sessionDataItems = [];
- if (userContextIds !== null) {
- for (const userContext of userContexts) {
- sessionDataItems.push({
- category: "geolocation-override",
- moduleName: "_configuration",
- values: [coordinates],
- contextDescriptor: {
- type: lazy.ContextDescriptorType.UserContext,
- id: userContext,
- },
- method: lazy.SessionDataMethod.Add,
- });
- }
- } else {
- for (const navigable of navigables) {
- sessionDataItems.push({
- category: "geolocation-override",
- moduleName: "_configuration",
- values: [coordinates],
- contextDescriptor: {
- type: lazy.ContextDescriptorType.TopBrowsingContext,
- id: navigable.browserId,
- },
- method: lazy.SessionDataMethod.Add,
- });
- }
- }
+ const sessionDataItems = this.#generateSessionDataUpdate({
+ category: "geolocation-override",
+ contextOverride: contextIds !== null,
+ hasGlobalOverride: false,
+ navigables,
+ resetValue: null,
+ userContexts,
+ userContextOverride: userContextIds !== null,
+ value: coordinates,
+ });
if (sessionDataItems.length) {
// TODO: Bug 1953079. Saving the geolocation override in the session data works fine
@@ -254,22 +236,16 @@ class EmulationModule extends RootBiDiModule {
await this.messageHandler.updateSessionData(sessionDataItems);
}
- const commands = [];
-
- for (const navigable of navigables) {
- commands.push(
- this._forwardToWindowGlobal(
- "_setGeolocationOverride",
- navigable.id,
- {
- coordinates,
- },
- { retryOnAbort: true }
- )
- );
- }
-
- await Promise.all(commands);
+ await this.#applyOverride({
+ async: true,
+ callback: this.#applyGeolocationOverride.bind(this),
+ category: "geolocation-override",
+ contextIds,
+ navigables,
+ resetValue: null,
+ userContextIds,
+ value: coordinates,
+ });
}
/**
@@ -932,6 +908,31 @@ class EmulationModule extends RootBiDiModule {
}
}
+ /**
+ * Apply the geolocation override to the top-level browsing context.
+ *
+ * @param {object} options
+ * @param {BrowsingContext} options.context
+ * Top-level browsing context object which is a target
+ * for the geolocation override.
+ * @param {(GeolocationCoordinates|null)} options.value
+ * Geolocation coordinates which have to override
+ * the return result of geolocation APIs.
+ * Null value resets the override.
+ */
+ #applyGeolocationOverride(options) {
+ const { context, value } = options;
+
+ return this._forwardToWindowGlobal(
+ "_setGeolocationOverride",
+ context.id,
+ {
+ coordinates: value,
+ },
+ { retryOnAbort: true }
+ );
+ }
+
async #applyOverride(options) {
const {
async = false,
diff --git a/remote/webdriver-bidi/modules/windowglobal/_configuration.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/_configuration.sys.mjs
@@ -316,6 +316,9 @@ class _ConfigurationModule extends WindowGlobalBiDiModule {
].includes(category) &&
!this.messageHandler.context.parent
) {
+ let geolocationOverridePerContext = null;
+ let geolocationOverridePerUserContext = null;
+
let localeOverridePerContext = null;
let localeOverridePerUserContext = null;
@@ -336,7 +339,16 @@ class _ConfigurationModule extends WindowGlobalBiDiModule {
switch (category) {
case "geolocation-override": {
- this.#geolocationConfiguration = value;
+ switch (contextDescriptor.type) {
+ case lazy.ContextDescriptorType.TopBrowsingContext: {
+ geolocationOverridePerContext = value;
+ break;
+ }
+ case lazy.ContextDescriptorType.UserContext: {
+ geolocationOverridePerUserContext = value;
+ break;
+ }
+ }
break;
}
case "viewport-overrides": {
@@ -419,6 +431,14 @@ class _ConfigurationModule extends WindowGlobalBiDiModule {
// Now from these items we have to choose the one that would take precedence.
// The order is the user context item overrides the global one, and the browsing context overrides the user context item.
switch (category) {
+ case "geolocation-override": {
+ this.#geolocationConfiguration = this.#findCorrectOverrideValue(
+ "object",
+ geolocationOverridePerContext,
+ geolocationOverridePerUserContext
+ );
+ break;
+ }
case "locale-override": {
this.#localeOverride = this.#findCorrectOverrideValue(
"string",