forked from mirrors/gecko-dev
And have it mirror in the parent process more automatically. The docShellIsActive setter in the browser-custom-element side needs to be there rather than in the usual DidSet() calls because the AsyncTabSwitcher code relies on getting an exact amount of notifications as response to that specific setter. Not pretty, but... BrowserChild no longer sets IsActive() on the docshell itself for OOP iframes. This fixes bug 1679521. PresShell activeness is used to throttle rAF as well, which handles OOP iframes nicely as well. Differential Revision: https://phabricator.services.mozilla.com/D96072
125 lines
3.6 KiB
JavaScript
125 lines
3.6 KiB
JavaScript
const { ContentTaskUtils } = ChromeUtils.import(
|
|
"resource://testing-common/ContentTaskUtils.jsm"
|
|
);
|
|
function waitForFullScreenState(browser, state) {
|
|
return new Promise(resolve => {
|
|
let eventReceived = false;
|
|
|
|
let observe = (subject, topic, data) => {
|
|
if (!eventReceived) {
|
|
return;
|
|
}
|
|
Services.obs.removeObserver(observe, "fullscreen-painted");
|
|
resolve();
|
|
};
|
|
Services.obs.addObserver(observe, "fullscreen-painted");
|
|
|
|
browser.ownerGlobal.addEventListener(
|
|
`MozDOMFullscreen:${state ? "Entered" : "Exited"}`,
|
|
() => {
|
|
eventReceived = true;
|
|
},
|
|
{ once: true }
|
|
);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Spawns content task in browser to enter / leave fullscreen
|
|
* @param browser - Browser to use for JS fullscreen requests
|
|
* @param {Boolean} fullscreenState - true to enter fullscreen, false to leave
|
|
* @returns {Promise} - Resolves once fullscreen change is applied
|
|
*/
|
|
async function changeFullscreen(browser, fullScreenState) {
|
|
await new Promise(resolve =>
|
|
SimpleTest.waitForFocus(resolve, browser.ownerGlobal)
|
|
);
|
|
let fullScreenChange = waitForFullScreenState(browser, fullScreenState);
|
|
SpecialPowers.spawn(browser, [fullScreenState], async state => {
|
|
// Wait for document focus before requesting full-screen
|
|
await ContentTaskUtils.waitForCondition(
|
|
() => content.browsingContext.isActive && content.document.hasFocus(),
|
|
"Waiting for document focus"
|
|
);
|
|
if (state) {
|
|
content.document.body.requestFullscreen();
|
|
} else {
|
|
content.document.exitFullscreen();
|
|
}
|
|
});
|
|
return fullScreenChange;
|
|
}
|
|
|
|
async function testExpectFullScreenExit(browser, leaveFS, action) {
|
|
let fsPromise = waitForFullScreenState(browser, !leaveFS);
|
|
if (leaveFS) {
|
|
if (action) {
|
|
await action();
|
|
}
|
|
await fsPromise;
|
|
ok(true, "Should leave full-screen");
|
|
} else {
|
|
if (action) {
|
|
await action();
|
|
}
|
|
let result = await Promise.race([
|
|
fsPromise,
|
|
new Promise(resolve => {
|
|
SimpleTest.requestFlakyTimeout("Wait for failure condition");
|
|
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
|
setTimeout(() => resolve(true), 2500);
|
|
}),
|
|
]);
|
|
ok(result, "Should not leave full-screen");
|
|
}
|
|
}
|
|
|
|
function jsWindowFocus(browser, iframeId) {
|
|
return ContentTask.spawn(browser, { iframeId }, async args => {
|
|
let destWin = content;
|
|
if (args.iframeId) {
|
|
let iframe = content.document.getElementById(args.iframeId);
|
|
if (!iframe) {
|
|
throw new Error("iframe not set");
|
|
}
|
|
destWin = iframe.contentWindow;
|
|
}
|
|
await content.wrappedJSObject.sendMessage(destWin, "focus");
|
|
});
|
|
}
|
|
|
|
async function jsWindowOpen(browser, iframeId) {
|
|
let windowOpened = BrowserTestUtils.waitForNewWindow();
|
|
ContentTask.spawn(browser, { iframeId }, async args => {
|
|
let destWin = content;
|
|
if (args.iframeId) {
|
|
// Create a cross origin iframe
|
|
destWin = (
|
|
await content.wrappedJSObject.createIframe(args.iframeId, true)
|
|
).contentWindow;
|
|
}
|
|
// Send message to either the iframe or the current page to open a popup
|
|
await content.wrappedJSObject.sendMessage(destWin, "open");
|
|
});
|
|
return windowOpened;
|
|
}
|
|
|
|
function waitForFocus(...args) {
|
|
return new Promise(resolve => SimpleTest.waitForFocus(resolve, ...args));
|
|
}
|
|
|
|
function waitForBrowserWindowActive(win) {
|
|
return new Promise(resolve => {
|
|
if (Services.focus.activeWindow == win) {
|
|
resolve();
|
|
} else {
|
|
win.addEventListener(
|
|
"activate",
|
|
() => {
|
|
resolve();
|
|
},
|
|
{ once: true }
|
|
);
|
|
}
|
|
});
|
|
}
|