Bug 1788437 - [remote] Update pprint call sites to avoid pretty printing known strings r=webdriver-reviewers,whimboo

Depends on D212469

Differential Revision: https://phabricator.services.mozilla.com/D216811
This commit is contained in:
Julian Descottes 2024-07-18 10:28:25 +00:00
Родитель 3cfc8b1b56
Коммит 1ac8b5537f
10 изменённых файлов: 106 добавлений и 93 удалений

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

@ -102,9 +102,8 @@ cookie.fromJSON = function (json) {
newCookie.sameSite = lazy.assert.in(
json.sameSite,
validOptions,
lazy.pprint`Expected cookie "sameSite" to be one of ${validOptions.toString()}, got ${
json.sameSite
}`
`Expected cookie "sameSite" to be one of ${validOptions.toString()}, ` +
lazy.pprint`got ${json.sameSite}`
);
}

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

@ -67,18 +67,21 @@ cookie.manager = {
add_task(function test_fromJSON() {
// object
for (let invalidType of ["foo", 42, true, [], null, undefined]) {
Assert.throws(() => cookie.fromJSON(invalidType), /Expected cookie object/);
Assert.throws(
() => cookie.fromJSON(invalidType),
/Expected "cookie" to be an object/
);
}
// name and value
for (let invalidType of [42, true, [], {}, null, undefined]) {
Assert.throws(
() => cookie.fromJSON({ name: invalidType }),
/Cookie name must be string/
/Expected cookie "name" to be a string/
);
Assert.throws(
() => cookie.fromJSON({ name: "foo", value: invalidType }),
/Cookie value must be string/
/Expected cookie "value" to be a string/
);
}
@ -91,7 +94,7 @@ add_task(function test_fromJSON() {
};
Assert.throws(
() => cookie.fromJSON(domainTest),
/Cookie domain must be string/
/Expected cookie "domain" to be a string/
);
}
let domainTest = {
@ -111,7 +114,7 @@ add_task(function test_fromJSON() {
};
Assert.throws(
() => cookie.fromJSON(pathTest),
/Cookie path must be string/
/Expected cookie "path" to be a string/
);
}
@ -124,7 +127,7 @@ add_task(function test_fromJSON() {
};
Assert.throws(
() => cookie.fromJSON(secureTest),
/Cookie secure flag must be boolean/
/Expected cookie "secure" to be a boolean/
);
}
@ -137,7 +140,7 @@ add_task(function test_fromJSON() {
};
Assert.throws(
() => cookie.fromJSON(httpOnlyTest),
/Cookie httpOnly flag must be boolean/
/Expected cookie "httpOnly" to be a boolean/
);
}
@ -158,7 +161,7 @@ add_task(function test_fromJSON() {
};
Assert.throws(
() => cookie.fromJSON(expiryTest),
/Cookie expiry must be a positive integer/
/Expected cookie "expiry" to be a positive integer/
);
}
@ -171,7 +174,7 @@ add_task(function test_fromJSON() {
};
Assert.throws(
() => cookie.fromJSON(sameSiteTest),
/Cookie SameSite flag must be one of None, Lax, or Strict/
/Expected cookie "sameSite" to be one of None,Lax,Strict/
);
}
@ -217,15 +220,15 @@ add_task(function test_add() {
for (let invalidType of [42, true, [], {}, null, undefined]) {
Assert.throws(
() => cookie.add({ name: invalidType }),
/Cookie name must be string/
/Expected cookie "name" to be a string/
);
Assert.throws(
() => cookie.add({ name: "name", value: invalidType }),
/Cookie value must be string/
/Expected cookie "value" to be a string/
);
Assert.throws(
() => cookie.add({ name: "name", value: "value", domain: invalidType }),
/Cookie domain must be string/
/Expected cookie "domain" to be a string/
);
}

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

@ -110,7 +110,7 @@ export class WebReference {
static fromJSON(json) {
lazy.assert.object(
json,
lazy.pprint`Expected web reference to be object, got ${json}`
lazy.pprint`Expected web reference to be an object, got ${json}`
);
if (json instanceof WebReference) {
return json;

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

@ -171,13 +171,10 @@ function parseRanges(ranges) {
limits = [range, range];
} else {
// We got a string presumably of the form <int> | <int>? "-" <int>?
const msg = `Expected "range" to be of the form <int> or <int>-<int>, got ${range}`;
const msg = lazy.pprint`Expected "range" to be of the form <int> or <int>-<int>, got ${range}`;
limits = range.split("-").map(x => x.trim());
lazy.assert.that(
o => [1, 2].includes(o.length),
lazy.pprint`${msg}`
)(limits);
lazy.assert.that(o => [1, 2].includes(o.length), msg)(limits);
// Single numbers map to a range with that page at the start and the end
if (limits.length == 1) {
@ -186,10 +183,7 @@ function parseRanges(ranges) {
// Need to check that both limits are strings consisting only of
// decimal digits (or empty strings)
const assertNumeric = lazy.assert.that(
o => /^\d*$/.test(o),
lazy.pprint`${msg}`
);
const assertNumeric = lazy.assert.that(o => /^\d*$/.test(o), msg);
limits.every(x => assertNumeric(x));
// Convert from strings representing numbers to actual numbers

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

@ -99,7 +99,8 @@ export class Timeouts {
case "implicit":
t.implicit = lazy.assert.positiveInteger(
ms,
lazy.pprint`Expected "${type}" to be a positive integer, got ${ms}`
`Expected "${type}" to be a positive integer, ` +
lazy.pprint`got ${ms}`
);
break;
@ -107,7 +108,8 @@ export class Timeouts {
if (ms !== null) {
lazy.assert.positiveInteger(
ms,
lazy.pprint`Expected "${type}" to be a positive integer, got ${ms}`
`Expected "${type}" to be a positive integer, ` +
lazy.pprint`got ${ms}`
);
}
t.script = ms;
@ -116,7 +118,8 @@ export class Timeouts {
case "pageLoad":
t.pageLoad = lazy.assert.positiveInteger(
ms,
lazy.pprint`Expected "${type}" to be a positive integer, got ${ms}`
`Expected "${type}" to be a positive integer, ` +
lazy.pprint`got ${ms}`
);
break;
@ -557,14 +560,14 @@ export class Capabilities extends Map {
case "acceptInsecureCerts":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
case "pageLoadStrategy":
lazy.assert.string(
v,
lazy.pprint`Expected "${k}" to be a string, got ${v}`
`Expected "${k}" to be a string, ` + lazy.pprint`got ${v}`
);
if (!Object.values(PageLoadStrategy).includes(v)) {
throw new lazy.error.InvalidArgumentError(
@ -580,7 +583,7 @@ export class Capabilities extends Map {
case "setWindowRect":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
if (!lazy.AppInfo.isAndroid && !v) {
throw new lazy.error.InvalidArgumentError(
@ -600,7 +603,7 @@ export class Capabilities extends Map {
case "strictFileInteractability":
v = lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
@ -611,12 +614,12 @@ export class Capabilities extends Map {
case "webSocketUrl":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
if (!v) {
throw new lazy.error.InvalidArgumentError(
lazy.pprint`Expected "${k}" to be true, got ${v}`
`Expected "${k}" to be true, ` + lazy.pprint`got ${v}`
);
}
break;
@ -624,42 +627,42 @@ export class Capabilities extends Map {
case "webauthn:virtualAuthenticators":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
case "webauthn:extension:uvm":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
case "webauthn:extension:prf":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
case "webauthn:extension:largeBlob":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
case "webauthn:extension:credBlob":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
case "moz:accessibilityChecks":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
@ -671,14 +674,14 @@ export class Capabilities extends Map {
case "moz:webdriverClick":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
break;
case "moz:windowless":
lazy.assert.boolean(
v,
lazy.pprint`Expected "${k}" to be a boolean, got ${v}`
`Expected "${k}" to be a boolean, ` + lazy.pprint`got ${v}`
);
// Only supported on MacOS
@ -718,7 +721,7 @@ export class Capabilities extends Map {
case "acceptInsecureCerts":
lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
return value;
@ -727,13 +730,13 @@ export class Capabilities extends Map {
case "platformName":
return lazy.assert.string(
value,
lazy.pprint`Expected "${name}" to be a string, got ${value}`
`Expected "${name}" to be a string, ` + lazy.pprint`got ${value}`
);
case "pageLoadStrategy":
lazy.assert.string(
value,
lazy.pprint`Expected "${name}" to be a string, got ${value}`
`Expected "${name}" to be a string, ` + lazy.pprint`got ${value}`
);
if (!Object.values(PageLoadStrategy).includes(value)) {
throw new lazy.error.InvalidArgumentError(
@ -748,7 +751,7 @@ export class Capabilities extends Map {
case "strictFileInteractability":
return lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
case "timeouts":
@ -760,12 +763,12 @@ export class Capabilities extends Map {
case "webSocketUrl":
lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
if (!value) {
throw new lazy.error.InvalidArgumentError(
lazy.pprint`Expected "${name}" to be true, got ${value}`
`Expected "${name}" to be true, ` + lazy.pprint`got ${value}`
);
}
return value;
@ -773,46 +776,46 @@ export class Capabilities extends Map {
case "webauthn:virtualAuthenticators":
lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
return value;
case "webauthn:extension:uvm":
lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
return value;
case "webauthn:extension:largeBlob":
lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
return value;
case "moz:firefoxOptions":
return lazy.assert.object(
value,
lazy.pprint`Expected "${name}" to be an object, got ${value}`
`Expected "${name}" to be an object, ` + lazy.pprint`got ${value}`
);
case "moz:accessibilityChecks":
return lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
case "moz:webdriverClick":
return lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
case "moz:windowless":
lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
// Only supported on MacOS
@ -826,13 +829,14 @@ export class Capabilities extends Map {
case "moz:debuggerAddress":
return lazy.assert.boolean(
value,
lazy.pprint`Expected "${name}" to be a boolean, got ${value}`
`Expected "${name}" to be a boolean, ` + lazy.pprint`got ${value}`
);
default:
lazy.assert.string(
name,
lazy.pprint`Expected capability "name" to be a string, got ${name}`
`Expected capability "name" to be a string, ` +
lazy.pprint`got ${name}`
);
if (name.includes(":")) {
const [prefix] = name.split(":");

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

@ -989,7 +989,8 @@ export function setDefaultAndAssertSerializationOptions(options = {}) {
lazy.assert.that(
includeShadowTree =>
includeShadowTreeModesValues.includes(includeShadowTree),
lazy.pprint`Expected "includeShadowTree" to be one of ${includeShadowTreeModesValues}, got ${includeShadowTree}`
`Expected "includeShadowTree" to be one of ${includeShadowTreeModesValues}, ` +
lazy.pprint`got ${includeShadowTree}`
)(includeShadowTree);
return serializationOptions;

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

@ -335,7 +335,8 @@ class BrowsingContextModule extends Module {
const originTypeValues = Object.values(OriginType);
lazy.assert.that(
value => originTypeValues.includes(value),
lazy.pprint`Expected "origin" to be one of ${originTypeValues}, got ${origin}`
`Expected "origin" to be one of ${originTypeValues}, ` +
lazy.pprint`got ${origin}`
)(origin);
if (clip !== null) {
@ -384,7 +385,7 @@ class BrowsingContextModule extends Module {
throw new lazy.error.InvalidArgumentError(
`Expected "type" to be one of ${Object.values(
ClipRectangleType
)}, got ${type}`
)}, ` + lazy.pprint`got ${type}`
);
}
}
@ -448,7 +449,7 @@ class BrowsingContextModule extends Module {
lazy.assert.boolean(
promptUnload,
`Expected "promptUnload" to be a boolean, got ${promptUnload}`
lazy.pprint`Expected "promptUnload" to be a boolean, got ${promptUnload}`
);
const context = lazy.TabManager.getBrowsingContextById(contextId);
@ -508,9 +509,8 @@ class BrowsingContextModule extends Module {
if (![CreateType.tab, CreateType.window].includes(typeHint)) {
throw new lazy.error.InvalidArgumentError(
`Expected "type" to be one of ${Object.values(
CreateType
)}, got ${typeHint}`
`Expected "type" to be one of ${Object.values(CreateType)}, ` +
lazy.pprint`got ${typeHint}`
);
}
@ -952,7 +952,8 @@ class BrowsingContextModule extends Module {
lazy.assert.that(
locatorType => locatorTypes.includes(locatorType),
lazy.pprint`Expected "locator.type" to be one of ${locatorTypes}, got ${locator.type}`
`Expected "locator.type" to be one of ${locatorTypes}, ` +
lazy.pprint`got ${locator.type}`
)(locator.type);
if (
@ -962,26 +963,30 @@ class BrowsingContextModule extends Module {
) {
lazy.assert.string(
locator.value,
lazy.pprint`Expected "locator.value" of "locator.type" "${locator.type}" to be a string, got ${locator.value}`
`Expected "locator.value" of "locator.type" "${locator.type}" to be a string, ` +
lazy.pprint`got ${locator.value}`
);
}
if (locator.type == LocatorType.accessibility) {
lazy.assert.object(
locator.value,
lazy.pprint`Expected "locator.value" of "locator.type" "${locator.type}" to be an object, got ${locator.value}`
`Expected "locator.value" of "locator.type" "${locator.type}" to be an object, ` +
lazy.pprint`got ${locator.value}`
);
const { name = null, role = null } = locator.value;
if (name !== null) {
lazy.assert.string(
locator.value.name,
lazy.pprint`Expected "locator.value.name" of "locator.type" "${locator.type}" to be a string, got ${name}`
`Expected "locator.value.name" of "locator.type" "${locator.type}" to be a string, ` +
lazy.pprint`got ${name}`
);
}
if (role !== null) {
lazy.assert.string(
locator.value.role,
lazy.pprint`Expected "locator.value.role" of "locator.type" "${locator.type}" to be a string, got ${role}`
`Expected "locator.value.role" of "locator.type" "${locator.type}" to be a string, ` +
lazy.pprint`got ${role}`
);
}
}
@ -997,11 +1002,11 @@ class BrowsingContextModule extends Module {
}
if (maxNodeCount != null) {
const maxNodeCountErrorMsg = `Expected "maxNodeCount" to be an integer and greater than 0, got ${maxNodeCount}`;
const maxNodeCountErrorMsg = lazy.pprint`Expected "maxNodeCount" to be an integer and greater than 0, got ${maxNodeCount}`;
lazy.assert.that(maxNodeCount => {
lazy.assert.integer(maxNodeCount, lazy.pprint`${maxNodeCountErrorMsg}`);
lazy.assert.integer(maxNodeCount, maxNodeCountErrorMsg);
return maxNodeCount > 0;
}, lazy.pprint`${maxNodeCountErrorMsg}`)(maxNodeCount);
}, maxNodeCountErrorMsg)(maxNodeCount);
}
const serializationOptionsWithDefaults =
@ -1085,7 +1090,8 @@ class BrowsingContextModule extends Module {
const waitConditions = Object.values(WaitCondition);
if (!waitConditions.includes(wait)) {
throw new lazy.error.InvalidArgumentError(
`Expected "wait" to be one of ${waitConditions}, got ${wait}`
`Expected "wait" to be one of ${waitConditions}, ` +
lazy.pprint`got ${wait}`
);
}
@ -1233,23 +1239,26 @@ class BrowsingContextModule extends Module {
for (const prop of ["top", "bottom", "left", "right"]) {
lazy.assert.positiveNumber(
settings.margin[prop],
lazy.pprint`Expected "margin.${prop}" to be a positive number, got ${settings.margin[prop]}`
`Expected "margin.${prop}" to be a positive number, ` +
lazy.pprint`got ${settings.margin[prop]}`
);
}
for (const prop of ["width", "height"]) {
lazy.assert.positiveNumber(
settings.page[prop],
lazy.pprint`Expected "page.${prop}" to be a positive number, got ${settings.page[prop]}`
`Expected "page.${prop}" to be a positive number, ` +
lazy.pprint`got ${settings.page[prop]}`
);
}
lazy.assert.positiveNumber(
settings.scale,
lazy.pprint`Expected "scale" to be a positive number, got ${settings.scale}`
`Expected "scale" to be a positive number, ` +
lazy.pprint`got ${settings.scale}`
);
lazy.assert.that(
scale =>
scale >= lazy.print.minScaleValue && scale <= lazy.print.maxScaleValue,
lazy.pprint`scale ${settings.scale} is outside the range ${lazy.print.minScaleValue}-${lazy.print.maxScaleValue}`
`scale ${settings.scale} is outside the range ${lazy.print.minScaleValue}-${lazy.print.maxScaleValue}`
)(settings.scale);
lazy.assert.boolean(
settings.shrinkToFit,
@ -1257,11 +1266,8 @@ class BrowsingContextModule extends Module {
);
lazy.assert.that(
orientation => lazy.print.defaults.orientationValue.includes(orientation),
lazy.pprint`orientation ${
settings.orientation
} doesn't match allowed values "${lazy.print.defaults.orientationValue.join(
"/"
)}"`
`Expected "orientation" to be one of ${lazy.print.defaults.orientationValue}", ` +
lazy.pprint`got {settings.orientation}`
)(settings.orientation);
lazy.assert.boolean(
settings.background,
@ -1323,7 +1329,8 @@ class BrowsingContextModule extends Module {
const waitConditions = Object.values(WaitCondition);
if (!waitConditions.includes(wait)) {
throw new lazy.error.InvalidArgumentError(
`Expected "wait" to be one of ${waitConditions}, got ${wait}`
`Expected "wait" to be one of ${waitConditions}, ` +
lazy.pprint`got ${wait}`
);
}

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

@ -696,9 +696,9 @@ class ScriptModule extends Module {
[lazy.OwnershipModel.None, lazy.OwnershipModel.Root].includes(
ownership
),
lazy.pprint`Expected channel argument "ownership" to be one of ${Object.values(
`Expected channel argument "ownership" to be one of ${Object.values(
lazy.OwnershipModel
)}, got ${ownership}`
)}, ` + lazy.pprint`got ${ownership}`
)(ownership);
return true;
@ -713,7 +713,7 @@ class ScriptModule extends Module {
throw new lazy.error.InvalidArgumentError(
`Expected "resultOwnership" to be one of ${Object.values(
lazy.OwnershipModel
)}, got ${resultOwnership}`
)}, ` + lazy.pprint`got ${resultOwnership}`
);
}
}

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

@ -135,16 +135,18 @@ class SessionModule extends Module {
#assertNonEmptyArrayWithStrings(array, variableName) {
lazy.assert.array(
array,
lazy.pprint`Expected "${variableName}" to be an array, got ${array}`
`Expected "${variableName}" to be an array, ` + lazy.pprint`got ${array}`
);
lazy.assert.that(
array => !!array.length,
lazy.pprint`Expected "${variableName}" array to have at least one item, got ${array}`
`Expected "${variableName}" array to have at least one item, ` +
lazy.pprint`got ${array}`
)(array);
array.forEach(item => {
lazy.assert.string(
item,
lazy.pprint`Expected elements of "${variableName}" to be a string, got ${item}`
`Expected elements of "${variableName}" to be a string, ` +
lazy.pprint`got ${item}`
);
});
}

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

@ -536,7 +536,8 @@ class StorageModule extends Module {
lazy.assert.in(
sameSite,
sameSiteTypeValue,
lazy.pprint`Expected "${fieldName}" to be one of ${sameSiteTypeValue}, got ${sameSite}`
`Expected "${fieldName}" to be one of ${sameSiteTypeValue}, ` +
lazy.pprint`got ${sameSite}`
);
}
}
@ -544,7 +545,7 @@ class StorageModule extends Module {
#assertValue(value, fieldName = "value") {
lazy.assert.object(
value,
lazy.pprint`Expected "${fieldName}" to be an object, got ${value}`
`Expected "${fieldName}" to be an object, ` + lazy.pprint`got ${value}`
);
const { type, value: protocolBytesValue } = value;
@ -553,12 +554,14 @@ class StorageModule extends Module {
lazy.assert.in(
type,
bytesValueTypeValue,
lazy.pprint`Expected ${fieldName} "type" to be one of ${bytesValueTypeValue}, got ${type}`
`Expected ${fieldName} "type" to be one of ${bytesValueTypeValue}, ` +
lazy.pprint`got ${type}`
);
lazy.assert.string(
protocolBytesValue,
lazy.pprint`Expected ${fieldName} "value" to be string, got ${protocolBytesValue}`
`Expected ${fieldName} "value" to be string, ` +
lazy.pprint`got ${protocolBytesValue}`
);
}