evaluator-different-document.tentative.html (2329B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Cross-document XPath evaluation</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <body> 7 <script> 8 function toArray(result) { 9 var a = []; 10 while (true) { 11 var node = result.iterateNext(); 12 if (node === null) break; 13 a.push(node); 14 } 15 return a; 16 } 17 18 var html_ns = "http://www.w3.org/1999/xhtml"; 19 var xml_doc = document.implementation.createDocument(html_ns, "html"); 20 var html_doc = document.implementation.createHTMLDocument(); 21 22 function ns_resolver(x) { 23 if (x === "html") { 24 return html_ns; 25 } else { 26 return null; 27 } 28 } 29 30 test(function() { 31 assert_array_equals(toArray(xml_doc.evaluate("//html", xml_doc)), []); 32 }, "evaluate operation on XML document, context node in XML document, no namespace resolver"); 33 34 test(function() { 35 assert_array_equals(toArray(html_doc.evaluate("//html", html_doc)), [html_doc.documentElement]); 36 }, "evaluate operation on HTML document, context node in HTML document, no namespace resolver"); 37 38 test(function() { 39 assert_array_equals(toArray(xml_doc.evaluate("//html", html_doc)), [html_doc.documentElement]); 40 }, "evaluate operation on XML document, context node in HTML document, no namespace resolver"); 41 42 test(function() { 43 assert_array_equals(toArray(html_doc.evaluate("//html", xml_doc)), []); 44 }, "evaluate operation on HTML document, context node in XML document, no namespace resolver"); 45 46 test(function() { 47 assert_array_equals(toArray(xml_doc.evaluate("//html", xml_doc, ns_resolver)), []); 48 }, "evaluate operation on XML document, context node in XML document, with namespace resolver"); 49 50 test(function() { 51 assert_array_equals(toArray(html_doc.evaluate("//html", html_doc, ns_resolver)), [html_doc.documentElement]); 52 }, "evaluate operation on HTML document, context node in HTML document, with namespace resolver"); 53 54 test(function() { 55 assert_array_equals(toArray(xml_doc.evaluate("//html", html_doc, ns_resolver)), [html_doc.documentElement]); 56 }, "evaluate operation on XML document, context node in HTML document, with namespace resolver"); 57 58 test(function() { 59 assert_array_equals(toArray(html_doc.evaluate("//html", xml_doc, ns_resolver)), []); 60 }, "evaluate operation on HTML document, context node in XML document, with namespace resolver"); 61 </script>