browser_rules_edit-value-after-name_01.js (4127B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that clicking on swatch-preceeded value while editing the property name 7 // will result in editing the property value. Also tests that the value span is updated 8 // only if the property name has changed. See also Bug 1248274. 9 10 const TEST_URI = ` 11 <style type="text/css"> 12 #testid { 13 color: red; 14 } 15 </style> 16 <div id="testid">Styled Node</div> 17 `; 18 19 add_task(async function () { 20 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 21 const { inspector, view } = await openRuleView(); 22 23 await selectNode("#testid", inspector); 24 const prop = getTextProperty(view, 1, { color: "red" }); 25 const propEditor = prop.editor; 26 27 await testColorValueSpanClickWithoutNameChange(propEditor, view); 28 await testColorValueSpanClickAfterNameChange(propEditor, view); 29 }); 30 31 async function testColorValueSpanClickWithoutNameChange(propEditor, view) { 32 info("Test click on color span while focusing property name editor"); 33 const colorSpan = propEditor.valueSpan.querySelector(".ruleview-color"); 34 35 info("Focus the color name span"); 36 await focusEditableField(view, propEditor.nameSpan); 37 let editor = inplaceEditor(propEditor.doc.activeElement); 38 39 // We add a click event to make sure the color span won't be cleared 40 // on nameSpan blur (which would lead to the click event not being triggered) 41 const onColorSpanClick = once(colorSpan, "click"); 42 43 // The property-value-updated is emitted when the valueSpan markup is being 44 // re-populated, which should not be the case when not modifying the property name 45 const onPropertyValueUpdated = function () { 46 ok(false, 'The "property-value-updated" should not be emitted'); 47 }; 48 view.on("property-value-updated", onPropertyValueUpdated); 49 50 info("blur propEditor.nameSpan by clicking on the color span"); 51 EventUtils.synthesizeMouse(colorSpan, 1, 1, {}, propEditor.doc.defaultView); 52 53 info("wait for the click event on the color span"); 54 await onColorSpanClick; 55 ok(true, "Expected click event was emitted"); 56 57 editor = inplaceEditor(propEditor.doc.activeElement); 58 is( 59 inplaceEditor(propEditor.valueSpan), 60 editor, 61 "The property value editor got focused" 62 ); 63 64 // We remove this listener in order to not cause unwanted conflict in the next test 65 view.off("property-value-updated", onPropertyValueUpdated); 66 67 info( 68 "blur valueSpan editor to trigger ruleview-changed event and prevent " + 69 "having pending request" 70 ); 71 const onRuleViewChanged = view.once("ruleview-changed"); 72 editor.input.blur(); 73 await onRuleViewChanged; 74 } 75 76 async function testColorValueSpanClickAfterNameChange(propEditor, view) { 77 info("Test click on color span after property name change"); 78 const colorSpan = propEditor.valueSpan.querySelector(".ruleview-color"); 79 80 info("Focus the color name span"); 81 await focusEditableField(view, propEditor.nameSpan); 82 let editor = inplaceEditor(propEditor.doc.activeElement); 83 84 info( 85 "Modify the property to border-color to trigger the " + 86 "property-value-updated event" 87 ); 88 editor.input.value = "border-color"; 89 90 let onRuleViewChanged = view.once("ruleview-changed"); 91 const onPropertyValueUpdate = view.once("property-value-updated"); 92 93 info("blur propEditor.nameSpan by clicking on the color span"); 94 EventUtils.synthesizeMouse(colorSpan, 1, 1, {}, propEditor.doc.defaultView); 95 96 info( 97 "wait for ruleview-changed event to be triggered to prevent pending requests" 98 ); 99 await onRuleViewChanged; 100 101 info("wait for the property value to be updated"); 102 await onPropertyValueUpdate; 103 ok(true, 'Expected "property-value-updated" event was emitted'); 104 105 editor = inplaceEditor(propEditor.doc.activeElement); 106 is( 107 inplaceEditor(propEditor.valueSpan), 108 editor, 109 "The property value editor got focused" 110 ); 111 112 info( 113 "blur valueSpan editor to trigger ruleview-changed event and prevent " + 114 "having pending request" 115 ); 116 onRuleViewChanged = view.once("ruleview-changed"); 117 editor.input.blur(); 118 await onRuleViewChanged; 119 }