mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 1522058 - Fix race in clearing global permissions. r=johannh
Differential Revision: https://phabricator.services.mozilla.com/D21381 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
f8bd8ea10e
commit
2fc441d686
@ -24,6 +24,11 @@ function autoplayBlockedIcon() {
|
||||
".blocked-permission-icon.autoplay-media-icon");
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
/* eslint-disable mozilla/no-arbitrary-setTimeout */
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async function blockedIconShown(browser) {
|
||||
// May need to wait for `GloballyAutoplayBlocked` event before showing icon.
|
||||
if (BrowserTestUtils.is_hidden(autoplayBlockedIcon())) {
|
||||
@ -117,3 +122,29 @@ add_task(async function testGloballyBlockedOnNewWindow() {
|
||||
SitePermissions.remove(uri, AUTOPLAY_PERM, tab.linkedBrowser);
|
||||
await BrowserTestUtils.closeWindow(win);
|
||||
});
|
||||
|
||||
add_task(async function testBFCache() {
|
||||
Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.BLOCKED);
|
||||
|
||||
await BrowserTestUtils.withNewTab("about:home", async function(browser) {
|
||||
await BrowserTestUtils.loadURI(browser, AUTOPLAY_PAGE);
|
||||
await blockedIconShown(browser);
|
||||
Services.prefs.setIntPref(AUTOPLAY_PREF, Ci.nsIAutoplay.ALLOWED);
|
||||
|
||||
gBrowser.goBack();
|
||||
await TestUtils.waitForCondition(() => {
|
||||
return BrowserTestUtils.is_hidden(autoplayBlockedIcon());
|
||||
});
|
||||
|
||||
gBrowser.goForward();
|
||||
|
||||
// Sleep here to prevent false positives, the icon gets shown with an
|
||||
// async `GloballyAutoplayBlocked` event. The sleep gives it a little
|
||||
// time for it to show otherwise there is a chance it passes before it
|
||||
// would have shown.
|
||||
await sleep(100);
|
||||
ok(BrowserTestUtils.is_hidden(autoplayBlockedIcon()), "Blocked icon is hidden");
|
||||
});
|
||||
|
||||
Services.perms.removeAll();
|
||||
});
|
||||
|
@ -157,7 +157,7 @@ const GloballyBlockedPermissions = {
|
||||
Ci.nsISupportsWeakReference]),
|
||||
onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {
|
||||
if (aWebProgress.isTopLevel) {
|
||||
GloballyBlockedPermissions.remove(browser, id);
|
||||
GloballyBlockedPermissions.remove(browser, id, prePath);
|
||||
browser.removeProgressListener(this);
|
||||
}
|
||||
},
|
||||
@ -165,9 +165,11 @@ const GloballyBlockedPermissions = {
|
||||
},
|
||||
|
||||
// Removes a permission with the specified id for the specified browser.
|
||||
remove(browser, id) {
|
||||
remove(browser, id, prePath = null) {
|
||||
let entry = this._stateByBrowser.get(browser);
|
||||
let prePath = browser.currentURI.prePath;
|
||||
if (!prePath) {
|
||||
prePath = browser.currentURI.prePath;
|
||||
}
|
||||
if (entry && entry[prePath]) {
|
||||
delete entry[prePath][id];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user