browser_rules_refresh-on-attribute-change_01.js (2712B)
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 changing the current element's attributes refreshes the rule-view 7 8 const TEST_URI = ` 9 <style type="text/css"> 10 #testid { 11 background-color: blue; 12 } 13 .testclass { 14 background-color: green; 15 } 16 </style> 17 <div id="testid" class="testclass" style="margin-top: 1px; padding-top: 5px;"> 18 Styled Node 19 </div> 20 `; 21 22 add_task(async function () { 23 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 24 const { inspector, view } = await openRuleView(); 25 await selectNode("#testid", inspector); 26 27 info( 28 "Checking that the rule-view has the element, #testid and .testclass selectors" 29 ); 30 checkRuleViewContent(view, [ 31 { 32 selector: "element", 33 selectorEditable: false, 34 declarations: [ 35 { name: "margin-top", value: "1px" }, 36 { name: "padding-top", value: "5px" }, 37 ], 38 }, 39 { 40 selector: "#testid", 41 declarations: [{ name: "background-color", value: "blue" }], 42 }, 43 { 44 selector: ".testclass", 45 declarations: [ 46 { name: "background-color", value: "green", overridden: true }, 47 ], 48 }, 49 ]); 50 51 info( 52 "Changing the node's ID attribute and waiting for the " + 53 "rule-view refresh" 54 ); 55 let ruleViewRefreshed = inspector.once("rule-view-refreshed"); 56 await setContentPageElementAttribute("#testid", "id", "differentid"); 57 await ruleViewRefreshed; 58 59 info("Checking that the rule-view doesn't have the #testid selector anymore"); 60 checkRuleViewContent(view, [ 61 { 62 selector: "element", 63 selectorEditable: false, 64 declarations: [ 65 { name: "margin-top", value: "1px" }, 66 { name: "padding-top", value: "5px" }, 67 ], 68 }, 69 { 70 selector: ".testclass", 71 declarations: [{ name: "background-color", value: "green" }], 72 }, 73 ]); 74 75 info("Reverting the ID attribute change"); 76 ruleViewRefreshed = inspector.once("rule-view-refreshed"); 77 await setContentPageElementAttribute("#differentid", "id", "testid"); 78 await ruleViewRefreshed; 79 80 info("Checking that the rule-view has all the selectors again"); 81 checkRuleViewContent(view, [ 82 { 83 selector: "element", 84 selectorEditable: false, 85 declarations: [ 86 { name: "margin-top", value: "1px" }, 87 { name: "padding-top", value: "5px" }, 88 ], 89 }, 90 { 91 selector: "#testid", 92 declarations: [{ name: "background-color", value: "blue" }], 93 }, 94 { 95 selector: ".testclass", 96 declarations: [ 97 { name: "background-color", value: "green", overridden: true }, 98 ], 99 }, 100 ]); 101 });