Skip to content

Commit 9372f2e

Browse files
committed
Bug 1988725 - [bidi] Update "emulation.setLocaleOverride" and "emulation.setTimezoneOverride" commands reset behavior. r=webdriver-reviewers,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D269021
1 parent 11c3429 commit 9372f2e

File tree

2 files changed

+169
-69
lines changed

2 files changed

+169
-69
lines changed

remote/webdriver-bidi/modules/root/emulation.sys.mjs

Lines changed: 133 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -454,31 +454,39 @@ class EmulationModule extends RootBiDiModule {
454454
}
455455

456456
const sessionDataItems = [];
457+
// In case of resetting the override, remove existing session data items
458+
// for the required context descriptors.
459+
const onlyRemoveSessionDataItem = locale === "";
460+
457461
if (userContextIds !== null) {
458462
for (const userContext of userContexts) {
459-
sessionDataItems.push({
460-
category: "locale-override",
461-
moduleName: "_configuration",
462-
values: [locale],
463-
contextDescriptor: {
464-
type: lazy.ContextDescriptorType.UserContext,
465-
id: userContext,
466-
},
467-
method: lazy.SessionDataMethod.Add,
468-
});
463+
sessionDataItems.push(
464+
...this.messageHandler.sessionData.generateSessionDataItemUpdate(
465+
"_configuration",
466+
"locale-override",
467+
{
468+
type: lazy.ContextDescriptorType.UserContext,
469+
id: userContext,
470+
},
471+
onlyRemoveSessionDataItem,
472+
locale
473+
)
474+
);
469475
}
470476
} else {
471477
for (const navigable of navigables) {
472-
sessionDataItems.push({
473-
category: "locale-override",
474-
moduleName: "_configuration",
475-
values: [locale],
476-
contextDescriptor: {
477-
type: lazy.ContextDescriptorType.TopBrowsingContext,
478-
id: navigable.browserId,
479-
},
480-
method: lazy.SessionDataMethod.Add,
481-
});
478+
sessionDataItems.push(
479+
...this.messageHandler.sessionData.generateSessionDataItemUpdate(
480+
"_configuration",
481+
"locale-override",
482+
{
483+
type: lazy.ContextDescriptorType.TopBrowsingContext,
484+
id: navigable.browserId,
485+
},
486+
onlyRemoveSessionDataItem,
487+
locale
488+
)
489+
);
482490
}
483491
}
484492

@@ -492,8 +500,23 @@ class EmulationModule extends RootBiDiModule {
492500
const commands = [];
493501

494502
for (const navigable of navigables) {
503+
const overrideValue = this.#getOverrideValue({
504+
category: "locale-override",
505+
context: navigable,
506+
contextIds,
507+
userContextIds,
508+
value: locale,
509+
});
510+
511+
if (overrideValue === null) {
512+
continue;
513+
}
514+
495515
commands.push(
496-
this._setLocaleForBrowsingContext({ locale, context: navigable })
516+
this._setLocaleForBrowsingContext({
517+
locale: overrideValue,
518+
context: navigable,
519+
})
497520
);
498521
}
499522

@@ -807,31 +830,39 @@ class EmulationModule extends RootBiDiModule {
807830
}
808831

809832
const sessionDataItems = [];
833+
// In case of resetting the override, remove existing session data items
834+
// for the required context descriptors.
835+
const onlyRemoveSessionDataItem = timezone === "";
836+
810837
if (userContextIds !== null) {
811838
for (const userContext of userContexts) {
812-
sessionDataItems.push({
813-
category: "timezone-override",
814-
moduleName: "_configuration",
815-
values: [timezone],
816-
contextDescriptor: {
817-
type: lazy.ContextDescriptorType.UserContext,
818-
id: userContext,
819-
},
820-
method: lazy.SessionDataMethod.Add,
821-
});
839+
sessionDataItems.push(
840+
...this.messageHandler.sessionData.generateSessionDataItemUpdate(
841+
"_configuration",
842+
"timezone-override",
843+
{
844+
type: lazy.ContextDescriptorType.UserContext,
845+
id: userContext,
846+
},
847+
onlyRemoveSessionDataItem,
848+
timezone
849+
)
850+
);
822851
}
823852
} else {
824853
for (const navigable of navigables) {
825-
sessionDataItems.push({
826-
category: "timezone-override",
827-
moduleName: "_configuration",
828-
values: [timezone],
829-
contextDescriptor: {
830-
type: lazy.ContextDescriptorType.TopBrowsingContext,
831-
id: navigable.browserId,
832-
},
833-
method: lazy.SessionDataMethod.Add,
834-
});
854+
sessionDataItems.push(
855+
...this.messageHandler.sessionData.generateSessionDataItemUpdate(
856+
"_configuration",
857+
"timezone-override",
858+
{
859+
type: lazy.ContextDescriptorType.TopBrowsingContext,
860+
id: navigable.browserId,
861+
},
862+
onlyRemoveSessionDataItem,
863+
timezone
864+
)
865+
);
835866
}
836867
}
837868

@@ -845,8 +876,23 @@ class EmulationModule extends RootBiDiModule {
845876
const commands = [];
846877

847878
for (const navigable of navigables) {
879+
const overrideValue = this.#getOverrideValue({
880+
category: "timezone-override",
881+
context: navigable,
882+
contextIds,
883+
userContextIds,
884+
value: timezone,
885+
});
886+
887+
if (overrideValue === null) {
888+
continue;
889+
}
890+
848891
commands.push(
849-
this._setTimezoneOverride({ context: navigable, timezone })
892+
this._setTimezoneOverride({
893+
context: navigable,
894+
timezone: overrideValue,
895+
})
850896
);
851897
}
852898

@@ -1017,35 +1063,22 @@ class EmulationModule extends RootBiDiModule {
10171063
}
10181064

10191065
for (const navigable of navigables) {
1020-
const [overridePerContext, overridePerUserContext, overrideGlobal] =
1021-
this.#findExistingOverrideForContext("user-agent-override", navigable);
1022-
1023-
if (contextIds) {
1024-
if (userAgent === "") {
1025-
// In case of resetting an override for navigable,
1026-
// if there is an existing override for user context or global,
1027-
// we should apply it to browsing context.
1028-
userAgent = overridePerUserContext || overrideGlobal || "";
1029-
}
1030-
} else if (userContextIds) {
1031-
// No need to do anything if there is an override
1032-
// for the browsing context.
1033-
if (overridePerContext) {
1034-
continue;
1035-
}
1066+
const overrideValue = this.#getOverrideValue({
1067+
category: "user-agent-override",
1068+
context: navigable,
1069+
contextIds,
1070+
userContextIds,
1071+
value: userAgent,
1072+
});
10361073

1037-
// In case of resetting an override for user context,
1038-
// apply a global override if it exists
1039-
if (userAgent === "" && overrideGlobal) {
1040-
userAgent = overrideGlobal;
1041-
}
1042-
} else if (overridePerContext || overridePerUserContext) {
1043-
// No need to do anything if there is an override
1044-
// for the browsing or user context.
1074+
if (overrideValue === null) {
10451075
continue;
10461076
}
10471077

1048-
this._setUserAgentOverride({ context: navigable, userAgent });
1078+
this._setUserAgentOverride({
1079+
context: navigable,
1080+
userAgent: overrideValue,
1081+
});
10491082
}
10501083
}
10511084

@@ -1162,6 +1195,39 @@ class EmulationModule extends RootBiDiModule {
11621195
}
11631196
}
11641197

1198+
#getOverrideValue(params) {
1199+
const { category, context, contextIds, userContextIds, value } = params;
1200+
const [overridePerContext, overridePerUserContext, overrideGlobal] =
1201+
this.#findExistingOverrideForContext(category, context);
1202+
1203+
if (contextIds) {
1204+
if (value === "") {
1205+
// In case of resetting an override for navigable,
1206+
// if there is an existing override for user context or global,
1207+
// we should apply it to browsing context.
1208+
return overridePerUserContext || overrideGlobal || "";
1209+
}
1210+
} else if (userContextIds) {
1211+
// No need to do anything if there is an override
1212+
// for the browsing context.
1213+
if (overridePerContext) {
1214+
return null;
1215+
}
1216+
1217+
// In case of resetting an override for user context,
1218+
// apply a global override if it exists
1219+
if (value === "" && overrideGlobal) {
1220+
return overrideGlobal;
1221+
}
1222+
} else if (overridePerContext || overridePerUserContext) {
1223+
// No need to do anything if there is an override
1224+
// for the browsing or user context.
1225+
return null;
1226+
}
1227+
1228+
return value;
1229+
}
1230+
11651231
/**
11661232
* Find the existing overrides for a given category and context.
11671233
*

remote/webdriver-bidi/modules/windowglobal/_configuration.sys.mjs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ class _ConfigurationModule extends WindowGlobalBiDiModule {
214214
}
215215
}
216216

217+
let localeOverridePerContext = null;
218+
let localeOverridePerUserContext = null;
219+
220+
let timezoneOverridePerContext = null;
221+
let timezoneOverridePerUserContext = null;
222+
217223
let userAgentOverrideGlobal = null;
218224
let userAgentOverridePerUserContext = null;
219225
let userAgentOverridePerContext = null;
@@ -252,15 +258,33 @@ class _ConfigurationModule extends WindowGlobalBiDiModule {
252258
break;
253259
}
254260
case "locale-override": {
255-
this.#localeOverride = value;
261+
switch (contextDescriptor.type) {
262+
case lazy.ContextDescriptorType.TopBrowsingContext: {
263+
localeOverridePerContext = value;
264+
break;
265+
}
266+
case lazy.ContextDescriptorType.UserContext: {
267+
localeOverridePerUserContext = value;
268+
break;
269+
}
270+
}
256271
break;
257272
}
258273
case "screen-orientation-override": {
259274
this.#screenOrientationOverride = value;
260275
break;
261276
}
262277
case "timezone-override": {
263-
this.#timezoneOverride = value;
278+
switch (contextDescriptor.type) {
279+
case lazy.ContextDescriptorType.TopBrowsingContext: {
280+
timezoneOverridePerContext = value;
281+
break;
282+
}
283+
case lazy.ContextDescriptorType.UserContext: {
284+
timezoneOverridePerUserContext = value;
285+
break;
286+
}
287+
}
264288
break;
265289
}
266290
case "user-agent-override": {
@@ -283,6 +307,16 @@ class _ConfigurationModule extends WindowGlobalBiDiModule {
283307
}
284308
}
285309

310+
this.#localeOverride = this.#findCorrectOverrideValue(
311+
localeOverridePerContext,
312+
localeOverridePerUserContext
313+
);
314+
315+
this.#timezoneOverride = this.#findCorrectOverrideValue(
316+
timezoneOverridePerContext,
317+
timezoneOverridePerUserContext
318+
);
319+
286320
this.#userAgentOverride = this.#findCorrectOverrideValue(
287321
userAgentOverridePerContext,
288322
userAgentOverridePerUserContext,

0 commit comments

Comments
 (0)