From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../tests/browser_searchChangedEngine.js | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 browser/components/preferences/tests/browser_searchChangedEngine.js (limited to 'browser/components/preferences/tests/browser_searchChangedEngine.js') diff --git a/browser/components/preferences/tests/browser_searchChangedEngine.js b/browser/components/preferences/tests/browser_searchChangedEngine.js new file mode 100644 index 0000000000..321cab4686 --- /dev/null +++ b/browser/components/preferences/tests/browser_searchChangedEngine.js @@ -0,0 +1,90 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { AddonTestUtils } = ChromeUtils.import( + "resource://testing-common/AddonTestUtils.jsm" +); +const { SearchTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/SearchTestUtils.sys.mjs" +); +const { SearchUtils } = ChromeUtils.importESModule( + "resource://gre/modules/SearchUtils.sys.mjs" +); + +AddonTestUtils.initMochitest(this); +SearchTestUtils.init(this); + +function findRow(tree, expectedName) { + for (let i = 0; i < tree.view.rowCount; i++) { + let name = tree.view.getCellText( + i, + tree.columns.getNamedColumn("engineName") + ); + + if (name == expectedName) { + return i; + } + } + return -1; +} + +add_task(async function test_change_engine() { + await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true }); + + let doc = gBrowser.selectedBrowser.contentDocument; + + await SearchTestUtils.installSearchExtension({ + id: "example@tests.mozilla.org", + name: "Example", + version: "1.0", + keyword: "foo", + favicon_url: "img123.png", + }); + + let tree = doc.querySelector("#engineList"); + + let row = findRow(tree, "Example"); + + Assert.notEqual(row, -1, "Should have found the entry"); + Assert.ok( + tree.view + .getImageSrc(row, tree.columns.getNamedColumn("engineName")) + .includes("img123.png"), + "Should have the correct image URL" + ); + Assert.equal( + tree.view.getCellText(row, tree.columns.getNamedColumn("engineKeyword")), + "foo", + "Should show the correct keyword" + ); + + let updatedPromise = SearchTestUtils.promiseSearchNotification( + SearchUtils.MODIFIED_TYPE.CHANGED, + SearchUtils.TOPIC_ENGINE_MODIFIED + ); + await SearchTestUtils.installSearchExtension({ + id: "example@tests.mozilla.org", + name: "Example 2", + version: "2.0", + keyword: "bar", + favicon_url: "img456.png", + }); + await updatedPromise; + + row = findRow(tree, "Example 2"); + + Assert.notEqual(row, -1, "Should have found the updated entry"); + Assert.ok( + tree.view + .getImageSrc(row, tree.columns.getNamedColumn("engineName")) + .includes("img456.png"), + "Should have the correct image URL" + ); + Assert.equal( + tree.view.getCellText(row, tree.columns.getNamedColumn("engineKeyword")), + "bar", + "Should show the correct keyword" + ); + + gBrowser.removeCurrentTab(); +}); -- cgit v1.2.3