test_defaultParagraphSeparatorBR_between_blocks.html (1913B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test for insertParagraph when defaultParagraphSeparator is br and between blocks</title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 8 <script> 9 "use strict"; 10 SimpleTest.waitForExplicitFinish(); 11 SimpleTest.waitForFocus(() => { 12 const editor = document.createElement("div"); 13 editor.setAttribute("contenteditable", ""); 14 editor.innerHTML = "<div>abc</div><div>def</div>"; 15 document.body.appendChild(editor); 16 editor.focus(); 17 document.execCommand("defaultParagraphSeparator", false, "br"); 18 getSelection().collapse(editor, 1); // put caret between the <div>s 19 ok( 20 document.execCommand("insertParagraph"), 21 'execCommand("insertParagraph") should return true' 22 ) 23 is( 24 editor.innerHTML, 25 "<div>abc</div><br><div>def</div>", 26 "<br> element should be inserted between the <div> elements" 27 ); 28 ok( 29 getSelection().isCollapsed, 30 "Selection should be collapsed after insertParagraph" 31 ); 32 is( 33 getSelection().focusNode, 34 editor, 35 "Caret should be in the editing host" 36 ); 37 is( 38 getSelection().focusOffset, 39 1, 40 "Caret should be around the <br> element" 41 ); 42 is( 43 SpecialPowers.wrap(getSelection()).interlinePosition, 44 true, 45 "Caret should be painted at start of the new line" 46 ); 47 document.execCommand("insertText", false, "X"); 48 todo_is( 49 editor.innerHTML, 50 "<div>abc</div><br>X<div>def</div>", 51 '"X" should be inserted after the inserted <br> element' 52 ); 53 SimpleTest.finish(); 54 }); 55 </script> 56 </head> 57 <body> 58 <p id="display"></p> 59 <div id="content" style="display: none"></div> 60 <pre id="test"></pre> 61 </body> 62 </html>