Bug 1134501 - add way for UITour'd page to force-show the reader mode button, r=margaret
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 13 Apr 2015 20:12:57 +0100
changeset 257373 9d319ca0f937765ebbbb5a095b0c5125ecf77fbb
parent 257372 a7de3e82fb1f10f3c7365547c18d6c983d4c2294
child 257374 fb97412bef73d9e9e7a4b71ce510ae7b0f699f0a
push id1541
push usermichael.l.comella@gmail.com
push dateWed, 15 Apr 2015 18:43:45 +0000
reviewersmargaret
bugs1134501
milestone40.0a1
Bug 1134501 - add way for UITour'd page to force-show the reader mode button, r=margaret
browser/components/uitour/UITour-lib.js
browser/components/uitour/UITour.jsm
browser/components/uitour/test/browser.ini
browser/components/uitour/test/browser_UITour_forceReaderMode.js
browser/modules/ReaderParent.jsm
--- a/browser/components/uitour/UITour-lib.js
+++ b/browser/components/uitour/UITour-lib.js
@@ -276,14 +276,18 @@ if (typeof Mozilla == 'undefined') {
 	};
 
 	Mozilla.UITour.openSearchPanel = function(callback) {
 		_sendEvent('openSearchPanel', {
 			callbackID: _waitForCallback(callback)
 		});
 	};
 
+	Mozilla.UITour.forceShowReaderIcon = function() {
+		_sendEvent('forceShowReaderIcon');
+	};
+
 })();
 
 // Make this library Require-able.
 if (typeof module !== 'undefined' && module.exports) {
   module.exports = Mozilla.UITour;
 }
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -22,23 +22,26 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
   "resource:///modules/CustomizableUI.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry",
   "resource://gre/modules/UITelemetry.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITelemetry",
   "resource:///modules/BrowserUITelemetry.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Metrics",
   "resource://gre/modules/Metrics.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "ReaderParent",
+  "resource:///modules/ReaderParent.jsm");
 
 // See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error".
 const PREF_LOG_LEVEL      = "browser.uitour.loglevel";
 const PREF_SEENPAGEIDS    = "browser.uitour.seenPageIDs";
 
 const BACKGROUND_PAGE_ACTIONS_ALLOWED = new Set([
   "endUrlbarCapture",
+  "forceShowReaderIcon",
   "getConfiguration",
   "getTreatmentTag",
   "hideHighlight",
   "hideInfo",
   "hideMenu",
   "ping",
   "registerPageID",
   "setConfiguration",
@@ -672,16 +675,21 @@ this.UITour = {
         break;
       }
 
       case "ping": {
         if (typeof data.callbackID == "string")
           this.sendPageCallback(messageManager, data.callbackID);
         break;
       }
+
+      case "forceShowReaderIcon": {
+        ReaderParent.forceShowReaderIcon(browser);
+        break;
+      }
     }
 
     if (!this.tourBrowsersByWindow.has(window)) {
       this.tourBrowsersByWindow.set(window, new Set());
     }
     this.tourBrowsersByWindow.get(window).add(browser);
 
     Services.obs.addObserver(this, "message-manager-close", false);
--- a/browser/components/uitour/test/browser.ini
+++ b/browser/components/uitour/test/browser.ini
@@ -13,16 +13,18 @@ skip-if = e10s # Bug 941428 - UITour.jsm
 # [browser_UITour3.js] Bug 1113038
 # skip-if = os == "linux" || e10s # Linux: Bug 986760, Bug 989101; e10s: Bug 941428 - UITour.jsm not e10s friendly
 [browser_UITour_availableTargets.js]
 skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
 [browser_UITour_detach_tab.js]
 skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly
 [browser_UITour_annotation_size_attributes.js]
 skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
+[browser_UITour_forceReaderMode.js]
+skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
 [browser_UITour_heartbeat.js]
 skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
 [browser_UITour_loop.js]
 skip-if = os == "linux" || e10s # Bug 941428 - UITour.jsm not e10s friendly.
 [browser_UITour_modalDialog.js]
 skip-if = os != "mac" || e10s # modal dialog disabling only working on OS X.Bug 941428 - UITour.jsm not e10s friendly
 [browser_UITour_observe.js]
 skip-if = e10s # Bug 941428 - UITour.jsm not e10s friendly.
new file mode 100644
--- /dev/null
+++ b/browser/components/uitour/test/browser_UITour_forceReaderMode.js
@@ -0,0 +1,23 @@
+"use strict";
+
+let gTestTab;
+let gContentAPI;
+let gContentWindow;
+
+Components.utils.import("resource:///modules/UITour.jsm");
+
+function test() {
+  UITourTest();
+}
+
+let tests = [
+  taskify(function*() {
+    ok(!gBrowser.selectedBrowser.isArticle, "Should not be an article when we start");
+    ok(document.getElementById("reader-mode-button").hidden, "Button should be hidden.");
+    gContentAPI.forceShowReaderIcon();
+    yield waitForConditionPromise(() => gBrowser.selectedBrowser.isArticle);
+    ok(gBrowser.selectedBrowser.isArticle, "Should suddenly be an article.");
+    ok(!document.getElementById("reader-mode-button").hidden, "Button should now be visible.");
+  })
+];
+
--- a/browser/modules/ReaderParent.jsm
+++ b/browser/modules/ReaderParent.jsm
@@ -154,16 +154,21 @@ let ReaderParent = {
       let enterText = gStringBundle.GetStringFromName("readerView.enter");
       button.setAttribute("tooltiptext", enterText);
       command.setAttribute("label", enterText);
       command.setAttribute("hidden", !browser.isArticle);
       command.setAttribute("accesskey", gStringBundle.GetStringFromName("readerView.enter.accesskey"));
     }
   },
 
+  forceShowReaderIcon: function(browser) {
+    browser.isArticle = true;
+    this.updateReaderButton(browser);
+  },
+
   buttonClick: function(event) {
     if (event.button != 0) {
       return;
     }
     this.toggleReaderMode(event);
   },
 
   toggleReaderMode: function(event) {