browser_rules_add-rule-iframes.js (1949B)
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 rule on elements nested in iframes. 7 8 const TEST_URI = `<div>outer</div> 9 <iframe id="frame1" src="data:text/html;charset=utf-8,<div>inner1</div>"> 10 </iframe> 11 <iframe id="frame2" src="data:text/html;charset=utf-8,<div>inner2</div>"> 12 </iframe>`; 13 14 add_task(async function () { 15 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 16 const { inspector, view } = await openRuleView(); 17 await selectNode("div", inspector); 18 await addNewRuleAndDismissEditor(inspector, view, "div", 1); 19 await addNewProperty(view, 1, "color", "red"); 20 21 await selectNodeInFrames(["#frame1", "div"], inspector); 22 await addNewRuleAndDismissEditor(inspector, view, "div", 1); 23 await addNewProperty(view, 1, "color", "blue"); 24 25 await selectNodeInFrames(["#frame2", "div"], inspector); 26 await addNewRuleAndDismissEditor(inspector, view, "div", 1); 27 await addNewProperty(view, 1, "color", "green"); 28 }); 29 30 /** 31 * Add a new property in the rule at the provided index in the rule view. 32 * 33 * @param {RuleView} view 34 * @param {number} index 35 * The index of the rule in which we should add a new property. 36 * @param {string} name 37 * The name of the new property. 38 * @param {string} value 39 * The value of the new property. 40 */ 41 async function addNewProperty(view, index, name, value) { 42 const idRuleEditor = getRuleViewRuleEditor(view, index); 43 info(`Adding new property "${name}: ${value};"`); 44 45 const onRuleViewChanged = view.once("ruleview-changed"); 46 idRuleEditor.addProperty(name, value, "", true); 47 await onRuleViewChanged; 48 49 const textProps = idRuleEditor.rule.textProps; 50 const lastProperty = textProps[textProps.length - 1]; 51 is(lastProperty.name, name, "Last property has the expected name"); 52 is(lastProperty.value, value, "Last property has the expected value"); 53 }