Bug 1111013 - Add aOpenParams.ignoreQueryString to switchToTabHavingURI to ignore query params without replacing. r+a=dolske
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Tue, 16 Dec 2014 01:26:24 -0800
changeset 242472 580995194044
parent 242471 823d8397f3fe
child 242473 c9d701cbd0d3
push id4311
push userraliiev@mozilla.com
push date2015-01-12 19:37 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1111013
milestone36.0a2
Bug 1111013 - Add aOpenParams.ignoreQueryString to switchToTabHavingURI to ignore query params without replacing. r+a=dolske
browser/base/content/browser.js
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_bug1025195_switchToTabHavingURI_aOpenParams.js
browser/base/content/test/general/browser_bug1025195_switchToTabHavingURI_ignoreFragment.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -7472,34 +7472,38 @@ let gRemoteTabsUI = {
  * @param aOpenParams
  *        If switching to this URI results in us opening a tab, aOpenParams
  *        will be the parameter object that gets passed to openUILinkIn. Please
  *        see the documentation for openUILinkIn to see what parameters can be
  *        passed via this object.
  *        This object also allows:
  *        - 'ignoreFragment' property to be set to true to exclude fragment-portion
  *        matching when comparing URIs.
+ *        - 'ignoreQueryString' property to be set to true to exclude query string
+ *        matching when comparing URIs.
  *        - 'replaceQueryString' property to be set to true to exclude query string
- *        matching when comparing URIs and ovewrite the initial query string with
+ *        matching when comparing URIs and overwrite the initial query string with
  *        the one from the new URI.
  * @return True if an existing tab was found, false otherwise
  */
 function switchToTabHavingURI(aURI, aOpenNew, aOpenParams={}) {
   // Certain URLs can be switched to irrespective of the source or destination
   // window being in private browsing mode:
   const kPrivateBrowsingWhitelist = new Set([
     "about:customizing",
   ]);
 
   let ignoreFragment = aOpenParams.ignoreFragment;
+  let ignoreQueryString = aOpenParams.ignoreQueryString;
   let replaceQueryString = aOpenParams.replaceQueryString;
 
-  // This property is only used by switchToTabHavingURI and should
+  // These properties are only used by switchToTabHavingURI and should
   // not be used as a parameter for the new load.
   delete aOpenParams.ignoreFragment;
+  delete aOpenParams.ignoreQueryString;
 
   // This will switch to the tab in aWindow having aURI, if present.
   function switchIfURIInWindow(aWindow) {
     // Only switch to the tab if neither the source nor the destination window
     // are private and they are not in permanent private browsing mode
     if (!kPrivateBrowsingWhitelist.has(aURI.spec) &&
         (PrivateBrowsingUtils.isWindowPrivate(window) ||
          PrivateBrowsingUtils.isWindowPrivate(aWindow)) &&
@@ -7518,22 +7522,24 @@ function switchToTabHavingURI(aURI, aOpe
         if (ignoreFragment) {
           let spec = aURI.spec;
           if (!aURI.ref)
             spec += "#";
           browser.loadURI(spec);
         }
         return true;
       }
-      if (replaceQueryString) {
+      if (ignoreQueryString || replaceQueryString) {
         if (browser.currentURI.spec.split("?")[0] == aURI.spec.split("?")[0]) {
           // Focus the matching window & tab
           aWindow.focus();
           aWindow.gBrowser.tabContainer.selectedIndex = i;
-          browser.loadURI(aURI.spec);
+          if (replaceQueryString) {
+            browser.loadURI(aURI.spec);
+          }
           return true;
         }
       }
     }
     return false;
   }
 
   // This can be passed either nsIURI or a string.
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -476,17 +476,17 @@ skip-if = e10s # Bug 1100703 - test dire
 skip-if = e10s # Bug 1094240 - has findbar-related failures
 [browser_registerProtocolHandler_notification.js]
 skip-if = e10s # Bug 940206 - nsIWebContentHandlerRegistrar::registerProtocolHandler doesn't work in e10s
 [browser_no_mcb_on_http_site.js]
 [browser_bug1003461-switchtab-override.js]
 skip-if = e10s
 [browser_bug1024133-switchtab-override-keynav.js]
 skip-if = e10s
-[browser_bug1025195_switchToTabHavingURI_ignoreFragment.js]
+[browser_bug1025195_switchToTabHavingURI_aOpenParams.js]
 [browser_addCertException.js]
 skip-if = e10s # Bug 1100687 - test directly manipulates content (content.document.getElementById)
 [browser_bug1045809.js]
 [browser_e10s_switchbrowser.js]
 [browser_blockHPKP.js]
 skip-if = e10s # bug 1100687 - test directly manipulates content (content.document.getElementById)
 [browser_mcb_redirect.js]
 skip-if = e10s # bug 1084504 - [e10s] Mixed content detection does not take redirection into account
rename from browser/base/content/test/general/browser_bug1025195_switchToTabHavingURI_ignoreFragment.js
rename to browser/base/content/test/general/browser_bug1025195_switchToTabHavingURI_aOpenParams.js
--- a/browser/base/content/test/general/browser_bug1025195_switchToTabHavingURI_ignoreFragment.js
+++ b/browser/base/content/test/general/browser_bug1025195_switchToTabHavingURI_aOpenParams.js
@@ -1,62 +1,83 @@
 /* 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/. */
 
-add_task(function() {
-  registerCleanupFunction(function() {
-    while (gBrowser.tabs.length > 1)
-      gBrowser.removeCurrentTab();
-  });
+add_task(function test_ignoreFragment() {
   let tabRefAboutHome = gBrowser.addTab("about:home#1");
   yield promiseTabLoaded(tabRefAboutHome);
   let tabRefAboutMozilla = gBrowser.addTab("about:mozilla");
   yield promiseTabLoaded(tabRefAboutMozilla);
 
   gBrowser.selectedTab = tabRefAboutMozilla;
   let numTabsAtStart = gBrowser.tabs.length;
 
-  switchTab("about:home#1", false, false, true);
-  switchTab("about:mozilla", false, false, true);
-  switchTab("about:home#2", true, false, true);
+  switchTab("about:home#1", true);
+  switchTab("about:mozilla", true);
+  switchTab("about:home#2", true, { ignoreFragment: true });
   is(tabRefAboutHome, gBrowser.selectedTab, "The same about:home tab should be switched to");
   is(gBrowser.currentURI.ref, "2", "The ref should be updated to the new ref");
-  switchTab("about:mozilla", false, false, true);
-  switchTab("about:home#1", false, false, false);
+  switchTab("about:mozilla", true);
+  switchTab("about:home#1", false);
   isnot(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should not be initial about:blank tab");
   is(gBrowser.tabs.length, numTabsAtStart + 1, "Should have one new tab opened");
-  switchTab("about:about", true, false, false);
+  switchTab("about:about", false, { ignoreFragment: true });
+  cleanupTestTabs();
 });
 
-
-// Test for replaceQueryString option.
-add_task(function() {
-  registerCleanupFunction(function() {
-    while (gBrowser.tabs.length > 1)
-      gBrowser.removeCurrentTab();
-  });
-
+add_task(function test_ignoreQueryString() {
   let tabRefAboutHome = gBrowser.addTab("about:home?hello=firefox");
   yield promiseTabLoaded(tabRefAboutHome);
+  let tabRefAboutMozilla = gBrowser.addTab("about:mozilla");
+  yield promiseTabLoaded(tabRefAboutMozilla);
+  gBrowser.selectedTab = tabRefAboutMozilla;
 
-  switchTab("about:home", false, false, false);
-  switchTab("about:home?hello=firefox", false, false, true);
-  switchTab("about:home?hello=firefoxos", false, false, false);
+  switchTab("about:home?hello=firefox", true);
+  switchTab("about:home?hello=firefoxos", false);
+  // Remove the last opened tab to test ignoreQueryString option.
+  gBrowser.removeCurrentTab();
+  switchTab("about:home?hello=firefoxos", true, { ignoreQueryString: true });
+  is(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should be the initial about:home tab");
+  is(gBrowser.currentURI.spec, "about:home?hello=firefox", "The spec should NOT be updated to the new query string");
+  cleanupTestTabs();
+});
+
+add_task(function test_replaceQueryString() {
+  let tabRefAboutHome = gBrowser.addTab("about:home?hello=firefox");
+  yield promiseTabLoaded(tabRefAboutHome);
+  let tabRefAboutMozilla = gBrowser.addTab("about:mozilla");
+  yield promiseTabLoaded(tabRefAboutMozilla);
+  gBrowser.selectedTab = tabRefAboutMozilla;
+
+  switchTab("about:home", false);
+  switchTab("about:home?hello=firefox", true);
+  switchTab("about:home?hello=firefoxos", false);
   // Remove the last opened tab to test replaceQueryString option.
   gBrowser.removeCurrentTab();
-  switchTab("about:home?hello=firefoxos", false, true, true);
+  switchTab("about:home?hello=firefoxos", true, { replaceQueryString: true });
   is(tabRefAboutHome, gBrowser.selectedTab, "Selected tab should be the initial about:home tab");
   // Wait for the tab to load the new URI spec.
   yield promiseTabLoaded(tabRefAboutHome);
   is(gBrowser.currentURI.spec, "about:home?hello=firefoxos", "The spec should be updated to the new spec");
+  cleanupTestTabs();
 });
 
-function switchTab(aURI, aIgnoreFragment, aReplaceQueryString, aShouldFindExistingTab) {
-  let tabFound = switchToTabHavingURI(aURI, true, {
-    ignoreFragment: aIgnoreFragment,
-    replaceQueryString: aReplaceQueryString
-  });
-  is(tabFound, aShouldFindExistingTab,
-     "Should switch to existing " + aURI + " tab if one existed, " +
-     (aIgnoreFragment ? "ignoring" : "including") + " fragment portion, " +
-     (aReplaceQueryString ? "ignoring" : "replacing") + " query string.");
+// Begin helpers
+
+function cleanupTestTabs() {
+  while (gBrowser.tabs.length > 1)
+    gBrowser.removeCurrentTab();
 }
+
+function switchTab(aURI, aShouldFindExistingTab, aOpenParams = {}) {
+  // Build the description before switchToTabHavingURI deletes the object properties.
+  let msg = "Should switch to existing " + aURI + " tab if one existed, " +
+        (aOpenParams.ignoreFragment ? "ignoring" : "including") + " fragment portion, " +
+        (aOpenParams.ignoreQueryString || aOpenParams.replaceQueryString ?
+         (aOpenParams.replaceQueryString ? "replacing" : "ignoring") :
+         "including"
+        ) + " query string.";
+  let tabFound = switchToTabHavingURI(aURI, true, aOpenParams);
+  is(tabFound, aShouldFindExistingTab, msg);
+}
+
+registerCleanupFunction(cleanupTestTabs);