browser_rules_edit-selector-commit.js (3455B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test selector value is correctly displayed when committing the inplace editor 7 // with ENTER, ESC, SHIFT+TAB and TAB 8 9 const TEST_URI = ` 10 <style type='text/css'> 11 #testid1 { 12 text-align: center; 13 } 14 #testid2 { 15 text-align: center; 16 } 17 #testid3 { 18 } 19 </style> 20 <div id='testid1'>Styled Node</div> 21 <div id='testid2'>Styled Node</div> 22 <div id='testid3'>Styled Node</div> 23 `; 24 25 const TEST_DATA = [ 26 { 27 node: "#testid1", 28 value: ".testclass", 29 commitKey: "VK_ESCAPE", 30 modifiers: {}, 31 expected: "#testid1", 32 }, 33 { 34 node: "#testid1", 35 value: ".testclass1", 36 commitKey: "VK_RETURN", 37 modifiers: {}, 38 expected: ".testclass1", 39 }, 40 { 41 node: "#testid2", 42 value: ".testclass2", 43 commitKey: "VK_TAB", 44 modifiers: {}, 45 expected: ".testclass2", 46 }, 47 { 48 node: "#testid3", 49 value: ".testclass3", 50 commitKey: "VK_TAB", 51 modifiers: { shiftKey: true }, 52 expected: ".testclass3", 53 }, 54 ]; 55 56 add_task(async function () { 57 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 58 const { inspector, view } = await openRuleView(); 59 60 for (const data of TEST_DATA) { 61 await runTestData(inspector, view, data); 62 } 63 }); 64 65 async function runTestData(inspector, view, data) { 66 const { node, value, commitKey, modifiers, expected } = data; 67 68 info( 69 "Updating " + 70 node + 71 " to " + 72 value + 73 " and committing with " + 74 commitKey + 75 ". Expecting: " + 76 expected 77 ); 78 79 info("Selecting the test element"); 80 await selectNode(node, inspector); 81 82 let idRuleEditor = getRuleViewRuleEditor(view, 1); 83 84 info("Focusing an existing selector name in the rule-view"); 85 const editor = await focusEditableField(view, idRuleEditor.selectorText); 86 is( 87 inplaceEditor(idRuleEditor.selectorText), 88 editor, 89 "The selector editor got focused" 90 ); 91 92 info("Enter the new selector value: " + value); 93 editor.input.value = value; 94 95 info("Entering the commit key " + commitKey + " " + modifiers); 96 EventUtils.synthesizeKey(commitKey, modifiers); 97 98 const activeElement = view.styleDocument.activeElement; 99 100 if (commitKey === "VK_ESCAPE") { 101 is( 102 idRuleEditor.rule.selectorText, 103 expected, 104 "Value is as expected: " + expected 105 ); 106 is(idRuleEditor.isEditing, false, "Selector is not being edited."); 107 is(idRuleEditor.selectorText, activeElement, "Focus is on selector span."); 108 return; 109 } 110 111 await once(view, "ruleview-changed"); 112 113 ok( 114 getRuleViewRule(view, expected), 115 "Rule with " + expected + " selector exists." 116 ); 117 118 if (modifiers.shiftKey) { 119 idRuleEditor = getRuleViewRuleEditor(view, 0); 120 } 121 122 if ( 123 commitKey === "VK_RETURN" && 124 !Services.prefs.getBoolPref("devtools.inspector.rule-view.focusNextOnEnter") 125 ) { 126 is(idRuleEditor.isEditing, false, "Selector is not being edited."); 127 is(idRuleEditor.selectorText, activeElement, "Focus is on selector span."); 128 return; 129 } 130 131 const rule = idRuleEditor.rule; 132 if (rule.textProps.length) { 133 is( 134 inplaceEditor(rule.textProps[0].editor.nameSpan).input, 135 activeElement, 136 "Focus is on the first property name span." 137 ); 138 } else { 139 is( 140 inplaceEditor(idRuleEditor.newPropSpan).input, 141 activeElement, 142 "Focus is on the new property span." 143 ); 144 } 145 }