delete-in-shadow-hosted-in-body.html (2635B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Delete editor in a shadow</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-vendor.js"></script> 10 <script src="/resources/testdriver-actions.js"></script> 11 <script src="../include/editor-test-utils.js"></script> 12 <script> 13 "use strict"; 14 15 addEventListener("load", () => { 16 const shadowRoot = document.body.attachShadow({mode: "open"}); 17 for (const tag of ["input", "textarea"]) { 18 promise_test(async t => { 19 const textControl = document.createElement(tag); 20 textControl.value = "text"; 21 shadowRoot.appendChild(textControl); 22 textControl.focus(); 23 textControl.selectionStart = textControl.value.length; 24 const utils = new EditorTestUtils(textControl); 25 await utils.sendBackspaceKey(); 26 assert_equals( 27 textControl.value, 28 "tex", 29 `Backspace in ${t.name} should delete character before the caret` 30 ); 31 textControl.value = "text"; 32 textControl.selectionStart = textControl.selectionEnd = 0; 33 await utils.sendDeleteKey(); 34 assert_equals( 35 textControl.value, 36 "ext", 37 `Delete in ${t.name} should delete character after the caret` 38 ); 39 textControl.value = "text"; 40 textControl.select(); 41 await utils.sendBackspaceKey(); 42 assert_equals( 43 textControl.value, 44 "", 45 `Backspace after selecting all text in ${t.name} should delete all text` 46 ); 47 }, `<${tag}> in shadow of the <body>`); 48 } 49 50 promise_test(async t => { 51 const editingHost = document.createElement("div"); 52 editingHost.setAttribute("contenteditable", ""); 53 shadowRoot.appendChild(editingHost); 54 const utils = new EditorTestUtils(editingHost); 55 utils.setupEditingHost("text[]"); 56 await utils.sendBackspaceKey(); 57 assert_equals( 58 editingHost.textContent, 59 "tex", 60 `Backspace in ${t.name} should delete character before the caret` 61 ); 62 utils.setupEditingHost("[]text"); 63 await utils.sendDeleteKey(); 64 assert_equals( 65 editingHost.textContent, 66 "ext", 67 `Delete in ${t.name} should delete character after the caret` 68 ); 69 utils.setupEditingHost("[text]"); 70 await utils.sendBackspaceKey(); 71 assert_equals( 72 editingHost.textContent, 73 "", 74 `Backspace after selecting all text in ${t.name} should delete all text` 75 ); 76 }, "<div contenteditable> in shadow of the <body>"); 77 }, {once: true}); 78 </script> 79 </head> 80 <body></body> 81 </html>