browser_rules_custom.js (2610B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_URI = URL_ROOT + "doc_custom.html"; 7 8 // Tests the display of custom declarations in the rule-view. 9 10 add_task(async function () { 11 await addTab(TEST_URI); 12 const { inspector, view } = await openRuleView(); 13 14 await simpleCustomOverride(inspector, view); 15 await importantCustomOverride(inspector, view); 16 await disableCustomOverride(inspector, view); 17 }); 18 19 async function simpleCustomOverride(inspector, view) { 20 await selectNode("#testidSimple", inspector); 21 22 const idRule = getRuleViewRuleEditor(view, 1).rule; 23 const idRuleProp = idRule.textProps[0]; 24 25 is( 26 idRuleProp.name, 27 "--background-color", 28 "First ID prop should be --background-color" 29 ); 30 ok(!idRuleProp.overridden, "ID prop should not be overridden."); 31 32 const classRule = getRuleViewRuleEditor(view, 2).rule; 33 const classRuleProp = classRule.textProps[0]; 34 35 is( 36 classRuleProp.name, 37 "--background-color", 38 "First class prop should be --background-color" 39 ); 40 ok(classRuleProp.overridden, "Class property should be overridden."); 41 42 // Override --background-color by changing the element style. 43 const elementProp = await addProperty( 44 view, 45 0, 46 "--background-color", 47 "purple" 48 ); 49 50 is( 51 classRuleProp.name, 52 "--background-color", 53 "First element prop should now be --background-color" 54 ); 55 ok( 56 !elementProp.overridden, 57 "Element style property should not be overridden" 58 ); 59 ok(idRuleProp.overridden, "ID property should be overridden"); 60 ok(classRuleProp.overridden, "Class property should be overridden"); 61 } 62 63 async function importantCustomOverride(inspector, view) { 64 await selectNode("#testidImportant", inspector); 65 66 const idRule = getRuleViewRuleEditor(view, 1).rule; 67 const idRuleProp = idRule.textProps[0]; 68 ok(idRuleProp.overridden, "Not-important rule should be overridden."); 69 70 const classRule = getRuleViewRuleEditor(view, 2).rule; 71 const classRuleProp = classRule.textProps[0]; 72 ok(!classRuleProp.overridden, "Important rule should not be overridden."); 73 } 74 75 async function disableCustomOverride(inspector, view) { 76 await selectNode("#testidDisable", inspector); 77 78 const idRule = getRuleViewRuleEditor(view, 1).rule; 79 const idRuleProp = idRule.textProps[0]; 80 81 await togglePropStatus(view, idRuleProp); 82 83 const classRule = getRuleViewRuleEditor(view, 2).rule; 84 const classRuleProp = classRule.textProps[0]; 85 ok( 86 !classRuleProp.overridden, 87 "Class prop should not be overridden after id prop was disabled." 88 ); 89 }