test_bug1257363.html (6301B)
1 <!DOCTYPE> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1257363 5 --> 6 <head> 7 <title>Test for Bug 1257363</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="backspaceCSS" contenteditable><p style="color:red;">12345</p>67</div> 17 <div id="backspace" contenteditable><p><font color="red">12345</font></p>67</div> 18 <div id="deleteCSS" contenteditable><p style="color:red;">x</p></div> 19 <div id="delete" contenteditable><p><font color="red">y</font></p></div> 20 21 <pre id="test"> 22 </pre> 23 24 <script class="testbody" type="application/javascript"> 25 26 /** Test for Bug 1257363 */ 27 SimpleTest.waitForExplicitFinish(); 28 SimpleTest.waitForFocus(function() { 29 // ***** Backspace test ***** 30 var div = document.getElementById("backspaceCSS"); 31 div.focus(); 32 synthesizeMouse(div, 100, 2, {}); /* click behind and down */ 33 34 var sel = window.getSelection(); 35 var selRange = sel.getRangeAt(0); 36 is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node"); 37 is(selRange.endOffset, 5, "offset should be 5"); 38 39 // Return and backspace should take us to where we started. 40 synthesizeKey("KEY_Enter"); 41 synthesizeKey("KEY_Backspace"); 42 43 selRange = sel.getRangeAt(0); 44 is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node"); 45 is(selRange.endOffset, 5, "offset should be 5"); 46 47 // Add an "a" to the end of the paragraph. 48 sendString("a"); 49 50 // Return and forward delete should take us to the following line. 51 synthesizeKey("KEY_Enter"); 52 synthesizeKey("KEY_Delete"); 53 54 // Add a "b" to the start. 55 sendString("b"); 56 57 is(div.innerHTML, "<p style=\"color:red;\">12345a</p>b67", 58 "unexpected HTML"); 59 60 // Let's repeat the whole thing, but a font tag instead of CSS. 61 // The behaviour is different since the font is carried over. 62 div = document.getElementById("backspace"); 63 div.focus(); 64 synthesizeMouse(div, 100, 2, {}); /* click behind and down */ 65 66 sel = window.getSelection(); 67 selRange = sel.getRangeAt(0); 68 is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node"); 69 is(selRange.endOffset, 5, "offset should be 5"); 70 71 // Return and backspace should take us to where we started. 72 synthesizeKey("KEY_Enter"); 73 synthesizeKey("KEY_Backspace"); 74 75 selRange = sel.getRangeAt(0); 76 is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node"); 77 is(selRange.endOffset, 5, "offset should be 5"); 78 79 // Add an "a" to the end of the paragraph. 80 sendString("a"); 81 82 // Return and forward delete should take us to the following line. 83 synthesizeKey("KEY_Enter"); 84 synthesizeKey("KEY_Delete"); 85 86 // Add a "b" to the start. 87 sendString("b"); 88 89 // Here we get a somewhat ugly result since the red sticks. 90 is(div.innerHTML, "<p><font color=\"red\">12345a</font></p><font color=\"#ff0000\">b</font>67", 91 "unexpected HTML"); 92 93 // ***** Delete test ***** 94 div = document.getElementById("deleteCSS"); 95 div.focus(); 96 synthesizeMouse(div, 100, 2, {}); /* click behind and down */ 97 98 sel = window.getSelection(); 99 selRange = sel.getRangeAt(0); 100 is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node"); 101 is(selRange.endOffset, 1, "offset should be 1"); 102 103 // left, enter should create a new empty paragraph before 104 // but leave the selection at the start of the existing paragraph. 105 synthesizeKey("KEY_ArrowLeft"); 106 synthesizeKey("KEY_Enter"); 107 108 selRange = sel.getRangeAt(0); 109 is(selRange.endContainer.nodeName, "#text", "selection should be at the start of text node"); 110 is(selRange.endOffset, 0, "offset should be 0"); 111 is(selRange.endContainer.nodeValue, "x", "we should be in the text node with the x"); 112 113 // Now moving up into the new empty paragraph. 114 synthesizeKey("KEY_ArrowUp"); 115 116 selRange = sel.getRangeAt(0); 117 is(selRange.endContainer.nodeName, "P", "selection should be the new empty paragraph"); 118 is(selRange.endOffset, 0, "offset should be 0"); 119 120 // Forward delete should now take us to where we started. 121 synthesizeKey("KEY_Delete"); 122 123 selRange = sel.getRangeAt(0); 124 is(selRange.endContainer.nodeName, "#text", "selection should be at the start of text node"); 125 is(selRange.endOffset, 0, "offset should be 0"); 126 127 // Add an "a" to the start of the paragraph. 128 sendString("a"); 129 130 is(div.innerHTML, "<p style=\"color:red;\">ax</p>", 131 "unexpected HTML"); 132 133 // Let's repeat the whole thing, but a font tag instead of CSS. 134 div = document.getElementById("delete"); 135 div.focus(); 136 synthesizeMouse(div, 100, 2, {}); /* click behind and down */ 137 138 sel = window.getSelection(); 139 selRange = sel.getRangeAt(0); 140 is(selRange.endContainer.nodeName, "#text", "selection should be at the end of text node"); 141 is(selRange.endOffset, 1, "offset should be 1"); 142 143 // left, enter should create a new empty paragraph before 144 // but leave the selection at the start of the existing paragraph. 145 synthesizeKey("KEY_ArrowLeft"); 146 synthesizeKey("KEY_Enter"); 147 148 selRange = sel.getRangeAt(0); 149 is(selRange.endContainer.nodeName, "#text", "selection should be at the start of text node"); 150 is(selRange.endOffset, 0, "offset should be 0"); 151 is(selRange.endContainer.nodeValue, "y", "we should be in the text node with the y"); 152 153 // Now moving up into the new empty paragraph. 154 synthesizeKey("KEY_ArrowUp"); 155 156 selRange = sel.getRangeAt(0); 157 is(selRange.endContainer.nodeName, "FONT", "selection should be the font tag"); 158 is(selRange.endOffset, 0, "offset should be 0"); 159 is(selRange.endContainer.parentNode.nodeName, "P", "the parent of the font should be a paragraph"); 160 161 // Forward delete should now take us to where we started. 162 synthesizeKey("KEY_Delete"); 163 164 selRange = sel.getRangeAt(0); 165 is(selRange.endContainer.nodeName, "#text", "selection should be at the start of text node"); 166 is(selRange.endOffset, 0, "offset should be 0"); 167 168 // Add an "a" to the start of the paragraph. 169 sendString("a"); 170 171 is(div.innerHTML, "<p><font color=\"red\">ay</font></p>", 172 "unexpected HTML"); 173 174 SimpleTest.finish(); 175 }); 176 177 </script> 178 </body> 179 180 </html>