Bug 1124271 - Entering reader mode from an app tab shouldn't open a new tab. r=jaws a=readinglist
authorMatt Hammerly <hammerly.matt@gmail.com>
Mon, 23 Feb 2015 20:44:27 -0800
changeset 248414 581298c4704e72b8f9b6b5da9bdcb2bfa2ab8e07
parent 248413 a024d69753b4791f534be8d182dcf8b100c80504
child 248415 6d3dc7ed4b28fa7fb95e48634cf3fa89b69f74e2
push id7837
push userjwein@mozilla.com
push dateFri, 27 Mar 2015 00:27:16 +0000
treeherdermozilla-aurora@cb0db44ce60e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, readinglist
bugs1124271
milestone38.0a2
Bug 1124271 - Entering reader mode from an app tab shouldn't open a new tab. r=jaws a=readinglist
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_bug1124271_readerModePinnedTab.js
browser/modules/ReaderParent.jsm
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -490,8 +490,11 @@ skip-if = e10s # Bug 1100687 - test dire
 skip-if = e10s # bug 1100687 - test directly manipulates content (content.document.getElementById)
 [browser_mcb_redirect.js]
 [browser_windowactivation.js]
 [browser_contextmenu_childprocess.js]
 [browser_bug963945.js]
 [browser_readerMode.js]
 support-files =
   readerModeArticle.html
+[browser_bug1124271_readerModePinnedTab.js]
+support-files =
+  readerModeArticle.html
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_bug1124271_readerModePinnedTab.js
@@ -0,0 +1,47 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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 won't open in a new tab when clicked from a pinned tab
+
+const PREF = "reader.parse-on-load.enabled";
+
+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(PREF);
+    while (gBrowser.tabs.length > 1) {
+      gBrowser.removeCurrentTab();
+    }
+  });
+
+  // Enable the reader mode button.
+  Services.prefs.setBoolPref(PREF, true);
+
+  let tab = gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.pinTab(tab);
+
+  let initialTabsCount = gBrowser.tabs.length;
+
+  // Point tab to a test page that is reader-able.
+  let url = TEST_PATH + "readerModeArticle.html";
+  yield promiseTabLoadEvent(tab, url);
+  yield promiseWaitForCondition(() => !readerButton.hidden);
+
+  readerButton.click();
+  yield promiseTabLoadEvent(tab);
+
+  // Ensure no new tabs are opened when exiting reader mode in a pinned tab
+  is(gBrowser.tabs.length, initialTabsCount, "No additional tabs were opened.");
+
+  readerButton.click();
+  yield promiseTabLoadEvent(tab);
+
+  // Ensure no new tabs are opened when exiting reader mode in a pinned tab
+  is(gBrowser.tabs.length, initialTabsCount, "No additional tabs were opened.");
+
+  gBrowser.removeCurrentTab();
+});
--- a/browser/modules/ReaderParent.jsm
+++ b/browser/modules/ReaderParent.jsm
@@ -134,20 +134,20 @@ let ReaderParent = {
     let win = event.target.ownerDocument.defaultView;
     let url = win.gBrowser.selectedBrowser.currentURI.spec;
 
     if (url.startsWith("about:reader")) {
       let originalURL = this._getOriginalUrl(url);
       if (!originalURL) {
         Cu.reportError("Error finding original URL for about:reader URL: " + url);
       } else {
-        win.openUILinkIn(originalURL, "current");
+        win.openUILinkIn(originalURL, "current", {"allowPinnedTabHostChange": true});
       }
     } else {
-      win.openUILinkIn("about:reader?url=" + encodeURIComponent(url), "current");
+      win.openUILinkIn("about:reader?url=" + encodeURIComponent(url), "current", {"allowPinnedTabHostChange": true});
     }
   },
 
   parseReaderUrl: function(url) {
     if (!url.startsWith("about:reader?")) {
       return null;
     }
     return this._getOriginalUrl(url);