browser_rules_cssom.js (2738B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test to ensure that CSSOM doesn't make the rule view blow up. 7 // https://bugzilla.mozilla.org/show_bug.cgi?id=1224121 8 9 const TEST_URI = URL_ROOT + "doc_cssom.html"; 10 11 add_task(async function () { 12 await addTab(TEST_URI); 13 const { inspector, view } = await openRuleView(); 14 await selectNode("#target", inspector); 15 16 const elementStyle = view._elementStyle; 17 let rule; 18 19 rule = elementStyle.rules[1]; 20 is(rule.textProps.length, 1, "rule 1 should have one property"); 21 is(rule.textProps[0].name, "color", "the property should be 'color'"); 22 is(rule.ruleLine, 1, "the property has no source line"); 23 24 rule = elementStyle.rules[2]; 25 is(rule.textProps.length, 1, "rule 2 should have one property"); 26 is( 27 rule.textProps[0].name, 28 "font-weight", 29 "the property should be 'font-weight'" 30 ); 31 is(rule.ruleLine, 2, "the property has no source line"); 32 33 info("Check that updating cssom declaration works"); 34 // Testing Bug 1933473 35 const prop = getTextProperty(view, 1, { color: "seagreen" }); 36 await setProperty(view, prop, "red"); 37 is( 38 await getComputedStyleProperty("#target", null, "color"), 39 "rgb(255, 0, 0)", 40 "target element color was properly updated" 41 ); 42 43 info("Select another node and re-select target node to update the rule view"); 44 await selectNode("body", inspector); 45 await selectNode("#target", inspector); 46 47 const newProp = getTextProperty(view, 1, { color: "red" }); 48 ok(!!newProp, "Rule is still visible after updating it"); 49 50 info("Check that updating cssom declaration in shadow DOM works"); 51 // Testing Bug 1986702 52 const shadowDomH2NodeFront = await getNodeFrontInShadowDom( 53 "h2", 54 "#host", 55 inspector 56 ); 57 await selectNode(shadowDomH2NodeFront, inspector); 58 59 const shadowDomH2ColorProp = getTextProperty(view, 1, { color: "tomato" }); 60 await setProperty(view, shadowDomH2ColorProp, "blue"); 61 62 const shadowDomH2Color = await SpecialPowers.spawn( 63 gBrowser.selectedBrowser, 64 [], 65 () => { 66 return content 67 .getComputedStyle( 68 content.document.getElementById("host").shadowRoot.querySelector("h2") 69 ) 70 .getPropertyValue("color"); 71 } 72 ); 73 is( 74 shadowDomH2Color, 75 "rgb(0, 0, 255)", 76 "shadow DOM h2 element color was properly updated" 77 ); 78 79 info( 80 "Select another node and re-select shadow DOM h2 node to update the rule view" 81 ); 82 await selectNode("body", inspector); 83 await selectNode(shadowDomH2NodeFront, inspector); 84 85 const updatedShadowDomH2Prop = getTextProperty(view, 1, { color: "blue" }); 86 ok(!!updatedShadowDomH2Prop, "Rule is still visible after updating it"); 87 });