tor-browser

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

interfaces.html (2639B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Test of interfaces</title>
      4 <link rel="author" title="Ms2ger" href="mailto:Ms2ger@gmail.com">
      5 <link rel="help" href="https://html.spec.whatwg.org/multipage/">
      6 <link rel="help" href="https://webidl.spec.whatwg.org/#host-objects">
      7 <link rel="help" href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf#page=96">
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src=interfaces.js></script>
     11 <div id="log"></div>
     12 <script>
     13 function do_test(local_name, iface, variant) {
     14  test(function() {
     15    var e;
     16    var i = "HTML" + iface + "Element";
     17    if (variant === "useNS") {
     18      // Use createElementNS here to preserve the case of local_name.
     19      e = document.createElementNS("http://www.w3.org/1999/xhtml", local_name);
     20    } else if (variant === "useParser") {
     21      e = new DOMParser().parseFromString("<" + local_name + ">", "text/html").querySelector(local_name);
     22    } else {
     23      e = document.createElement(local_name);
     24    }
     25    assert_class_string(e, i,
     26                        "Element " + local_name + " should have " + i +
     27                        " as its primary interface.");
     28    assert_true(e instanceof window[i],
     29                "Element " + local_name + " should implement " + i + ".");
     30    assert_true(e instanceof HTMLElement,
     31                "Element " + local_name + " should implement HTMLElement.");
     32    assert_true(e instanceof Element,
     33                "Element " + local_name + " should implement Element.");
     34    assert_true(e instanceof Node,
     35                "Element " + local_name + " should implement Node.");
     36  }, "Interfaces for " + local_name + ": " + variant);
     37 }
     38 
     39 // Some elements have weird parser behavior / insertion modes and would be
     40 // skipped by the parser, so skip those.
     41 function should_do_parser_test(local_name) {
     42  return ![
     43    "foo-BAR",
     44    "tbody",
     45    "td",
     46    "tfoot",
     47    "th",
     48    "thead",
     49    "tr",
     50    "å-bar",
     51    "caption",
     52    "col",
     53    "colgroup",
     54    "frame",
     55    "image",
     56    "frameset",
     57  ].includes(local_name)
     58 }
     59 
     60 elements.forEach(function(a) {
     61  do_test(a[0], a[1], "useNS");
     62 
     63  if (should_do_parser_test(a[0])) {
     64    do_test(a[0], a[1], "useParser");
     65  }
     66 
     67  // Only run the createElement variant if the input is all-lowercase, because createElement
     68  // case-folds to lowercase. Custom elements are required to use all-lowercase to implement
     69  // HTMLElement, otherwise they use HTMLUnknownElement per spec. Example: "foo-BAR".
     70  if (a[0] === a[0].toLowerCase()) {
     71    do_test(a[0].toUpperCase(), a[1], "createElement");
     72  }
     73 })
     74 </script>