page-break-legacy-shorthands.html (3426B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>Test for the page-break-* legacy shorthands.</title> 4 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> 5 <link rel="author" title="Mozilla" href="https://mozilla.org"> 6 <link rel="help" href="https://drafts.csswg.org/css-cascade-4/#legacy-shorthand"> 7 <link rel="help" href="https://drafts.csswg.org/css-break/#page-break-properties"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="../support/shorthand-testcommon.js"></script> 11 <div></div> 12 <script> 13 const NEW_VALUES = ["page", "column"].filter(v => CSS.supports("break-before", v)); 14 const LEGACY_VALUES = ["always", "auto", "left", "right", "avoid"]; 15 const LEGACY_MAPPING = { "always": "page" }; 16 const REVERSE_LEGACY_MAPPING = { "page": "always" }; 17 const div = document.querySelector("div"); 18 const cs = getComputedStyle(div); 19 20 test(function() { 21 for (const property of ["break-before", "break-after"]) { 22 for (const val of LEGACY_VALUES) { 23 const mapped_value = LEGACY_MAPPING[val] || val; 24 25 div.style["page-" + property] = val; 26 27 assert_equals(div.style["page-" + property], val); 28 assert_equals(div.style[property], mapped_value); 29 assert_equals(cs.getPropertyValue("page-" + property), val); 30 assert_equals(cs.getPropertyValue(property), mapped_value); 31 assert_not_equals(div.style.cssText.indexOf(property + ": " + mapped_value + ";"), -1); 32 assert_equals(div.style.cssText.indexOf("page-" + property), -1, 33 "Legacy shorthands don't appear in cssText"); 34 } 35 } 36 }, "Legacy values of the shorthands work as expected") 37 38 test(function() { 39 for (const property of ["break-before", "break-after"]) { 40 for (const val of NEW_VALUES) { 41 const mapped_value = REVERSE_LEGACY_MAPPING[val] || ""; 42 43 div.style[property] = val; 44 45 assert_equals(div.style[property], val); 46 assert_equals(div.style["page-" + property], mapped_value); 47 assert_equals(cs.getPropertyValue("page-" + property), mapped_value); 48 assert_equals(cs.getPropertyValue(property), val); 49 } 50 } 51 }, "New values work on the new longhands, but serialize to the empty string in the legacy shorthands"); 52 53 test(function() { 54 for (const property of ["break-before", "break-after"]) { 55 for (const val of NEW_VALUES) { 56 div.style["page-" + property] = ""; 57 div.style["page-" + property] = val; 58 assert_equals(div.style["page-" + property], ""); 59 assert_equals(div.style[property], ""); 60 assert_equals(cs.getPropertyValue("page-" + property), "auto"); 61 assert_equals(cs.getPropertyValue(property), "auto"); 62 } 63 } 64 }, "New values of the break longhands don't work on legacy shorthands"); 65 66 // See https://github.com/w3c/csswg-drafts/issues/3332 67 test(function() { 68 for (const property of ["break-before", "break-after"]) { 69 div.style["page-" + property] = "var(--a)"; 70 71 assert_equals(div.style["page-" + property], "var(--a)"); 72 assert_equals(div.style[property], ""); 73 assert_equals(div.style.cssText.indexOf("page-" + property), -1); 74 } 75 }, "Legacy shorthands really never appear on cssText, even when there are variable references"); 76 77 test_is_legacy_shorthand("page-break-before", "break-before"); 78 test_is_legacy_shorthand("page-break-after", "break-after"); 79 test_is_legacy_shorthand("page-break-inside", "break-inside"); 80 </script>