Bug 1111013 - Add aOpenParams.ignoreQueryString to switchToTabHavingURI to ignore query params without replacing. r=dolske

--HG--
rename : browser/base/content/test/general/browser_bug1025195_switchToTabHavingURI_ignoreFragment.js => browser/base/content/test/general/browser_bug1025195_switchToTabHavingURI_aOpenParams.js
extra : rebase_source : 201b4ff0e007045d73884de51a8f6574a82c1e64
This commit is contained in:
Matthew Noorenberghe 2014-12-16 01:26:24 -08:00
parent 21f49e4b37
commit 26aec3e5ad
4 changed files with 94 additions and 67 deletions

View File

@ -7492,8 +7492,10 @@ let gRemoteTabsUI = {
* This object also allows: * This object also allows:
* - 'ignoreFragment' property to be set to true to exclude fragment-portion * - 'ignoreFragment' property to be set to true to exclude fragment-portion
* matching when comparing URIs. * 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 * - '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. * the one from the new URI.
* @return True if an existing tab was found, false otherwise * @return True if an existing tab was found, false otherwise
*/ */
@ -7505,11 +7507,13 @@ function switchToTabHavingURI(aURI, aOpenNew, aOpenParams={}) {
]); ]);
let ignoreFragment = aOpenParams.ignoreFragment; let ignoreFragment = aOpenParams.ignoreFragment;
let ignoreQueryString = aOpenParams.ignoreQueryString;
let replaceQueryString = aOpenParams.replaceQueryString; 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. // not be used as a parameter for the new load.
delete aOpenParams.ignoreFragment; delete aOpenParams.ignoreFragment;
delete aOpenParams.ignoreQueryString;
// This will switch to the tab in aWindow having aURI, if present. // This will switch to the tab in aWindow having aURI, if present.
function switchIfURIInWindow(aWindow) { function switchIfURIInWindow(aWindow) {
@ -7538,12 +7542,14 @@ function switchToTabHavingURI(aURI, aOpenNew, aOpenParams={}) {
} }
return true; return true;
} }
if (replaceQueryString) { if (ignoreQueryString || replaceQueryString) {
if (browser.currentURI.spec.split("?")[0] == aURI.spec.split("?")[0]) { if (browser.currentURI.spec.split("?")[0] == aURI.spec.split("?")[0]) {
// Focus the matching window & tab // Focus the matching window & tab
aWindow.focus(); aWindow.focus();
aWindow.gBrowser.tabContainer.selectedIndex = i; aWindow.gBrowser.tabContainer.selectedIndex = i;
browser.loadURI(aURI.spec); if (replaceQueryString) {
browser.loadURI(aURI.spec);
}
return true; return true;
} }
} }

View File

@ -482,7 +482,7 @@ skip-if = e10s # Bug 940206 - nsIWebContentHandlerRegistrar::registerProtocolHan
skip-if = e10s skip-if = e10s
[browser_bug1024133-switchtab-override-keynav.js] [browser_bug1024133-switchtab-override-keynav.js]
skip-if = e10s skip-if = e10s
[browser_bug1025195_switchToTabHavingURI_ignoreFragment.js] [browser_bug1025195_switchToTabHavingURI_aOpenParams.js]
[browser_addCertException.js] [browser_addCertException.js]
skip-if = e10s # Bug 1100687 - test directly manipulates content (content.document.getElementById) skip-if = e10s # Bug 1100687 - test directly manipulates content (content.document.getElementById)
[browser_bug1045809.js] [browser_bug1045809.js]

View File

@ -0,0 +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 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", 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", 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", false, { ignoreFragment: true });
cleanupTestTabs();
});
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?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", 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();
});
// 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);

View File

@ -1,62 +0,0 @@
/* 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();
});
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);
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);
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);
});
// Test for replaceQueryString option.
add_task(function() {
registerCleanupFunction(function() {
while (gBrowser.tabs.length > 1)
gBrowser.removeCurrentTab();
});
let tabRefAboutHome = gBrowser.addTab("about:home?hello=firefox");
yield promiseTabLoaded(tabRefAboutHome);
switchTab("about:home", false, false, false);
switchTab("about:home?hello=firefox", false, false, true);
switchTab("about:home?hello=firefoxos", false, false, false);
// Remove the last opened tab to test replaceQueryString option.
gBrowser.removeCurrentTab();
switchTab("about:home?hello=firefoxos", false, true, 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");
});
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.");
}