/* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; const { sinon } = ChromeUtils.importESModule( "resource://testing-common/Sinon.sys.mjs" ); const { IPProtectionWidget } = ChromeUtils.importESModule( "moz-src:///browser/components/ipprotection/IPProtection.sys.mjs" ); const { IPPNimbusHelper } = ChromeUtils.importESModule( "moz-src:///toolkit/components/ipprotection/IPPNimbusHelper.sys.mjs" ); const { IPProtectionService, IPProtectionStates } = ChromeUtils.importESModule( "moz-src:///toolkit/components/ipprotection/IPProtectionService.sys.mjs" ); // Enabling IP Protection adds its button to the navbar defaults, so put them // back for the next run in the same browser. const navbarArea = CustomizableUI.getTestOnlyInternalProp("gAreas").get( CustomizableUI.AREA_NAVBAR ); const navbarDefaults = [...navbarArea.get("defaultPlacements")]; const sandbox = sinon.createSandbox(); registerCleanupFunction(() => { sandbox.restore(); navbarArea.set("defaultPlacements", navbarDefaults); CustomizableUI.reset(); }); add_task(async function test_default_state_while_unavailable() { sandbox.stub(IPPNimbusHelper, "hidesFeature").returns(true); let unavailable = BrowserTestUtils.waitForEvent( IPProtectionService, "IPProtectionService:StateChanged", false, () => IPProtectionService.state === IPProtectionStates.UNAVAILABLE ); await SpecialPowers.pushPrefEnv({ set: [["browser.ipProtection.enabled", true]], }); await unavailable; ok( CustomizableUI.getDefaultPlacementsForArea( CustomizableUI.AREA_NAVBAR ).includes(IPProtectionWidget.WIDGET_ID), `${IPProtectionWidget.WIDGET_ID} should be in the navbar defaults` ); ok( !document.getElementById(IPProtectionWidget.WIDGET_ID), `${IPProtectionWidget.WIDGET_ID} shouldn't be created` ); ok(CustomizableUI.inDefaultState, "Should be in default state"); await startCustomizing(); ok( document.getElementById("customization-reset-button").disabled, "Restore Defaults should be disabled" ); await endCustomizing(); await SpecialPowers.popPrefEnv(); });