browser_rules_add-property-cancel_02.js (2130B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests adding a new property and escapes the new empty property value editor. 7 8 const TEST_URI = ` 9 <style type='text/css'> 10 #testid { 11 background-color: blue; 12 } 13 </style> 14 <div id='testid'>Styled Node</div> 15 `; 16 17 add_task(async function () { 18 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 19 const { inspector, view } = await openRuleView(); 20 await selectNode("#testid", inspector); 21 22 let elementRuleEditor = getRuleViewRuleEditor(view, 1); 23 is( 24 elementRuleEditor.rule.textProps.length, 25 1, 26 "Sanity check, the rule has 1 property at the beginning of the test." 27 ); 28 29 info("Creating a new property but don't commit…"); 30 const textProp = await addProperty(view, 1, "color", "red", { 31 commitValueWith: null, 32 blurNewProperty: false, 33 }); 34 35 info("The autocomplete popup should be displayed, hit Escape to hide it"); 36 await waitFor(() => view.popup && view.popup.isOpen); 37 ok(true, "Popup was opened"); 38 const onPopupClosed = once(view.popup, "popup-closed"); 39 EventUtils.synthesizeKey("VK_ESCAPE", {}, view.styleWindow); 40 await onPopupClosed; 41 ok(true, "Popup was closed"); 42 43 is( 44 view.styleDocument.activeElement, 45 inplaceEditor(textProp.editor.valueSpan).input, 46 "The autocomplete was closed, but focus is still on the new property value" 47 ); 48 49 is( 50 elementRuleEditor.rule.textProps.length, 51 2, 52 "The new property is still displayed" 53 ); 54 55 info("Hit escape to remove the property"); 56 const onRuleViewChanged = view.once("ruleview-changed"); 57 EventUtils.synthesizeKey("VK_ESCAPE", {}, view.styleWindow); 58 await onRuleViewChanged; 59 60 is( 61 view.styleDocument.activeElement, 62 view.styleDocument.body, 63 "Correct element has focus" 64 ); 65 66 elementRuleEditor = getRuleViewRuleEditor(view, 1); 67 is( 68 elementRuleEditor.rule.textProps.length, 69 1, 70 "Removed the new text property." 71 ); 72 is( 73 elementRuleEditor.propertyList.children.length, 74 1, 75 "Removed the property editor." 76 ); 77 });