content/xul/document/test/test_bug311681.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/xul/document/test/test_bug311681.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=311681
     1.9 +-->
    1.10 +<window title="Mozilla Bug 311681"
    1.11 +  xmlns:html="http://www.w3.org/1999/xhtml"
    1.12 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.13 +
    1.14 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
    1.15 +
    1.16 +<body  xmlns="http://www.w3.org/1999/xhtml">
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=311681">Mozilla Bug 311681</a>
    1.18 +<script class="testbody" type="text/javascript">
    1.19 +<![CDATA[
    1.20 +  // Setup script
    1.21 +  SimpleTest.waitForExplicitFinish();
    1.22 +
    1.23 +  // Make sure to trigger the hashtable case by asking for enough elements
    1.24 +  // by ID.
    1.25 +  for (var i = 0; i < 256; ++i) {
    1.26 +    var x = document.getElementById(i);
    1.27 +  }
    1.28 +
    1.29 +  // save off the document.getElementById function, since getting it as a
    1.30 +  // property off the document it causes a content flush.      
    1.31 +  var fun = document.getElementById;
    1.32 +
    1.33 +  // Slot for our initial element with id "content"
    1.34 +  var testNode;
    1.35 +
    1.36 +  function getCont() {
    1.37 +    return fun.call(document, "content");
    1.38 +  }
    1.39 +  
    1.40 +  function testClone() {
    1.41 +    // Test to make sure that if we have multiple nodes with the same ID in
    1.42 +    // a document we don't forget about one of them when the other is
    1.43 +    // removed.
    1.44 +    var newParent = $("display");
    1.45 +    var node = testNode.cloneNode(true);
    1.46 +    isnot(node, testNode, "Clone should be a different node");
    1.47 +
    1.48 +    newParent.appendChild(node);
    1.49 +
    1.50 +    // Check what getElementById returns, no flushing
    1.51 +    is(getCont(), node, "Should be getting new node pre-flush 1")
    1.52 +    
    1.53 +    // Trigger a layout flush, just in case.
    1.54 +    var itemHeight = newParent.offsetHeight/10;
    1.55 +
    1.56 +    // Check what getElementById returns now.
    1.57 +    is(getCont(), node, "Should be getting new node post-flush 1")
    1.58 +    
    1.59 +    clear(newParent);
    1.60 +    
    1.61 +    // Check what getElementById returns, no flushing
    1.62 +    is(getCont(), testNode, "Should be getting orig node pre-flush 2");
    1.63 +    
    1.64 +    // Trigger a layout flush, just in case.
    1.65 +    var itemHeight = newParent.offsetHeight/10;
    1.66 +
    1.67 +    // Check what getElementById returns now.
    1.68 +    is(getCont(), testNode, "Should be getting orig node post-flush 2");
    1.69 +
    1.70 +    node = testNode.cloneNode(true);
    1.71 +    newParent.appendChild(node);
    1.72 +    testNode.parentNode.removeChild(testNode);
    1.73 +
    1.74 +    // Check what getElementById returns, no flushing
    1.75 +    is(getCont(), node, "Should be getting clone pre-flush");
    1.76 +    
    1.77 +    // Trigger a layout flush, just in case.
    1.78 +    var itemHeight = newParent.offsetHeight/10;
    1.79 +
    1.80 +    // Check what getElementById returns now.
    1.81 +    is(getCont(), node, "Should be getting clone post-flush");
    1.82 +
    1.83 +  }
    1.84 +
    1.85 +  function clear(node) {
    1.86 +    while (node.hasChildNodes()) {
    1.87 +      node.removeChild(node.firstChild);
    1.88 +    }
    1.89 +  }
    1.90 +
    1.91 +  addLoadEvent(testClone);
    1.92 +  addLoadEvent(SimpleTest.finish);
    1.93 +]]>
    1.94 +</script>
    1.95 +<p id="display"></p>
    1.96 +<div id="content" style="display: none">
    1.97 +  <script class="testbody" type="text/javascript">
    1.98 +  <![CDATA[
    1.99 +    testNode = fun.call(document, "content");
   1.100 +    // Needs incremental XML parser
   1.101 +    isnot(testNode, null, "Should have node here");
   1.102 +  ]]>
   1.103 +  </script>  
   1.104 +</div>
   1.105 +<pre id="test">
   1.106 +</pre>
   1.107 +</body>
   1.108 +
   1.109 +</window>

mercurial