test_bug311681.xul 3.2 KB

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