dom/base/test/test_treewalker_nextsibling.xml
author Nicholas Nethercote <nnethercote@mozilla.com>
Mon, 05 Oct 2015 16:59:32 -0700
changeset 301715 3897da20e42dec0bcf73987af1eaac4f8ce950b8
parent 238779 2db29c0ae60b6eb0e196165631127d195fe2ef0b
child 457152 062e1d691fc5a875f78073101ae13779cd99af2b
permissions -rw-r--r--
Bug 1211324 (part 3) - Remove GraphicsFilter::FILTER_FAST and replace it with FILTER_BEST. r=mattwoodrow. This may sound like an odd change but it's what the current code effectively already does due to the way ToFilter() and ThebesFilter() are defined.

<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css" ?>
<root>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js" xmlns="http://www.w3.org/1999/xhtml"/>

  <body xmlns="http://www.w3.org/1999/xhtml">
    <p id="display"></p>
    <div id="content" style="display: none;"></div>
    <textarea id="test" style="height: 300px; max-width: 800px; overflow: scroll;"
              rows="10" cols="160" readonly="readonly"/>
  </body>

<pre id="test" xmlns="http://www.w3.org/1999/xhtml">
<script class="testbody" type="text/javascript" xmlns="http://www.w3.org/1999/xhtml">
<![CDATA[
var passedNodes = new WeakMap();
function setPass(aNode) {
  passedNodes.set(aNode, true);
}

SimpleTest.waitForExplicitFinish();

window.addEventListener("load", function() {
  const nsIDOMNodeFilter = SpecialPowers.Ci.nsIDOMNodeFilter;
  var walker = document.createTreeWalker(
    document,
    nsIDOMNodeFilter.SHOW_TEXT | nsIDOMNodeFilter.SHOW_DOCUMENT,
    null
  );
  setPass(walker.firstChild());
  while (walker.nextSibling()) {
    setPass(walker.currentNode);
  }

/*
From http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/traversal.html#Traversal-TreeWalker
Omitting nodes from the logical view of a subtree can result in a structure that
is substantially different from the same subtree in the complete, unfiltered
document. Nodes that are siblings in the TreeWalker view may be children of
different, widely separated nodes in the original view. For instance, consider a
NodeFilter that skips all nodes except for Text nodes and the root node of a
document. In the logical view that results, all text nodes will be siblings and
appear as direct children of the root node, no matter how deeply nested the
structure of the original document.
*/

  walker2 = document.createTreeWalker(document, nsIDOMNodeFilter.SHOW_TEXT, null);
  while (walker2.nextNode()) {
    var cNode = walker2.currentNode;
    ok(passedNodes.get(cNode), "Every text node should appear: " + walker2.currentNode.nodeValue);
    walker.currentNode = cNode;
    var parent = walker.parentNode();
    is(parent, document, "parent of text node should be document");

    // Check nextSibling's previousSibling.
    walker.currentNode = cNode;
    if (walker.nextSibling()) {
      is(cNode, walker.previousSibling(), "nextSibling.previousSibling should be consistent");
    }

    // Check previousSibling's nextSibling.
    walker.currentNode = cNode;
    if (walker.previousSibling()) {
      is(cNode, walker.nextSibling(), "previousSibling.nextSibling should be consistent");
    }
  }
  SimpleTest.finish();
}, true);
]]>
</script>
</pre>

  <test>
    zero
    <one>
      one-A
      <two>
        two-A
      </two>
      <two>
        two-B
      </two>
      one-B
    </one>
    <one>
      one-C
      <two>
        two-D
      </two>
      <two>
        two-E
      </two>
      one-F
    </one>
    zero
  </test>
</root>