browser_rules_add-rule-edit-selector.js (1662B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests the behaviour of adding a new rule to the rule view and editing 7 // its selector. 8 9 const TEST_URI = ` 10 <style type="text/css"> 11 #testid { 12 text-align: center; 13 } 14 </style> 15 <div id="testid">Styled Node</div> 16 <span>This is a span</span> 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 await selectNode("#testid", inspector); 23 24 await addNewRule(inspector, view); 25 await testEditSelector(view, "span"); 26 27 info("Selecting the modified element with the new rule"); 28 await selectNode("span", inspector); 29 await checkModifiedElement(view, "span"); 30 }); 31 32 async function testEditSelector(view, name) { 33 info("Test editing existing selector field"); 34 const idRuleEditor = getRuleViewRuleEditor(view, 1); 35 const editor = idRuleEditor.selectorText.ownerDocument.activeElement; 36 37 info("Entering a new selector name and committing"); 38 editor.value = name; 39 40 info("Waiting for rule view to update"); 41 const onRuleViewChanged = once(view, "ruleview-changed"); 42 43 info("Entering the commit key"); 44 EventUtils.synthesizeKey("KEY_Enter"); 45 await onRuleViewChanged; 46 47 is(view._elementStyle.rules.length, 3, "Should have 3 rules."); 48 ok(getRuleViewRule(view, name), "Rule with " + name + " selector exists."); 49 } 50 51 function checkModifiedElement(view, name) { 52 is(view._elementStyle.rules.length, 2, "Should have 2 rules."); 53 ok(getRuleViewRule(view, name), "Rule with " + name + " selector exists."); 54 }