browser_changes_declaration_edit_value.js (4908B)
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 editing the value of a CSS declaration in the Rule view is tracked. 7 8 const TEST_URI = ` 9 <style type='text/css'> 10 div { 11 color: red; 12 font-family: "courier"; 13 } 14 </style> 15 <div>test</div> 16 `; 17 18 /* 19 This object contains iteration steps to modify various CSS properties of the 20 test element, keyed by property name,. 21 Each value is an array which will be iterated over in order and the `value` 22 property will be used to update the value of the property. 23 The `add` and `remove` objects hold the expected values of the tracked declarations 24 shown in the Changes panel. If `add` or `remove` are null, it means we don't expect 25 any corresponding tracked declaration to show up in the Changes panel. 26 */ 27 const ITERATIONS = { 28 color: [ 29 // No changes should be tracked if the value did not actually change. 30 { 31 value: "red", 32 add: null, 33 remove: null, 34 }, 35 // Changing the priority flag "!important" should be tracked. 36 { 37 value: "red !important", 38 add: { value: "red !important" }, 39 remove: { value: "red" }, 40 }, 41 // Repeated changes should still show the original value as the one removed. 42 { 43 value: "blue", 44 add: { value: "blue" }, 45 remove: { value: "red" }, 46 }, 47 // Restoring the original value should clear tracked changes. 48 { 49 value: "red", 50 add: null, 51 remove: null, 52 }, 53 ], 54 "font-family": [ 55 // Set a value with an opening quote, missing the closing one. 56 // The closing quote should still appear in the "add" value. 57 { 58 value: '"ar', 59 add: { value: '"ar"' }, 60 remove: { value: '"courier"' }, 61 // For some reason we need an additional flush the first time we set a 62 // value with a quote. Since the ruleview is manually flushed when opened 63 // openRuleView, we need to pass this information all the way down to the 64 // setProperty helper. 65 needsExtraFlush: true, 66 }, 67 // Add an escaped character 68 { 69 value: '"ar\\i', 70 add: { value: '"ar\\i"' }, 71 remove: { value: '"courier"' }, 72 }, 73 // Add some more text 74 { 75 value: '"ar\\ia', 76 add: { value: '"ar\\ia"' }, 77 remove: { value: '"courier"' }, 78 }, 79 // Remove the backslash 80 { 81 value: '"aria', 82 add: { value: '"aria"' }, 83 remove: { value: '"courier"' }, 84 }, 85 // Add the rest of the text, still no closing quote 86 { 87 value: '"arial', 88 add: { value: '"arial"' }, 89 remove: { value: '"courier"' }, 90 }, 91 // Restoring the original value should clear tracked changes. 92 { 93 value: '"courier"', 94 add: null, 95 remove: null, 96 }, 97 ], 98 }; 99 100 add_task(async function () { 101 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 102 const { inspector, view: ruleView } = await openRuleView(); 103 const { document: doc, store } = selectChangesView(inspector); 104 105 await selectNode("div", inspector); 106 107 const colorProp = getTextProperty(ruleView, 1, { color: "red" }); 108 await assertEditValue(ruleView, doc, store, colorProp, ITERATIONS.color); 109 110 const fontFamilyProp = getTextProperty(ruleView, 1, { 111 "font-family": '"courier"', 112 }); 113 await assertEditValue( 114 ruleView, 115 doc, 116 store, 117 fontFamilyProp, 118 ITERATIONS["font-family"] 119 ); 120 }); 121 122 async function assertEditValue(ruleView, doc, store, prop, iterations) { 123 let onTrackChange; 124 for (const { value, add, needsExtraFlush, remove } of iterations) { 125 onTrackChange = waitForDispatch(store, "TRACK_CHANGE"); 126 127 info(`Change the CSS declaration value to ${value}`); 128 await setProperty(ruleView, prop, value, { 129 flushCount: needsExtraFlush ? 2 : 1, 130 }); 131 info("Wait for the change to be tracked"); 132 await onTrackChange; 133 134 if (add) { 135 await waitFor(() => { 136 const decl = getAddedDeclarations(doc); 137 return decl.length == 1 && decl[0].value == add.value; 138 }, "Only one declaration was tracked as added."); 139 const addDecl = getAddedDeclarations(doc); 140 is( 141 addDecl[0].value, 142 add.value, 143 `Added declaration has expected value: ${add.value}` 144 ); 145 } else { 146 await waitFor( 147 () => !getAddedDeclarations(doc).length, 148 "Added declaration was cleared" 149 ); 150 } 151 152 if (remove) { 153 await waitFor( 154 () => getRemovedDeclarations(doc).length == 1, 155 "Only one declaration was tracked as removed." 156 ); 157 const removeDecl = getRemovedDeclarations(doc); 158 is( 159 removeDecl[0].value, 160 remove.value, 161 `Removed declaration has expected value: ${remove.value}` 162 ); 163 } else { 164 await waitFor( 165 () => !getRemovedDeclarations(doc).length, 166 "Removed declaration was cleared" 167 ); 168 } 169 } 170 }