Bug 1104165 - "Switch to Tab" doesn't work for some encoded URIs. r=dao

This commit is contained in:
Marco Bonardo 2015-04-23 10:35:36 +02:00
Родитель e14d480a72
Коммит b51f67ee85
4 изменённых файлов: 56 добавлений и 3 удалений

Просмотреть файл

@ -2391,6 +2391,8 @@ function URLBarSetURI(aURI) {
function losslessDecodeURI(aURI) {
var value = aURI.spec;
if (aURI.schemeIs("moz-action"))
throw new Error("losslessDecodeURI should never get a moz-action URI");
// Try to decode as UTF-8 if there's no encoding sequence that we would break.
if (!/%25(?:3B|2F|3F|3A|40|26|3D|2B|24|2C|23)/i.test(value))
try {

Просмотреть файл

@ -466,6 +466,7 @@ 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_bug1104165-switchtab-decodeuri.js]
[browser_bug1003461-switchtab-override.js]
[browser_bug1024133-switchtab-override-keynav.js]
[browser_bug1025195_switchToTabHavingURI_aOpenParams.js]

Просмотреть файл

@ -0,0 +1,29 @@
add_task(function* test_switchtab_decodeuri() {
info("Opening first tab");
let tab = gBrowser.addTab("http://example.org/browser/browser/base/content/test/general/dummy_page.html#test%7C1");
yield promiseTabLoadEvent(tab);
info("Opening and selecting second tab");
let newTab = gBrowser.selectedTab = gBrowser.addTab();
info("Wait for autocomplete")
yield promiseAutocompleteResultPopup("dummy_page");
info("Select autocomplete popup entry");
EventUtils.synthesizeKey("VK_DOWN" , {});
ok(gURLBar.value.startsWith("moz-action:switchtab"), "switch to tab entry found");
info("switch-to-tab");
yield new Promise((resolve, reject) => {
// In case of success it should switch tab.
gBrowser.tabContainer.addEventListener("TabSelect", function select() {
gBrowser.tabContainer.removeEventListener("TabSelect", select, false);
is(gBrowser.selectedTab, tab, "Should have switched to the right tab");
resolve();
}, false);
EventUtils.synthesizeKey("VK_RETURN" , { });
});
gBrowser.removeCurrentTab();
yield PlacesTestUtils.clearHistory();
});

Просмотреть файл

@ -305,7 +305,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
if (this.hasAttribute("actiontype")) {
this.handleRevert();
let prevTab = gBrowser.selectedTab;
if (switchToTabHavingURI(url) &&
if (switchToTabHavingURI(action.params.originalUrl || url) &&
isTabEmpty(prevTab))
gBrowser.removeTab(prevTab);
return;
@ -716,9 +716,24 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
]]></getter>
<setter>
<![CDATA[
let uri;
try {
val = losslessDecodeURI(makeURI(val));
} catch (ex) { }
uri = makeURI(val);
} catch (ex) {}
if (uri) {
let action = this._parseActionUrl(val);
if (action) {
if (action.params.url) {
// Store the original URL in the action URL.
action.params.originalUrl = action.params.url;
action.params.url = losslessDecodeURI(makeURI(action.params.url));
val = "moz-action:" + action.type + "," + JSON.stringify(action.params);
}
} else {
val = losslessDecodeURI(uri);
}
}
// Trim popup selected values, but never trim results coming from
// autofill.
@ -758,6 +773,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
try {
action.params = JSON.parse(params);
if (action.params.input) {
action.params.input = decodeURIComponent(action.params.input);
}
if (action.params.searchQuery) {
action.params.searchQuery = decodeURIComponent(action.params.searchQuery);
}
} catch (e) {
// If this failed, we assume that params is not a JSON object, and
// is instead just a flat string. This will happen when