flexbox-dyn-insertAroundText-2.xhtml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Any copyright is dedicated to the Public Domain.
  4. http://creativecommons.org/publicdomain/zero/1.0/
  5. -->
  6. <!--
  7. This test verifies that we reconstruct frames as necessary, after content
  8. (including whitespace & divs) is dynamically inserted as a child of a
  9. flexbox. (Note that in cases where we know the whitespace is going to be
  10. dropped, we don't bother reconstructing frames. This test is to be sure we
  11. aren't overzealous with that optimization.)
  12. -->
  13. <html xmlns="http://www.w3.org/1999/xhtml"
  14. class="reftest-wait">
  15. <head>
  16. <style>
  17. body {
  18. font-size: 10px;
  19. }
  20. div.inserted {
  21. background: teal; /* To make inserted div elements stand out. */
  22. }
  23. div.flexbox {
  24. border: 1px dashed blue;
  25. width: 300px;
  26. display: flex;
  27. justify-content: space-around;
  28. margin-bottom: 1px;
  29. white-space: pre;
  30. }
  31. </style>
  32. <script>
  33. function insertNodeAtPosnInElem(aNodeToInsert, aPosn, aParentId) {
  34. var parent = document.getElementById(aParentId);
  35. var insertBeforeTarget = parent.firstChild;
  36. for (var i = 0; i &lt; aPosn; i++) {
  37. insertBeforeTarget = insertBeforeTarget.nextSibling;
  38. }
  39. parent.insertBefore(aNodeToInsert, insertBeforeTarget);
  40. }
  41. function createDivElem() {
  42. var div = document.createElement("div");
  43. div.setAttribute("class", "inserted");
  44. div.appendChild(document.createTextNode("[NewDiv]"));
  45. return div;
  46. }
  47. function tweak() {
  48. // Inserting div, adjacent to inline content
  49. // -----------------------------------------
  50. insertNodeAtPosnInElem(createDivElem(), 0, "f0");
  51. insertNodeAtPosnInElem(createDivElem(), 1, "f1");
  52. // Inserting div and whitespace, before inline content
  53. // ---------------------------------------------------
  54. insertNodeAtPosnInElem(document.createTextNode(" "), 0, "f2");
  55. insertNodeAtPosnInElem(createDivElem(), 0, "f2");
  56. insertNodeAtPosnInElem(createDivElem(), 0, "f3");
  57. insertNodeAtPosnInElem(document.createTextNode(" "), 0, "f3");
  58. // Inserting div and whitespace, after inline content
  59. // ---------------------------------------------------
  60. insertNodeAtPosnInElem(document.createTextNode(" "), 1, "f4");
  61. insertNodeAtPosnInElem(createDivElem(), 1, "f4");
  62. insertNodeAtPosnInElem(createDivElem(), 1, "f5");
  63. insertNodeAtPosnInElem(document.createTextNode(" "), 1, "f5");
  64. // Inserting div and text, before inline content
  65. // ---------------------------------------------------
  66. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 0, "f6");
  67. insertNodeAtPosnInElem(createDivElem(), 0, "f6");
  68. insertNodeAtPosnInElem(createDivElem(), 0, "f7");
  69. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 0, "f7");
  70. // Inserting div and text, after inline content
  71. // ---------------------------------------------------
  72. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 1, "f8");
  73. insertNodeAtPosnInElem(createDivElem(), 1, "f8");
  74. insertNodeAtPosnInElem(createDivElem(), 1, "f9");
  75. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 1, "f9");
  76. document.documentElement.removeAttribute("class");
  77. }
  78. window.addEventListener("MozReftestInvalidate", tweak, false);
  79. </script>
  80. </head>
  81. <body>
  82. <div class="flexbox" id="f0">[OldText]</div>
  83. <div class="flexbox" id="f1">[OldText]</div>
  84. <div class="flexbox" id="f2">[OldText]</div>
  85. <div class="flexbox" id="f3">[OldText]</div>
  86. <div class="flexbox" id="f4">[OldText]</div>
  87. <div class="flexbox" id="f5">[OldText]</div>
  88. <div class="flexbox" id="f6">[OldText]</div>
  89. <div class="flexbox" id="f7">[OldText]</div>
  90. <div class="flexbox" id="f8">[OldText]</div>
  91. <div class="flexbox" id="f9">[OldText]</div>
  92. </body>
  93. </html>