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:
Marco Bonardo 2019-03-26 15:15:54 +00:00
Родитель 67c33bc3d3
Коммит 6b5b1c40cd
5 изменённых файлов: 62 добавлений и 18 удалений

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

@ -554,6 +554,7 @@ class UrlbarInput {
muxer: "UnifiedComplete", muxer: "UnifiedComplete",
providers: ["UnifiedComplete"], providers: ["UnifiedComplete"],
searchString, searchString,
userContextId: this.window.gBrowser.selectedBrowser.getAttribute("usercontextid"),
})); }));
} }
@ -989,12 +990,18 @@ class UrlbarInput {
*/ */
_loadURL(url, openUILinkWhere, params, result = {}, _loadURL(url, openUILinkWhere, params, result = {},
browser = this.window.gBrowser.selectedBrowser) { browser = this.window.gBrowser.selectedBrowser) {
this.value = url; // No point in setting these because we'll handleRevert() a few rows below.
browser.userTypedValue = url; 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; browser.initialPageLoadedFromUserAction = url;
} }
try { try {
UrlbarUtils.addToUrlbarHistory(url, this.window); UrlbarUtils.addToUrlbarHistory(url, this.window);
} catch (ex) { } catch (ex) {

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

@ -395,6 +395,8 @@ class UrlbarQueryContext {
* The maximum number of results that will be displayed for this query. * The maximum number of results that will be displayed for this query.
* @param {boolean} options.allowAutofill * @param {boolean} options.allowAutofill
* Whether or not to allow providers to include autofill results. * 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 = {}) { constructor(options = {}) {
this._checkRequiredOptions(options, [ this._checkRequiredOptions(options, [
@ -418,6 +420,8 @@ class UrlbarQueryContext {
(!Array.isArray(options.sources) || !options.sources.length)) { (!Array.isArray(options.sources) || !options.sources.length)) {
throw new Error(`Invalid sources list`); throw new Error(`Invalid sources list`);
} }
this.userContextId = options.userContextId;
} }
/** /**

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

@ -226,6 +226,17 @@ var UrlbarTestUtils = {
let urlbar = getUrlbarAbstraction(win); let urlbar = getUrlbarAbstraction(win);
return urlbar.isPopupOpen(); 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); "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) { async promiseResultAt(index) {
if (!this.quantumbar) { if (!this.quantumbar) {
// In the legacy address bar, old results are replaced when new results // In the legacy address bar, old results are replaced when new results

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

@ -70,7 +70,13 @@ async function withNewWindow(callback) {
"", "chrome"); "", "chrome");
await BrowserTestUtils.waitForEvent(win, "load"); 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 // Clone the elements into the new window, so we get exact copies without having
// to replicate the xul. // to replicate the xul.

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

@ -11,8 +11,10 @@ const START_VALUE = "example.org";
add_task(async function setup() { add_task(async function setup() {
await SpecialPowers.pushPrefEnv({ await SpecialPowers.pushPrefEnv({
set: [["browser.altClickSave", true], set: [
["browser.urlbar.autoFill", false]], ["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; await saveURLPromise;
ok(true, "SaveURL was called"); ok(true, "SaveURL was called");
@ -41,7 +43,7 @@ add_task(async function shift_left_click_test() {
let destinationURL = "http://" + TEST_VALUE + "/"; let destinationURL = "http://" + TEST_VALUE + "/";
let newWindowPromise = BrowserTestUtils.waitForNewWindow({url: destinationURL}); let newWindowPromise = BrowserTestUtils.waitForNewWindow({url: destinationURL});
triggerCommand("click", {shiftKey: true}); await triggerCommand("click", {shiftKey: true});
let win = await newWindowPromise; let win = await newWindowPromise;
info("URL should be loaded in a new window"); info("URL should be loaded in a new window");
@ -65,7 +67,7 @@ add_task(async function right_click_test() {
// Add a new tab. // Add a new tab.
await promiseOpenNewTab(); await promiseOpenNewTab();
triggerCommand("click", {button: 2}); await triggerCommand("click", {button: 2});
// Right click should do nothing (context menu will be shown). // Right click should do nothing (context menu will be shown).
is(gURLBar.value, TEST_VALUE, "Urlbar still has the value we entered"); 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 tab = await promiseOpenNewTab();
let loadStartedPromise = promiseLoadStarted(); let loadStartedPromise = promiseLoadStarted();
triggerCommand("click", {accelKey: true, shiftKey: true}); await triggerCommand("click", {accelKey: true, shiftKey: true});
await loadStartedPromise; await loadStartedPromise;
// Check the load occurred in a new background tab. // 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 // Select the new background tab
gBrowser.selectedTab = gBrowser.selectedTab.nextElementSibling; 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. // Cleanup.
gBrowser.removeCurrentTab(); 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. // Trigger a load and check it occurs in the current tab.
let loadStartedPromise = promiseLoadStarted(); let loadStartedPromise = promiseLoadStarted();
triggerCommand(type, details); await triggerCommand(type, details);
await loadStartedPromise; await loadStartedPromise;
info("URL should be loaded in the current tab"); 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", desc: "Ctrl/Cmd left click on go button",
type: "click", type: "click",
details: {accelKey: true}, details: {accelKey: true},
url: null, url: "about:blank",
}, },
{ {
desc: "Alt+Return keypress in a dirty tab", 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}`); info(`Running test: ${desc}`);
// Add a new tab. // 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. // Trigger a load and check it occurs in the current tab.
let tabSwitchedPromise = promiseNewTabSwitched(); let tabSwitchedPromise = promiseNewTabSwitched();
triggerCommand(type, details); await triggerCommand(type, details);
await tabSwitchedPromise; await tabSwitchedPromise;
// Check the load occurred in a new tab. // Check the load occurred in a new tab.
info("URL should be loaded in a new focused 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); await promiseCheckChildNoFocusedElement(gBrowser.selectedBrowser);
is(document.activeElement, gBrowser.selectedBrowser, "Content window should be focused"); is(document.activeElement, gBrowser.selectedBrowser, "Content window should be focused");
isnot(gBrowser.selectedTab, tab, "New URL was loaded in a new tab"); 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.focus();
gURLBar.value = ""; gURLBar.value = "";
EventUtils.sendString(TEST_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") { if (type == "click") {
ok(gURLBar.hasAttribute("usertyping"), ok(gURLBar.hasAttribute("usertyping"),
"usertyping attribute must be set for the go button to be visible"); "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") { async function promiseOpenNewTab(url = "about:blank") {
let tab = BrowserTestUtils.addTab(gBrowser, url); let tab = BrowserTestUtils.addTab(gBrowser, url, {userContextId: gUserContextIdSerial++});
let tabSwitchPromise = promiseNewTabSwitched(tab); let tabSwitchPromise = promiseNewTabSwitched(tab);
gBrowser.selectedTab = tab; gBrowser.selectedTab = tab;
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);