tor-browser

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

parser-constructs-custom-elements-with-is.html (2663B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>Custom Elements: Changes to the HTML parser</title>
      5 <meta name="author" title="John Dai" href="mailto:jdai@mozilla.com">
      6 <meta name="assert" content="HTML parser creates a custom element which contains is attribute">
      7 <link rel="help" href="https://html.spec.whatwg.org/#create-an-element-for-the-token">
      8 <link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element">
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 </head>
     12 <body>
     13 <div id="log"></div>
     14 <autonomous-custom-element id="instance1" is="is-custom-element"></autonomous-custom-element>
     15 <script>
     16 
     17 class AutonomousCustomElement extends HTMLElement { };
     18 class IsCustomElement extends HTMLElement { };
     19 
     20 customElements.define('autonomous-custom-element', AutonomousCustomElement);
     21 customElements.define('is-custom-element', IsCustomElement);
     22 
     23 test(function () {
     24    var customElement = document.getElementById('instance1');
     25 
     26    assert_true(customElement instanceof HTMLElement, 'A resolved custom element must be an instance of HTMLElement');
     27    assert_false(customElement instanceof HTMLUnknownElement, 'A resolved custom element must NOT be an instance of HTMLUnknownElement');
     28    assert_true(customElement instanceof AutonomousCustomElement, 'A resolved custom element must be an instance of that custom element');
     29    assert_equals(customElement.localName, 'autonomous-custom-element');
     30    assert_equals(customElement.namespaceURI, 'http://www.w3.org/1999/xhtml', 'A custom element HTML must use HTML namespace');
     31 
     32 }, 'HTML parser must create a defined autonomous custom element when customElements.define comes after HTML parser creation');
     33 
     34 </script>
     35 <autonomous-custom-element id="instance2" is="is-custom-element"></autonomous-custom-element>
     36 <script>
     37 
     38 test(function () {
     39    var customElement = document.getElementById('instance2');
     40 
     41    assert_true(customElement instanceof HTMLElement, 'A resolved custom element must be an instance of HTMLElement');
     42    assert_false(customElement instanceof HTMLUnknownElement, 'A resolved custom element must NOT be an instance of HTMLUnknownElement');
     43    assert_true(customElement instanceof AutonomousCustomElement, 'A resolved custom element must be an instance of that custom element');
     44    assert_equals(customElement.localName, 'autonomous-custom-element');
     45    assert_equals(customElement.namespaceURI, 'http://www.w3.org/1999/xhtml', 'A custom element HTML must use HTML namespace');
     46 
     47 }, 'HTML parser must create a defined autonomous custom element when customElements.define comes before HTML parser creation');
     48 
     49 </script>
     50 </body>
     51 </html>