test_align_shorthand_serialization.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=utf-8>
  5. <title>Test serialization of CSS Align shorthand properties</title>
  6. <link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
  7. <script src="/resources/testharness.js"></script>
  8. <script src="/resources/testharnessreport.js"></script>
  9. <link rel='stylesheet' href='/resources/testharness.css'>
  10. </head>
  11. <body>
  12. <script>
  13. var initial_values = {
  14. alignContent: "normal",
  15. alignItems: "normal",
  16. alignSelf: "auto",
  17. justifyContent: "normal",
  18. justifyItems: "auto",
  19. justifySelf: "auto",
  20. };
  21. var place_content_test_cases = [
  22. {
  23. alignContent: "center",
  24. shorthand: "center normal",
  25. },
  26. {
  27. alignContent: "baseline right safe",
  28. shorthand: "",
  29. },
  30. {
  31. justifyContent: "start safe",
  32. shorthand: "",
  33. },
  34. {
  35. justifyContent: "space-evenly start",
  36. shorthand: "",
  37. },
  38. {
  39. alignContent: "start",
  40. justifyContent: "end",
  41. shorthand: "start end",
  42. },
  43. ];
  44. var place_items_test_cases = [
  45. {
  46. alignItems: "center",
  47. shorthand: "center auto",
  48. },
  49. {
  50. alignItems: "baseline",
  51. shorthand: "baseline auto",
  52. },
  53. {
  54. justifyItems: "start safe",
  55. shorthand: "",
  56. },
  57. {
  58. justifyItems: "stretch",
  59. shorthand: "normal stretch",
  60. },
  61. {
  62. justifyItems: "left legacy",
  63. shorthand: "",
  64. },
  65. {
  66. alignItems: "stretch",
  67. justifyItems: "end",
  68. shorthand: "stretch end",
  69. },
  70. ];
  71. var place_self_test_cases = [
  72. {
  73. alignSelf: "right",
  74. shorthand: "right auto",
  75. },
  76. {
  77. alignSelf: "self-end safe",
  78. shorthand: "",
  79. },
  80. {
  81. justifySelf: "unsafe start",
  82. shorthand: "",
  83. },
  84. {
  85. justifySelf: "last baseline start",
  86. shorthand: "",
  87. },
  88. {
  89. alignSelf: "baseline",
  90. justifySelf: "last baseline",
  91. shorthand: "baseline last baseline",
  92. },
  93. ];
  94. function run_tests(test_cases, shorthand, subproperties) {
  95. test_cases.forEach(function(test_case) {
  96. test(function() {
  97. var element = document.createElement('div');
  98. document.body.appendChild(element);
  99. subproperties.forEach(function(longhand) {
  100. element.style[longhand] = test_case[longhand] ||
  101. initial_values[longhand];
  102. });
  103. assert_equals(element.style[shorthand], test_case.shorthand);
  104. }, "test shorthand serialization " + JSON.stringify(test_case));
  105. });
  106. }
  107. run_tests(place_content_test_cases, "placeContent", [
  108. "alignContent", "justifyContent"]);
  109. run_tests(place_items_test_cases, "placeItems", [
  110. "alignItems", "justifyItems"]);
  111. run_tests(place_self_test_cases, "placeSelf", [
  112. "alignSelf", "justifySelf"]);
  113. </script>
  114. </body>
  115. </html>