| <?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.testRunner) |
| testRunner.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 < 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> |