tor-browser

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

CustomElementRegistry-getName.html (3326B)


      1 <!DOCTYPE html>
      2 <title>Custom Elements: CustomElementRegistry.getName function</title>
      3 <meta name="author" title="Keith Cirkel" href="mailto:keithamus@github.com">
      4 <meta name="assert" content="CustomElementRegistry.getName function exists">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 test(function () {
      9  assert_equals(customElements.getName(class extends HTMLElement {}), null);
     10 }, 'customElements.getName must return null when the registry does not contain an entry with the given constructor');
     11 
     12 test(function () {
     13  assert_throws_js(TypeError, function () { customElements.getName(undefined); },
     14        'customElements.getName must throw a TypeError when the element interface is undefined');
     15  assert_throws_js(TypeError, function () { customElements.getName(null); },
     16        'customElements.getName must throw a TypeError when the element interface is null');
     17  assert_throws_js(TypeError, function () { customElements.getName('foo-bar'); },
     18        'customElements.getName must throw a TypeError when the element interface is a string');
     19  assert_throws_js(TypeError, function () { customElements.getName(1); },
     20        'customElements.getName must throw a TypeError when the element interface is a number');
     21  assert_throws_js(TypeError, function () { customElements.getName({}); },
     22        'customElements.getName must throw a TypeError when the element interface is an object');
     23  assert_throws_js(TypeError, function () { customElements.getName([]) },
     24        'customElements.getName must throw a TypeError when the element interface is an array');
     25 }, 'customElements.getName must throw when the element interface is not a constructor');
     26 
     27 test(function () {
     28    class OtherExistingCustomElement extends HTMLElement {};
     29    class SecondExistingCustomElement extends HTMLElement {};
     30    assert_throws_js(TypeError, function () { customElements.getName(customElements.getName(OtherExistingCustomElement)); },
     31        'customElements.getName must throw a TypeError when the element interface is undefined');
     32    customElements.define('other-existing-custom-element', OtherExistingCustomElement);
     33    customElements.define('second-existing-custom-element', SecondExistingCustomElement);
     34    assert_equals(customElements.getName(OtherExistingCustomElement), 'other-existing-custom-element');
     35    assert_equals(customElements.getName(SecondExistingCustomElement), 'second-existing-custom-element');
     36 }, 'customElements.getName returns the name of the entry with the given constructor when there is a matching entry.');
     37 
     38 test(function () {
     39    class ButtonCustomBuiltInElement extends HTMLButtonElement {};
     40    class InputCustomBuiltInElement extends HTMLInputElement {};
     41    customElements.define('button-custom-built-in-element', ButtonCustomBuiltInElement, { extends: 'button' });
     42    customElements.define('input-custom-built-in-element', InputCustomBuiltInElement, { extends: 'input' });
     43    assert_equals(customElements.getName(ButtonCustomBuiltInElement), 'button-custom-built-in-element');
     44    assert_equals(customElements.getName(InputCustomBuiltInElement), 'input-custom-built-in-element');
     45 }, 'customElements.getName returns the name of the entry with the given customized built in constructor when there is a matching entry.');
     46 </script>