tor-browser

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

test_custom_element_define_parser.html (1808B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=783129
      5 -->
      6 <head>
      7  <title>Test for customElements.define for elements created by the parser</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10 <script>
     11 
     12 var uncaughtError;
     13 window.onerror = function(message, url, lineNumber, columnNumber, error) {
     14  uncaughtError = error;
     15 };
     16 
     17 var isConnectedCallbackCalled = false;
     18 class XButton extends HTMLButtonElement {
     19  connectedCallback() {
     20    ok(!isConnectedCallbackCalled, "ConnectedCallback should only be called once.");
     21    is(this.tagName, "BUTTON", "Only the <button> element should be upgraded.");
     22    isConnectedCallbackCalled = true;
     23  }
     24 };
     25 
     26 customElements.define("x-button", XButton, { extends: "button" });
     27 
     28 class XDiv extends HTMLDivElement {
     29  constructor() {
     30    // Queue a task to check error and callbacks.
     31    setTimeout(() => {
     32      ok(isConnectedCallbackCalled, "ConnectedCallback should be called.");
     33      ok(uncaughtError instanceof TypeError,
     34       "TypeError should be filed for upgrading <x-div> element.");
     35      SimpleTest.finish();
     36    }, 0);
     37    super();
     38  }
     39 
     40  connectedCallback() {
     41    ok(false, "Connected callback for x-div should not be called.");
     42  }
     43 };
     44 
     45 customElements.define("x-div", XDiv);
     46 
     47 SimpleTest.waitForExplicitFinish();
     48 
     49 </script>
     50 </head>
     51 <body>
     52 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=783129">Bug 783129</a>
     53 <button is="x-button"></button><!-- should be upgraded -->
     54 <x-button></x-button><!-- should not be upgraded -->
     55 <span is="x-button"></span><!-- should not be upgraded -->
     56 <div is="x-div"></div><!-- should not be upgraded -->
     57 <x-div></x-div><!-- should be upgraded, but failed -->
     58 <script>
     59 </script>
     60 </body>
     61 </html>