Backed out changeset f6ca02568bef (bug 1899439) for causing xcpshell failures in xpcshell/test_PanelTestProvider.js. CLOSED TREE

This commit is contained in:
Stanca Serban
2024-06-18 05:14:28 +03:00
parent 2c7403182a
commit 47ba18b7d7
5 changed files with 3 additions and 220 deletions

View File

@@ -50,7 +50,6 @@ module.exports = {
},
globals: {
assert: true,
expect: true,
chai: true,
sinon: true,
},

View File

@@ -529,29 +529,6 @@ export const MessageLoaderUtils = {
provider: provider.id,
};
// Render local messages with experiment l10n structure if devtools
// are enabled. This is not a production feature, since local messages
// do not use experiment localization, and experimental messages are
// translated in ExperimentAPI.sys.mjs. This is useful for development
// to allow quickly testing experimental messages without needing to
// manually convert all the $l10n objects to strings. We lock this
// behind the devtools because it requires recursively processing
// every message at least once, for a small performance hit.
if (
provider.type === "local" &&
lazy.ASRouterPreferences.devtoolsEnabled
) {
try {
return this._delocalizeValues(message);
} catch (e) {
lazy.log.error(
`Failed to delocalize message ${message.id}:`,
e.message,
e.cause
);
}
}
return message;
})
.filter(message => message.weight > 0),
@@ -560,52 +537,6 @@ export const MessageLoaderUtils = {
};
},
/**
* For a given input (e.g. a message or a property), search for $l10n
* properties and flatten them to just their `text` property. This is done so
* that a message set up for experiment localization can be tested locally.
* Without this, the messaging surface would not be able to read the message
* because all the localized copy would be in $l10n objects. Normally, these
* objects are translated by ExperimentFeature.substituteLocalizations. Rather
* than returning $l10n.text, it would return localizations[$l10n.id] for the
* active language. Localizations are included in the recipe, not in the
* message, so we can't actually translate the message. But every $l10n object
* should have a `text` property with the original English copy. So you can
* copy a message straight from the recipe into a local message provider, and
* it should render the English version with no issues.
*
* @param {object} values An object to delocalize
* @returns {object} The object, stripped of any $l10n objects
*/
_delocalizeValues(values) {
if (typeof values !== "object" || values === null) {
return values;
}
if (Array.isArray(values)) {
return values.map(value => this._delocalizeValues(value));
}
const substituted = Object.assign({}, values);
for (const [key, value] of Object.entries(values)) {
if (key === "$l10n") {
if (typeof value === "object" && value !== null) {
if (value?.text) {
return value.text;
}
throw new Error(`Expected $l10n to have a text property, but got`, {
cause: value,
});
}
throw new Error(`Expected $l10n to be an object, but got`, {
cause: value,
});
}
substituted[key] = this._delocalizeValues(value);
}
return substituted;
},
/**
* cleanupCache - Removes cached data of removed providers.
*

View File

@@ -629,116 +629,6 @@ const MESSAGES = () => [
],
},
},
{
id: "EXPERIMENT_L10N_TEST",
template: "feature_callout",
description:
"Test ASRouter support for flattening experiment-translated messages into plain English text. See bug 1899439.",
content: {
id: "EXPERIMENT_L10N_TEST",
template: "multistage",
backdrop: "transparent",
transitions: false,
disableHistoryUpdates: true,
metrics: "block",
screens: [
{
id: "EXPERIMENT_L10N_TEST_1",
anchors: [
{
selector: "#PanelUI-menu-button",
panel_position: {
anchor_attachment: "bottomcenter",
callout_attachment: "topright",
},
},
],
content: {
position: "callout",
layout: "survey",
width: "min-content",
padding: "16",
title: {
raw: {
$l10n: {
id: "question-title",
text: "Help Firefox improve this page",
comment:
"The title of a popup asking the user to give feedback by answering a short survey",
},
},
marginInline: "0 42px",
whiteSpace: "nowrap",
},
title_logo: {
imageURL: "chrome://branding/content/about-logo.png",
alignment: "top",
},
subtitle: {
raw: {
$l10n: {
id: "relevance-question",
text: "How relevant are the contents of this Firefox page to you?",
comment: "Survey question about relevance",
},
},
},
secondary_button: {
label: {
raw: {
$l10n: {
id: "advance-button-label",
text: "Next",
comment:
"Label for the button that submits the user's response to question 1 and advances to question 2",
},
},
},
style: "primary",
action: { navigate: true },
disabled: "hasActiveMultiSelect",
},
dismiss_button: {
size: "small",
marginBlock: "12px 0",
marginInline: "0 12px",
action: { dismiss: true },
},
tiles: {
type: "multiselect",
style: { flexDirection: "column", alignItems: "flex-start" },
data: [
{
id: "radio-no-opinion",
type: "radio",
group: "radios",
defaultValue: true,
icon: {
style: {
width: "14px",
height: "14px",
marginInline: "0 0.5em",
},
},
label: {
raw: {
$l10n: {
id: "radio-no-opinion-label",
text: "No opinion",
comment:
"Answer choice indicating that the user has no opinion about how relevant the New Tab Page is",
},
},
},
action: { navigate: true },
},
],
},
},
},
],
},
},
];
export const PanelTestProvider = {

View File

@@ -497,9 +497,9 @@ describe("ASRouter", () => {
);
});
describe("lazily loading local test providers", () => {
let justIdAndContent = ({ id, content }) => ({ id, content });
afterEach(() => Router.uninit());
afterEach(() => {
Router.uninit();
});
it("should add the local test providers on init if devtools are enabled", async () => {
sandbox.stub(ASRouterPreferences, "devtoolsEnabled").get(() => true);
@@ -514,38 +514,6 @@ describe("ASRouter", () => {
assert.notProperty(Router._localProviders, "PanelTestProvider");
});
it("should flatten experiment translated messages from local test providers if devtools are enabled...", async () => {
sandbox.stub(ASRouterPreferences, "devtoolsEnabled").get(() => true);
await createRouterAndInit();
assert.property(Router._localProviders, "PanelTestProvider");
expect(
Router.state.messages.map(justIdAndContent)
).to.deep.include.members([
{ id: "experimentL10n", content: { text: "UniqueText" } },
]);
});
it("...but not if devtools are disabled", async () => {
sandbox.stub(ASRouterPreferences, "devtoolsEnabled").get(() => false);
await createRouterAndInit();
assert.notProperty(Router._localProviders, "PanelTestProvider");
let justIdAndContentMessages =
Router.state.messages.map(justIdAndContent);
expect(justIdAndContentMessages).not.to.deep.include.members([
{ id: "experimentL10n", content: { text: "UniqueText" } },
]);
expect(justIdAndContentMessages).to.deep.include.members([
{
id: "experimentL10n",
content: { text: { $l10n: { text: "UniqueText" } } },
},
]);
});
});
});

View File

@@ -42,11 +42,6 @@ export const FAKE_LOCAL_MESSAGES = [
template: "fancy_template",
content: { text: "Foo" },
},
{
id: "experimentL10n",
template: "fancy_template",
content: { text: { $l10n: { text: "UniqueText" } } },
},
];
export const FAKE_LOCAL_PROVIDER = {
id: "onboarding",