Bug 1659064 - wait until tab becomes a focus tab. r=bryce

Differential Revision: https://phabricator.services.mozilla.com/D87836
This commit is contained in:
alwu 2020-08-21 18:38:59 +00:00
Родитель 6e60dd681f
Коммит db978c9443
1 изменённых файлов: 19 добавлений и 0 удалений

Просмотреть файл

@ -62,6 +62,7 @@ add_task(async function testNoSrcOrErrorMediaEntersFullscreen() {
};
info(`enter fullscreen several times and controller should keep inactive`);
await ensureTabIsAlreadyFocused(tab);
for (let idx = 0; idx < 3; idx++) {
await enterAndLeaveFullScreen(tab, testVideoId);
}
@ -75,6 +76,24 @@ add_task(async function testNoSrcOrErrorMediaEntersFullscreen() {
/**
* The following is helper function.
*/
function ensureTabIsAlreadyFocused(tab) {
return SpecialPowers.spawn(tab.linkedBrowser, [], () => {
// fullscreen can only be request from a visible tab, sometime we excecute
// this method too early where the tab hasn't become a focus tab.
if (content.document.visibilityState != "visible") {
info(`wait until tab becomes a focus tab`);
return new Promise(r => {
content.document.onvisibilitychange = () => {
if (content.document.visibilityState == "visible") {
r();
}
};
});
}
return Promise.resolve();
});
}
function enterAndLeaveFullScreen(tab, elementId) {
return SpecialPowers.spawn(tab.linkedBrowser, [elementId], elementId => {
return new Promise(r => {