Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e3dccec5db
Fetching contributors…

Cannot retrieve contributors at this time

file 117 lines (100 sloc) 3.235 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
<script>
function doLog(msg)
{
    var d = document.createElement("div");
    d.innerHTML = msg;
    document.body.appendChild(d);
}

function report(msg, res)
{
    if (res)
        msg = "<font color=green>PASS:</font>" + msg;
    else
        msg = "<font color=red>FAIL:</font>" + msg;
    doLog(msg);
}

/*
Tree:
a
b
c
d
e
f
g
h
b, c are rejected,
d is skipped.
g is rejected
*/
function kid(parent) {
    var newKid = document.createElement("div");
    parent.appendChild(newKid);
    return newKid;
}

function test() {
    if (window.layoutTestController)
        layoutTestController.dumpAsText();

    var wrapper = document.createElement("div"); // just to have one more level up.

    var a = kid(wrapper);
        var b = kid(a);
            var c = kid(b);
        var d = kid(a);
            var e = kid(d);
        var f = kid(a);
        var g = kid(a);
            var h = kid(g);
    a.setAttribute("id", "a");
    b.setAttribute("id", "b");
    c.setAttribute("id", "c");
    d.setAttribute("id", "d");
    e.setAttribute("id", "e");
    f.setAttribute("id", "f");
    g.setAttribute("id", "g");
    h.setAttribute("id", "h");

    function filter(node) {
        if (node == b || node == c || node == g)
            return NodeFilter.FILTER_REJECT;
        if (node == d)
            return NodeFilter.FILTER_SKIP;
        return NodeFilter.FILTER_ACCEPT;
    }
    
    var tw = document.createTreeWalker(a, NodeFilter.SHOW_ALL, filter, true);
    report("Proper a.firstChild()", tw.firstChild() == e);

    tw.currentNode = b;
    report("Proper b.firstChild()", tw.firstChild() == null);
    // shouldn't move.
    report("Shouldn't move", tw.currentNode == b);

    tw.currentNode = b;
    report("Proper b.nextSibling()", tw.nextSibling() == e);

    // This is because we should treat 'b' as skipped when we are under it.
    tw.currentNode = c;
    report("Proper c.nextSibling()", tw.nextSibling() == e);

    tw.currentNode = e;
    report("Proper e.nextSibling()", tw.nextSibling() == f);

    tw.currentNode = f;
    report("Proper f.previousSibling()", tw.previousSibling() == e);
    tw.currentNode = e;
    report("Proper e.previousSibling()", tw.previousSibling() == null);
    report("Shouldn't move", tw.currentNode == e);

    tw.currentNode = h;
    report("Proper h.previousSibling()", tw.previousSibling() == f);

    tw.currentNode = g;
    report("Proper g.previousSibling()", tw.previousSibling() == f);
    // f is g's previous sibling, but not the other way around :-)
    tw.currentNode = f;
    report("Proper f.nextSibling()", tw.nextSibling() == null);
    report("Proper f.parentNode()", tw.parentNode() == a);
    report("Proper a.parentNode()", tw.parentNode() == null);

    // Test exit/capture.
    tw.currentNode = a.parentNode;
    report("Proper a's parent.nextNode()", tw.nextNode() == a);
    // Should get caught..
    report("Re-capture #1", tw.previousNode() == null);
    report("Re-capture #2", tw.parentNode() == null);
    report("nextNode from a", tw.nextNode() == e);
    report("prevNode to a", tw.previousNode() == a);

    doLog("All done!");
}

</script>
<body onload="test()">
Something went wrong with that request. Please try again.