1 /* eslint-disable mozilla/no-arbitrary-setTimeout */
4 // Bug 1318389 - This test does a lot of window and tab manipulation,
5 // causing it to take a long time on debug.
6 requestLongerTimeout(2);
8 add_task(setupPrefsAndRecentWindowBehavior);
10 // Each of the test cases below is run twice: once for login-success and once
11 // for login-abort (aSuccess set to true and false respectively).
12 let testCasesForBothSuccessAndAbort = [
14 * A portal is detected when there's no browser window, then a browser
15 * window is opened, then the portal is freed.
16 * The portal tab should be added and focused when the window is
17 * opened, and closed automatically when the success event is fired.
18 * The captive portal notification should be shown when the window is
19 * opened, and closed automatically when the success event is fired.
21 async function test_detectedWithNoBrowserWindow_Open(aSuccess) {
22 await portalDetected();
23 let win = await focusWindowAndWaitForPortalUI();
24 await freePortal(aSuccess);
25 ensureNoPortalTab(win);
26 ensureNoPortalNotification(win);
27 await closeWindowAndWaitForWindowActivate(win);
31 * A portal is detected when multiple browser windows are open but none
32 * have focus. A browser window is focused, then the portal is freed.
33 * The portal tab should be added and focused when the window is
34 * focused, and closed automatically when the success event is fired.
35 * The captive portal notification should be shown in all windows upon
36 * detection, and closed automatically when the success event is fired.
38 async function test_detectedWithNoBrowserWindow_Focused(aSuccess) {
39 let win1 = await openWindowAndWaitForFocus();
40 let win2 = await openWindowAndWaitForFocus();
41 // Defocus both windows.
42 await SimpleTest.promiseFocus(window);
44 await portalDetected();
46 // Notification should be shown in both windows.
47 ensurePortalNotification(win1);
48 ensureNoPortalTab(win1);
49 ensurePortalNotification(win2);
50 ensureNoPortalTab(win2);
52 await focusWindowAndWaitForPortalUI(false, win2);
54 await freePortal(aSuccess);
56 ensureNoPortalNotification(win1);
57 ensureNoPortalTab(win2);
58 ensureNoPortalNotification(win2);
60 await closeWindowAndWaitForWindowActivate(win2);
61 // No need to wait for xul-window-visible: after win2 is closed, focus
62 // is restored to the default window and win1 remains in the background.
63 await BrowserTestUtils.closeWindow(win1);
67 * A portal is detected when there's no browser window, then a browser
68 * window is opened, then the portal is freed.
69 * The recheck triggered when the browser window is opened takes a
70 * long time. No portal tab should be added.
71 * The captive portal notification should be shown when the window is
72 * opened, and closed automatically when the success event is fired.
74 async function test_detectedWithNoBrowserWindow_LongRecheck(aSuccess) {
75 await portalDetected();
76 let win = await focusWindowAndWaitForPortalUI(true);
77 await freePortal(aSuccess);
78 ensureNoPortalTab(win);
79 ensureNoPortalNotification(win);
80 await closeWindowAndWaitForWindowActivate(win);
84 * A portal is detected when there's no browser window, and the
85 * portal is freed before a browser window is opened. No portal
86 * UI should be shown when a browser window is opened.
88 async function test_detectedWithNoBrowserWindow_GoneBeforeOpen(aSuccess) {
89 await portalDetected();
90 await freePortal(aSuccess);
91 let win = await openWindowAndWaitForFocus();
92 // Wait for a while to make sure no UI is shown.
93 await new Promise(resolve => {
94 setTimeout(resolve, 1000);
96 ensureNoPortalTab(win);
97 ensureNoPortalNotification(win);
98 await closeWindowAndWaitForWindowActivate(win);
102 * A portal is detected when a browser window has focus. No portal tab should
103 * be opened. A notification bar should be displayed in all browser windows.
105 async function test_detectedWithFocus(aSuccess) {
106 let win1 = await openWindowAndWaitForFocus();
107 let win2 = await openWindowAndWaitForFocus();
108 await portalDetected();
109 ensureNoPortalTab(win1);
110 ensureNoPortalTab(win2);
111 ensurePortalNotification(win1);
112 ensurePortalNotification(win2);
113 await freePortal(aSuccess);
114 ensureNoPortalNotification(win1);
115 ensureNoPortalNotification(win2);
116 await BrowserTestUtils.closeWindow(win2);
117 await BrowserTestUtils.closeWindow(win1);
118 await waitForBrowserWindowActive(window);
122 for (let testcase of testCasesForBothSuccessAndAbort) {
123 add_task(testcase.bind(null, true));
124 add_task(testcase.bind(null, false));