Bug 1372067 - Part 2: Add the test cases, r=mossop
This commit
- splits up the browser_onboarding_notification.js test
- adds the test_mute_notification_on_1st_session test case
- adds the test_move_on_to_next_notification_when_reaching_max_prompt_count test case
- adds the test_move_on_to_next_notification_when_reaching_max_life_time test case
- adds the test_move_on_to_next_notification_after_interacting_with_notification test case
- updates the existing test cases for the new notification timing policy
- updates the browser_newtab_focus.js test
MozReview-Commit-ID: Ej2bHJSr35z
--- a/browser/base/content/test/newtab/browser_newtab_focus.js
+++ b/browser/base/content/test/newtab/browser_newtab_focus.js
@@ -16,16 +16,19 @@ add_task(async function() {
// bar; search button; and toggle button. Additionaly there may or may not be
// a scroll bar caused by fix to 1180387, which will eat an extra focus
let FOCUS_COUNT = 30;
// Create a new tab page.
await setLinks("0,1,2,3,4,5,6,7,8");
setPinnedLinks("");
+ if (onbardingEnabled) {
+ await promiseNoMuteNotificationOnFirstSession();
+ }
let tab = await addNewTabPageTab();
if (onbardingEnabled) {
FOCUS_COUNT += 2;
await promiseTourNotificationOpened(tab.linkedBrowser);
}
gURLBar.focus();
// Count the focus with the enabled page.
countFocus(FOCUS_COUNT);
@@ -51,16 +54,20 @@ function countFocus(aExpectedCount) {
if (document.activeElement == gBrowser.selectedBrowser) {
focusCount++;
}
} while (document.activeElement != gURLBar.inputField);
ok(focusCount == aExpectedCount || focusCount == (aExpectedCount + 1),
"Validate focus count in the new tab page.");
}
+function promiseNoMuteNotificationOnFirstSession() {
+ return SpecialPowers.pushPrefEnv({set: [["browser.onboarding.notification.mute-duration-on-first-session-ms", 0]]});
+}
+
/**
* Wait for the onboarding tour notification opens
*/
function promiseTourNotificationOpened(browser) {
let condition = () => {
return ContentTask.spawn(browser, {}, function() {
return new Promise(resolve => {
let bar = content.document.querySelector("#onboarding-notification-bar");
--- a/browser/extensions/onboarding/test/browser/browser.ini
+++ b/browser/extensions/onboarding/test/browser/browser.ini
@@ -1,7 +1,10 @@
[DEFAULT]
support-files =
head.js
[browser_onboarding_notification.js]
+[browser_onboarding_notification_2.js]
+[browser_onboarding_notification_3.js]
+[browser_onboarding_notification_4.js]
[browser_onboarding_tours.js]
[browser_onboarding_tourset.js]
--- a/browser/extensions/onboarding/test/browser/browser_onboarding_notification.js
+++ b/browser/extensions/onboarding/test/browser/browser_onboarding_notification.js
@@ -1,106 +1,64 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_show_tour_notifications_in_order() {
resetOnboardingDefaultState();
+ Preferences.set("browser.onboarding.notification.max-prompt-count-per-tour", 1);
+ skipMuteNotificationOnFirstSession();
let tourIds = TOUR_IDs;
let tab = null;
let targetTourId = null;
let reloadPromise = null;
let expectedPrefUpdate = null;
- for (let i = 0; i < tourIds.length; ++i) {
- expectedPrefUpdate = promisePrefUpdated("browser.onboarding.notification.lastPrompted", tourIds[i]);
- if (tab) {
- reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- tab.linkedBrowser.reload();
- await reloadPromise;
- } else {
- tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
- await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
- }
- await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
- await promiseTourNotificationOpened(tab.linkedBrowser);
- targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
- is(targetTourId, tourIds[i], "Should show tour notifications in order");
- await expectedPrefUpdate;
- }
+ await loopTourNotificationQueueOnceInOrder();
+ await loopTourNotificationQueueOnceInOrder();
- expectedPrefUpdate = promisePrefUpdated("browser.onboarding.notification.lastPrompted", tourIds[0]);
+ expectedPrefUpdate = promisePrefUpdated("browser.onboarding.notification.finished", true);
reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
tab.linkedBrowser.reload();
await reloadPromise;
await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
- await promiseTourNotificationOpened(tab.linkedBrowser);
- targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
- is(targetTourId, tourIds[0], "Should loop back to the 1st tour notification after showing all notifications");
await expectedPrefUpdate;
+ let tourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ ok(!tourId, "Should not prompt each tour for more than 2 chances.");
await BrowserTestUtils.removeTab(tab);
+
+ async function loopTourNotificationQueueOnceInOrder() {
+ for (let i = 0; i < tourIds.length; ++i) {
+ if (tab) {
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ } else {
+ tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ }
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ is(targetTourId, tourIds[i], "Should show tour notifications in order");
+ }
+ }
});
add_task(async function test_open_target_tour_from_notification() {
resetOnboardingDefaultState();
+ skipMuteNotificationOnFirstSession();
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
await promiseTourNotificationOpened(tab.linkedBrowser);
let targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
await BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-notification-action-btn", {}, tab.linkedBrowser);
await promiseOnboardingOverlayOpened(tab.linkedBrowser);
let { activeNavItemId, activePageId } = await getCurrentActiveTour(tab.linkedBrowser);
is(targetTourId, activeNavItemId, "Should navigate to the target tour item.");
is(`${targetTourId}-page`, activePageId, "Should display the target tour page.");
await BrowserTestUtils.removeTab(tab);
});
-add_task(async function test_not_show_notification_for_completed_tour() {
- resetOnboardingDefaultState();
-
- let tourIds = TOUR_IDs;
- // Make only the last tour uncompleted
- let lastTourId = tourIds[tourIds.length - 1];
- for (let id of tourIds) {
- if (id != lastTourId) {
- setTourCompletedState(id, true);
- }
- }
-
- let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
- await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
- await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
- await promiseTourNotificationOpened(tab.linkedBrowser);
- let targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
- is(targetTourId, lastTourId, "Should not show notification for completed tour");
- await BrowserTestUtils.removeTab(tab);
-});
-
-add_task(async function test_skip_notification_for_completed_tour() {
- resetOnboardingDefaultState();
- await SpecialPowers.pushPrefEnv({set: [["browser.onboarding.enabled", true]]});
-
- let tourIds = TOUR_IDs;
- // Make only 2nd tour completed
- await setTourCompletedState(tourIds[1], true);
-
- // Test show notification for the 1st tour
- let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
- await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
- await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
- await promiseTourNotificationOpened(tab.linkedBrowser);
- let targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
- is(targetTourId, tourIds[0], "Should show notification for incompleted tour");
-
- // Test skip the 2nd tour and show notification for the 3rd tour
- let reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
- tab.linkedBrowser.reload();
- await reloadPromise;
- await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
- await promiseTourNotificationOpened(tab.linkedBrowser);
- targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
- is(targetTourId, tourIds[2], "Should skip notification for the completed 2nd tour");
- await BrowserTestUtils.removeTab(tab);
-});
new file mode 100644
--- /dev/null
+++ b/browser/extensions/onboarding/test/browser/browser_onboarding_notification_2.js
@@ -0,0 +1,87 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function test_not_show_notification_for_completed_tour() {
+ resetOnboardingDefaultState();
+ skipMuteNotificationOnFirstSession();
+
+ let tourIds = TOUR_IDs;
+ // Make only the last tour uncompleted
+ let lastTourId = tourIds[tourIds.length - 1];
+ for (let id of tourIds) {
+ if (id != lastTourId) {
+ setTourCompletedState(id, true);
+ }
+ }
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ let targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ is(targetTourId, lastTourId, "Should not show notification for completed tour");
+ await BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function test_skip_notification_for_completed_tour() {
+ resetOnboardingDefaultState();
+ Preferences.set("browser.onboarding.notification.max-prompt-count-per-tour", 1);
+ skipMuteNotificationOnFirstSession();
+
+ let tourIds = TOUR_IDs;
+ // Make only 2nd tour completed
+ await setTourCompletedState(tourIds[1], true);
+
+ // Test show notification for the 1st tour
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ let targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ is(targetTourId, tourIds[0], "Should show notification for incompleted tour");
+
+ // Test skip the 2nd tour and show notification for the 3rd tour
+ let reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ is(targetTourId, tourIds[2], "Should skip notification for the completed 2nd tour");
+ await BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function test_mute_notification_on_1st_session() {
+ resetOnboardingDefaultState();
+
+ // Test no notifications during the mute duration on the 1st session
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ // The tour notification would be prompted on idle, so we wait idle twice here before proceeding
+ await waitUntilWindowIdle(tab.linkedBrowser);
+ await waitUntilWindowIdle(tab.linkedBrowser);
+ let reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await waitUntilWindowIdle(tab.linkedBrowser);
+ await waitUntilWindowIdle(tab.linkedBrowser);
+ let promptCount = Preferences.get("browser.onboarding.notification.prompt-count", 0);
+ is(0, promptCount, "Should not prompt tour notification during the mute duration on the 1st session");
+
+ // Test notification prompted after the mute duration on the 1st session
+ let muteTime = Preferences.get("browser.onboarding.notification.mute-duration-on-first-session-ms");
+ let lastTime = Math.floor((Date.now() - muteTime - 1) / 1000);
+ Preferences.set("browser.onboarding.notification.last-time-of-changing-tour-sec", lastTime);
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ promptCount = Preferences.get("browser.onboarding.notification.prompt-count", 0);
+ is(1, promptCount, "Should prompt tour notification after the mute duration on the 1st session");
+ await BrowserTestUtils.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/extensions/onboarding/test/browser/browser_onboarding_notification_3.js
@@ -0,0 +1,94 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function test_move_on_to_next_notification_when_reaching_max_prompt_count() {
+ resetOnboardingDefaultState();
+ skipMuteNotificationOnFirstSession();
+ let maxCount = Preferences.get("browser.onboarding.notification.max-prompt-count-per-tour");
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ let previousTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+
+ let currentTourId = null;
+ let reloadPromise = null;
+ for (let i = maxCount - 1; i > 0; --i) {
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ currentTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ is(previousTourId, currentTourId, "Should not move on to next tour notification until reaching the max prompt count per tour");
+ }
+
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ currentTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ isnot(previousTourId, currentTourId, "Should move on to next tour notification when reaching the max prompt count per tour");
+
+ await BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function test_move_on_to_next_notification_when_reaching_max_life_time() {
+ resetOnboardingDefaultState();
+ skipMuteNotificationOnFirstSession();
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ let previousTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+
+ let maxTime = Preferences.get("browser.onboarding.notification.max-life-time-per-tour-ms");
+ let lastTime = Math.floor((Date.now() - maxTime - 1) / 1000);
+ Preferences.set("browser.onboarding.notification.last-time-of-changing-tour-sec", lastTime);
+ let reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ let currentTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ isnot(previousTourId, currentTourId, "Should move on to next tour notification when reaching the max life time per tour");
+
+ await BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function test_move_on_to_next_notification_after_interacting_with_notification() {
+ resetOnboardingDefaultState();
+ skipMuteNotificationOnFirstSession();
+
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ let previousTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ await BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-notification-close-btn", {}, tab.linkedBrowser);
+
+ let reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ let currentTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ isnot(previousTourId, currentTourId, "Should move on to next tour notification after clicking #onboarding-notification-close-btn");
+ await BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-notification-action-btn", {}, tab.linkedBrowser);
+ previousTourId = currentTourId;
+
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ currentTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ isnot(previousTourId, currentTourId, "Should move on to next tour notification after clicking #onboarding-notification-action-btn");
+
+ await BrowserTestUtils.removeTab(tab);
+});
new file mode 100644
--- /dev/null
+++ b/browser/extensions/onboarding/test/browser/browser_onboarding_notification_4.js
@@ -0,0 +1,84 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function test_remove_all_tour_notifications_through_close_button() {
+ resetOnboardingDefaultState();
+ skipMuteNotificationOnFirstSession();
+
+ let tourIds = TOUR_IDs;
+ let tab = null;
+ let targetTourId = null;
+ let reloadPromise = null;
+ await closeTourNotificationsOneByOne();
+
+ let expectedPrefUpdate = promisePrefUpdated("browser.onboarding.notification.finished", true);
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await expectedPrefUpdate;
+ let tourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ ok(!tourId, "Should not prompt tour notifications any more after closing all notifcations.");
+ await BrowserTestUtils.removeTab(tab);
+
+ async function closeTourNotificationsOneByOne() {
+ for (let i = 0; i < tourIds.length; ++i) {
+ if (tab) {
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ } else {
+ tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ }
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ is(targetTourId, tourIds[i], `Should show tour notifications of ${targetTourId}`);
+ await BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-notification-close-btn", {}, tab.linkedBrowser);
+ await promiseTourNotificationClosed(tab.linkedBrowser);
+ }
+ }
+});
+
+add_task(async function test_remove_all_tour_notifications_through_action_button() {
+ resetOnboardingDefaultState();
+ skipMuteNotificationOnFirstSession();
+
+ let tourIds = TOUR_IDs;
+ let tab = null;
+ let targetTourId = null;
+ let reloadPromise = null;
+ await clickTourNotificationActionButtonsOneByOne();
+
+ let expectedPrefUpdate = promisePrefUpdated("browser.onboarding.notification.finished", true);
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await expectedPrefUpdate;
+ let tourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ ok(!tourId, "Should not prompt tour notifcations any more after taking actions on all notifcations.");
+ await BrowserTestUtils.removeTab(tab);
+
+ async function clickTourNotificationActionButtonsOneByOne() {
+ for (let i = 0; i < tourIds.length; ++i) {
+ if (tab) {
+ reloadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ tab.linkedBrowser.reload();
+ await reloadPromise;
+ } else {
+ tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
+ await BrowserTestUtils.loadURI(tab.linkedBrowser, ABOUT_NEWTAB_URL);
+ }
+ await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+ await promiseTourNotificationOpened(tab.linkedBrowser);
+ targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+ is(targetTourId, tourIds[i], `Should show tour notifications of ${targetTourId}`);
+ await BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-notification-action-btn", {}, tab.linkedBrowser);
+ await promiseTourNotificationClosed(tab.linkedBrowser);
+ }
+ }
+});
--- a/browser/extensions/onboarding/test/browser/head.js
+++ b/browser/extensions/onboarding/test/browser/head.js
@@ -11,24 +11,31 @@ const TOUR_IDs = [
"onboarding-tour-addons",
"onboarding-tour-customize",
"onboarding-tour-search",
"onboarding-tour-default-browser",
"onboarding-tour-sync",
];
const UPDATE_TOUR_IDs = [];
+registerCleanupFunction(resetOnboardingDefaultState);
+
function resetOnboardingDefaultState() {
// All the prefs should be reset to the default states
// and no need to revert back so we don't use `SpecialPowers.pushPrefEnv` here.
Preferences.set("browser.onboarding.enabled", true);
Preferences.set("browser.onboarding.hidden", false);
Preferences.set("browser.onboarding.notification.finished", false);
- Preferences.set("browser.onboarding.notification.lastPrompted", "");
- TOUR_IDs.forEach(id => Preferences.set(`browser.onboarding.tour.${id}.completed`, false));
+ Preferences.set("browser.onboarding.notification.mute-duration-on-first-session-ms", 300000);
+ Preferences.set("browser.onboarding.notification.max-life-time-per-tour-ms", 432000000);
+ Preferences.set("browser.onboarding.notification.max-prompt-count-per-tour", 8);
+ Preferences.reset("browser.onboarding.notification.last-time-of-changing-tour-sec");
+ Preferences.reset("browser.onboarding.notification.prompt-count");
+ Preferences.reset("browser.onboarding.notification.tour-ids-queue");
+ TOUR_IDs.forEach(id => Preferences.reset(`browser.onboarding.tour.${id}.completed`));
}
function setTourCompletedState(tourId, state) {
Preferences.set(`browser.onboarding.tour.${tourId}.completed`, state);
}
function promiseOnboardingOverlayLoaded(browser) {
// The onboarding overlay is init inside window.requestIdleCallback, not immediately,
@@ -101,16 +108,37 @@ function promiseTourNotificationOpened(b
return BrowserTestUtils.waitForCondition(
condition,
"Should open tour notification",
100,
30
);
}
+function promiseTourNotificationClosed(browser) {
+ let condition = () => {
+ return ContentTask.spawn(browser, {}, function() {
+ return new Promise(resolve => {
+ let bar = content.document.querySelector("#onboarding-notification-bar");
+ if (bar && !bar.classList.contains("onboarding-opened")) {
+ resolve(true);
+ return;
+ }
+ resolve(false);
+ });
+ })
+ };
+ return BrowserTestUtils.waitForCondition(
+ condition,
+ "Should close tour notification",
+ 100,
+ 30
+ );
+}
+
function getCurrentNotificationTargetTourId(browser) {
return ContentTask.spawn(browser, {}, function() {
let bar = content.document.querySelector("#onboarding-notification-bar");
return bar ? bar.dataset.targetTourId : null;
});
}
function getCurrentActiveTour(browser) {
@@ -130,8 +158,18 @@ function getCurrentActiveTour(browser) {
if (page.style.display != "none") {
activePageId = page.id;
break;
}
}
return { activeNavItemId, activePageId };
});
}
+
+function waitUntilWindowIdle(browser) {
+ return ContentTask.spawn(browser, {}, function() {
+ return new Promise(resolve => content.requestIdleCallback(resolve));
+ });
+}
+
+function skipMuteNotificationOnFirstSession() {
+ Preferences.set("browser.onboarding.notification.mute-duration-on-first-session-ms", 0);
+}