browser_styleeditor_opentab.js (3453B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // A test to check the 'Open Link in new tab' functionality in the 7 // context menu item for stylesheets (bug 992947). 8 const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html"; 9 10 add_task(async function () { 11 const { panel, ui } = await openStyleEditorForURL(TESTCASE_URI); 12 13 const openLinkNewTabItem = panel.panelWindow.document.getElementById( 14 "context-openlinknewtab" 15 ); 16 17 let menu = await rightClickStyleSheet(panel, ui.editors[0]); 18 is( 19 openLinkNewTabItem.getAttribute("disabled"), 20 "false", 21 "The menu item is not disabled" 22 ); 23 ok(!openLinkNewTabItem.hidden, "The menu item is not hidden"); 24 25 const url = TEST_BASE_HTTPS + "simple.css"; 26 27 const browserWindow = Services.wm.getMostRecentWindow( 28 gDevTools.chromeWindowType 29 ); 30 const originalOpenWebLinkIn = browserWindow.openWebLinkIn; 31 const tabOpenedDefer = new Promise(resolve => { 32 browserWindow.openWebLinkIn = newUrl => { 33 // Reset the actual openWebLinkIn function before proceeding. 34 browserWindow.openWebLinkIn = originalOpenWebLinkIn; 35 36 is(newUrl, url, "The correct tab has been opened"); 37 resolve(); 38 }; 39 }); 40 41 const hidden = onPopupHide(menu); 42 43 menu.activateItem(openLinkNewTabItem); 44 45 info(`Waiting for a tab to open - ${url}`); 46 await tabOpenedDefer; 47 48 await hidden; 49 50 menu = await rightClickInlineStyleSheet(panel, ui.editors[1]); 51 is( 52 openLinkNewTabItem.getAttribute("disabled"), 53 "true", 54 "The menu item is disabled" 55 ); 56 ok(!openLinkNewTabItem.hidden, "The menu item should not be hidden"); 57 menu.hidePopup(); 58 59 menu = await rightClickNoStyleSheet(panel); 60 ok(openLinkNewTabItem.hidden, "The menu item should be hidden"); 61 menu.hidePopup(); 62 }); 63 64 function onPopupShow(contextMenu) { 65 return new Promise(resolve => { 66 contextMenu.addEventListener( 67 "popupshown", 68 function () { 69 resolve(); 70 }, 71 { once: true } 72 ); 73 }); 74 } 75 76 function onPopupHide(contextMenu) { 77 return new Promise(resolve => { 78 contextMenu.addEventListener( 79 "popuphidden", 80 function () { 81 resolve(); 82 }, 83 { once: true } 84 ); 85 }); 86 } 87 88 function rightClickStyleSheet(panel, editor) { 89 const contextMenu = getContextMenuElement(panel); 90 return new Promise(resolve => { 91 onPopupShow(contextMenu).then(() => { 92 resolve(contextMenu); 93 }); 94 95 EventUtils.synthesizeMouseAtCenter( 96 editor.summary.querySelector(".stylesheet-name"), 97 { button: 2, type: "contextmenu" }, 98 panel.panelWindow 99 ); 100 }); 101 } 102 103 function rightClickInlineStyleSheet(panel, editor) { 104 const contextMenu = getContextMenuElement(panel); 105 return new Promise(resolve => { 106 onPopupShow(contextMenu).then(() => { 107 resolve(contextMenu); 108 }); 109 110 EventUtils.synthesizeMouseAtCenter( 111 editor.summary.querySelector(".stylesheet-name"), 112 { button: 2, type: "contextmenu" }, 113 panel.panelWindow 114 ); 115 }); 116 } 117 118 function rightClickNoStyleSheet(panel) { 119 const contextMenu = getContextMenuElement(panel); 120 return new Promise(resolve => { 121 onPopupShow(contextMenu).then(() => { 122 resolve(contextMenu); 123 }); 124 125 EventUtils.synthesizeMouseAtCenter( 126 panel.panelWindow.document.querySelector( 127 "#splitview-tpl-summary-stylesheet" 128 ), 129 { button: 2, type: "contextmenu" }, 130 panel.panelWindow 131 ); 132 }); 133 }