browser_rules_edit-selector_08.js (2283B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test that reverting a selector edit does the right thing. 7 // Bug 1241046. 8 9 const TEST_URI = ` 10 <style type="text/css"> 11 span { 12 color: chartreuse; 13 } 14 </style> 15 <span> 16 <div id="testid" class="testclass">Styled Node</div> 17 </span> 18 `; 19 20 add_task(async function () { 21 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 22 const { inspector, view } = await openRuleView(); 23 24 info("Selecting the test element"); 25 await selectNode("#testid", inspector); 26 27 let idRuleEditor = getRuleViewRuleEditor(view, 2); 28 29 info("Focusing an existing selector name in the rule-view"); 30 let editor = await focusEditableField(view, idRuleEditor.selectorText); 31 32 is( 33 inplaceEditor(idRuleEditor.selectorText), 34 editor, 35 "The selector editor got focused" 36 ); 37 38 info("Entering a new selector name and committing"); 39 editor.input.value = "pre"; 40 41 info("Waiting for rule view to update"); 42 let onRuleViewChanged = once(view, "ruleview-changed"); 43 44 info("Entering the commit key"); 45 EventUtils.synthesizeKey("KEY_Enter"); 46 await onRuleViewChanged; 47 48 info("Re-focusing the selector name in the rule-view"); 49 idRuleEditor = getRuleViewRuleEditor(view, 2); 50 editor = await focusEditableField(view, idRuleEditor.selectorText); 51 52 is(view._elementStyle.rules.length, 2, "Should have 2 rules."); 53 ok(getRuleViewRule(view, "pre"), "Rule with pre selector exists."); 54 is( 55 getRuleViewRuleEditor(view, 2).element.getAttribute("unmatched"), 56 "true", 57 "Rule with pre does not match the current element." 58 ); 59 60 // Now change it back. 61 info("Re-entering original selector name and committing"); 62 editor.input.value = "span"; 63 64 info("Waiting for rule view to update"); 65 onRuleViewChanged = once(view, "ruleview-changed"); 66 67 info("Entering the commit key"); 68 EventUtils.synthesizeKey("KEY_Enter"); 69 await onRuleViewChanged; 70 71 is(view._elementStyle.rules.length, 2, "Should have 2 rules."); 72 ok(getRuleViewRule(view, "span"), "Rule with span selector exists."); 73 is( 74 getRuleViewRuleEditor(view, 2).element.getAttribute("unmatched"), 75 "false", 76 "Rule with span matches the current element." 77 ); 78 });