4 https://bugzilla.mozilla.org/show_bug.cgi?id=696253
8 <title>Test for Bug
696253</title>
9 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <script type=
"text/javascript" src=
"property_database.js"></script>
11 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
14 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=696253">Mozilla Bug
696253</a>
20 <script type=
"application/javascript">
23 /** Test for Bug
696253 **/
24 /* (Testing the 'flex' CSS shorthand property) */
26 // The CSS property name for the shorthand we're testing:
27 const gFlexPropName =
"flex";
29 // Info from property_database.js on this property:
30 const gFlexPropInfo = gCSSProperties[gFlexPropName];
32 // The name of the property in the DOM (i.e. in elem.style):
33 // (NOTE: In this case it's actually the same as the CSS property name --
34 //
"flex" -- but that's not guaranteed in general.)
35 const gFlexDOMName = gFlexPropInfo.domProp;
37 // Default values for shorthand subproperties, when they're not specified
38 // explicitly in a testcase. This lets the testcases be more concise.
40 // The values here are from the flexbox spec on the 'flex' shorthand:
41 //
"When omitted, [flex-grow and flex-shrink are] set to '1'."
42 //
"When omitted [..., flex-basis's] specified value is '0%'."
43 let gFlexShorthandDefaults = {
49 let gFlexShorthandTestcases = [
52 "flex":
"SPECIFIED value for flex shorthand",
54 // Expected Computed Values of Subproperties
55 // Semi-optional -- if unspecified, the expected value is taken
56 // from gFlexShorthandDefaults.
57 "flex-grow":
"EXPECTED computed value for flex-grow property",
58 "flex-shrink":
"EXPECTED computed value for flex-shrink property",
59 "flex-basis":
"EXPECTED computed value for flex-basis property",
63 // Initial values of subproperties:
64 // --------------------------------
65 // (checked by another test that uses property_database.js, too, but
66 // might as well check here, too, for thoroughness).
80 // Special keyword
"none" -->
"0 0 auto"
81 // -------------------------------------
89 // One Value (numeric) --> sets flex-grow
90 // --------------------------------------
109 "flex-grow":
"20000000",
112 // One Value (length or other nonnumeric) --> sets flex-basis
113 // ----------------------------------------------------------
124 "flex-basis":
"25px",
132 "flex-basis":
"auto",
135 "flex":
"fit-content",
136 "flex-basis":
"fit-content",
139 "flex":
"calc(5px + 6px)",
140 "flex-basis":
"11px",
143 "flex":
"calc(15% + 30px)",
144 "flex-basis":
"calc(15% + 30px)",
147 // Two Values (numeric) --> sets flex-grow, flex-shrink
148 // ----------------------------------------------------
165 "flex":
"0.5000 2.03",
167 "flex-shrink":
"2.03",
170 "flex":
"300.0 500.0",
172 "flex-shrink":
"500",
175 // Two Values (numeric & length-ish) --> sets flex-grow, flex-basis
176 // ----------------------------------------------------------------
190 "flex-basis":
"30px",
195 "flex-basis":
"99px",
205 "flex-basis":
"auto",
208 "flex":
"5 fit-content",
210 "flex-basis":
"fit-content",
213 "flex":
"calc(5% + 10px) 3",
215 "flex-basis":
"calc(5% + 10px)",
218 // Three Values --> Sets all three subproperties
219 // ---------------------------------------------
227 "flex":
"0.0 0.00 0px",
242 "flex-basis":
"10px",
246 function runFlexShorthandTest(aFlexShorthandTestcase)
248 let content = document.getElementById(
"content");
250 let elem = document.createElement(
"div");
252 elem.style[gFlexDOMName] = aFlexShorthandTestcase[gFlexPropName];
253 content.appendChild(elem);
255 gFlexPropInfo.subproperties.forEach(function(aSubPropName) {
256 var expectedVal = aSubPropName in aFlexShorthandTestcase ?
257 aFlexShorthandTestcase[aSubPropName] :
258 gFlexShorthandDefaults[aSubPropName];
260 // Compare computed value against expected computed value (from testcase)
261 is(window.getComputedStyle(elem).getPropertyValue(aSubPropName),
263 "Computed value of subproperty \"" + aSubPropName + "\
" when we set \"" +
264 gFlexPropName + ":
" + aFlexShorthandTestcase[gFlexPropName] + "\
"");
268 content.removeChild(elem);
272 gFlexShorthandTestcases.forEach(runFlexShorthandTest);