range-and-constructors.html (1655B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Custom elements: Range APIs should invoke constructor in tree order</title> 5 <meta name="author" title="Edgar Chen" href="mailto:echen@mozilla.com"> 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-element"> 7 <link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element"> 8 <link rel="help" href="https://dom.spec.whatwg.org/#concept-range-extract"> 9 <link rel="help" href="https://dom.spec.whatwg.org/#concept-range-clone"> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 </head> 13 <body> 14 <div id="log"></div> 15 16 <c-e id="root"> 17 <c-e id="root-0"> 18 <c-e id="root-0-0"> 19 <c-e id="root-0-0-0"></c-e> 20 <span id="start"></span> 21 </c-e> 22 </c-e> 23 <c-e id="root-1"></c-e> 24 <span id="end"></span> 25 </c-e> 26 27 <script> 28 29 var logs = []; 30 class CE extends HTMLElement { 31 constructor() { 32 super(); 33 logs.push(this.id); 34 } 35 } 36 customElements.define('c-e', CE); 37 38 function getRange() { 39 const range = new Range(); 40 range.setStart(document.getElementById('start'), 0); 41 range.setEnd(document.getElementById('end'), 0); 42 return range; 43 } 44 45 test(function () { 46 // Clear log for testing. 47 logs = []; 48 getRange().cloneContents(); 49 assert_array_equals(logs, ['root-0', 'root-0-0', 'root-1']); 50 }, 'Range.cloneContents should invoke constructor in tree order'); 51 52 test(function () { 53 // Clear log for testing. 54 logs = []; 55 getRange().extractContents(); 56 assert_array_equals(logs, ['root-0', 'root-0-0']); 57 }, 'Range.extractContents should invoke constructor in tree order'); 58 59 </script> 60 </body> 61 </html>