Bug 1928452 - Add donation_tab in app notification type. r=freaktechnik
Differential Revision: https://phabricator.services.mozilla.com/D229824 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6ffc6f3df8
Коммит
afeb48721e
|
@ -45,9 +45,9 @@ export class NotificationManager extends EventTarget {
|
|||
|
||||
/**
|
||||
* Check if a notification has UI that should be shown. The only notification
|
||||
* type that doesn't have UI is the "donation_browser" type, which imitates the
|
||||
* appeal behavior, where we open a webseite in the user's browser.
|
||||
* Setting name and private explicitly to work around jsdoc parsing issue.
|
||||
* types that don't have UI are the "donation_browser" or "donation_tab"
|
||||
* types, which imitate the appeal behavior, where we open a website. Setting
|
||||
* name and private explicitly to work around jsdoc parsing issue.
|
||||
*
|
||||
* @name NotificationManager.isNotificationWithUI
|
||||
* @private
|
||||
|
@ -55,7 +55,7 @@ export class NotificationManager extends EventTarget {
|
|||
* @returns {boolean} If this notification should show a popup in the UI.
|
||||
*/
|
||||
static #isNotificationWithUI(notification) {
|
||||
return notification.type !== "donation_browser";
|
||||
return !["donation_browser", "donation_tab"].includes(notification.type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,10 +137,29 @@ export class NotificationManager extends EventTarget {
|
|||
detail: notificationId,
|
||||
})
|
||||
);
|
||||
|
||||
const formattedURL = Services.urlFormatter.formatURL(
|
||||
this.#currentNotification.URL
|
||||
);
|
||||
lazy.openLinkExternally(formattedURL);
|
||||
const needsTabmail = this.#currentNotification.type === "donation_tab";
|
||||
const tabmail =
|
||||
needsTabmail &&
|
||||
Services.wm
|
||||
.getMostRecentWindow("mail:3pane")
|
||||
?.document.getElementById("tabmail");
|
||||
|
||||
// Fall back to opening a browser window if we don't have a tabmail.
|
||||
if (this.#currentNotification.type !== "donation_tab" || !tabmail) {
|
||||
lazy.openLinkExternally(formattedURL);
|
||||
} else {
|
||||
tabmail.openTab("contentTab", {
|
||||
url: formattedURL,
|
||||
background: false,
|
||||
linkHandler: "single-page",
|
||||
});
|
||||
tabmail.ownerGlobal.focus();
|
||||
}
|
||||
|
||||
Glean.inappnotifications.interaction.record({
|
||||
notification_id: notificationId,
|
||||
active_this_session: this.#getActiveNotificationDuration(),
|
||||
|
|
|
@ -23,3 +23,4 @@ subsuite = "thunderbird"
|
|||
["browser_inAppNotificationContainer.js"]
|
||||
["browser_inAppNotificationFocus.js"]
|
||||
["browser_inAppNotificationMessengerIntegration.js"]
|
||||
["browser_inAppNotificationIntegration.js"]
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { InAppNotifications } = ChromeUtils.importESModule(
|
||||
"resource:///modules/InAppNotifications.sys.mjs"
|
||||
);
|
||||
|
||||
add_task(async function testInAppNotificationDonationTab() {
|
||||
const tabmail = document.getElementById("tabmail");
|
||||
Assert.strictEqual(
|
||||
Services.wm.getMostRecentWindow("mail:3pane"),
|
||||
window,
|
||||
"Test window should be most recent window"
|
||||
);
|
||||
|
||||
const tabPromise = BrowserTestUtils.waitForEvent(
|
||||
tabmail.tabContainer,
|
||||
"TabOpen"
|
||||
);
|
||||
|
||||
InAppNotifications.updateNotifications([
|
||||
{
|
||||
id: "testNotification" + Date.now(),
|
||||
title: "Test notification with a really really long title",
|
||||
description: "Long prose text",
|
||||
URL: "https://example.com",
|
||||
CTA: "Click me!",
|
||||
severity: 1,
|
||||
type: "donation_tab",
|
||||
start_at: new Date(Date.now() - 100000).toISOString(),
|
||||
end_at: new Date(Date.now() + 9999999999).toISOString(),
|
||||
targeting: {},
|
||||
},
|
||||
]);
|
||||
|
||||
const {
|
||||
detail: { tabInfo },
|
||||
} = await tabPromise;
|
||||
|
||||
await BrowserTestUtils.browserLoaded(
|
||||
tabInfo.browser,
|
||||
false,
|
||||
"https://example.com/"
|
||||
);
|
||||
|
||||
Assert.equal(
|
||||
tabInfo.browser.currentURI.spec,
|
||||
"https://example.com/",
|
||||
"loaded url in new tab"
|
||||
);
|
||||
|
||||
InAppNotifications.updateNotifications([]);
|
||||
tabmail.closeOtherTabs(0);
|
||||
});
|
|
@ -359,7 +359,7 @@ add_task(function test_dismissNotification_noop() {
|
|||
notificationManager.updatedNotifications([]);
|
||||
});
|
||||
|
||||
add_task(async function test_showDonationsOldNotification() {
|
||||
add_task(async function test_showDonationsBrowserNotification() {
|
||||
didOpen = false;
|
||||
const now = Date.now();
|
||||
const notifications = [
|
||||
|
@ -403,6 +403,50 @@ add_task(async function test_showDonationsOldNotification() {
|
|||
notificationManager.updatedNotifications([]);
|
||||
});
|
||||
|
||||
add_task(async function test_showDonationsTabNotification() {
|
||||
didOpen = false;
|
||||
const now = Date.now();
|
||||
const notifications = [
|
||||
{
|
||||
id: "tabdonation",
|
||||
type: "donation_tab",
|
||||
start_at: new Date(now - SAFETY_MARGIN_MS).toISOString(),
|
||||
end_at: new Date(now + SAFETY_MARGIN_MS).toISOString(),
|
||||
URL: "about:blank",
|
||||
CTA: "Appeal",
|
||||
severity: 5,
|
||||
},
|
||||
];
|
||||
const notificationManager = new NotificationManager();
|
||||
notificationManager.addEventListener(
|
||||
NotificationManager.NEW_NOTIFICATION_EVENT,
|
||||
() => {
|
||||
Assert.ok(false, "Should not get any new notification event");
|
||||
}
|
||||
);
|
||||
|
||||
const notificationInteractionEvent = BrowserTestUtils.waitForEvent(
|
||||
notificationManager,
|
||||
NotificationManager.NOTIFICATION_INTERACTION_EVENT
|
||||
);
|
||||
const clearNotificationEvent = BrowserTestUtils.waitForEvent(
|
||||
notificationManager,
|
||||
NotificationManager.CLEAR_NOTIFICATION_EVENT
|
||||
);
|
||||
notificationManager.updatedNotifications(notifications);
|
||||
|
||||
const { detail: notificationId } = await notificationInteractionEvent;
|
||||
Assert.equal(
|
||||
notificationId,
|
||||
"tabdonation",
|
||||
"Should have interacted with the notification"
|
||||
);
|
||||
await clearNotificationEvent;
|
||||
Assert.ok(didOpen, "Should open URL externally");
|
||||
|
||||
notificationManager.updatedNotifications([]);
|
||||
});
|
||||
|
||||
add_task(async function test_newNotificationReemit_handleEvent() {
|
||||
const notificationManager = new NotificationManager();
|
||||
notificationManager.updatedNotifications(getMockNotifications());
|
||||
|
|
Загрузка…
Ссылка в новой задаче