tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

expression-different-document.tentative.html (2802B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Cross-document XPath expressions</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  var xml_doc_expression = xml_doc.createExpression("//html");
     32  assert_array_equals(toArray(xml_doc_expression.evaluate(xml_doc)), []);
     33 }, "expression from XML document, context node in XML document, no namespace resolver");
     34 
     35 test(function() {
     36  var html_doc_expression = html_doc.createExpression("//html");
     37  assert_array_equals(toArray(html_doc_expression.evaluate(html_doc)), [html_doc.documentElement]);
     38 }, "expression from HTML document, context node in HTML document, no namespace resolver");
     39 
     40 test(function() {
     41  var xml_doc_expression = xml_doc.createExpression("//html");
     42  assert_array_equals(toArray(xml_doc_expression.evaluate(html_doc)), [html_doc.documentElement]);
     43 }, "expression from XML document, context node in HTML document, no namespace resolver");
     44 
     45 test(function() {
     46  var html_doc_expression = html_doc.createExpression("//html");
     47  assert_array_equals(toArray(html_doc_expression.evaluate(xml_doc)), []);
     48 }, "expression from HTML document, context node in XML document, no namespace resolver");
     49 
     50 test(function() {
     51  var xml_doc_expression = xml_doc.createExpression("//html", ns_resolver);
     52  assert_array_equals(toArray(xml_doc_expression.evaluate(xml_doc)), []);
     53 }, "expression from XML document, context node in XML document, with namespace resolver");
     54 
     55 test(function() {
     56  var html_doc_expression = html_doc.createExpression("//html", ns_resolver);
     57  assert_array_equals(toArray(html_doc_expression.evaluate(html_doc)), [html_doc.documentElement]);
     58 }, "expression from HTML document, context node in HTML document, with namespace resolver");
     59 
     60 test(function() {
     61  var xml_doc_expression = xml_doc.createExpression("//html", ns_resolver);
     62  assert_array_equals(toArray(xml_doc_expression.evaluate(html_doc)), [html_doc.documentElement]);
     63 }, "expression from XML document, context node in HTML document, with namespace resolver");
     64 
     65 test(function() {
     66  var html_doc_expression = html_doc.createExpression("//html", ns_resolver);
     67  assert_array_equals(toArray(html_doc_expression.evaluate(xml_doc)), []);
     68 }, "expression from HTML document, context node in XML document, with namespace resolver");
     69 </script>