FormControlRange-unsupported-elements.html (2589B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="/html/resources/common.js"></script> 5 <body></body> 6 <script> 7 test(() => { 8 const range = new FormControlRange(); 9 const textNode = document.createTextNode("test"); 10 assert_throws_dom("NotSupportedError", () => { 11 range.setFormControlRange(textNode, 0, 0); 12 }); 13 }, "FormControlRange throws NotSupportedError for text node."); 14 15 // Test all HTML5 elements; only <textarea> and <input> support FormControlRange. 16 test(() => { 17 const supportedElements = ['textarea', 'input']; 18 19 HTML5_ELEMENTS.forEach(elementName => { 20 if (supportedElements.includes(elementName)) { 21 return; 22 } 23 24 var doc = newHTMLDocument(); 25 const element = doc.createElement(elementName); 26 doc.body.appendChild(element); 27 28 const range = new FormControlRange(); 29 assert_throws_dom("NotSupportedError", () => { 30 range.setFormControlRange(element, 0, 0); 31 }, `FormControlRange should throw NotSupportedError for ${element.outerHTML}`); 32 }); 33 }, "FormControlRange should throw NotSupportedError for all unsupported HTML5 elements."); 34 35 // Test all HTML5_INPUT_TYPES. 36 // Only these input types support the Selection API: text, search, url, tel, password. 37 // https://html.spec.whatwg.org/multipage/input.html#do-not-apply 38 39 test(() => { 40 const supportedInputTypes = ['text', 'search', 'url', 'tel', 'password']; 41 42 HTML5_INPUT_TYPES.forEach(inputType => { 43 if (supportedInputTypes.includes(inputType)) { 44 return; 45 } 46 var doc = newHTMLDocument(); 47 var input = doc.createElement('input'); 48 input.type = inputType; 49 doc.body.appendChild(input); 50 51 const range = new FormControlRange(); 52 53 assert_throws_dom("NotSupportedError", () => { 54 range.setFormControlRange(input, 0, 0); 55 }, `FormControlRange should throw NotSupportedError for ${input.outerHTML}`); 56 }); 57 }, "FormControlRange should throw NotSupportedError for unsupported input types."); 58 59 // Test which error "wins" when both element type and index are invalid. 60 test(() => { 61 var doc = newHTMLDocument(); 62 doc.body.innerHTML = '<div contenteditable>Test</div>'; 63 const element = doc.body.firstElementChild; 64 65 const range = new FormControlRange(); 66 67 // Both element type (div) and index (-1, 100) are invalid. 68 assert_throws_dom("NotSupportedError", () => { 69 range.setFormControlRange(element, -1, 100); 70 }); 71 }, "NotSupportedError should take precedence over IndexSizeError when both element type and index are invalid for a FormControlRange."); 72 </script>