keep-collapsible-white-space-after-web-app-delete-padding-br.html (3524B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>If browsers inserts a br element to make preceding collapsible white-space visible, 6 it should be maintained even if the web app deletes the br element</title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/resources/testdriver.js"></script> 10 <script src="/resources/testdriver-vendor.js"></script> 11 <script src="/resources/testdriver-actions.js"></script> 12 <script src="../include/editor-test-utils.js"></script> 13 <script> 14 "use strict"; 15 16 document.addEventListener("DOMContentLoaded", () => { 17 const editingHost = document.querySelector("div[contenteditable]"); 18 editingHost.focus(); 19 const utils = new EditorTestUtils(editingHost); 20 21 promise_test(async t => { 22 utils.setupEditingHost("abc d[]"); 23 await utils.sendBackspaceKey(); 24 assert_in_array( 25 editingHost.innerHTML, 26 ["abc <br>", "abc "], 27 `${t.name}: Deleting the first char of the second word should not make the preceding white-space invisible` 28 ); 29 const br = editingHost.querySelector("br"); 30 if (br) { 31 br.remove(); 32 assert_in_array( 33 editingHost.innerHTML, 34 ["abc <br>", "abc "], 35 `${t.name}: Browser should keep the collapsible white-space as visible even if the padding <br> is removed` 36 ); 37 } 38 await utils.sendKey("d"); 39 assert_equals( 40 editingHost.innerHTML, 41 "abc d", 42 `${t.name}: Typing a character should make the last white-space as an ASCII space and delete the unnecessary <br>` 43 ); 44 }, "The last ASCII white-space should be replaced with an NBSP even if <br> is removed by web app"); 45 46 promise_test(async t => { 47 utils.setupEditingHost("abc d[]<div>ef</div>"); 48 await utils.sendBackspaceKey(); 49 assert_in_array( 50 editingHost.innerHTML, 51 ["abc <br><div>ef</div>", "abc <div>ef</div>"], 52 `${t.name}: Deleting the first char of the second word should not make the preceding white-space invisible` 53 ); 54 const br = editingHost.querySelector("br"); 55 if (br) { 56 br.remove(); 57 assert_in_array( 58 editingHost.innerHTML, 59 ["abc <br><div>ef</div>", "abc <div>ef</div>"], 60 `${t.name}: Browser should keep the collapsible white-space as visible even if the padding <br> is removed` 61 ); 62 } 63 await utils.sendKey("d"); 64 assert_equals( 65 editingHost.innerHTML, 66 "abc d<div>ef</div>", 67 `${t.name}: Typing a character should make the last white-space as an ASCII space and delete the unnecessary <br>` 68 ); 69 }, "The last ASCII white-space should be replaced with an NBSP even if <br> followed by a child block boundary is removed by web app"); 70 71 promise_test(async t => { 72 utils.setupEditingHost("abc <br>def"); 73 editingHost.querySelector("br").remove(); 74 assert_equals( 75 editingHost.innerHTML, 76 "abc def" 77 ); 78 }, "The last ASCII white-space should not be replaced with an NBSP if following <br> is not a padding <br>"); 79 80 promise_test(async t => { 81 utils.setupEditingHost(`<div contenteditable="false">abc <br></div>`); 82 editingHost.querySelector("br").remove(); 83 assert_equals( 84 editingHost.innerHTML, 85 `<div contenteditable="false">abc </div>` 86 ); 87 }, "The last ASCII white-space in non-editable Text node should not be replaced with an NBSP if following <br> is not a padding <br>"); 88 }, {once: true}); 89 </script> 90 </head> 91 <body> 92 <div contenteditable></div> 93 </body> 94 </html>