test_bug1250010.html (2711B)
1 <!DOCTYPE> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1250010 5 --> 6 <head> 7 <title>Test for Bug 1250010</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 </head> 12 <body> 13 <div id="display"> 14 </div> 15 16 <div id="test1" contenteditable><p><b><font color="red">1234567890</font></b></p></div> 17 <div id="test2" contenteditable><p><tt>xyz</tt></p><p><tt><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAIAAABvrngfAAAAFklEQVQImWMwjWhCQwxECoW3oCHihAB0LyYv5/oAHwAAAABJRU5ErkJggg=="></tt></p></div> 18 19 <pre id="test"> 20 </pre> 21 22 <script class="testbody" type="application/javascript"> 23 24 function getImageDataURI() { 25 return document.getElementsByTagName("img")[0].getAttribute("src"); 26 } 27 28 /** Test for Bug 1250010 */ 29 SimpleTest.waitForExplicitFinish(); 30 SimpleTest.waitForFocus(function() { 31 // First test: Empty paragraph is split correctly. 32 var div = document.getElementById("test1"); 33 div.focus(); 34 synthesizeMouseAtCenter(div, {}); 35 36 var sel = window.getSelection(); 37 var selRange = sel.getRangeAt(0); 38 is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node"); 39 is(selRange.endOffset, 10, "offset should be 10"); 40 41 synthesizeKey("KEY_Enter"); 42 synthesizeKey("KEY_Enter"); 43 sendString("b"); 44 synthesizeKey("KEY_ArrowUp"); 45 sendString("a"); 46 47 is(div.innerHTML, "<p><b><font color=\"red\">1234567890</font></b></p>" + 48 "<p><b><font color=\"red\">a</font></b></p>" + 49 "<p><b><font color=\"red\">b</font></b></p>", 50 "unexpected HTML"); 51 52 // Second test: Since we modified the code path that splits non-text nodes, 53 // test that this works, if the split node is not empty. 54 div = document.getElementById("test2"); 55 div.focus(); 56 synthesizeMouseAtCenter(div, {}); 57 58 selRange = sel.getRangeAt(0); 59 is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node"); 60 is(selRange.endOffset, 3, "offset should be 3"); 61 62 // Move behind the image and press enter, insert an "A". 63 // That should insert a new empty paragraph with the "A" after what we have. 64 synthesizeKey("KEY_ArrowRight"); 65 synthesizeKey("KEY_ArrowRight"); 66 synthesizeKey("KEY_Enter"); 67 sendString("A"); 68 69 const expectedHTML = 70 "<p><tt>xyz</tt></p><p><tt><img src=\"" + getImageDataURI() + "\"></tt></p>" + 71 "<p><tt>A</tt></p>"; 72 is( 73 div.innerHTML, 74 expectedHTML, 75 "Pressing Enter after the <img> should create new paragraph and which contain <tt> and new text should be inserted in it" 76 ); 77 78 SimpleTest.finish(); 79 }); 80 81 </script> 82 </body> 83 84 </html>