|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset="utf-8"> |
| 3 | +<title>Setting flex shorthand</title> |
| 4 | +<link rel="help" href="https://drafts.csswg.org/css-flexbox/#flex-property"> |
| 5 | +<script src="/resources/testharness.js"></script> |
| 6 | +<script src="/resources/testharnessreport.js"></script> |
| 7 | +<!-- regression test for https://github.com/jsdom/cssstyle/pull/245 --> |
| 8 | + |
| 9 | +<div id="div"></div> |
| 10 | +<script> |
| 11 | +"use strict"; |
| 12 | + |
| 13 | +test(() => { |
| 14 | + const div = document.getElementById("div"); |
| 15 | + div.style.display = "flex"; |
| 16 | + div.style.flex = "none"; |
| 17 | + assert_equals(div.style.getPropertyValue("flex-grow"), "0"); |
| 18 | + assert_equals(div.style.getPropertyValue("flex-shrink"), "0"); |
| 19 | + assert_equals(div.style.getPropertyValue("flex-basis"), "auto"); |
| 20 | +}, "resolve flex none shorthand"); |
| 21 | + |
| 22 | +test(() => { |
| 23 | + const div = document.getElementById("div"); |
| 24 | + div.style.display = "flex"; |
| 25 | + div.style.flex = "auto"; |
| 26 | + assert_equals(div.style.getPropertyValue("flex-grow"), "1"); |
| 27 | + assert_equals(div.style.getPropertyValue("flex-shrink"), "1"); |
| 28 | + assert_equals(div.style.getPropertyValue("flex-basis"), "auto"); |
| 29 | +}, "resolve flex auto shorthand"); |
| 30 | + |
| 31 | +test(() => { |
| 32 | + const div = document.getElementById("div"); |
| 33 | + div.style.display = "flex"; |
| 34 | + div.style.flex = "0 1 250px"; |
| 35 | + assert_equals(div.style.getPropertyValue("flex-grow"), "0"); |
| 36 | + assert_equals(div.style.getPropertyValue("flex-shrink"), "1"); |
| 37 | + assert_equals(div.style.getPropertyValue("flex-basis"), "250px"); |
| 38 | +}, "resolve flex shorthand with explicit basis"); |
| 39 | + |
| 40 | +test(() => { |
| 41 | + const div = document.getElementById("div"); |
| 42 | + div.style.display = "flex"; |
| 43 | + div.style.flex = "0 0 auto"; |
| 44 | + assert_equals(div.style.getPropertyValue("flex-grow"), "0"); |
| 45 | + assert_equals(div.style.getPropertyValue("flex-shrink"), "0"); |
| 46 | + assert_equals(div.style.getPropertyValue("flex-basis"), "auto"); |
| 47 | +}, "resolve flex shorthand with auto basis"); |
| 48 | + |
| 49 | +test(() => { |
| 50 | + const div = document.getElementById("div"); |
| 51 | + div.style.display = "flex"; |
| 52 | + div.style.flex = "0 auto"; |
| 53 | + assert_equals(div.style.getPropertyValue("flex-grow"), "0"); |
| 54 | + assert_equals(div.style.getPropertyValue("flex-shrink"), "1"); |
| 55 | + assert_equals(div.style.getPropertyValue("flex-basis"), "auto"); |
| 56 | +}, "resolve flex shorthand with grow and basis"); |
| 57 | + |
| 58 | +test(() => { |
| 59 | + const div = document.getElementById("div"); |
| 60 | + div.style.display = "flex"; |
| 61 | + div.style.flex = "2"; |
| 62 | + assert_equals(div.style.getPropertyValue("flex-grow"), "2"); |
| 63 | + assert_equals(div.style.getPropertyValue("flex-shrink"), "1"); |
| 64 | + assert_equals(div.style.getPropertyValue("flex-basis"), "0%"); |
| 65 | +}, "resolve flex shorthand with grow only"); |
| 66 | + |
| 67 | +test(() => { |
| 68 | + const div = document.getElementById("div"); |
| 69 | + div.style.display = "flex"; |
| 70 | + div.style.flex = "20%"; |
| 71 | + assert_equals(div.style.getPropertyValue("flex-grow"), "1"); |
| 72 | + assert_equals(div.style.getPropertyValue("flex-shrink"), "1"); |
| 73 | + assert_equals(div.style.getPropertyValue("flex-basis"), "20%"); |
| 74 | +}, "resolve flex shorthand with basis only"); |
| 75 | + |
| 76 | +test(() => { |
| 77 | + const div = document.getElementById("div"); |
| 78 | + div.style.display = "flex"; |
| 79 | + div.style.flex = "2 2"; |
| 80 | + assert_equals(div.style.getPropertyValue("flex-grow"), "2"); |
| 81 | + assert_equals(div.style.getPropertyValue("flex-shrink"), "2"); |
| 82 | + assert_equals(div.style.getPropertyValue("flex-basis"), "0%"); |
| 83 | +}, "resolve flex shorthand with grow and shrink"); |
| 84 | +</script> |
0 commit comments