test_bug311681.xhtml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <!--
  3. https://bugzilla.mozilla.org/show_bug.cgi?id=311681
  4. -->
  5. <head>
  6. <title>Test for Bug 311681</title>
  7. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  8. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  9. </head>
  10. <body>
  11. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=311681">Mozilla Bug 311681</a>
  12. <script class="testbody" type="text/javascript">
  13. <![CDATA[
  14. // Setup script
  15. SimpleTest.waitForExplicitFinish();
  16. // Make sure to trigger the hashtable case by asking for enough elements
  17. // by ID.
  18. for (var i = 0; i < 256; ++i) {
  19. var x = document.getElementById(i);
  20. }
  21. // save off the document.getElementById function, since getting it as a
  22. // property off the document it causes a content flush.
  23. var fun = document.getElementById;
  24. // Slot for our initial element with id "content"
  25. var testNode;
  26. function getCont() {
  27. return fun.call(document, "content");
  28. }
  29. function testClone() {
  30. // Test to make sure that if we have multiple nodes with the same ID in
  31. // a document we don't forget about one of them when the other is
  32. // removed.
  33. var newParent = $("display");
  34. var node = testNode.cloneNode(true);
  35. isnot(node, testNode, "Clone should be a different node");
  36. newParent.appendChild(node);
  37. // Check what getElementById returns, no flushing
  38. is(getCont(), node, "Should be getting new node pre-flush 1");
  39. // Trigger a layout flush, just in case.
  40. var itemHeight = newParent.offsetHeight/10;
  41. // Check what getElementById returns now.
  42. is(getCont(), node, "Should be getting new node post-flush 1");
  43. clear(newParent);
  44. // Check what getElementById returns, no flushing
  45. is(getCont(), testNode, "Should be getting orig node pre-flush 2");
  46. // Trigger a layout flush, just in case.
  47. var itemHeight = newParent.offsetHeight/10;
  48. // Check what getElementById returns now.
  49. is(getCont(), testNode, "Should be getting orig node post-flush 2");
  50. node = testNode.cloneNode(true);
  51. newParent.appendChild(node);
  52. testNode.parentNode.removeChild(testNode);
  53. // Check what getElementById returns, no flushing
  54. is(getCont(), node, "Should be getting clone pre-flush");
  55. // Trigger a layout flush, just in case.
  56. var itemHeight = newParent.offsetHeight/10;
  57. // Check what getElementById returns now.
  58. is(getCont(), node, "Should be getting clone post-flush");
  59. }
  60. function clear(node) {
  61. while (node.hasChildNodes()) {
  62. node.removeChild(node.firstChild);
  63. }
  64. }
  65. addLoadEvent(testClone);
  66. addLoadEvent(SimpleTest.finish);
  67. ]]>
  68. </script>
  69. <p id="display"></p>
  70. <div id="content" style="display: none">
  71. <script class="testbody" type="text/javascript">
  72. <![CDATA[
  73. testNode = fun.call(document, "content");
  74. ok(testNode != null, "Should have node here");
  75. ]]>
  76. </script>
  77. </div>
  78. <pre id="test">
  79. </pre>
  80. </body>
  81. </html>