diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js b/toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js new file mode 100644 index 0000000000..a1863cc25c --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_enabled.js @@ -0,0 +1,103 @@ +"use strict"; + +add_setup(async function() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["extensions.InstallTrigger.enabled", true], + ["extensions.InstallTriggerImpl.enabled", true], + // Relax the user input requirements while running this test. + ["xpinstall.userActivation.required", false], + ], + }); +}); + +// Test whether an InstallTrigger.enabled is working +add_task(async function test_enabled() { + await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TESTROOT + "enabled.html" + ); + + let text = await ContentTask.spawn( + gBrowser.selectedBrowser, + undefined, + () => content.document.getElementById("enabled").textContent + ); + + is(text, "true", "installTrigger should have been enabled"); + gBrowser.removeCurrentTab(); +}); + +// Test whether an InstallTrigger.enabled is working +add_task(async function test_disabled() { + Services.prefs.setBoolPref("xpinstall.enabled", false); + await BrowserTestUtils.openNewForegroundTab( + gBrowser, + TESTROOT + "enabled.html" + ); + + let text = await ContentTask.spawn( + gBrowser.selectedBrowser, + undefined, + () => content.document.getElementById("enabled").textContent + ); + + is(text, "false", "installTrigger should have not been enabled"); + Services.prefs.clearUserPref("xpinstall.enabled"); + gBrowser.removeCurrentTab(); +}); + +// Test whether an InstallTrigger.install call fails when xpinstall is disabled +add_task(async function test_disabled2() { + let installDisabledCalled = false; + + Harness.installDisabledCallback = installInfo => { + installDisabledCalled = true; + ok(true, "Saw installation disabled"); + }; + + Harness.installBlockedCallback = installInfo => { + ok(false, "Should never see the blocked install notification"); + return false; + }; + + Harness.installConfirmCallback = panel => { + ok(false, "Should never see an install confirmation dialog"); + return false; + }; + + Harness.setup(); + Services.prefs.setBoolPref("xpinstall.enabled", false); + + var triggers = encodeURIComponent( + JSON.stringify({ + "Unsigned XPI": TESTROOT + "amosigned.xpi", + }) + ); + + BrowserTestUtils.openNewForegroundTab( + gBrowser, + TESTROOT + "installtrigger.html?" + triggers + ); + + await BrowserTestUtils.waitForContentEvent( + gBrowser.selectedBrowser, + "InstallTriggered", + true, + undefined, + true + ); + + let text = await ContentTask.spawn( + gBrowser.selectedBrowser, + undefined, + () => content.document.getElementById("return").textContent + ); + + is(text, "false", "installTrigger should have not been enabled"); + ok(installDisabledCalled, "installDisabled callback was called"); + + Services.prefs.clearUserPref("xpinstall.enabled"); + gBrowser.removeCurrentTab(); + Harness.finish(); +}); |