browser_987492_window_api.js (2076B)
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 "use strict"; 6 7 add_task(async function testOneWindow() { 8 let windows = []; 9 for (let win of CustomizableUI.windows) { 10 windows.push(win); 11 } 12 is(windows.length, 1, "Should have one customizable window"); 13 }); 14 15 add_task(async function testOpenCloseWindow() { 16 let newWindow = null; 17 let openListener = { 18 onWindowOpened(window) { 19 newWindow = window; 20 }, 21 }; 22 CustomizableUI.addListener(openListener); 23 24 { 25 let win = await openAndLoadWindow(null, true); 26 is( 27 newWindow, 28 win, 29 "onWindowOpen event should have received expected window" 30 ); 31 isnot(newWindow, null, "Should have gotten onWindowOpen event"); 32 } 33 34 CustomizableUI.removeListener(openListener); 35 36 let windows = []; 37 for (let win of CustomizableUI.windows) { 38 windows.push(win); 39 } 40 is(windows.length, 2, "Should have two customizable windows"); 41 isnot( 42 windows.indexOf(window), 43 -1, 44 "Current window should be in window collection." 45 ); 46 isnot( 47 windows.indexOf(newWindow), 48 -1, 49 "New window should be in window collection." 50 ); 51 52 let closedWindow = null; 53 let closeListener = { 54 onWindowClosed(window) { 55 closedWindow = window; 56 }, 57 }; 58 CustomizableUI.addListener(closeListener); 59 await promiseWindowClosed(newWindow); 60 isnot(closedWindow, null, "Should have gotten onWindowClosed event"); 61 is( 62 newWindow, 63 closedWindow, 64 "Closed window should match previously opened window" 65 ); 66 CustomizableUI.removeListener(closeListener); 67 68 windows = []; 69 for (let win of CustomizableUI.windows) { 70 windows.push(win); 71 } 72 is(windows.length, 1, "Should have one customizable window"); 73 isnot( 74 windows.indexOf(window), 75 -1, 76 "Current window should be in window collection." 77 ); 78 is( 79 windows.indexOf(closedWindow), 80 -1, 81 "Closed window should not be in window collection." 82 ); 83 });