browser_exit_button.js (2058B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_URL = "data:text/html;charset=utf-8,"; 7 8 // Test global exit button 9 addRDMTask(TEST_URL, async function (...args) { 10 await testExitButton(...args); 11 }); 12 13 // Test global exit button on detached tab. 14 // See Bug 1262806 15 addRDMTask( 16 null, 17 async function () { 18 let tab = await addTab(TEST_URL); 19 const { ui, manager } = await openRDM(tab); 20 21 await waitBootstrap(ui); 22 23 const waitTabIsDetached = Promise.all([ 24 once(tab, "TabClose"), 25 once(tab.linkedBrowser, "SwapDocShells"), 26 ]); 27 28 // Detach the tab with RDM open. 29 const newWindow = gBrowser.replaceTabWithWindow(tab); 30 31 // Wait until the tab is detached and the new window is fully initialized. 32 await waitTabIsDetached; 33 await newWindow.delayedStartupPromise; 34 35 // Get the new tab instance. 36 tab = newWindow.gBrowser.tabs[0]; 37 38 // Detaching a tab closes RDM. 39 ok( 40 !manager.isActiveForTab(tab), 41 "Responsive Design Mode is not active for the tab" 42 ); 43 44 // Reopen the RDM and test the exit button again. 45 await testExitButton(await openRDM(tab)); 46 await BrowserTestUtils.closeWindow(newWindow); 47 }, 48 { onlyPrefAndTask: true } 49 ); 50 51 async function waitBootstrap(ui) { 52 const { toolWindow, tab } = ui; 53 const { store } = toolWindow; 54 const url = String(tab.linkedBrowser.currentURI.spec); 55 56 // Wait until the viewport has been added. 57 await waitUntilState(store, state => state.viewports.length == 1); 58 59 // Wait until the document has been loaded. 60 await waitForFrameLoad(ui, url); 61 } 62 63 async function testExitButton({ ui, manager }) { 64 await waitBootstrap(ui); 65 66 const exitButton = ui.toolWindow.document.getElementById("exit-button"); 67 68 ok( 69 manager.isActiveForTab(ui.tab), 70 "Responsive Design Mode active for the tab" 71 ); 72 73 exitButton.click(); 74 75 await once(manager, "off"); 76 77 ok( 78 !manager.isActiveForTab(ui.tab), 79 "Responsive Design Mode is not active for the tab" 80 ); 81 }