Bug 1500486 - QuantumBar: Handle loading of non-urls entered in the new address bar. r=dao

Differential Revision: https://phabricator.services.mozilla.com/D10346

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2018-12-21 14:31:08 +00:00
Родитель fea1d97f08
Коммит 1e2dcbea63
4 изменённых файлов: 88 добавлений и 14 удалений

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

@ -234,23 +234,21 @@ class UrlbarInput {
try {
new URL(url);
} catch (ex) {
// TODO: Figure out why we need lastLocationChange here.
// let lastLocationChange = browser.lastLocationChange;
// UrlbarUtils.getShortcutOrURIAndPostData(text).then(data => {
// if (where != "current" ||
// browser.lastLocationChange == lastLocationChange) {
// params.postData = data.postData;
// params.allowInheritPrincipal = data.mayInheritPrincipal;
// this._loadURL(data.url, browser, where,
// openUILinkParams);
// }
// });
let browser = this.window.gBrowser.selectedBrowser;
let lastLocationChange = browser.lastLocationChange;
UrlbarUtils.getShortcutOrURIAndPostData(url).then(data => {
if (where != "current" ||
browser.lastLocationChange == lastLocationChange) {
openParams.postData = data.postData;
openParams.allowInheritPrincipal = data.mayInheritPrincipal;
this._loadURL(data.url, where, openParams);
}
});
return;
}
this._loadURL(url, where, openParams);
this.view.close();
}
/**
@ -560,7 +558,7 @@ class UrlbarInput {
browser.initialPageLoadedFromURLBar = url;
}
try {
UrlbarUtils.addToUrlbarHistory(url);
UrlbarUtils.addToUrlbarHistory(url, this.window);
} catch (ex) {
// Things may go wrong when adding url to session history,
// but don't let that interfere with the loading of the url.
@ -602,6 +600,8 @@ class UrlbarInput {
// TODO This should probably be handed via input.
// Ensure the start of the URL is visible for usability reasons.
// this.selectionStart = this.selectionEnd = 0;
this.closePopup();
}
/**

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

@ -13,3 +13,4 @@ support-files =
subsuite = clipboard
[browser_UrlbarInput_unit.js]
support-files = empty.xul
[browser_UrlbarLoadRace.js]

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

@ -0,0 +1,72 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// This test is for testing races of loading the Urlbar when loading shortcuts.
// For example, ensuring that if a search query is entered, but something causes
// a page load whilst we're getting the search url, then we don't handle the
// original search query.
add_task(async function setup() {
sandbox = sinon.sandbox.create();
registerCleanupFunction(async () => {
sandbox.restore();
});
});
async function checkShortcutLoading(modifierKeys) {
let deferred = PromiseUtils.defer();
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: "about:robots",
});
// We stub getShortcutOrURIAndPostData so that we can guarentee it doesn't resolve
// until after we've loaded a new page.
sandbox.stub(UrlbarUtils, "getShortcutOrURIAndPostData").callsFake(() => deferred.promise);
gURLBar.focus();
gURLBar.value = "search";
gURLBar.userTypedValue = true;
EventUtils.synthesizeKey("KEY_Enter", modifierKeys);
Assert.ok(UrlbarUtils.getShortcutOrURIAndPostData.calledOnce,
"should have called getShortcutOrURIAndPostData");
BrowserTestUtils.loadURI(tab.linkedBrowser, "about:license");
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
let openedTab;
function listener(event) {
openedTab = event.target;
}
window.addEventListener("TabOpen", listener);
deferred.resolve({
url: "https://example.com/1/",
postData: {},
mayInheritPrincipal: true,
});
await deferred.promise;
if (modifierKeys) {
Assert.ok(openedTab, "Should have attempted to open the shortcut page");
BrowserTestUtils.removeTab(openedTab);
} else {
Assert.ok(!openedTab, "Should have not attempted to open the shortcut page");
}
window.removeEventListener("TabOpen", listener);
BrowserTestUtils.removeTab(tab);
sandbox.restore();
}
add_task(async function test_location_change_stops_load() {
await checkShortcutLoading();
});
add_task(async function test_opening_different_tab_with_location_change() {
await checkShortcutLoading({altKey: true});
});

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

@ -11,6 +11,7 @@ let sandbox;
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
PromiseUtils: "resource://gre/modules/PromiseUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
QueryContext: "resource:///modules/UrlbarUtils.jsm",
UrlbarController: "resource:///modules/UrlbarController.jsm",