/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ /* eslint-disable mozilla/no-arbitrary-setTimeout */ "use strict"; const ORIGIN = "https://example.com"; const PERMISSIONS_PAGE = getRootDirectory(gTestPath).replace("chrome://mochitests/content", ORIGIN) + "permissions.html"; // Ignore promise rejection caused by clicking Deny button. const { PromiseTestUtils } = ChromeUtils.import( "resource://testing-common/PromiseTestUtils.jsm" ); PromiseTestUtils.allowMatchingRejectionsGlobally(/The request is not allowed/); const EXPIRE_TIME_MS = 100; const TIMEOUT_MS = 500; const kVREnabled = SpecialPowers.getBoolPref("dom.vr.enabled"); // Test that temporary permissions can be re-requested after they expired // and that the identity block is updated accordingly. add_task(async function testTempPermissionRequestAfterExpiry() { await SpecialPowers.pushPrefEnv({ set: [ ["privacy.temporary_permission_expire_time_ms", EXPIRE_TIME_MS], ["media.navigator.permission.fake", true], ["dom.vr.always_support_vr", true], ], }); let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin( ORIGIN ); let ids = ["geo", "camera"]; if (kVREnabled) { ids.push("xr"); } for (let id of ids) { await BrowserTestUtils.withNewTab(PERMISSIONS_PAGE, async function( browser ) { let blockedIcon = gIdentityHandler._identityBox.querySelector( `.blocked-permission-icon[data-permission-id='${id}']` ); SitePermissions.setForPrincipal( principal, id, SitePermissions.BLOCK, SitePermissions.SCOPE_TEMPORARY, browser ); Assert.deepEqual( SitePermissions.getForPrincipal(principal, id, browser), { state: SitePermissions.BLOCK, scope: SitePermissions.SCOPE_TEMPORARY, } ); ok( blockedIcon.hasAttribute("showing"), "blocked permission icon is shown" ); await new Promise(c => setTimeout(c, TIMEOUT_MS)); Assert.deepEqual( SitePermissions.getForPrincipal(principal, id, browser), { state: SitePermissions.UNKNOWN, scope: SitePermissions.SCOPE_PERSISTENT, } ); let popupshown = BrowserTestUtils.waitForEvent( PopupNotifications.panel, "popupshown" ); // Request a permission; await BrowserTestUtils.synthesizeMouseAtCenter(`#${id}`, {}, browser); await popupshown; ok( !blockedIcon.hasAttribute("showing"), "blocked permission icon is not shown" ); let popuphidden = BrowserTestUtils.waitForEvent( PopupNotifications.panel, "popuphidden" ); let notification = PopupNotifications.panel.firstElementChild; EventUtils.synthesizeMouseAtCenter(notification.secondaryButton, {}); await popuphidden; SitePermissions.removeFromPrincipal(principal, id, browser); }); } });