tor-browser

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

perform-microtask-checkpoint-before-construction-xml-parser.xhtml (3383B)


      1 <?xml version="1.0" encoding="utf-8"?>
      2 <html xmlns="http://www.w3.org/1999/xhtml">
      3 <head>
      4 <title>Custom Elements: create an element for a token must perform a microtask checkpoint</title>
      5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org" />
      6 <meta name="assert" content="When the HTML parser creates an element for a token, it must perform a microtask checkpoint before invoking the constructor" />
      7 <meta name="help" content="https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token" />
      8 <meta name="help" content="https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint" />
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 <script src="resources/custom-elements-helpers.js"></script>
     12 </head>
     13 <body>
     14 <div id="log"></div>
     15 <script>
     16 <![CDATA[
     17 
     18 async function construct_custom_element_in_parser(test, markup)
     19 {
     20    const window = await create_window_in_test_async(test, 'application/xml', `<?xml version="1.0" encoding="utf-8"?>
     21 <html xmlns="http://www.w3.org/1999/xhtml">
     22 <body><script>
     23 class SomeElement extends HTMLElement {
     24    constructor() {
     25        super();
     26        window.recordsListInConstructor = recordsList.map((records) => records.slice(0));
     27    }
     28 }
     29 customElements.define('some-element', SomeElement);
     30 
     31 const recordsList = [];
     32 const observer = new MutationObserver((records) => {
     33    recordsList.push(records);
     34 });
     35 observer.observe(document.body, {childList: true, subtree: true});
     36 
     37 window.onload = () => {
     38    window.recordsListInDOMContentLoaded = recordsList.map((records) => records.slice(0));
     39 }
     40 
     41 </scr` + `ipt>${markup}</body></html>`);
     42    return window;
     43 }
     44 
     45 promise_test(async function () {
     46    const contentWindow = await construct_custom_element_in_parser(this, '<b><some-element></some-element></b>');
     47    const contentDocument = contentWindow.document;
     48 
     49    let recordsList = contentWindow.recordsListInConstructor;
     50    assert_true(Array.isArray(recordsList));
     51    assert_equals(recordsList.length, 1);
     52    assert_true(Array.isArray(recordsList[0]));
     53    assert_equals(recordsList[0].length, 1);
     54    let record = recordsList[0][0];
     55    assert_equals(record.type, 'childList');
     56    assert_equals(record.target, contentDocument.body);
     57    assert_equals(record.previousSibling, contentDocument.querySelector('script'));
     58    assert_equals(record.nextSibling, null);
     59    assert_equals(record.removedNodes.length, 0);
     60    assert_equals(record.addedNodes.length, 1);
     61    assert_equals(record.addedNodes[0], contentDocument.querySelector('b'));
     62 
     63    recordsList = contentWindow.recordsListInDOMContentLoaded;
     64    assert_true(Array.isArray(recordsList));
     65    assert_equals(recordsList.length, 2);
     66    assert_true(Array.isArray(recordsList[1]));
     67    assert_equals(recordsList[1].length, 1);
     68    record = recordsList[1][0];
     69    assert_equals(record.type, 'childList');
     70    assert_equals(record.target, contentDocument.querySelector('b'));
     71    assert_equals(record.previousSibling, null);
     72    assert_equals(record.nextSibling, null);
     73    assert_equals(record.removedNodes.length, 0);
     74    assert_equals(record.addedNodes.length, 1);
     75    assert_equals(record.addedNodes[0], contentDocument.querySelector('some-element'));
     76 }, 'XML parser must perform a microtask checkpoint before constructing a custom element');
     77 
     78 ]]>
     79 </script>
     80 </body>
     81 </html>