flexbox-dyn-insertAroundSpan-3.xhtml 4.3 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 & 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 {
  18. font-size: 10px;
  19. }
  20. span.inserted {
  21. background: teal; /* To make inserted span 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 createSpanElem() {
  42. var span = document.createElement("span");
  43. span.setAttribute("class", "inserted");
  44. span.appendChild(document.createTextNode("[NewSpan]"));
  45. return span;
  46. }
  47. function tweak() {
  48. // Inserting span, on either side of existing content
  49. // --------------------------------------------------
  50. insertNodeAtPosnInElem(createSpanElem(), 0, "f0");
  51. insertNodeAtPosnInElem(createSpanElem(), 1, "f1");
  52. // Inserting span and whitespace, before existing content
  53. // ------------------------------------------------------
  54. insertNodeAtPosnInElem(document.createTextNode(" "), 0, "f2");
  55. insertNodeAtPosnInElem(createSpanElem(), 0, "f2");
  56. insertNodeAtPosnInElem(createSpanElem(), 0, "f3");
  57. insertNodeAtPosnInElem(document.createTextNode(" "), 0, "f3");
  58. // Inserting span and whitespace, after existing content
  59. // -----------------------------------------------------
  60. insertNodeAtPosnInElem(document.createTextNode(" "), 1, "f4");
  61. insertNodeAtPosnInElem(createSpanElem(), 1, "f4");
  62. insertNodeAtPosnInElem(createSpanElem(), 1, "f5");
  63. insertNodeAtPosnInElem(document.createTextNode(" "), 1, "f5");
  64. // Inserting span and text, before existing content
  65. // ------------------------------------------------
  66. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 0, "f6");
  67. insertNodeAtPosnInElem(createSpanElem(), 0, "f6");
  68. insertNodeAtPosnInElem(createSpanElem(), 0, "f7");
  69. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 0, "f7");
  70. // Inserting span and text, after existing content
  71. // -----------------------------------------------
  72. insertNodeAtPosnInElem(document.createTextNode("[NewText]"), 1, "f8");
  73. insertNodeAtPosnInElem(createSpanElem(), 1, "f8");
  74. insertNodeAtPosnInElem(createSpanElem(), 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"><span>[OldText]</span></div>
  83. <div class="flexbox" id="f1"><span>[OldText]</span></div>
  84. <div class="flexbox" id="f2"><span>[OldText]</span></div>
  85. <div class="flexbox" id="f3"><span>[OldText]</span></div>
  86. <div class="flexbox" id="f4"><span>[OldText]</span></div>
  87. <div class="flexbox" id="f5"><span>[OldText]</span></div>
  88. <div class="flexbox" id="f6"><span>[OldText]</span></div>
  89. <div class="flexbox" id="f7"><span>[OldText]</span></div>
  90. <div class="flexbox" id="f8"><span>[OldText]</span></div>
  91. <div class="flexbox" id="f9"><span>[OldText]</span></div>
  92. </body>
  93. </html>