selection-range-after-textcontrol-removed.html (1838B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="variant" content="?textControl=text"> 6 <meta name="variant" content="?textControl=password"> 7 <meta name="variant" content="?textControl=number"> 8 <meta name="variant" content="?textControl=textarea"> 9 <title>Selection range after text control is removed</title> 10 <script src=/resources/testharness.js></script> 11 <script src=/resources/testharnessreport.js></script> 12 <script> 13 "use strict"; 14 15 /** 16 * Browsers may use internal Selection and/or Range to implement the selection 17 * in text controls. They should not be appear outside the host text control 18 * after the host is removed. 19 */ 20 addEventListener("load", () => { 21 const textControlType = (new URLSearchParams(document.location.search)).get("mode"); 22 function createTextControlElement() { 23 const textControl = 24 document.createElement(textControlType == "textarea" ? "textarea" : "input"); 25 if (textControlType != "textarea") { 26 textControl.type = textControlType; 27 } 28 return textControl; 29 } 30 31 test(() => { 32 const textControl = createTextControlElement(); 33 document.body.appendChild(textControl); 34 textControl.select(); 35 getSelection().removeAllRanges(); 36 textControl.remove(); 37 assert_equals(getSelection().rangeCount, 0); 38 }, "Removing the text control should not add selection range"); 39 40 test(() => { 41 const wrapper = document.createElement("div"); 42 wrapper.id = "wrapper"; 43 const textControl = createTextControlElement(); 44 wrapper.appendChild(textControl); 45 document.body.appendChild(wrapper); 46 textControl.select(); 47 getSelection().removeAllRanges(); 48 wrapper.remove(); 49 assert_equals(getSelection().rangeCount, 0); 50 }, "Removing the text control parent should not add selection range"); 51 }, {once: true}); 52 </script> 53 </head> 54 <body></body> 55 </html>