Bug 1134446 - Automatically open the ReadingList sidebar the first time ReaderMode is used. r=unfocused, a=sledru
authorMark Capella <markcapella@twcny.rr.com>
Sun, 29 Mar 2015 08:35:23 -0400
changeset 258270 887be7f12f1e
parent 258269 3e828a466ece
child 258271 7d883361e554
push id4632
push userryanvm@gmail.com
push date2015-04-06 15:16 +0000
treeherdermozilla-beta@887be7f12f1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersunfocused, sledru
bugs1134446
milestone38.0
Bug 1134446 - Automatically open the ReadingList sidebar the first time ReaderMode is used. r=unfocused, a=sledru
browser/base/content/browser-readinglist.js
browser/base/content/test/general/browser_readerMode.js
testing/profiles/prefs_general.js
toolkit/components/reader/AboutReader.jsm
--- a/browser/base/content/browser-readinglist.js
+++ b/browser/base/content/browser-readinglist.js
@@ -12,16 +12,17 @@ const READINGLIST_COMMAND_ID = "readingL
 let ReadingListUI = {
   /**
    * Frame-script messages we want to listen to.
    * @type {[string]}
    */
   MESSAGES: [
     "ReadingList:GetVisibility",
     "ReadingList:ToggleVisibility",
+    "ReadingList:ShowIntro",
   ],
 
   /**
    * Add-to-ReadingList toolbar button in the URLbar.
    * @type {Element}
    */
   toolbarButton: null,
 
@@ -217,16 +218,24 @@ let ReadingListUI = {
         }
         break;
       }
 
       case "ReadingList:ToggleVisibility": {
         this.toggleSidebar();
         break;
       }
+
+      case "ReadingList:ShowIntro": {
+        if (this.enabled && !Preferences.get("browser.readinglist.introShown", false)) {
+          Preferences.set("browser.readinglist.introShown", true);
+          this.showSidebar();
+        }
+        break;
+      }
     }
   },
 
   /**
    * Handles toolbar button styling based on page proxy state changes.
    *
    * @see SetPageProxyState()
    *
--- a/browser/base/content/test/general/browser_readerMode.js
+++ b/browser/base/content/test/general/browser_readerMode.js
@@ -2,82 +2,87 @@
  * 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/. */
 
 /**
  * Test that the reader mode button appears and works properly on
  * reader-able content, and that ReadingList button can open and close
  * its Sidebar UI.
  */
-const READER_PREF = "reader.parse-on-load.enabled";
-const READING_LIST_PREF = "browser.readinglist.enabled";
+const TEST_PREFS = [
+  ["reader.parse-on-load.enabled", true],
+  ["browser.readinglist.enabled", true],
+  ["browser.readinglist.introShown", false],
+];
 
 const TEST_PATH = "http://example.com/browser/browser/base/content/test/general/";
 
 let readerButton = document.getElementById("reader-mode-button");
 
 add_task(function* () {
   registerCleanupFunction(function() {
-    Services.prefs.clearUserPref(READER_PREF);
-    Services.prefs.clearUserPref(READING_LIST_PREF);
+    // Reset test prefs.
+    TEST_PREFS.forEach(([name, value]) => {
+      Services.prefs.clearUserPref(name);
+    });
     while (gBrowser.tabs.length > 1) {
       gBrowser.removeCurrentTab();
     }
   });
 
-  // Enable the reader mode and ReadingList buttons.
-  Services.prefs.setBoolPref(READER_PREF, true);
-  Services.prefs.setBoolPref(READING_LIST_PREF, true);
+  // Set required test prefs.
+  TEST_PREFS.forEach(([name, value]) => {
+    Services.prefs.setBoolPref(name, value);
+  });
 
   let tab = gBrowser.selectedTab = gBrowser.addTab();
   is_element_hidden(readerButton, "Reader mode button is not present on a new tab");
 
   // Point tab to a test page that is reader-able.
   let url = TEST_PATH + "readerModeArticle.html";
   yield promiseTabLoadEvent(tab, url);
   yield promiseWaitForCondition(() => !readerButton.hidden);
   is_element_visible(readerButton, "Reader mode button is present on a reader-able page");
 
+  // Switch page into reader mode.
   readerButton.click();
   yield promiseTabLoadEvent(tab);
 
   let readerUrl = gBrowser.selectedBrowser.currentURI.spec;
   ok(readerUrl.startsWith("about:reader"), "about:reader loaded after clicking reader mode button");
   is_element_visible(readerButton, "Reader mode button is present on about:reader");
 
   is(gURLBar.value, readerUrl, "gURLBar value is about:reader URL");
   is(gURLBar.textValue, url.substring("http://".length), "gURLBar is displaying original article URL");
 
-  // Readinglist button should be present, and status should be "closed".
+  // Readinglist button should be present, and status should be "openned", as the
+  // first time in readerMode opens the Sidebar ReadingList as a feature introduction.
   let listButton;
   yield promiseWaitForCondition(() =>
     listButton = gBrowser.contentDocument.getElementById("list-button"));
   is_element_visible(listButton, "List button is present on a reader-able page");
-  yield promiseWaitForCondition(() => !listButton.classList.contains("on"));
-  ok(!listButton.classList.contains("on"),
-    "List button should not indicate SideBar-ReadingList open.");
-  ok(!ReadingListUI.isSidebarOpen,
-    "The ReadingListUI should not indicate SideBar-ReadingList open.");
-
-  // After we click ReadingList button, status should be "open".
-  listButton.click();
   yield promiseWaitForCondition(() => listButton.classList.contains("on"));
   ok(listButton.classList.contains("on"),
-    "List button should now indicate SideBar-ReadingList open.");
+    "List button should indicate SideBar-ReadingList open.");
   ok(ReadingListUI.isSidebarOpen,
-    "The ReadingListUI should now indicate SideBar-ReadingList open.");
+    "The ReadingListUI should indicate SideBar-ReadingList open.");
 
-  // Now close the sidebar.
+  // Now close the Sidebar ReadingList.
   listButton.click();
   yield promiseWaitForCondition(() => !listButton.classList.contains("on"));
-  ok(!ReadingListUI.isSidebarOpen, "The sidebar should be closed.");
+  ok(!listButton.classList.contains("on"),
+    "List button should now indicate SideBar-ReadingList closed.");
+  ok(!ReadingListUI.isSidebarOpen,
+    "The ReadingListUI should now indicate SideBar-ReadingList closed.");
 
+  // Switch page back out of reader mode.
   readerButton.click();
   yield promiseTabLoadEvent(tab);
-  is(gBrowser.selectedBrowser.currentURI.spec, url, "Original page loaded after clicking active reader mode button");
+  is(gBrowser.selectedBrowser.currentURI.spec, url,
+    "Original page loaded after clicking active reader mode button");
 
   // Load a new tab that is NOT reader-able.
   let newTab = gBrowser.selectedTab = gBrowser.addTab();
   yield promiseTabLoadEvent(newTab, "about:robots");
   yield promiseWaitForCondition(() => readerButton.hidden);
   is_element_hidden(readerButton, "Reader mode button is not present on a non-reader-able page");
 
   // Switch back to the original tab to make sure reader mode button is still visible.
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -292,8 +292,11 @@ user_pref("media.decoder.heuristic.dorma
 #endif
 
 // Don't prompt about e10s
 user_pref("browser.displayedE10SPrompt.1", 5);
 // Don't use auto-enabled e10s
 user_pref("browser.tabs.remote.autostart.1", false);
 // Don't forceably kill content processes after a timeout
 user_pref("dom.ipc.tabs.shutdownTimeoutSecs", 0);
+
+// Avoid performing Readinglist Intro during tests.
+user_pref("browser.readinglist.introShown", true);
--- a/toolkit/components/reader/AboutReader.jsm
+++ b/toolkit/components/reader/AboutReader.jsm
@@ -297,16 +297,24 @@ AboutReader.prototype = {
     this._mm.sendAsyncMessage("Reader:Share", {
       url: this._article.url,
       title: this._article.title
     });
     UITelemetry.addEvent("share.1", "list", null);
   },
 
   /**
+   * To help introduce ReadingList, we want to automatically
+   * open the Desktop sidebar the first time ReaderMode is used.
+   */
+  _showListIntro: function() {
+    this._mm.sendAsyncMessage("ReadingList:ShowIntro");
+  },
+
+  /**
    * Toggle ReadingList Sidebar visibility. SidebarUI will trigger
    * _updateListButtonStyle().
    */
   _onList: function() {
     this._mm.sendAsyncMessage("ReadingList:ToggleVisibility");
   },
 
   /**
@@ -719,16 +727,17 @@ AboutReader.prototype = {
     this._contentElement.innerHTML = "";
     this._contentElement.appendChild(contentFragment);
     this._maybeSetTextDirection(article);
 
     this._contentElement.style.display = "block";
     this._updateImageMargins();
     this._requestReadingListStatus();
 
+    this._showListIntro();
     this._requestFavicon();
     this._doc.body.classList.add("loaded");
   },
 
   _hideContent: function Reader_hideContent() {
     this._headerElement.style.display = "none";
     this._contentElement.style.display = "none";
   },