зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1533038 - Test that userContextId is properly added to the queryContext. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D24357 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
67c33bc3d3
Коммит
6b5b1c40cd
|
@ -554,6 +554,7 @@ class UrlbarInput {
|
|||
muxer: "UnifiedComplete",
|
||||
providers: ["UnifiedComplete"],
|
||||
searchString,
|
||||
userContextId: this.window.gBrowser.selectedBrowser.getAttribute("usercontextid"),
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -989,12 +990,18 @@ class UrlbarInput {
|
|||
*/
|
||||
_loadURL(url, openUILinkWhere, params, result = {},
|
||||
browser = this.window.gBrowser.selectedBrowser) {
|
||||
this.value = url;
|
||||
browser.userTypedValue = url;
|
||||
// No point in setting these because we'll handleRevert() a few rows below.
|
||||
if (openUILinkWhere == "current") {
|
||||
this.value = url;
|
||||
browser.userTypedValue = url;
|
||||
}
|
||||
|
||||
if (this.window.gInitialPages.includes(url)) {
|
||||
// No point in setting this if we are loading in a new window.
|
||||
if (openUILinkWhere != "window" &&
|
||||
this.window.gInitialPages.includes(url)) {
|
||||
browser.initialPageLoadedFromUserAction = url;
|
||||
}
|
||||
|
||||
try {
|
||||
UrlbarUtils.addToUrlbarHistory(url, this.window);
|
||||
} catch (ex) {
|
||||
|
|
|
@ -395,6 +395,8 @@ class UrlbarQueryContext {
|
|||
* The maximum number of results that will be displayed for this query.
|
||||
* @param {boolean} options.allowAutofill
|
||||
* Whether or not to allow providers to include autofill results.
|
||||
* @param {number} options.userContextId
|
||||
* The container id where this context was generated, if any.
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
this._checkRequiredOptions(options, [
|
||||
|
@ -418,6 +420,8 @@ class UrlbarQueryContext {
|
|||
(!Array.isArray(options.sources) || !options.sources.length)) {
|
||||
throw new Error(`Invalid sources list`);
|
||||
}
|
||||
|
||||
this.userContextId = options.userContextId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -226,6 +226,17 @@ var UrlbarTestUtils = {
|
|||
let urlbar = getUrlbarAbstraction(win);
|
||||
return urlbar.isPopupOpen();
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the userContextId (container id) for the last search.
|
||||
* @param {object} win The browser window
|
||||
* @returns {Promise} resolved when fetching is complete
|
||||
* @resolves {number} a userContextId
|
||||
*/
|
||||
promiseUserContextId(win) {
|
||||
let urlbar = getUrlbarAbstraction(win);
|
||||
return urlbar.promiseUserContextId();
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -340,6 +351,15 @@ class UrlbarAbstraction {
|
|||
"waiting urlbar search to complete", 100, 50);
|
||||
}
|
||||
|
||||
async promiseUserContextId() {
|
||||
const defaultId = Ci.nsIScriptSecurityManager.DEFAULT_USER_CONTEXT_ID;
|
||||
if (this.quantumbar) {
|
||||
let context = await this.urlbar.lastQueryContextPromise;
|
||||
return context.userContextId || defaultId;
|
||||
}
|
||||
return this.urlbar.userContextId || defaultId;
|
||||
}
|
||||
|
||||
async promiseResultAt(index) {
|
||||
if (!this.quantumbar) {
|
||||
// In the legacy address bar, old results are replaced when new results
|
||||
|
|
|
@ -70,7 +70,13 @@ async function withNewWindow(callback) {
|
|||
"", "chrome");
|
||||
await BrowserTestUtils.waitForEvent(win, "load");
|
||||
|
||||
win.gBrowser = {};
|
||||
win.gBrowser = {
|
||||
selectedBrowser: {
|
||||
getAttribute() {
|
||||
return undefined;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Clone the elements into the new window, so we get exact copies without having
|
||||
// to replicate the xul.
|
||||
|
|
|
@ -11,8 +11,10 @@ const START_VALUE = "example.org";
|
|||
|
||||
add_task(async function setup() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.altClickSave", true],
|
||||
["browser.urlbar.autoFill", false]],
|
||||
set: [
|
||||
["browser.altClickSave", true],
|
||||
["browser.urlbar.autoFill", false],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -29,7 +31,7 @@ add_task(async function alt_left_click_test() {
|
|||
};
|
||||
});
|
||||
|
||||
triggerCommand("click", {altKey: true});
|
||||
await triggerCommand("click", {altKey: true});
|
||||
|
||||
await saveURLPromise;
|
||||
ok(true, "SaveURL was called");
|
||||
|
@ -41,7 +43,7 @@ add_task(async function shift_left_click_test() {
|
|||
|
||||
let destinationURL = "http://" + TEST_VALUE + "/";
|
||||
let newWindowPromise = BrowserTestUtils.waitForNewWindow({url: destinationURL});
|
||||
triggerCommand("click", {shiftKey: true});
|
||||
await triggerCommand("click", {shiftKey: true});
|
||||
let win = await newWindowPromise;
|
||||
|
||||
info("URL should be loaded in a new window");
|
||||
|
@ -65,7 +67,7 @@ add_task(async function right_click_test() {
|
|||
// Add a new tab.
|
||||
await promiseOpenNewTab();
|
||||
|
||||
triggerCommand("click", {button: 2});
|
||||
await triggerCommand("click", {button: 2});
|
||||
|
||||
// Right click should do nothing (context menu will be shown).
|
||||
is(gURLBar.value, TEST_VALUE, "Urlbar still has the value we entered");
|
||||
|
@ -81,7 +83,7 @@ add_task(async function shift_accel_left_click_test() {
|
|||
let tab = await promiseOpenNewTab();
|
||||
|
||||
let loadStartedPromise = promiseLoadStarted();
|
||||
triggerCommand("click", {accelKey: true, shiftKey: true});
|
||||
await triggerCommand("click", {accelKey: true, shiftKey: true});
|
||||
await loadStartedPromise;
|
||||
|
||||
// Check the load occurred in a new background tab.
|
||||
|
@ -92,7 +94,7 @@ add_task(async function shift_accel_left_click_test() {
|
|||
|
||||
// Select the new background tab
|
||||
gBrowser.selectedTab = gBrowser.selectedTab.nextElementSibling;
|
||||
is(gURLBar.value, TEST_VALUE, "New URL is loaded in new tab");
|
||||
is(gURLBar.textValue, TEST_VALUE, "New URL is loaded in new tab");
|
||||
|
||||
// Cleanup.
|
||||
gBrowser.removeCurrentTab();
|
||||
|
@ -129,7 +131,7 @@ add_task(async function load_in_current_tab_test() {
|
|||
|
||||
// Trigger a load and check it occurs in the current tab.
|
||||
let loadStartedPromise = promiseLoadStarted();
|
||||
triggerCommand(type, details);
|
||||
await triggerCommand(type, details);
|
||||
await loadStartedPromise;
|
||||
|
||||
info("URL should be loaded in the current tab");
|
||||
|
@ -149,7 +151,7 @@ add_task(async function load_in_new_tab_test() {
|
|||
desc: "Ctrl/Cmd left click on go button",
|
||||
type: "click",
|
||||
details: {accelKey: true},
|
||||
url: null,
|
||||
url: "about:blank",
|
||||
},
|
||||
{
|
||||
desc: "Alt+Return keypress in a dirty tab",
|
||||
|
@ -163,16 +165,16 @@ add_task(async function load_in_new_tab_test() {
|
|||
info(`Running test: ${desc}`);
|
||||
|
||||
// Add a new tab.
|
||||
let tab = await promiseOpenNewTab(url || "about:blank");
|
||||
let tab = await promiseOpenNewTab(url);
|
||||
|
||||
// Trigger a load and check it occurs in the current tab.
|
||||
let tabSwitchedPromise = promiseNewTabSwitched();
|
||||
triggerCommand(type, details);
|
||||
await triggerCommand(type, details);
|
||||
await tabSwitchedPromise;
|
||||
|
||||
// Check the load occurred in a new tab.
|
||||
info("URL should be loaded in a new focused tab");
|
||||
is(gURLBar.inputField.value, TEST_VALUE, "Urlbar still has the value we entered");
|
||||
is(gURLBar.textValue, TEST_VALUE, "Urlbar still has the value we entered");
|
||||
await promiseCheckChildNoFocusedElement(gBrowser.selectedBrowser);
|
||||
is(document.activeElement, gBrowser.selectedBrowser, "Content window should be focused");
|
||||
isnot(gBrowser.selectedTab, tab, "New URL was loaded in a new tab");
|
||||
|
@ -183,11 +185,15 @@ add_task(async function load_in_new_tab_test() {
|
|||
}
|
||||
});
|
||||
|
||||
function triggerCommand(type, details = {}) {
|
||||
async function triggerCommand(type, details = {}) {
|
||||
gURLBar.focus();
|
||||
gURLBar.value = "";
|
||||
EventUtils.sendString(TEST_VALUE);
|
||||
|
||||
Assert.equal(await UrlbarTestUtils.promiseUserContextId(window),
|
||||
gBrowser.selectedTab.getAttribute("usercontextid"),
|
||||
"userContextId must be the same as the originating tab");
|
||||
|
||||
if (type == "click") {
|
||||
ok(gURLBar.hasAttribute("usertyping"),
|
||||
"usertyping attribute must be set for the go button to be visible");
|
||||
|
@ -212,8 +218,9 @@ function promiseLoadStarted() {
|
|||
});
|
||||
}
|
||||
|
||||
let gUserContextIdSerial = 1;
|
||||
async function promiseOpenNewTab(url = "about:blank") {
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, url);
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, url, {userContextId: gUserContextIdSerial++});
|
||||
let tabSwitchPromise = promiseNewTabSwitched(tab);
|
||||
gBrowser.selectedTab = tab;
|
||||
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
||||
|
|
Загрузка…
Ссылка в новой задаче