Bug 1931782 - Format in-app notification CTA URLs with the URL formatter. r=arschmitz
Differential Revision: https://phabricator.services.mozilla.com/D229790 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
eff7ea3cfb
Коммит
c7766ffb33
|
@ -137,7 +137,10 @@ export class NotificationManager extends EventTarget {
|
|||
detail: notificationId,
|
||||
})
|
||||
);
|
||||
lazy.openLinkExternally(this.#currentNotification.URL);
|
||||
const formattedURL = Services.urlFormatter.formatURL(
|
||||
this.#currentNotification.URL
|
||||
);
|
||||
lazy.openLinkExternally(formattedURL);
|
||||
Glean.inappnotifications.interaction.record({
|
||||
notification_id: notificationId,
|
||||
active_this_session: this.#getActiveNotificationDuration(),
|
||||
|
|
|
@ -46,6 +46,7 @@ function getMockNotifications() {
|
|||
}
|
||||
|
||||
let didOpen = false;
|
||||
let expectedURI = "about:blank";
|
||||
|
||||
add_setup(async function () {
|
||||
// PlacesUtils when executing the CTA needs the profile.
|
||||
|
@ -59,7 +60,7 @@ add_setup(async function () {
|
|||
didOpen = true;
|
||||
Assert.equal(
|
||||
uri.spec,
|
||||
"about:blank",
|
||||
expectedURI,
|
||||
"Should only receive about blank load request"
|
||||
);
|
||||
},
|
||||
|
@ -431,3 +432,42 @@ add_task(async function test_newNotificationReemit_handleEvent() {
|
|||
);
|
||||
notificationManager.updatedNotifications([]);
|
||||
});
|
||||
|
||||
add_task(async function test_executeNotificationCTA_formatURL() {
|
||||
didOpen = false;
|
||||
const notificationManager = new NotificationManager();
|
||||
const mockNotifications = getMockNotifications();
|
||||
const url = "https://example.com/%LOCALE%/file.json";
|
||||
mockNotifications[1].URL = url;
|
||||
expectedURI = Services.urlFormatter.formatURL(url);
|
||||
notificationManager.updatedNotifications(mockNotifications);
|
||||
const { detail: notification } = await BrowserTestUtils.waitForEvent(
|
||||
notificationManager,
|
||||
NotificationManager.NEW_NOTIFICATION_EVENT
|
||||
);
|
||||
Assert.equal(notification.id, "bar", "Should pick the second notification");
|
||||
|
||||
const notificationInteractionEvent = BrowserTestUtils.waitForEvent(
|
||||
notificationManager,
|
||||
NotificationManager.NOTIFICATION_INTERACTION_EVENT
|
||||
);
|
||||
const clearNotificationEvent = BrowserTestUtils.waitForEvent(
|
||||
notificationManager,
|
||||
NotificationManager.CLEAR_NOTIFICATION_EVENT
|
||||
);
|
||||
notificationManager.executeNotificationCTA(notification.id);
|
||||
const { detail: notificationId } = await notificationInteractionEvent;
|
||||
Assert.equal(
|
||||
notificationId,
|
||||
notification.id,
|
||||
"Should have interacted with the notification"
|
||||
);
|
||||
Assert.ok(didOpen, "Should open URL externally");
|
||||
await clearNotificationEvent;
|
||||
await BrowserTestUtils.waitForEvent(
|
||||
notificationManager,
|
||||
NotificationManager.REQUEST_NOTIFICATIONS_EVENT
|
||||
);
|
||||
|
||||
notificationManager.updatedNotifications([]);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче