From d42d78e05a262d1981f00986e56a853fdcfeecb8 Mon Sep 17 00:00:00 2001 From: Meg Viar Date: Fri, 2 May 2025 22:38:39 +0000 Subject: [PATCH] Bug 1964116 - Update infobar schema to reflect that 'text' can be an array r=jprickett,omc-reviewers Differential Revision: https://phabricator.services.mozilla.com/D247646 --- .../schemas/MessagingExperiment.schema.json | 95 ++++++++++++++++++- .../CFR/templates/InfoBar.schema.json | 58 ++++++++++- .../modules/PanelTestProvider.sys.mjs | 42 ++++++++ .../tests/xpcshell/test_PanelTestProvider.js | 1 + 4 files changed, 192 insertions(+), 4 deletions(-) diff --git a/browser/components/asrouter/content-src/schemas/MessagingExperiment.schema.json b/browser/components/asrouter/content-src/schemas/MessagingExperiment.schema.json index a0f66e84b7bb..f0c66f4c39f2 100644 --- a/browser/components/asrouter/content-src/schemas/MessagingExperiment.schema.json +++ b/browser/components/asrouter/content-src/schemas/MessagingExperiment.schema.json @@ -556,8 +556,62 @@ ] }, "text": { - "$ref": "chrome://browser/content/asrouter/schemas/MessagingExperiment.schema.json#/$defs/localizableText", - "description": "The text show in the notification box." + "description": "Either a single localizableText, or an array of raw strings and/or localizableText objects. localizableText can contain an optional href property for the text to be rendered as a link.", + "oneOf": [ + { + "$ref": "file:///InfoBar.schema.json#/$defs/plainText" + }, + { + "allOf": [ + { + "$ref": "chrome://browser/content/asrouter/schemas/MessagingExperiment.schema.json#/$defs/localizableText" + }, + { + "not": { + "required": [ + "href" + ] + } + } + ] + }, + { + "$ref": "file:///InfoBar.schema.json#/$defs/localizableTextWithHref" + }, + { + "$ref": "file:///InfoBar.schema.json#/$defs/rawTextWithHref" + }, + { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "file:///InfoBar.schema.json#/$defs/plainText" + }, + { + "allOf": [ + { + "$ref": "chrome://browser/content/asrouter/schemas/MessagingExperiment.schema.json#/$defs/localizableText" + }, + { + "not": { + "required": [ + "href" + ] + } + } + ] + }, + { + "$ref": "file:///InfoBar.schema.json#/$defs/localizableTextWithHref" + }, + { + "$ref": "file:///InfoBar.schema.json#/$defs/rawTextWithHref" + } + ] + } + } + ] }, "priority": { "description": "Infobar priority level https://searchfox.org/mozilla-central/rev/3aef835f6cb12e607154d56d68726767172571e4/toolkit/content/widgets/notificationbox.js#387", @@ -640,6 +694,43 @@ "description": "Target for links or buttons", "type": "string", "format": "uri" + }, + "localizableTextWithHref": { + "description": "Everything a localizableText allows, plus a required href", + "allOf": [ + { + "$ref": "chrome://browser/content/asrouter/schemas/MessagingExperiment.schema.json#/$defs/localizableText" + }, + { + "type": "object", + "properties": { + "href": { + "$ref": "file:///InfoBar.schema.json#/$defs/linkUrl" + } + }, + "required": [ + "href" + ], + "additionalProperties": true + } + ] + }, + "rawTextWithHref": { + "description": "A literal text chunk that must include href", + "type": "object", + "properties": { + "raw": { + "type": "string" + }, + "href": { + "$ref": "file:///InfoBar.schema.json#/$defs/linkUrl" + } + }, + "required": [ + "raw", + "href" + ], + "additionalProperties": false } } }, diff --git a/browser/components/asrouter/content-src/templates/CFR/templates/InfoBar.schema.json b/browser/components/asrouter/content-src/templates/CFR/templates/InfoBar.schema.json index 4006f7f34d4c..5351fdf029f2 100644 --- a/browser/components/asrouter/content-src/templates/CFR/templates/InfoBar.schema.json +++ b/browser/components/asrouter/content-src/templates/CFR/templates/InfoBar.schema.json @@ -15,8 +15,38 @@ "enum": ["global", "tab", "universal"] }, "text": { - "$ref": "file:///FxMSCommon.schema.json#/$defs/localizableText", - "description": "The text show in the notification box." + "description": "Either a single localizableText, or an array of raw strings and/or localizableText objects. localizableText can contain an optional href property for the text to be rendered as a link.", + "oneOf": [ + { "$ref": "#/$defs/plainText" }, + { + "allOf": [ + { + "$ref": "file:///FxMSCommon.schema.json#/$defs/localizableText" + }, + { "not": { "required": ["href"] } } + ] + }, + { "$ref": "#/$defs/localizableTextWithHref" }, + { "$ref": "#/$defs/rawTextWithHref" }, + { + "type": "array", + "items": { + "oneOf": [ + { "$ref": "#/$defs/plainText" }, + { + "allOf": [ + { + "$ref": "file:///FxMSCommon.schema.json#/$defs/localizableText" + }, + { "not": { "required": ["href"] } } + ] + }, + { "$ref": "#/$defs/localizableTextWithHref" }, + { "$ref": "#/$defs/rawTextWithHref" } + ] + } + } + ] }, "priority": { "description": "Infobar priority level https://searchfox.org/mozilla-central/rev/3aef835f6cb12e607154d56d68726767172571e4/toolkit/content/widgets/notificationbox.js#387", @@ -88,6 +118,30 @@ "description": "Target for links or buttons", "type": "string", "format": "uri" + }, + "localizableTextWithHref": { + "description": "Everything a localizableText allows, plus a required href", + "allOf": [ + { "$ref": "file:///FxMSCommon.schema.json#/$defs/localizableText" }, + { + "type": "object", + "properties": { + "href": { "$ref": "#/$defs/linkUrl" } + }, + "required": ["href"], + "additionalProperties": true + } + ] + }, + "rawTextWithHref": { + "description": "A literal text chunk that must include href", + "type": "object", + "properties": { + "raw": { "type": "string" }, + "href": { "$ref": "#/$defs/linkUrl" } + }, + "required": ["raw", "href"], + "additionalProperties": false } } } diff --git a/browser/components/asrouter/modules/PanelTestProvider.sys.mjs b/browser/components/asrouter/modules/PanelTestProvider.sys.mjs index 8ffbc430239f..7987ebb9f014 100644 --- a/browser/components/asrouter/modules/PanelTestProvider.sys.mjs +++ b/browser/components/asrouter/modules/PanelTestProvider.sys.mjs @@ -1570,6 +1570,48 @@ const MESSAGES = () => [ }, groups: [], }, + { + id: "UNIVERSAL_INFOBAR_WITH_EMBEDDED_LINKS", + content: { + text: [ + "Read the release notes ", + { + raw: "here. ", + href: "https://www.mozilla.org/en-US/firefox/releases/", + }, + { + string_id: "cookie-banner-blocker-onboarding-learn-more", + href: "https://mozilla.org/privacy/firefox/?v=product", + }, + "!", + ], + type: "universal", + dismissable: false, + buttons: [ + { + label: "Continue", + action: { + type: "SET_PREF", + data: { + pref: { + name: "universal-infobar-test-pref", + value: true, + }, + }, + }, + primary: true, + accessKey: "C", + }, + ], + }, + trigger: { + id: "defaultBrowserCheck", + }, + template: "infobar", + frequency: { + lifetime: 100, + }, + }, ]; export const PanelTestProvider = { diff --git a/browser/components/asrouter/tests/xpcshell/test_PanelTestProvider.js b/browser/components/asrouter/tests/xpcshell/test_PanelTestProvider.js index fe6ae7f03d05..2605cc1624a8 100644 --- a/browser/components/asrouter/tests/xpcshell/test_PanelTestProvider.js +++ b/browser/components/asrouter/tests/xpcshell/test_PanelTestProvider.js @@ -29,6 +29,7 @@ add_task(async function test_PanelTestProvider() { bookmarks_bar_button: 1, menu_message: 1, newtab_message: 2, + infobar: 1, }; const EXPECTED_TOTAL_MESSAGE_COUNT = Object.values(