Bug 1913431 - modify activeNotifications to account for newtab topic selection modal r=omc-reviewers,mviar,emcminn

Differential Revision: https://phabricator.services.mozilla.com/D222379
This commit is contained in:
hanna alemu
2024-09-24 21:15:26 +00:00
parent b7ed3fb089
commit 7598b19c9a
2 changed files with 53 additions and 1 deletions

View File

@@ -5,6 +5,9 @@
const FXA_ENABLED_PREF = "identity.fxaccounts.enabled"; const FXA_ENABLED_PREF = "identity.fxaccounts.enabled";
const DISTRIBUTION_ID_PREF = "distribution.id"; const DISTRIBUTION_ID_PREF = "distribution.id";
const DISTRIBUTION_ID_CHINA_REPACK = "MozillaOnline"; const DISTRIBUTION_ID_CHINA_REPACK = "MozillaOnline";
const TOPIC_SELECTION_MODAL_LAST_DISPLAYED_PREF =
"browser.newtabpage.activity-stream.discoverystream.topicSelection.onboarding.lastDisplayed";
const NOTIFICATION_INTERVAL_AFTER_TOPIC_MODAL_MS = 60000; // Assuming avoid notification up to 1 minute after newtab Topic Notification Modal
// We use importESModule here instead of static import so that // We use importESModule here instead of static import so that
// the Karma test environment won't choke on this module. This // the Karma test environment won't choke on this module. This
@@ -153,6 +156,17 @@ XPCOMUtils.defineLazyPreferenceGetter(
"browser.search.totalSearches", "browser.search.totalSearches",
0 0
); );
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
"newTabTopicModalLastSeen",
TOPIC_SELECTION_MODAL_LAST_DISPLAYED_PREF,
null,
lastSeenString => {
return Number.isInteger(parseInt(lastSeenString, 10))
? parseInt(lastSeenString, 10)
: 0;
}
);
XPCOMUtils.defineLazyServiceGetters(lazy, { XPCOMUtils.defineLazyServiceGetters(lazy, {
AUS: ["@mozilla.org/updates/update-service;1", "nsIApplicationUpdateService"], AUS: ["@mozilla.org/updates/update-service;1", "nsIApplicationUpdateService"],
@@ -823,10 +837,14 @@ const TargetingGetters = {
return true; return true;
} }
let duration = Date.now() - lazy.newTabTopicModalLastSeen;
if ( if (
window.gURLBar?.view.isOpen || window.gURLBar?.view.isOpen ||
window.gNotificationBox?.currentNotification || window.gNotificationBox?.currentNotification ||
window.gBrowser.getNotificationBox()?.currentNotification window.gBrowser.getNotificationBox()?.currentNotification ||
// Avoid showing messages if the newtab Topic selection modal was shown in
// the past 1 minute
duration <= NOTIFICATION_INTERVAL_AFTER_TOPIC_MODAL_MS
) { ) {
return true; return true;
} }

View File

@@ -1712,3 +1712,37 @@ add_task(async function check_totalSearches() {
"should return a value of 20" "should return a value of 20"
); );
}); });
add_task(
async function check_activeNotifications_newtab_topic_selection_modal_shown_past() {
// 10 minutes ago
let timestamp10MinsAgo = `${new Date().getTime() - 600000}`;
await pushPrefs([
"browser.newtabpage.activity-stream.discoverystream.topicSelection.onboarding.lastDisplayed",
timestamp10MinsAgo,
]);
is(
await ASRouterTargeting.Environment.activeNotifications,
false,
"activeNotifications should be false if the topic selection modal on newtab was last shown more than a minute ago"
);
}
);
add_task(
async function check_activeNotifications_newtab_topic_selection_modal_shown_recently() {
// 1 second ago
let timestamp1SecAgo = `${new Date().getTime() - 1000}`;
await pushPrefs([
"browser.newtabpage.activity-stream.discoverystream.topicSelection.onboarding.lastDisplayed",
timestamp1SecAgo,
]);
is(
await ASRouterTargeting.Environment.activeNotifications,
true,
"activeNotifications should be true if the topic selection modal on newtab was last shown less than a minute ago"
);
}
);