diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/mozapps/extensions/test/browser/browser_html_discover_view_prefs.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | toolkit/mozapps/extensions/test/browser/browser_html_discover_view_prefs.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/browser/browser_html_discover_view_prefs.js b/toolkit/mozapps/extensions/test/browser/browser_html_discover_view_prefs.js new file mode 100644 index 0000000000..474cd424b9 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_html_discover_view_prefs.js @@ -0,0 +1,83 @@ +/* eslint max-len: ["error", 80] */ +"use strict"; + +const { AddonTestUtils } = ChromeUtils.importESModule( + "resource://testing-common/AddonTestUtils.sys.mjs" +); + +AddonTestUtils.initMochitest(this); +const server = AddonTestUtils.createHttpServer(); +const TEST_API_URL = `http://localhost:${server.identity.primaryPort}/discoapi`; + +async function checkIfDiscoverVisible(expectVisible) { + let requestCount = 0; + let requestPromise = new Promise(resolve => { + // Overwrites previous request handler, if any. + server.registerPathHandler("/discoapi", (request, response) => { + ++requestCount; + response.write(`{"results": []}`); + resolve(); + }); + }); + + // Open about:addons with default view. + let managerWindow = await open_manager(null); + let categoryUtilities = new CategoryUtilities(managerWindow); + + is( + categoryUtilities.isTypeVisible("discover"), + expectVisible, + "Visibility of discopane" + ); + + await wait_for_view_load(managerWindow); + if (expectVisible) { + is( + categoryUtilities.selectedCategory, + "discover", + "Expected discopane as the default view" + ); + await requestPromise; + is(requestCount, 1, "Expected discovery API request"); + } else { + // The next view (after discopane) is the extension list. + is( + categoryUtilities.selectedCategory, + "extension", + "Should fall back to another view when the discopane is disabled" + ); + is(requestCount, 0, "Discovery API should not be requested"); + } + + await close_manager(managerWindow); +} + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["extensions.getAddons.discovery.api_url", TEST_API_URL], + // Disable recommendations at the HTML about:addons view to avoid sending + // a discovery API request from the fallback view (extension list) in the + // showPane_false test. + ["extensions.htmlaboutaddons.recommendations.enabled", false], + ], + }); +}); + +add_task(async function showPane_true() { + await SpecialPowers.pushPrefEnv({ + set: [[PREF_DISCOVER_ENABLED, true]], + clear: [[PREF_UI_LASTCATEGORY]], + }); + await checkIfDiscoverVisible(true); + await SpecialPowers.popPrefEnv(); +}); + +add_task(async function showPane_false() { + await SpecialPowers.pushPrefEnv({ + set: [[PREF_DISCOVER_ENABLED, false]], + clear: [[PREF_UI_LASTCATEGORY]], + }); + await checkIfDiscoverVisible(false); + await SpecialPowers.popPrefEnv(); +}); |