Bug 1134501 - add way for UITour'd page to force-show the reader mode button, r=margaret a=lmandel
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 13 Apr 2015 20:12:57 +0100
changeset 260500 5741ccc7bb74
parent 260499 964442785c00
child 260504 af199be24df9
push id801
push userkwierso@gmail.com
push date2015-05-14 20:31 +0000
treeherdermozilla-release@5741ccc7bb74 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, lmandel
bugs1134501
milestone38.0.1
Bug 1134501 - add way for UITour'd page to force-show the reader mode button, r=margaret a=lmandel
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
@@ -280,14 +280,18 @@ if (typeof Mozilla == 'undefined') {
 			callbackID: _waitForCallback(callback)
 		});
 	};
 
 	Mozilla.UITour.toggleReaderMode = function(feature) {
 		_sendEvent('toggleReaderMode');
 	};
 
+	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
@@ -24,24 +24,27 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 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, "ReaderMode",
   "resource://gre/modules/ReaderMode.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 PREF_READERVIEW_TRIGGER = "browser.uitour.readerViewTrigger";
 
 const BACKGROUND_PAGE_ACTIONS_ALLOWED = new Set([
   "endUrlbarCapture",
+  "forceShowReaderIcon",
   "getConfiguration",
   "getTreatmentTag",
   "hideHighlight",
   "hideInfo",
   "hideMenu",
   "ping",
   "registerPageID",
   "setConfiguration",
@@ -704,16 +707,21 @@ this.UITour = {
       }
 
       case "toggleReaderMode": {
         let targetPromise = this.getTarget(window, "readerMode-urlBar");
         targetPromise.then(target => {
           ReaderParent.toggleReaderMode({target: target.node});
         });
       }
+
+      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-disconnect", false);
--- a/browser/components/uitour/test/browser.ini
+++ b/browser/components/uitour/test/browser.ini
@@ -12,17 +12,19 @@ skip-if = os == "linux" || e10s # Interm
 skip-if = e10s # Bug 1073247 - UITour.jsm not e10s friendly
 # [browser_UITour3.js] Bug 1113038
 # skip-if = os == "linux" || e10s # Linux: Bug 986760, Bug 989101; e10s: Bug 1073247 - UITour.jsm not e10s friendly
 [browser_UITour_availableTargets.js]
 skip-if = e10s # Bug 1073247 - UITour.jsm not e10s friendly
 [browser_UITour_detach_tab.js]
 skip-if = e10s # Bug 1073247 - UITour.jsm not e10s friendly
 [browser_UITour_annotation_size_attributes.js]
-skip-if = e10s # Bug 1073247 - UITour.jsm not e10s friendly.
+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 1073247 - UITour.jsm not e10s friendly.
 [browser_UITour_loop.js]
 skip-if = os == "linux" || e10s # Bug 1073247 - UITour.jsm not e10s friendly.
 [browser_UITour_modalDialog.js]
 run-if = os == "mac" # modal dialog disabling only working on OS X
 skip-if = e10s # Bug 1073247 - UITour.jsm not e10s friendly
 [browser_UITour_observe.js]
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
@@ -197,16 +197,21 @@ let ReaderParent = {
     } else if (this._readerModeInfoPanelOpen) {
       if (UITour.isInfoOnTarget(win, "readerMode-urlBar")) {
         UITour.hideInfo(win);
       }
       this._readerModeInfoPanelOpen = false;
     }
   },
 
+  forceShowReaderIcon: function(browser) {
+    browser.isArticle = true;
+    this.updateReaderButton(browser);
+  },
+
   buttonClick: function(event) {
     if (event.button != 0) {
       return;
     }
     this.toggleReaderMode(event);
   },
 
   toggleReaderMode: function(event) {