browser_615394-SSWindowState_events_undoCloseWindow.js (3651B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const lameMultiWindowState = { 6 windows: [ 7 { 8 tabs: [ 9 { 10 entries: [ 11 { url: "http://example.org#1", triggeringPrincipal_base64 }, 12 ], 13 extData: { uniq: r() }, 14 }, 15 { 16 entries: [ 17 { url: "http://example.org#2", triggeringPrincipal_base64 }, 18 ], 19 extData: { uniq: r() }, 20 }, 21 { 22 entries: [ 23 { url: "http://example.org#3", triggeringPrincipal_base64 }, 24 ], 25 extData: { uniq: r() }, 26 }, 27 { 28 entries: [ 29 { url: "http://example.org#4", triggeringPrincipal_base64 }, 30 ], 31 extData: { uniq: r() }, 32 }, 33 ], 34 selected: 1, 35 }, 36 { 37 tabs: [ 38 { 39 entries: [ 40 { url: "http://example.com#1", triggeringPrincipal_base64 }, 41 ], 42 extData: { uniq: r() }, 43 }, 44 { 45 entries: [ 46 { url: "http://example.com#2", triggeringPrincipal_base64 }, 47 ], 48 extData: { uniq: r() }, 49 }, 50 { 51 entries: [ 52 { url: "http://example.com#3", triggeringPrincipal_base64 }, 53 ], 54 extData: { uniq: r() }, 55 }, 56 { 57 entries: [ 58 { url: "http://example.com#4", triggeringPrincipal_base64 }, 59 ], 60 extData: { uniq: r() }, 61 }, 62 ], 63 selected: 3, 64 }, 65 ], 66 }; 67 68 function test() { 69 /** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore */ 70 waitForExplicitFinish(); 71 72 let newWindow, reopenedWindow; 73 74 function firstWindowObserver(aSubject, aTopic) { 75 if (aTopic == "domwindowopened") { 76 newWindow = aSubject; 77 Services.ww.unregisterNotification(firstWindowObserver); 78 } 79 } 80 Services.ww.registerNotification(firstWindowObserver); 81 82 waitForBrowserState(lameMultiWindowState, function () { 83 // Close the window which isn't window 84 BrowserTestUtils.closeWindow(newWindow).then(() => { 85 // Now give it time to close 86 reopenedWindow = ss.undoCloseWindow(0); 87 reopenedWindow.addEventListener("SSWindowStateBusy", onSSWindowStateBusy); 88 reopenedWindow.addEventListener( 89 "SSWindowStateReady", 90 onSSWindowStateReady 91 ); 92 93 reopenedWindow.addEventListener( 94 "load", 95 function () { 96 reopenedWindow.gBrowser.tabContainer.addEventListener( 97 "SSTabRestored", 98 onSSTabRestored 99 ); 100 }, 101 { once: true } 102 ); 103 }); 104 }); 105 106 let busyEventCount = 0, 107 readyEventCount = 0, 108 tabRestoredCount = 0; 109 // These will listen to the reopened closed window... 110 function onSSWindowStateBusy() { 111 busyEventCount++; 112 } 113 114 function onSSWindowStateReady() { 115 readyEventCount++; 116 } 117 118 function onSSTabRestored() { 119 if (++tabRestoredCount < 4) { 120 return; 121 } 122 123 is(busyEventCount, 1); 124 is(readyEventCount, 1); 125 126 reopenedWindow.removeEventListener( 127 "SSWindowStateBusy", 128 onSSWindowStateBusy 129 ); 130 reopenedWindow.removeEventListener( 131 "SSWindowStateReady", 132 onSSWindowStateReady 133 ); 134 reopenedWindow.gBrowser.tabContainer.removeEventListener( 135 "SSTabRestored", 136 onSSTabRestored 137 ); 138 139 reopenedWindow.close(); 140 while (gBrowser.tabs.length > 1) { 141 gBrowser.removeTab(gBrowser.tabs[1]); 142 } 143 144 finish(); 145 } 146 }