Skip to content

Commit

Permalink
Bug 1800207 - Make test browser_fullscreen-document-mutation-navigati…
Browse files Browse the repository at this point in the history
…on.js more robust; r=smaug

`window.fullscreen` on chrome window is for whether the corresponding widget is
in fullscreen screen state, wait DOM fullscreen event for its state change isn't
accurate, so wait for `fullscreen` event fired on chrome window which is used
for widget fullscreen state change instead.

Differential Revision: https://phabricator.services.mozilla.com/D161883
  • Loading branch information
EdgarChen committed Nov 11, 2022
1 parent 0c19873 commit f86aaf6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ async function startTests(testFun, name) {
await promiseFsState;

// This test triggers a fullscreen request during the fullscreen exit
// process, so it could be possible that document goes into fullscreen
// process, so it could be possible that widget goes into fullscreen
// mode again, but it should end up leave fullscreen mode again.
if (window.fullScreen) {
info("still in fullscreen, wait again");
await waitForFullscreenState(document, false, true);
info("widget is still in fullscreen, wait again");
await waitWidgetFullscreenEvent(window, false, true);
}

// Ensure the browser exits fullscreen state.
ok(!window.fullScreen, "The widget should not be in fullscreen");
ok(
!window.fullScreen,
!document.documentElement.hasAttribute("inFullscreen"),
"The chrome window should not be in fullscreen"
);
ok(
Expand Down
42 changes: 37 additions & 5 deletions dom/base/test/fullscreen/fullscreen_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function waitRemoteFullscreenExitEvents(aBrowsingContexts) {
return;
}

ok(true, `check remote fullscreen event (${name})`);
ok(true, `check remote DOM fullscreen event (${name})`);
document.removeEventListener("fullscreenchange", changeHandler);
resolve();
}
Expand All @@ -45,7 +45,11 @@ function waitRemoteFullscreenExitEvents(aBrowsingContexts) {
return Promise.all(promises);
}

function waitFullscreenEvent(aDocument, aIsInFullscreen, aWaitUntil = false) {
function waitDOMFullscreenEvent(
aDocument,
aIsInFullscreen,
aWaitUntil = false
) {
return new Promise(resolve => {
function errorHandler() {
ok(false, "should not get fullscreenerror event");
Expand All @@ -62,7 +66,7 @@ function waitFullscreenEvent(aDocument, aIsInFullscreen, aWaitUntil = false) {
is(
aIsInFullscreen,
!!aDocument.fullscreenElement,
"check fullscreen (event)"
"check DOM fullscreen (event)"
);
aDocument.removeEventListener("fullscreenchange", changeHandler);
aDocument.removeEventListener("fullscreenerror", errorHandler);
Expand All @@ -74,6 +78,29 @@ function waitFullscreenEvent(aDocument, aIsInFullscreen, aWaitUntil = false) {
});
}

function waitWidgetFullscreenEvent(
aWindow,
aIsInFullscreen,
aWaitUntil = false
) {
return BrowserTestUtils.waitForEvent(aWindow, "fullscreen", false, aEvent => {
if (
aWaitUntil &&
aIsInFullscreen !=
aWindow.document.documentElement.hasAttribute("inFullscreen")
) {
return false;
}

is(
aIsInFullscreen,
aWindow.document.documentElement.hasAttribute("inFullscreen"),
"check widget fullscreen (event)"
);
return true;
});
}

function waitForFullScreenObserver(
aDocument,
aIsInFullscreen,
Expand Down Expand Up @@ -103,7 +130,12 @@ function waitForFullscreenState(
aWaitUntil = false
) {
return Promise.all([
waitFullscreenEvent(aDocument, aIsInFullscreen, aWaitUntil),
waitWidgetFullscreenEvent(
aDocument.defaultView,
aIsInFullscreen,
aWaitUntil
),
waitDOMFullscreenEvent(aDocument, aIsInFullscreen, aWaitUntil),
waitForFullScreenObserver(aDocument, aIsInFullscreen, aWaitUntil),
]);
}
Expand All @@ -122,7 +154,7 @@ async function waitForFullscreenExit(aDocument) {
};
Services.obs.addObserver(observer, "fullscreen-painted");

await waitFullscreenEvent(aDocument, false, true);
await waitDOMFullscreenEvent(aDocument, false, true);
// If there is a fullscreen-painted observer notified for inDOMFullscreen set,
// we expect to have a subsequent fullscreen-painted observer notified with
// inDOMFullscreen unset.
Expand Down

0 comments on commit f86aaf6

Please sign in to comment.