diff --git a/layout/style/test/flexbox_layout_testcases.js b/layout/style/test/flexbox_layout_testcases.js index d6295bd685e8..9230166313bb 100644 --- a/layout/style/test/flexbox_layout_testcases.js +++ b/layout/style/test/flexbox_layout_testcases.js @@ -12,12 +12,17 @@ * hash-entry for each CSS property that is to be set. In these per-property * entries, the key is the property-name, and the value can be either of the * following: - * (a) the property's specified value - * ...or... - * (b) an array with 2 entries: [specifiedValue, expectedComputedValue] if the - * property's computed value is intended to be checked. The first entry - * (for the specified value) may be null; this means that no value should - * be explicitly specified for this property. + * (a) the property's specified value (which indicates that we don't need to + * bother checking the computed value of this particular property) + * ...OR... + * (b) an array with 2-3 entries... + * [specifiedValue, expectedComputedValue (, epsilon) ] + * ...which indicates that the property's computed value should be + * checked. The array's first entry (for the specified value) may be + * null; this means that no value should be explicitly specified for this + * property. The second entry is the property's expected computed + * value. The third (optional) entry is an epsilon value, which allows for + * fuzzy equality when testing the computed value. * * To allow these testcases to be re-used in both horizontal and vertical * flex containers, we specify "width"/"min-width"/etc. using the aliases @@ -385,7 +390,7 @@ var gFlexboxTestcases = }, { "flex": "1", - "_main-size": [ null, "1px" ] + "_main-size": [ null, "1px", 0.2 ] }, ] }, @@ -416,15 +421,15 @@ var gFlexboxTestcases = }, { "flex": "1", - "_main-size": [ null, "1px" ] + "_main-size": [ null, "1px", 0.2 ] }, { "flex": "1", - "_main-size": [ null, "1px" ] + "_main-size": [ null, "1px", 0.2 ] }, { "flex": "1", - "_main-size": [ null, "1px" ] + "_main-size": [ null, "1px", 0.2 ] }, ] }, @@ -441,19 +446,19 @@ var gFlexboxTestcases = "flex": "1", // NOTE: Expected value is off slightly, from float error when // resolving flexible lengths: - "_main-size": [ null, "0.966667px" ] + "_main-size": [ null, "1px", 0.2 ] }, { "flex": "1", // NOTE: Expected value is off slightly, from float error when // resolving flexible lengths: - "_main-size": [ null, "0.983333px" ] + "_main-size": [ null, "1px", 0.2 ] }, { "flex": "1", // NOTE: Expected value is off slightly, from float error when // resolving flexible lengths: - "_main-size": [ null, "0.983333px" ] + "_main-size": [ null, "1px", 0.2 ] }, { "flex": "3000000", diff --git a/layout/style/test/test_flexbox_layout.html b/layout/style/test/test_flexbox_layout.html index 5712d4a220db..c484030be676 100644 --- a/layout/style/test/test_flexbox_layout.html +++ b/layout/style/test/test_flexbox_layout.html @@ -52,6 +52,19 @@ function setPossiblyAliasedProperty(aElem, aPropertyName, aPropertyValue, } } +// Helper function to strip "px" off the end of a string +// (so that we can compare two lengths using "isfuzzy()" with an epsilon) +function stripPx(aLengthInPx) +{ + let pxOffset = aLengthInPx.length - 2; // subtract off length of "px" + + // Sanity-check the arg: + ok(pxOffset > 0 && aLengthInPx.substr(pxOffset) == "px", + "expecting value with 'px' units"); + + return aLengthInPx.substr(0, pxOffset); +} + // The main test function. // aFlexboxTestcase is an entry from the list in flexbox_layout_testcases.js function testFlexboxTestcase(aFlexboxTestcase, aFlexDirection, aPropertyMapping) @@ -90,7 +103,8 @@ function testFlexboxTestcase(aFlexboxTestcase, aFlexDirection, aPropertyMapping) // SANITY CHECK: if (Array.isArray(aChildSpec[propName])) { - is(aChildSpec[propName].length, 2, + ok(aChildSpec[propName].length >= 2 && + aChildSpec[propName].length <= 3, "unexpected number of elements in array within child spec"); } @@ -120,8 +134,20 @@ function testFlexboxTestcase(aFlexboxTestcase, aFlexDirection, aPropertyMapping) let expectedVal = childSpec[propName][1]; let actualPropName = (propName in aPropertyMapping ? aPropertyMapping[propName] : propName); - is(getComputedStyleWrapper(child, actualPropName), expectedVal, - "computed value of '" + actualPropName + "' should match expected"); + let actualVal = getComputedStyleWrapper(child, actualPropName); + let message = "computed value of '" + actualPropName + + "' should match expected"; + + if (childSpec[propName].length > 2) { + // 3rd entry in array is epsilon + // Need to strip off "px" units in order to use epsilon: + let actualValNoPx = stripPx(actualVal); + let expectedValNoPx = stripPx(expectedVal); + isfuzzy(actualValNoPx, expectedValNoPx, + childSpec[propName][2], message); + } else { + is(actualVal, expectedVal, message); + } } }