From ae924c0d7f6599a02fc76f253296b58f79c0b77c Mon Sep 17 00:00:00 2001 From: Moritz Beier Date: Fri, 9 May 2025 15:39:14 +0000 Subject: [PATCH] Bug 1661664 - Part 3: Add tests for UserSearchEngine favicons. r=search-reviewers,Standard8,settings-reviewers,mossop Differential Revision: https://phabricator.services.mozilla.com/D247575 --- .../tests/browser_search_userEngineDialog.js | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/browser/components/preferences/tests/browser_search_userEngineDialog.js b/browser/components/preferences/tests/browser_search_userEngineDialog.js index 95a0d897e708..974d5866cfb9 100644 --- a/browser/components/preferences/tests/browser_search_userEngineDialog.js +++ b/browser/components/preferences/tests/browser_search_userEngineDialog.js @@ -3,6 +3,9 @@ "use strict"; +const { PlacesTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/PlacesTestUtils.sys.mjs" +); const { SearchTestUtils } = ChromeUtils.importESModule( "resource://testing-common/SearchTestUtils.sys.mjs" ); @@ -525,6 +528,69 @@ add_task(async function test_editPostEngine() { await Services.search.removeEngine(engine); }); +add_task(async function test_icon() { + // Set up favicon. + let pageUrl = "https://search.test/"; + let iconUrl = "https://search.test/favicon.svg"; + let dataURL = "data:image/svg+xml;base64,PHN2Zy8+"; + + await PlacesTestUtils.addVisits({ uri: new URL(pageUrl).URI }); + await PlacesTestUtils.setFaviconForPage(pageUrl, iconUrl, dataURL); + + // Open Settings. + await openPreferencesViaOpenPreferencesAPI("search", { + leaveOpen: true, + }); + + let doc = gBrowser.contentDocument; + let tree = doc.querySelector("#engineList"); + let view = tree.view.wrappedJSObject; + + let addButton = doc.querySelector("#addEngineButton"); + let editButton = doc.querySelector("#editEngineButton"); + + // Add engine and check favicon. + let dialogWin = await openDialogWith(doc, () => addButton.click()); + setName("Bugzilla", dialogWin); + setUrl("https://search.test/search?q=%s", dialogWin); + + let promiseIcon = SearchTestUtils.promiseSearchNotification( + SearchUtils.MODIFIED_TYPE.ICON_CHANGED, + SearchUtils.TOPIC_ENGINE_MODIFIED + ); + dialogWin.document.querySelector("dialog").getButton("accept").click(); + let engine = await promiseIcon; + + Assert.ok(true, "Icon was added"); + Assert.equal(await engine.getIconURL(), dataURL, "Icon is correct"); + + // Change favicon. + dataURL = "data:image/svg+xml;base64,PHN2Zz48Y2lyY2xlIHI9IjEiLz48L3N2Zz4="; + await PlacesTestUtils.setFaviconForPage(pageUrl, iconUrl, dataURL); + + // Edit engine and check favicon. + let engines = await Services.search.getEngines(); + let i = engines.findIndex(e => e.id == engine.id); + view.selection.select(i); + dialogWin = await openDialogWith(doc, () => editButton.click()); + + promiseIcon = SearchTestUtils.promiseSearchNotification( + SearchUtils.MODIFIED_TYPE.ICON_CHANGED, + SearchUtils.TOPIC_ENGINE_MODIFIED + ); + dialogWin.document.querySelector("dialog").getButton("accept").click(); + await promiseIcon; + + Assert.ok(true, "Icon was changed"); + Assert.equal(await engine.getIconURL(), dataURL, "New icon is correct"); + + // Clean up. + BrowserTestUtils.removeTab(gBrowser.selectedTab); + await Services.search.removeEngine(engine); + PlacesUtils.favicons.expireAllFavicons(); + await PlacesUtils.history.clear(); +}); + /** * Checks the error label of an input of the add engine dialog. * @@ -545,11 +611,12 @@ async function assertError(elt, error = null) { } async function openDialogWith(doc, fn) { + info("Opening dialog."); let dialogLoaded = TestUtils.topicObserved("subdialog-loaded"); await fn(); let [dialogWin] = await dialogLoaded; await doc.ownerGlobal.gSubDialog.dialogs[0]._dialogReady; - Assert.ok(true, "Engine dialog opened."); + Assert.ok(true, "Engine dialog opened"); return dialogWin; }