From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../captivePortal/browser_CaptivePortalWatcher.js | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 browser/base/content/test/captivePortal/browser_CaptivePortalWatcher.js (limited to 'browser/base/content/test/captivePortal/browser_CaptivePortalWatcher.js') diff --git a/browser/base/content/test/captivePortal/browser_CaptivePortalWatcher.js b/browser/base/content/test/captivePortal/browser_CaptivePortalWatcher.js new file mode 100644 index 0000000000..aeafae21d8 --- /dev/null +++ b/browser/base/content/test/captivePortal/browser_CaptivePortalWatcher.js @@ -0,0 +1,125 @@ +/* eslint-disable mozilla/no-arbitrary-setTimeout */ +"use strict"; + +// Bug 1318389 - This test does a lot of window and tab manipulation, +// causing it to take a long time on debug. +requestLongerTimeout(2); + +add_task(setupPrefsAndRecentWindowBehavior); + +// Each of the test cases below is run twice: once for login-success and once +// for login-abort (aSuccess set to true and false respectively). +let testCasesForBothSuccessAndAbort = [ + /** + * A portal is detected when there's no browser window, then a browser + * window is opened, then the portal is freed. + * The portal tab should be added and focused when the window is + * opened, and closed automatically when the success event is fired. + * The captive portal notification should be shown when the window is + * opened, and closed automatically when the success event is fired. + */ + async function test_detectedWithNoBrowserWindow_Open(aSuccess) { + await portalDetected(); + let win = await focusWindowAndWaitForPortalUI(); + await freePortal(aSuccess); + ensureNoPortalTab(win); + ensureNoPortalNotification(win); + await closeWindowAndWaitForWindowActivate(win); + }, + + /** + * A portal is detected when multiple browser windows are open but none + * have focus. A browser window is focused, then the portal is freed. + * The portal tab should be added and focused when the window is + * focused, and closed automatically when the success event is fired. + * The captive portal notification should be shown in all windows upon + * detection, and closed automatically when the success event is fired. + */ + async function test_detectedWithNoBrowserWindow_Focused(aSuccess) { + let win1 = await openWindowAndWaitForFocus(); + let win2 = await openWindowAndWaitForFocus(); + // Defocus both windows. + await SimpleTest.promiseFocus(window); + + await portalDetected(); + + // Notification should be shown in both windows. + ensurePortalNotification(win1); + ensureNoPortalTab(win1); + ensurePortalNotification(win2); + ensureNoPortalTab(win2); + + await focusWindowAndWaitForPortalUI(false, win2); + + await freePortal(aSuccess); + + ensureNoPortalNotification(win1); + ensureNoPortalTab(win2); + ensureNoPortalNotification(win2); + + await closeWindowAndWaitForWindowActivate(win2); + // No need to wait for xul-window-visible: after win2 is closed, focus + // is restored to the default window and win1 remains in the background. + await BrowserTestUtils.closeWindow(win1); + }, + + /** + * A portal is detected when there's no browser window, then a browser + * window is opened, then the portal is freed. + * The recheck triggered when the browser window is opened takes a + * long time. No portal tab should be added. + * The captive portal notification should be shown when the window is + * opened, and closed automatically when the success event is fired. + */ + async function test_detectedWithNoBrowserWindow_LongRecheck(aSuccess) { + await portalDetected(); + let win = await focusWindowAndWaitForPortalUI(true); + await freePortal(aSuccess); + ensureNoPortalTab(win); + ensureNoPortalNotification(win); + await closeWindowAndWaitForWindowActivate(win); + }, + + /** + * A portal is detected when there's no browser window, and the + * portal is freed before a browser window is opened. No portal + * UI should be shown when a browser window is opened. + */ + async function test_detectedWithNoBrowserWindow_GoneBeforeOpen(aSuccess) { + await portalDetected(); + await freePortal(aSuccess); + let win = await openWindowAndWaitForFocus(); + // Wait for a while to make sure no UI is shown. + await new Promise(resolve => { + setTimeout(resolve, 1000); + }); + ensureNoPortalTab(win); + ensureNoPortalNotification(win); + await closeWindowAndWaitForWindowActivate(win); + }, + + /** + * A portal is detected when a browser window has focus. No portal tab should + * be opened. A notification bar should be displayed in all browser windows. + */ + async function test_detectedWithFocus(aSuccess) { + let win1 = await openWindowAndWaitForFocus(); + let win2 = await openWindowAndWaitForFocus(); + await portalDetected(); + ensureNoPortalTab(win1); + ensureNoPortalTab(win2); + ensurePortalNotification(win1); + ensurePortalNotification(win2); + await freePortal(aSuccess); + ensureNoPortalNotification(win1); + ensureNoPortalNotification(win2); + await BrowserTestUtils.closeWindow(win2); + await BrowserTestUtils.closeWindow(win1); + await waitForBrowserWindowActive(window); + }, +]; + +for (let testcase of testCasesForBothSuccessAndAbort) { + add_task(testcase.bind(null, true)); + add_task(testcase.bind(null, false)); +} -- cgit v1.2.3