diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
commit | 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch) | |
tree | a4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js | |
parent | Adding debian version 124.0.1-1. (diff) | |
download | firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js')
-rw-r--r-- | browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js | 97 |
1 files changed, 64 insertions, 33 deletions
diff --git a/browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js b/browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js index 0aafba8fb3..ad262a7e67 100644 --- a/browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js +++ b/browser/components/screenshots/tests/browser/browser_screenshots_test_toggle_pref.js @@ -9,6 +9,7 @@ const { sinon } = ChromeUtils.importESModule( ChromeUtils.defineESModuleGetters(this, { ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs", + AddonManager: "resource://gre/modules/AddonManager.sys.mjs", }); ChromeUtils.defineLazyGetter(this, "ExtensionManagement", () => { const { Management } = ChromeUtils.importESModule( @@ -17,7 +18,11 @@ ChromeUtils.defineLazyGetter(this, "ExtensionManagement", () => { return Management; }); -add_task(async function test() { +const COMPONENT_PREF = "screenshots.browser.component.enabled"; +const SCREENSHOTS_PREF = "extensions.screenshots.disabled"; +const SCREENSHOT_EXTENSION = "screenshots@mozilla.org"; + +add_task(async function test_toggling_screenshots_pref() { let observerSpy = sinon.spy(); let notifierSpy = sinon.spy(); @@ -31,13 +36,24 @@ add_task(async function test() { ScreenshotsUtils.notify.wrappedMethod.apply(this, arguments); }); + // wait for startup idle tasks to complete + await new Promise(resolve => ChromeUtils.idleDispatch(resolve)); + ok(Services.prefs.getBoolPref(COMPONENT_PREF), "Component enabled"); + ok(!Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots enabled"); + + let addon = await AddonManager.getAddonByID(SCREENSHOT_EXTENSION); + await BrowserTestUtils.waitForCondition( + () => !addon.isActive, + "The extension is not active when the component is prefd on" + ); + await BrowserTestUtils.withNewTab( { gBrowser, url: SHORT_TEST_PAGE, }, async browser => { - function awaitExtensionEvent(eventName, id) { + function extensionEventPromise(eventName, id) { return new Promise(resolve => { let listener = (_eventName, ...args) => { let extension = args[0]; @@ -49,9 +65,21 @@ add_task(async function test() { ExtensionManagement.on(eventName, listener); }); } - const SCREENSHOT_EXTENSION = "screenshots@mozilla.org"; let helper = new ScreenshotsHelper(browser); + ok( + addon.userDisabled, + "The extension is disabled when the component is prefd on" + ); + ok( + !addon.isActive, + "The extension is not initially active when the component is prefd on" + ); + await BrowserTestUtils.waitForCondition( + () => ScreenshotsUtils.initialized, + "The component is initialized" + ); + ok(ScreenshotsUtils.initialized, "The component is initialized"); ok(observerSpy.notCalled, "Observer not called"); helper.triggerUIFromToolbar(); @@ -80,12 +108,20 @@ add_task(async function test() { Assert.equal(observerSpy.callCount, 3, "Observer function called thrice"); - const COMPONENT_PREF = "screenshots.browser.component.enabled"; - await SpecialPowers.pushPrefEnv({ - set: [[COMPONENT_PREF, false]], - }); + let extensionReadyPromise = extensionEventPromise( + "ready", + SCREENSHOT_EXTENSION + ); + Services.prefs.setBoolPref(COMPONENT_PREF, false); ok(!Services.prefs.getBoolPref(COMPONENT_PREF), "Extension enabled"); - await awaitExtensionEvent("ready", SCREENSHOT_EXTENSION); + + info("Waiting for the extension ready event"); + await extensionReadyPromise; + await BrowserTestUtils.waitForCondition( + () => !addon.userDisabled, + "The extension gets un-disabled when the component is prefd off" + ); + ok(addon.isActive, "Extension is active"); helper.triggerUIFromToolbar(); Assert.equal( @@ -94,6 +130,7 @@ add_task(async function test() { "Observer function still called thrice" ); + info("Waiting for the extensions overlay"); await SpecialPowers.spawn( browser, ["#firefox-screenshots-preselection-iframe"], @@ -115,6 +152,7 @@ add_task(async function test() { } ); + info("Waiting for the extensions overlay"); helper.triggerUIFromToolbar(); await SpecialPowers.spawn( browser, @@ -202,9 +240,7 @@ add_task(async function test() { "screenshots-component-initialized" ); - await SpecialPowers.pushPrefEnv({ - set: [[COMPONENT_PREF, true]], - }); + Services.prefs.setBoolPref(COMPONENT_PREF, true); ok(Services.prefs.getBoolPref(COMPONENT_PREF), "Component enabled"); // Needed for component to initialize await componentReady; @@ -215,12 +251,6 @@ add_task(async function test() { 4, "Observer function called four times" ); - - const SCREENSHOTS_PREF = "extensions.screenshots.disabled"; - await SpecialPowers.pushPrefEnv({ - set: [[SCREENSHOTS_PREF, true]], - }); - ok(Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots disabled"); } ); @@ -230,7 +260,9 @@ add_task(async function test() { url: SHORT_TEST_PAGE, }, async browser => { - const SCREENSHOTS_PREF = "extensions.screenshots.disabled"; + Services.prefs.setBoolPref(SCREENSHOTS_PREF, true); + Services.prefs.setBoolPref(COMPONENT_PREF, true); + ok(Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots disabled"); ok( @@ -255,22 +287,23 @@ add_task(async function test() { menu.hidePopup(); await popuphidden; - await SpecialPowers.pushPrefEnv({ - set: [[SCREENSHOTS_PREF, false]], - }); - ok(!Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots enabled"); - } - ); + let componentReady = TestUtils.topicObserved( + "screenshots-component-initialized" + ); + + Services.prefs.setBoolPref(SCREENSHOTS_PREF, false); - await BrowserTestUtils.withNewTab( - { - gBrowser, - url: SHORT_TEST_PAGE, - }, - async browser => { - const SCREENSHOTS_PREF = "extensions.screenshots.disabled"; ok(!Services.prefs.getBoolPref(SCREENSHOTS_PREF), "Screenshots enabled"); + await componentReady; + + ok(ScreenshotsUtils.initialized, "The component is initialized"); + + ok( + !document.getElementById("screenshot-button").disabled, + "Toolbar button is enabled" + ); + let helper = new ScreenshotsHelper(browser); helper.triggerUIFromToolbar(); @@ -284,6 +317,4 @@ add_task(async function test() { observerStub.restore(); notifierStub.restore(); - - await SpecialPowers.popPrefEnv(); }); |