flexbox-dyn-insertAroundDiv-3.xhtml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 & spans) 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 { font-size: 10px; }
  18. <!-- to make inserted span elements stand out -->
  19. span.inserted { background: teal; }
  20. div.flexbox {
  21. border: 1px dashed blue;
  22. width: 300px;
  23. display: flex;
  24. justify-content: space-around;
  25. margin-bottom: 1px;
  26. white-space: pre;
  27. }
  28. </style>
  29. <script>
  30. function insertNodeAtPosnInElem(aNodeToInsert, aPosn, aParentId) {
  31. var parent = document.getElementById(aParentId);
  32. var insertBeforeTarget = parent.firstChild;
  33. for (var i = 0; i &lt; aPosn; i++) {
  34. insertBeforeTarget = insertBeforeTarget.nextSibling;
  35. }
  36. parent.insertBefore(aNodeToInsert, insertBeforeTarget);
  37. }
  38. function createSpanElem() {
  39. var span = document.createElement("span");
  40. span.setAttribute("class", "inserted");
  41. span.appendChild(document.createTextNode("[NewSpan]"));
  42. return span;
  43. }
  44. function tweak() {
  45. // Inserting span, on either side of existing content
  46. // --------------------------------------------------
  47. insertNodeAtPosnInElem(createSpanElem(), 0, "f0");
  48. insertNodeAtPosnInElem(createSpanElem(), 1, "f1");
  49. // Inserting span and whitespace, before existing content
  50. // ------------------------------------------------------
  51. insertNodeAtPosnInElem(document.createTextNode(" "), 0, "f2");
  52. insertNodeAtPosnInElem(createSpanElem(), 0, "f2");
  53. insertNodeAtPosnInElem(createSpanElem(), 0, "f3");
  54. insertNodeAtPosnInElem(document.createTextNode(" "), 0, "f3");
  55. // Inserting span and whitespace, after existing content
  56. // -----------------------------------------------------
  57. insertNodeAtPosnInElem(document.createTextNode(" "), 1, "f4");
  58. insertNodeAtPosnInElem(createSpanElem(), 1, "f4");
  59. insertNodeAtPosnInElem(createSpanElem(), 1, "f5");
  60. insertNodeAtPosnInElem(document.createTextNode(" "), 1, "f5");
  61. // Inserting span and text, before existing content
  62. // ------------------------------------------------
  63. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 0, "f6");
  64. insertNodeAtPosnInElem(createSpanElem(), 0, "f6");
  65. insertNodeAtPosnInElem(createSpanElem(), 0, "f7");
  66. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 0, "f7");
  67. // Inserting span and text, after existing content
  68. // -----------------------------------------------
  69. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 1, "f8");
  70. insertNodeAtPosnInElem(createSpanElem(), 1, "f8");
  71. insertNodeAtPosnInElem(createSpanElem(), 1, "f9");
  72. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 1, "f9");
  73. document.documentElement.removeAttribute("class");
  74. }
  75. window.addEventListener("MozReftestInvalidate", tweak, false);
  76. </script>
  77. </head>
  78. <body>
  79. <div class="flexbox" id="f0"><div>[OldText]</div></div>
  80. <div class="flexbox" id="f1"><div>[OldText]</div></div>
  81. <div class="flexbox" id="f2"><div>[OldText]</div></div>
  82. <div class="flexbox" id="f3"><div>[OldText]</div></div>
  83. <div class="flexbox" id="f4"><div>[OldText]</div></div>
  84. <div class="flexbox" id="f5"><div>[OldText]</div></div>
  85. <div class="flexbox" id="f6"><div>[OldText]</div></div>
  86. <div class="flexbox" id="f7"><div>[OldText]</div></div>
  87. <div class="flexbox" id="f8"><div>[OldText]</div></div>
  88. <div class="flexbox" id="f9"><div>[OldText]</div></div>
  89. </body>
  90. </html>