Bug 1586861 - Use promiseDocumentFlushed in SearchOneOffs.__rebuild. r=dao

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Harry Twyford 2019-10-16 14:46:44 +00:00
parent 58fd4f9f86
commit e897e72031
5 changed files with 26 additions and 23 deletions

View File

@ -447,14 +447,16 @@ class SearchOneOffs {
this._rebuildAddEngineList();
}
// Check if the one-off buttons really need to be rebuilt.
if (this._textbox) {
// We can't get a reliable value for the popup width without flushing,
// but the popup width won't change if the textbox width doesn't.
let DOMUtils = window.windowUtils;
let textboxWidth = DOMUtils.getBoundsWithoutFlushing(this._textbox).width;
// We can return early if neither the list of engines nor the panel
// width has changed.
// Return early if the list of engines has not changed.
if (!this.popup && this._engines) {
return;
}
// Return early if the engines and panel width have not changed.
if (this.popup && this._textbox) {
let textboxWidth = await window.promiseDocumentFlushed(() => {
return this._textbox.clientWidth;
});
if (this._engines && this._textboxWidth == textboxWidth) {
return;
}
@ -551,6 +553,8 @@ class SearchOneOffs {
this.buttons.appendChild(button);
}
this.dispatchEvent(new Event("rebuild"));
}
_rebuildAddEngineList() {

View File

@ -779,11 +779,7 @@
width = Math.max(width, this.oneOffButtons.buttonWidth * 3);
}
// The CSS minWidth is necessary for the searchbar to be the correct
// width in the overflow menu. The width attribute is necessary for
// _invalidate().
popup.style.minWidth = width + "px";
popup.setAttribute("width", width);
popup._invalidate();

View File

@ -51,19 +51,20 @@ add_task(async function test_hidden() {
add_task(async function test_shown() {
Preferences.set("browser.search.hiddenOneOffs", "");
let promise = promiseEvent(searchPopup, "popupshown");
let oneOffsContainer = searchPopup.searchOneOffsContainer;
let shownPromise = promiseEvent(searchPopup, "popupshown");
let builtPromise = promiseEvent(oneOffsContainer, "rebuild");
info("Opening search panel");
SimpleTest.executeSoon(() => {
EventUtils.synthesizeMouseAtCenter(searchIcon, {});
});
await promise;
EventUtils.synthesizeMouseAtCenter(searchIcon, {});
await Promise.all([shownPromise, builtPromise]);
ok(
getOneOffs().some(x => x.getAttribute("tooltiptext") == diacritic_engine),
"Search engines with diacritics are shown when removed from hiddenOneOffs preference."
);
promise = promiseEvent(searchPopup, "popuphidden");
let promise = promiseEvent(searchPopup, "popuphidden");
searchPopup.hidePopup();
await promise;
});

View File

@ -30,10 +30,11 @@ add_task(async function init() {
add_task(async function telemetry() {
// Open the popup.
let promise = promiseEvent(searchPopup, "popupshown");
let shownPromise = promiseEvent(searchPopup, "popupshown");
let builtPromise = promiseEvent(oneOffInstance, "rebuild");
info("Opening search panel");
EventUtils.synthesizeMouseAtCenter(searchIcon, {});
await promise;
await Promise.all([shownPromise, builtPromise]);
// Get the one-off button for the test engine.
let oneOffButton;
@ -50,7 +51,7 @@ add_task(async function telemetry() {
);
// Open the context menu on the one-off.
promise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
let promise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
EventUtils.synthesizeMouseAtCenter(oneOffButton, {
type: "contextmenu",
button: 2,

View File

@ -282,12 +282,13 @@ async function openPopupAndGetEngineButton(
if (isSearch) {
// Open the popup.
win.gURLBar.blur();
let promise = promiseEvent(popup, "popupshown");
let shownPromise = promiseEvent(popup, "popupshown");
let builtPromise = promiseEvent(oneOffInstance, "rebuild");
let searchbar = win.document.getElementById("searchbar");
let searchIcon = searchbar.querySelector(".searchbar-search-button");
// Use the search icon to avoid hitting the network.
EventUtils.synthesizeMouseAtCenter(searchIcon, {}, win);
await promise;
await Promise.all([shownPromise, builtPromise]);
} else {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window: win,