Skip to content

Commit

Permalink
Bug 1879855 - Test, r=Gijs
Browse files Browse the repository at this point in the history
  • Loading branch information
Trikolon committed Feb 13, 2024
1 parent 5c1a5ee commit 8b4f4b7
Showing 1 changed file with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,118 @@ add_task(async function test_notificationWindowMove() {
// Reset window position
window.moveTo(screenX, screenY);
});

/**
* Tests that the security delay gets extended if a notification is shown during
* a full screen transition.
*/
add_task(async function test_notificationDuringFullScreenTransition() {
await BrowserTestUtils.withNewTab("https://example.com", async browser => {
await SpecialPowers.pushPrefEnv({
set: [
// Set a short security delay so we can observe it being extended.
["security.notification_enable_delay", 1],
// Set a longer full screen exit transition so the test works on slow builds.
["full-screen-api.transition-duration.leave", "1000 1000"],
// Waive the user activation requirement for full screen requests.
// The PoC this test is based on relies on spam clicking which grants
// user activation in the popup that requests full screen.
// This isn't reliable in automation.
["full-screen-api.allow-trusted-requests-only", false],
// macOS native full screen is not affected by the full screen
// transition overlap. Test with the old full screen implementation.
["full-screen-api.macos-native-full-screen", false],
],
});

await ensureSecurityDelayReady();

ok(
!PopupNotifications.isPanelOpen,
"PopupNotification panel should not be open initially."
);

info("Open a notification.");
let popupShownPromise = waitForNotificationPanel();
showNotification();
await popupShownPromise;
ok(
PopupNotifications.isPanelOpen,
"PopupNotification should be open after show call."
);

let notification = PopupNotifications.getNotification("foo", browser);
is(notification?.id, "foo", "There should be a notification with id foo");

info(
"Open a new tab via window.open, enter full screen and remove the tab."
);

let fullScreenTransitionEnded = false;
let promiseFullScreenTransitionStart = TestUtils.topicObserved(
"fullscreen-transition-start"
);
let promiseFullScreenTransitionEnd = TestUtils.topicObserved(
"fullscreen-transition-end"
).then(() => {
fullScreenTransitionEnded = true;
});
let notificationShownPromise = waitForNotificationPanel();

await SpecialPowers.spawn(browser, [], () => {
// Use eval to execute in the privilege context of the website.
content.eval(`
let button = document.createElement("button");
button.id = "triggerBtn";
button.innerText = "Open Popup";
button.addEventListener("click", () => {
let popup = window.open("about:blank");
popup.document.write(
"<script>setTimeout(() => document.documentElement.requestFullscreen(), 500)</script>"
);
popup.document.write(
"<script>setTimeout(() => window.close(), 1500)</script>"
);
});
// Insert button at the top so the synthesized click works. Otherwise
// the button may be outside of the viewport.
document.body.prepend(button);
`);
});

await BrowserTestUtils.synthesizeMouseAtCenter("#triggerBtn", {}, browser);

await promiseFullScreenTransitionStart;
info("Full screen transition start");
ok(true, "Full screen transition started");
ok(!fullScreenTransitionEnded, "Full screen transition is still running.");

info(
"Wait for notification to re-show on tab switch, after the popup has been closed"
);
await notificationShownPromise;

info(
"Trigger main action via button click during the extended security delay."
);
triggerMainCommand(PopupNotifications.panel);

await new Promise(resolve => setTimeout(resolve, 0));

ok(
PopupNotifications.isPanelOpen,
"PopupNotification should still be open."
);
notification = PopupNotifications.getNotification(
"foo",
gBrowser.selectedBrowser
);
ok(
notification,
"Notification should still be open because we clicked during the security delay."
);

info("Wait for full screen transition end.");
await promiseFullScreenTransitionEnd;
});
});

0 comments on commit 8b4f4b7

Please sign in to comment.