Bug 1782311: Do not hide oneoff buttons area when there is additional engine. r=Standard8,adw
The cause of this bug was that we don’t consider the Add Engines to show/hide the container of SearchOneOffs. To resolve the issue, we incorporated that into __rebuild() function. This feature is only for search bar. Differential Revision: https://phabricator.services.mozilla.com/D154627
This commit is contained in:
@@ -446,7 +446,11 @@ export class SearchOneOffs {
|
||||
headerText.id = this.telemetryOrigin + "-one-offs-header-label";
|
||||
this.buttons.setAttribute("aria-labelledby", headerText.id);
|
||||
|
||||
let hideOneOffs = await this.willHide();
|
||||
// For the search-bar, always show the one-off buttons where there is an
|
||||
// option to add an engine.
|
||||
let addEngineNeeded =
|
||||
this.hasAttribute("is_searchbar") && addEngines.length;
|
||||
let hideOneOffs = (await this.willHide()) && !addEngineNeeded;
|
||||
|
||||
// The _engineInfo cache is used by more consumers, thus it is not a good
|
||||
// representation of whether this method already updated the one-off buttons
|
||||
|
||||
@@ -19,6 +19,7 @@ add_setup(async function() {
|
||||
|
||||
registerCleanupFunction(async function() {
|
||||
gCUITestUtils.removeSearchBar();
|
||||
Services.search.restoreDefaultEngines();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,3 +66,34 @@ add_task(async function test_invalidEngine() {
|
||||
await PromptTestUtils.handlePrompt(prompt);
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(async function test_onOnlyDefaultEngine() {
|
||||
info("Remove engines except default");
|
||||
const defaultEngine = Services.search.defaultEngine;
|
||||
const engines = await Services.search.getVisibleEngines();
|
||||
for (const engine of engines) {
|
||||
if (defaultEngine.name !== engine.name) {
|
||||
await Services.search.removeEngine(engine);
|
||||
}
|
||||
}
|
||||
|
||||
info("Show popup");
|
||||
const rootDir = getRootDirectory(gTestPath);
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
rootDir + "opensearch.html"
|
||||
);
|
||||
const onShown = promiseEvent(searchPopup, "popupshown");
|
||||
await EventUtils.synthesizeMouseAtCenter(
|
||||
searchbar.querySelector(".searchbar-search-button"),
|
||||
{}
|
||||
);
|
||||
await onShown;
|
||||
|
||||
const addEngineList = searchPopup.querySelectorAll(
|
||||
".searchbar-engine-one-off-add-engine"
|
||||
);
|
||||
Assert.equal(addEngineList.length, 3, "Add engines should be shown");
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
||||
@@ -207,3 +207,36 @@ function promiseEngine(expectedData, expectedEngineName) {
|
||||
}
|
||||
).then(([engine, data]) => engine);
|
||||
}
|
||||
|
||||
add_task(async function shortcuts_without_other_engines() {
|
||||
info("Checks the shortcuts without other engines.");
|
||||
|
||||
info("Remove search engines except default");
|
||||
const defaultEngine = Services.search.defaultEngine;
|
||||
const engines = await Services.search.getVisibleEngines();
|
||||
for (const engine of engines) {
|
||||
if (defaultEngine.name !== engine.name) {
|
||||
await Services.search.removeEngine(engine);
|
||||
}
|
||||
}
|
||||
|
||||
info("Remove local engines");
|
||||
for (const { pref } of UrlbarUtils.LOCAL_SEARCH_MODES) {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [[`browser.urlbar.${pref}`, false]],
|
||||
});
|
||||
}
|
||||
|
||||
const url = getRootDirectory(gTestPath) + "add_search_engine_many.html";
|
||||
await BrowserTestUtils.withNewTab(url, async () => {
|
||||
await UrlbarTestUtils.promiseAutocompleteResultPopup({
|
||||
window,
|
||||
value: "test",
|
||||
});
|
||||
|
||||
const shortcutButtons = UrlbarTestUtils.getOneOffSearchButtons(window);
|
||||
Assert.ok(shortcutButtons.container.hidden, "It should be hidden");
|
||||
});
|
||||
|
||||
Services.search.restoreDefaultEngines();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user