summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/xpath/union-context-node.xhtml
blob: 5b91bd7baf184c3d00c241f91533d7fe1cb3c3cb (plain)
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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>XPath queries with predicates incorrectly retains the current node across unions</title>
<style>div#msg { white-space: pre; }</style>
<script>
if (window.layoutTestController)
    layoutTestController.dumpAsText();

window.addEventListener("load", function() {
    var msg = document.getElementById("msg");
    function print(s) { msg.textContent += s; }
    function id(el) { return el.tagName + (el.id ? "#" + el.id : ""); }
    function query(el, xpath, expected) {
        print("Query \"" + xpath + "\" from " + id(el) + "\n");
        var res = document.evaluate(xpath,
                                    el,
                                    function() { return "http://www.w3.org/1999/xhtml"; },
                                    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                                    null);

        var resstr = "";
        for (var i = 0; i &lt; res.snapshotLength; i++) {
            var el = res.snapshotItem(i);
            resstr += " " + id(el);
        }
        print("Result:" + resstr + "\n");
        print("Expected: " + expected + "\n");
        if (resstr != (" " + expected)) {
            print("FAIL\n");
        } else {
            print("SUCCESS\n");
        }
        print("\n");
    }
    
    print("Querying in the following...\n\n");
    print(document.getElementById("test").outerHTML + "\n\n");
    
    query(document.getElementById("B"), "ancestor::xhtml:span", "span#A");
    query(document.getElementById("B"), ".|ancestor::xhtml:span", "span#A span#B");
    query(document.getElementById("B"), "ancestor::xhtml:span|.", "span#A span#B");

    query(document.getElementById("B"), "ancestor::xhtml:*[local-name()='span']", "span#A");
    query(document.getElementById("B"), ".|ancestor::xhtml:*[local-name()='span']", "span#A span#B");
    query(document.getElementById("B"), "ancestor::xhtml:*[local-name()='span']|.", "span#A span#B");
    query(document.getElementById("B"), "(ancestor::xhtml:*[local-name()='span'])|.", "span#A span#B");
    
    query(document.getElementById("B"), "following::xhtml:*[local-name()='span']", "span#C span#D");
    query(document.getElementById("B"), ".|following::xhtml:*[local-name()='span']", "span#B span#C span#D");
    query(document.getElementById("B"), "following::xhtml:*[local-name()='span']|.", "span#B span#C span#D");
}, false);
</script>
</head>
<body>
<div id="test">
    <span id="A">
        <span id="B"/>
    </span>
    <span id="C">
        <span id="D"/>
    </span>
</div>
<div id="msg"/>
</body>
</html>