Home | History | Annotate | Download | only in xpath
      1 <?xml version="1.0" encoding="utf-8"?>
      2 <!DOCTYPE html>
      3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
      4 <head>
      5 <title>XPath queries with predicates incorrectly retains the current node across unions</title>
      6 <style>div#msg { white-space: pre; }</style>
      7 <script>
      8 if (window.layoutTestController)
      9     layoutTestController.dumpAsText();
     10 
     11 window.addEventListener("load", function() {
     12     var msg = document.getElementById("msg");
     13     function print(s) { msg.textContent += s; }
     14     function id(el) { return el.tagName + (el.id ? "#" + el.id : ""); }
     15     function query(el, xpath, expected) {
     16         print("Query \"" + xpath + "\" from " + id(el) + "\n");
     17         var res = document.evaluate(xpath,
     18                                     el,
     19                                     function() { return "http://www.w3.org/1999/xhtml"; },
     20                                     XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
     21                                     null);
     22 
     23         var resstr = "";
     24         for (var i = 0; i &lt; res.snapshotLength; i++) {
     25             var el = res.snapshotItem(i);
     26             resstr += " " + id(el);
     27         }
     28         print("Result:" + resstr + "\n");
     29         print("Expected: " + expected + "\n");
     30         if (resstr != (" " + expected)) {
     31             print("FAIL\n");
     32         } else {
     33             print("SUCCESS\n");
     34         }
     35         print("\n");
     36     }
     37     
     38     print("Querying in the following...\n\n");
     39     print(document.getElementById("test").outerHTML + "\n\n");
     40     
     41     query(document.getElementById("B"), "ancestor::xhtml:span", "span#A");
     42     query(document.getElementById("B"), ".|ancestor::xhtml:span", "span#A span#B");
     43     query(document.getElementById("B"), "ancestor::xhtml:span|.", "span#A span#B");
     44 
     45     query(document.getElementById("B"), "ancestor::xhtml:*[local-name()='span']", "span#A");
     46     query(document.getElementById("B"), ".|ancestor::xhtml:*[local-name()='span']", "span#A span#B");
     47     query(document.getElementById("B"), "ancestor::xhtml:*[local-name()='span']|.", "span#A span#B");
     48     query(document.getElementById("B"), "(ancestor::xhtml:*[local-name()='span'])|.", "span#A span#B");
     49     
     50     query(document.getElementById("B"), "following::xhtml:*[local-name()='span']", "span#C span#D");
     51     query(document.getElementById("B"), ".|following::xhtml:*[local-name()='span']", "span#B span#C span#D");
     52     query(document.getElementById("B"), "following::xhtml:*[local-name()='span']|.", "span#B span#C span#D");
     53 }, false);
     54 </script>
     55 </head>
     56 <body>
     57 <div id="test">
     58     <span id="A">
     59         <span id="B"/>
     60     </span>
     61     <span id="C">
     62         <span id="D"/>
     63     </span>
     64 </div>
     65 <div id="msg"/>
     66 </body>
     67 </html>
     68