grid-child-utils.js (1624B)
1 // Any copyright is dedicated to the Public Domain. 2 // https://creativecommons.org/publicdomain/zero/1.0/ 3 4 const gridChildHelperRow = "row"; 5 const gridChildHelperCol = "col"; 6 7 // Helper for building testcases for grid-template-* with a child div in 8 // multiple positions. Prop is expected to be one of gridChildHelperRow or 9 // gridChildHelperCol, to select testing grid rows or grid columns, 10 // respectively. 11 // The child div is found by the id of 'child'. 12 function GridChildHelper(prop, style){ 13 this.child = document.getElementById("child"); 14 this.style = style; 15 this.prop = prop; 16 } 17 18 // Runs a test for computed values on the property the helper object was 19 // constructed with. The childStyle is used for choosing the grid row/column 20 // of the child div. 21 // expected is passed as-is to the computed value test. 22 // The child style is appended to the test name in such a way that different 23 // tests for the same parent style but different child style values will have 24 // different test names. 25 GridChildHelper.prototype.runTest = function(childStyle, expected) { 26 'use strict'; 27 const childProps = { 28 [gridChildHelperCol]:"gridColumn", 29 [gridChildHelperRow]:"gridRow" 30 }; 31 const childProp = childProps[this.prop]; 32 33 const parentProps = { 34 [gridChildHelperCol]:"grid-template-columns", 35 [gridChildHelperRow]:"grid-template-rows" 36 }; 37 const parentProp = parentProps[this.prop]; 38 39 const oldChildStyle = this.child[childProp]; 40 this.child.style[childProp] = childStyle; 41 42 test_computed_value(parentProp, this.style, expected, childProp + " = " + childStyle); 43 44 this.child[childProp] = oldChildStyle; 45 }