Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

/* Any copyright is dedicated to the Public Domain.
"use strict";
const { sinon } = ChromeUtils.importESModule(
);
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();
});