Bug 1522504 - Update browser_PageActions.js and browser_UsageTelemetry_urlbar.js to be able to run with QuantumBar. r=adw

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2019-02-14 22:23:43 +00:00
Родитель 6717d9383e
Коммит 0baadc8693
3 изменённых файлов: 46 добавлений и 49 удалений

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

@ -111,6 +111,16 @@ var UrlbarTestUtils = {
return urlbar.getSelectedIndex();
},
/**
* Selects the item at the index specified.
* @param {object} win The window containing the urlbar.
* @param {index} index The index to select.
*/
setSelectedIndex(win, index) {
let urlbar = getUrlbarAbstraction(win);
urlbar.setSelectedIndex(index);
},
/**
* Gets the number of results.
* You must wait for the query to be complete before using this.
@ -308,6 +318,13 @@ class UrlbarAbstraction {
: this.panel.selectedIndex;
}
setSelectedIndex(index) {
if (!this.quantumbar) {
return this.panel.selectedIndex = index;
}
return this.urlbar.view.selectedIndex;
}
getResultCount() {
return this.quantumbar ? this.urlbar.view._rows.children.length
: this.urlbar.controller.matchCount;

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

@ -1464,7 +1464,7 @@ add_task(async function contextMenu() {
// urlbar tests that run after this one can break if the mouse is left over
// the area where the urlbar popup appears, which seems to happen due to the
// above synthesized mouse events. Move it over the urlbar.
EventUtils.synthesizeMouseAtCenter(gURLBar, { type: "mousemove" });
EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, { type: "mousemove" });
gURLBar.focus();
});

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

@ -8,62 +8,42 @@ const SUGGEST_URLBAR_PREF = "browser.urlbar.suggest.searches";
const SUGGESTION_ENGINE_NAME = "browser_UsageTelemetry usageTelemetrySearchSuggestions.xml";
const ONEOFF_URLBAR_PREF = "browser.urlbar.oneOffSearches";
ChromeUtils.defineModuleGetter(this, "URLBAR_SELECTED_RESULT_TYPES",
"resource:///modules/BrowserUsageTelemetry.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
SearchTelemetry: "resource:///modules/SearchTelemetry.jsm",
UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.jsm",
URLBAR_SELECTED_RESULT_TYPES: "resource:///modules/BrowserUsageTelemetry.jsm",
URLBAR_SELECTED_RESULT_METHODS: "resource:///modules/BrowserUsageTelemetry.jsm",
});
ChromeUtils.defineModuleGetter(this, "URLBAR_SELECTED_RESULT_METHODS",
"resource:///modules/BrowserUsageTelemetry.jsm");
ChromeUtils.defineModuleGetter(this, "SearchTelemetry",
"resource:///modules/SearchTelemetry.jsm");
let searchInAwesomebar = async function(inputText, win = window) {
await new Promise(r => waitForFocus(r, win));
// Write the search query in the urlbar.
win.gURLBar.focus();
win.gURLBar.value = inputText;
// This is not strictly necessary, but some things, like clearing oneoff
// buttons status, depend on actual input events that the user would normally
// generate.
let event = win.document.createEvent("Events");
event.initEvent("input", true, true);
win.gURLBar.dispatchEvent(event);
win.gURLBar.controller.startSearch(inputText);
// Wait for the popup to show.
await BrowserTestUtils.waitForEvent(win.gURLBar.popup, "popupshown");
// And then for the search to complete.
await BrowserTestUtils.waitForCondition(() => win.gURLBar.controller.searchStatus >=
Ci.nsIAutoCompleteController.STATUS_COMPLETE_NO_MATCH);
};
function searchInAwesomebar(inputText, win = window) {
return UrlbarTestUtils.promiseAutocompleteResultPopup(win, inputText, waitForFocus, true);
}
/**
* Click one of the entries in the urlbar suggestion popup.
*
* @param {String} entryName
* The name of the elemet to click on.
* @param {String} resultTitle
* The title of the result to click on.
* @param {Number} button [optional]
* which button to click.
*/
function clickURLBarSuggestion(entryName, button = 1) {
// The entry in the suggestion list should follow the format:
// "<search term> <engine name> Search"
const expectedSuggestionName = entryName + " " + SUGGESTION_ENGINE_NAME + " Search";
return BrowserTestUtils.waitForCondition(() => {
for (let child of gURLBar.popup.richlistbox.children) {
if (child.label === expectedSuggestionName) {
// This entry is the search suggestion we're looking for.
if (button == 1)
child.click();
else if (button == 2) {
EventUtils.synthesizeMouseAtCenter(child, {type: "mousedown", button: 2});
}
return true;
async function clickURLBarSuggestion(resultTitle, button = 1) {
await UrlbarTestUtils.promiseSearchComplete(window);
const count = UrlbarTestUtils.getResultCount(window);
for (let i = 0; i < count; i++) {
let result = await UrlbarTestUtils.getDetailsOfResultAt(window, i);
if (result.displayed.title == resultTitle) {
// This entry is the search suggestion we're looking for.
let element = await UrlbarTestUtils.waitForAutocompleteResultAt(window, i);
if (button == 1)
EventUtils.synthesizeMouseAtCenter(element, {});
else if (button == 2) {
EventUtils.synthesizeMouseAtCenter(element, {type: "mousedown", button: 2});
}
return;
}
return false;
}, "Waiting for the expected suggestion to appear");
}
}
/**
@ -353,7 +333,7 @@ add_task(async function test_oneOff_click() {
let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
await searchInAwesomebar("query");
info("Click the first one-off button.");
gURLBar.popup.oneOffSearchButtons.getSelectableButtons(false)[0].click();
UrlbarTestUtils.getOneOffSearchButtons(window).getSelectableButtons(false)[0].click();
await p;
TelemetryTestUtils.assertHistogram(resultMethodHist,
@ -476,7 +456,7 @@ add_task(async function test_suggestion_enterSelection() {
let p = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
await searchInAwesomebar("query");
info("Select the second result and press Return.");
gURLBar.popup.selectedIndex = 1;
UrlbarTestUtils.setSelectedIndex(window, 1);
EventUtils.synthesizeKey("KEY_Enter");
await p;