Skip to content

Commit

Permalink
Bug 1596897 - Updated tests for decoupled permissions panel. r=johann…
Browse files Browse the repository at this point in the history
…h,remote-protocol-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D99893
  • Loading branch information
Trikolon committed Jan 29, 2021
1 parent 6445d18 commit 3d47675
Show file tree
Hide file tree
Showing 31 changed files with 348 additions and 320 deletions.
2 changes: 1 addition & 1 deletion accessible/tests/browser/mac/browser_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ add_task(async () => {
is(rootChildCount(), 5, "Root has 5 children");

// Open site identity popup
document.getElementById("identity-box").click();
document.getElementById("identity-icon-box").click();
const identityPopup = document.getElementById("identity-popup");
await BrowserTestUtils.waitForPopupEvent(identityPopup, "shown");

Expand Down
12 changes: 7 additions & 5 deletions browser/base/content/test/fullscreen/browser_bug1557041.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ add_task(async function test_identityPopupCausesFSExit() {
BrowserTestUtils.loadURI(browser, url);
await loaded;

let identityBox = document.getElementById("identity-box");
let identityPermissionBox = document.getElementById(
"identity-permission-box"
);

info("Entering DOM fullscreen");
await changeFullscreen(browser, true);
Expand All @@ -30,16 +32,16 @@ add_task(async function test_identityPopupCausesFSExit() {
window,
"popupshown",
true,
event => event.target == document.getElementById("identity-popup")
event => event.target == document.getElementById("permission-popup")
);
let fsExit = waitForFullScreenState(browser, false);

identityBox.click();
identityPermissionBox.click();

info("Waiting for fullscreen exit and identity popup to show");
info("Waiting for fullscreen exit and permission popup to show");
await Promise.all([fsExit, popupShown]);

let identityPopup = document.getElementById("identity-popup");
let identityPopup = document.getElementById("permission-popup");
ok(
identityPopup.hasAttribute("panelopen"),
"Identity popup should be open"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add_task(async function() {
true,
event => event.target == gIdentityHandler._identityPopup
);
gIdentityHandler._identityBox.click();
gIdentityHandler._identityIconBox.click();
await promisePanelOpen;

let promiseViewShown = BrowserTestUtils.waitForEvent(
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/test/general/browser_drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function test() {
gURLBar.setPageProxyState("valid");
let result = await EventUtils.synthesizePlainDragAndCancel(
{
srcElement: document.getElementById("identity-box"),
srcElement: document.getElementById("identity-icon-box"),
},
expected
);
Expand Down
11 changes: 9 additions & 2 deletions browser/base/content/test/keyboard/browser_toolbarKeyNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,18 +353,25 @@ add_task(async function testPanelCloseRestoresFocus() {
// Test that the arrow key works in the group of the
// 'tracking-protection-icon-container' and the 'identity-box'.
add_task(async function testArrowKeyForTPIconContainerandIdentityBox() {
await BrowserTestUtils.withNewTab("https://example.com", async function() {
await BrowserTestUtils.withNewTab("https://example.com", async function(
browser
) {
// Simulate geo sharing so the permission box shows
gBrowser.updateBrowserSharing(browser, { geo: true });
await waitUntilReloadEnabled();
startFromUrlBar();
await expectFocusAfterKey(
"Shift+Tab",
"tracking-protection-icon-container"
);
await expectFocusAfterKey("ArrowRight", "identity-box");
await expectFocusAfterKey("ArrowRight", "identity-icon-box");
await expectFocusAfterKey("ArrowRight", "identity-permission-box");
await expectFocusAfterKey("ArrowLeft", "identity-icon-box");
await expectFocusAfterKey(
"ArrowLeft",
"tracking-protection-icon-container"
);
gBrowser.updateBrowserSharing(browser, { geo: false });
});
});

Expand Down
62 changes: 34 additions & 28 deletions browser/base/content/test/permissions/browser_autoplay_blocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ const EMPTY_PAGE =
const AUTOPLAY_PREF = "media.autoplay.default";
const AUTOPLAY_PERM = "autoplay-media";

function openIdentityPopup() {
function openPermissionPopup() {
let promise = BrowserTestUtils.waitForEvent(
gBrowser.ownerGlobal,
"popupshown",
true,
event => event.target == gIdentityHandler._identityPopup
event => event.target == gPermissionPanel._permissionPopup
);
gIdentityHandler._identityBox.click();
gPermissionPanel._identityPermissionBox.click();
return promise;
}

function closeIdentityPopup() {
function closePermissionPopup() {
let promise = BrowserTestUtils.waitForEvent(
gIdentityHandler._identityPopup,
gPermissionPanel._permissionPopup,
"popuphidden"
);
gIdentityHandler._identityPopup.hidePopup();
gPermissionPanel._permissionPopup.hidePopup();
return promise;
}

Expand All @@ -58,7 +58,7 @@ function autoplayBlockedIcon() {

function permissionListBlockedIcons() {
return document.querySelectorAll(
"image.identity-popup-permission-icon.blocked-permission-icon"
"image.permission-popup-permission-icon.blocked-permission-icon"
);
}

Expand All @@ -79,6 +79,20 @@ async function blockedIconHidden() {
}, "Blocked icon is hidden");
}

function testPermListHasEntries(expectEntries) {
let permissionsList = document.getElementById(
"permission-popup-permission-list"
);
let listEntryCount = permissionsList.querySelectorAll(
".permission-popup-permission-item"
).length;
if (expectEntries) {
ok(listEntryCount, "List of permissions is not empty");
return;
}
ok(!listEntryCount, "List of permissions is empty");
}

add_task(async function setup() {
registerCleanupFunction(() => {
Services.perms.removeAll();
Expand All @@ -90,44 +104,36 @@ add_task(async function testMainViewVisible() {
Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.ALLOWED);

await BrowserTestUtils.withNewTab(AUTOPLAY_PAGE, async function() {
let permissionsList = document.getElementById(
"identity-popup-permission-list"
);
let emptyLabel = permissionsList.nextElementSibling.nextElementSibling;

ok(
BrowserTestUtils.is_hidden(autoplayBlockedIcon()),
"Blocked icon not shown"
);

await openIdentityPopup();
ok(!BrowserTestUtils.is_hidden(emptyLabel), "List of permissions is empty");
await closeIdentityPopup();
await openPermissionPopup();
testPermListHasEntries(false);
await closePermissionPopup();
});

Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.BLOCKED);

await BrowserTestUtils.withNewTab(AUTOPLAY_PAGE, async function(browser) {
let permissionsList = document.getElementById(
"identity-popup-permission-list"
"permission-popup-permission-list"
);
let emptyLabel = permissionsList.nextElementSibling.nextElementSibling;

await blockedIconShown();

await openIdentityPopup();
ok(
BrowserTestUtils.is_hidden(emptyLabel),
"List of permissions is not empty"
);
await openPermissionPopup();
testPermListHasEntries(true);

let labelText = SitePermissions.getPermissionLabel(AUTOPLAY_PERM);
let labels = permissionsList.querySelectorAll(
".identity-popup-permission-label"
".permission-popup-permission-label"
);
is(labels.length, 1, "One permission visible in main view");
is(labels[0].textContent, labelText, "Correct value");

let menulist = document.getElementById("identity-popup-popup-menulist");
let menulist = document.getElementById("permission-popup-menulist");
Assert.equal(menulist.label, "Block Audio");

await EventUtils.synthesizeMouseAtCenter(menulist, { type: "mousedown" });
Expand All @@ -143,7 +149,7 @@ add_task(async function testMainViewVisible() {

menuitem.click();
menulist.menupopup.hidePopup();
await closeIdentityPopup();
await closePermissionPopup();

let uri = Services.io.newURI(AUTOPLAY_PAGE);
let state = PermissionTestUtils.getPermissionObject(uri, AUTOPLAY_PERM)
Expand Down Expand Up @@ -311,15 +317,15 @@ add_task(async function testBlockedAll() {
BrowserTestUtils.loadURI(browser, MUTED_AUTOPLAY_PAGE);
await blockedIconShown();

await openIdentityPopup();
await openPermissionPopup();

Assert.equal(
permissionListBlockedIcons().length,
1,
"Blocked icon is shown"
);

let menulist = document.getElementById("identity-popup-popup-menulist");
let menulist = document.getElementById("permission-popup-menulist");
await EventUtils.synthesizeMouseAtCenter(menulist, { type: "mousedown" });
await TestUtils.waitForCondition(() => {
return (
Expand All @@ -330,7 +336,7 @@ add_task(async function testBlockedAll() {
let menuitem = menulist.getElementsByTagName("menuitem")[0];
menuitem.click();
menulist.menupopup.hidePopup();
await closeIdentityPopup();
await closePermissionPopup();
gBrowser.reload();
await blockedIconHidden();
});
Expand Down
Loading

0 comments on commit 3d47675

Please sign in to comment.