browser_inspector_textbox-menu.js (3978B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test that when right-clicking on various text boxes throughout the inspector does use 6 // the toolbox's context menu (copy/cut/paste/selectAll/Undo). 7 8 add_task(async function () { 9 await addTab(`data:text/html;charset=utf-8, 10 <style>h1 { color: red; }</style> 11 <h1 id="title">textbox context menu test</h1>`); 12 const { toolbox, inspector } = await openInspector(); 13 await selectNode("h1", inspector); 14 15 info("Testing the markup-view tagname"); 16 const container = await focusNode("h1", inspector); 17 const tag = container.editor.tag; 18 tag.focus(); 19 EventUtils.sendKey("return", inspector.panelWin); 20 await checkTextBox(inspector.markup.doc.activeElement, toolbox); 21 22 info("Testing the markup-view attribute"); 23 EventUtils.sendKey("tab", inspector.panelWin); 24 await checkTextBox(inspector.markup.doc.activeElement, toolbox); 25 26 info("Testing the markup-view new attribute"); 27 // It takes 2 tabs to focus the newAttr field, the first one just moves the cursor to 28 // the end of the field. 29 EventUtils.sendKey("tab", inspector.panelWin); 30 EventUtils.sendKey("tab", inspector.panelWin); 31 await checkTextBox(inspector.markup.doc.activeElement, toolbox); 32 33 info("Testing the markup-view textcontent"); 34 EventUtils.sendKey("tab", inspector.panelWin); 35 await checkTextBox(inspector.markup.doc.activeElement, toolbox); 36 // Blur this last markup-view field, since we're moving on to the rule-view next. 37 EventUtils.sendKey("escape", inspector.panelWin); 38 39 info("Testing the rule-view selector"); 40 const ruleView = inspector.getPanel("ruleview").view; 41 const cssRuleEditor = getRuleViewRuleEditor(ruleView, 1); 42 EventUtils.synthesizeMouseAtCenter( 43 cssRuleEditor.selectorText, 44 {}, 45 inspector.panelWin 46 ); 47 await checkTextBox(inspector.panelDoc.activeElement, toolbox); 48 49 info("Testing the rule-view property name"); 50 EventUtils.sendKey("tab", inspector.panelWin); 51 await checkTextBox(inspector.panelDoc.activeElement, toolbox); 52 53 info("Testing the rule-view property value"); 54 EventUtils.sendKey("tab", inspector.panelWin); 55 await checkTextBox(inspector.panelDoc.activeElement, toolbox); 56 57 info("Testing the rule-view new property"); 58 // Tabbing out of the value field triggers a ruleview-changed event that we need to wait 59 // for. 60 const onRuleViewChanged = once(ruleView, "ruleview-changed"); 61 EventUtils.sendKey("tab", inspector.panelWin); 62 await onRuleViewChanged; 63 await checkTextBox(inspector.panelDoc.activeElement, toolbox); 64 65 info("Switching to the layout-view"); 66 const onBoxModelUpdated = inspector.once("boxmodel-view-updated"); 67 selectLayoutView(inspector); 68 await onBoxModelUpdated; 69 70 info("Testing the box-model region"); 71 const margin = inspector.panelDoc.querySelector( 72 ".boxmodel-margin.boxmodel-top > span" 73 ); 74 EventUtils.synthesizeMouseAtCenter(margin, {}, inspector.panelWin); 75 await checkTextBox(inspector.panelDoc.activeElement, toolbox); 76 77 // Move the mouse out of the box-model region to avoid triggering the box model 78 // highlighter. 79 EventUtils.synthesizeMouseAtCenter(tag, {}, inspector.panelWin); 80 }); 81 82 async function checkTextBox(textBox, toolbox) { 83 let textboxContextMenu = toolbox.getTextBoxContextMenu(); 84 ok(!textboxContextMenu, "The menu is closed"); 85 86 info( 87 "Simulating context click on the textbox and expecting the menu to open" 88 ); 89 const onContextMenu = toolbox.once("menu-open"); 90 synthesizeContextMenuEvent(textBox); 91 await onContextMenu; 92 93 textboxContextMenu = toolbox.getTextBoxContextMenu(); 94 ok(textboxContextMenu, "The menu is now visible"); 95 96 info("Closing the menu"); 97 const onContextMenuHidden = toolbox.once("menu-close"); 98 textboxContextMenu.hidePopup(); 99 await onContextMenuHidden; 100 101 textboxContextMenu = toolbox.getTextBoxContextMenu(); 102 ok(!textboxContextMenu, "The menu is closed again"); 103 }