Bug 1392791 - not call gotoPage while hide overlay;r=rexboy draft
authorgasolin <gasolin@gmail.com>
Thu, 24 Aug 2017 10:53:55 +0800
changeset 655423 13454c794437240337a5d1c2fbcc3b5ae0cb9242
parent 655385 db7f19e26e571ae1dd309f5d2f387b06ba670c30
child 728841 a8b06fb042c9fb9175e0f83b4b3aa3ecc26c24a6
push id76881
push userbmo:gasolin@mozilla.com
push dateWed, 30 Aug 2017 01:55:13 +0000
reviewersrexboy
bugs1392791
milestone57.0a1
Bug 1392791 - not call gotoPage while hide overlay;r=rexboy MozReview-Commit-ID: 483GaTb0a4C
browser/extensions/onboarding/content/onboarding.js
browser/extensions/onboarding/test/browser/browser.ini
browser/extensions/onboarding/test/browser/browser_onboarding_notification_click_auto_complete_tour.js
--- a/browser/extensions/onboarding/content/onboarding.js
+++ b/browser/extensions/onboarding/content/onboarding.js
@@ -452,31 +452,33 @@ class Onboarding {
     // Only containers receive pointer events in onboarding tour tab list,
     // actual semantic tab is their first child.
     if (classList.contains("onboarding-tour-item-container")) {
       ({ id, classList } = target.firstChild);
     }
 
     switch (id) {
       case "onboarding-overlay-button":
+        this.showOverlay();
+        this.gotoPage(this.selectedTour.id);
+        break;
       case "onboarding-overlay-close-btn":
       // If the clicking target is directly on the outer-most overlay,
       // that means clicking outside the tour content area.
       // Let's toggle the overlay.
       case "onboarding-overlay":
-        this.toggleOverlay();
-        this.gotoPage(this.selectedTour.id);
+        this.hideOverlay();
         break;
       case "onboarding-notification-close-btn":
         this.hideNotification();
         this._removeTourFromNotificationQueue(this._notificationBar.dataset.targetTourId);
         break;
       case "onboarding-notification-action-btn":
         let tourId = this._notificationBar.dataset.targetTourId;
-        this.toggleOverlay();
+        this.showOverlay();
         this.gotoPage(tourId);
         this._removeTourFromNotificationQueue(tourId);
         break;
     }
     if (classList.contains("onboarding-tour-item")) {
       this.gotoPage(id);
       // Keep focus (not visible) on current item for potential keyboard
       // navigation.
@@ -559,17 +561,17 @@ class Onboarding {
         if (targetIndex > -1 && targetIndex < this._tourItems.length - 1) {
           let next = this._tourItems[targetIndex + 1];
           this.handleClick(next);
           next.focus();
         }
         event.preventDefault();
         break;
       case "Escape":
-        this.toggleOverlay();
+        this.hideOverlay();
         break;
       case "Tab":
         let next = this.wrapMoveFocus(target, shiftKey);
         // If focus was wrapped, prevent Tab key default action.
         if (next) {
           event.preventDefault();
         }
         break;
@@ -610,30 +612,32 @@ class Onboarding {
     this._overlay.remove();
     if (this._notificationBar) {
       this._notificationBar.remove();
     }
     this._tourItems = this._tourPages =
     this._overlayIcon = this._overlay = this._notificationBar = null;
   }
 
-  toggleOverlay() {
+  showOverlay() {
     if (this._tourItems.length == 0) {
       // Lazy loading until first toggle.
       this._loadTours(this._tours);
     }
 
     this.hideNotification();
-    this._overlay.classList.toggle("onboarding-opened");
-    this.toggleModal(this._overlay.classList.contains("onboarding-opened"));
+    this.toggleModal(this._overlay.classList.toggle("onboarding-opened"));
+  }
 
+  hideOverlay() {
     let hiddenCheckbox = this._window.document.getElementById("onboarding-tour-hidden-checkbox");
     if (hiddenCheckbox.checked) {
       this.hide();
     }
+    this.toggleModal(this._overlay.classList.toggle("onboarding-opened"));
   }
 
   /**
    * Set modal dialog state and properties for accessibility purposes.
    * @param  {Boolean} opened  whether the dialog is opened or closed.
    */
   toggleModal(opened) {
     let { document: doc } = this._window;
--- a/browser/extensions/onboarding/test/browser/browser.ini
+++ b/browser/extensions/onboarding/test/browser/browser.ini
@@ -5,11 +5,12 @@ support-files =
 [browser_onboarding_accessibility.js]
 [browser_onboarding_hide_all.js]
 [browser_onboarding_keyboard.js]
 skip-if = debug || os == "mac" # Full keyboard navigation on OSX only works if Full Keyboard Access setting is set to All Control in System Keyboard Preferences
 [browser_onboarding_notification.js]
 [browser_onboarding_notification_2.js]
 [browser_onboarding_notification_3.js]
 [browser_onboarding_notification_4.js]
+[browser_onboarding_notification_click_auto_complete_tour.js]
 [browser_onboarding_select_default_tour.js]
 [browser_onboarding_tours.js]
 [browser_onboarding_tourset.js]
new file mode 100644
--- /dev/null
+++ b/browser/extensions/onboarding/test/browser/browser_onboarding_notification_click_auto_complete_tour.js
@@ -0,0 +1,33 @@
+add_task(async function test_show_click_auto_complete_tour_in_notification() {
+  resetOnboardingDefaultState();
+  skipMuteNotificationOnFirstSession();
+  // the second tour is an click-auto-complete tour
+  await SpecialPowers.pushPrefEnv({set: [
+    ["browser.onboarding.newtour", "customize,library"],
+  ]});
+
+  let tab = await openTab(ABOUT_NEWTAB_URL);
+  await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+  await BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-overlay-button", {}, tab.linkedBrowser);
+  await promiseOnboardingOverlayOpened(tab.linkedBrowser);
+
+  // Trigger CTA button to mark the tour as complete
+  let expectedPrefUpdates = [
+    promisePrefUpdated(`browser.onboarding.tour.onboarding-tour-customize.completed`, true),
+  ]
+  BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-tour-customize", {}, tab.linkedBrowser);
+  BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-tour-customize-button", {}, tab.linkedBrowser);
+  await Promise.all(expectedPrefUpdates);
+
+  await BrowserTestUtils.synthesizeMouseAtCenter("#onboarding-overlay-close-btn", {}, gBrowser.selectedBrowser);
+  let { activeNavItemId } = await getCurrentActiveTour(tab.linkedBrowser);
+  is("onboarding-tour-customize", activeNavItemId, "the active tour should be the previous shown tour");
+
+  await reloadTab(tab);
+  await promiseOnboardingOverlayLoaded(tab.linkedBrowser);
+  await promiseTourNotificationOpened(tab.linkedBrowser);
+  let targetTourId = await getCurrentNotificationTargetTourId(tab.linkedBrowser);
+  is("onboarding-tour-library", targetTourId, "correctly show the click-autocomplete-tour in notification");
+
+  await BrowserTestUtils.removeTab(tab);
+});