1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/html/tests/test_bug414526.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,252 @@ 1.4 +<html> 1.5 +<head> 1.6 + <title>Test for backspace key and delete key shouldn't remove another editing host's text</title> 1.7 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.10 +</head> 1.11 +<body> 1.12 +<div id="display"></div> 1.13 +<div id="content" style="display: none"> 1.14 + 1.15 +</div> 1.16 +<pre id="test"> 1.17 +</pre> 1.18 + 1.19 +<script class="testbody" type="application/javascript"> 1.20 + 1.21 +SimpleTest.waitForExplicitFinish(); 1.22 +SimpleTest.waitForFocus(runTests); 1.23 + 1.24 +function runTests() 1.25 +{ 1.26 + 1.27 + var container = document.getElementById("display"); 1.28 + 1.29 + function reset() 1.30 + { 1.31 + document.execCommand("Undo", false, null); 1.32 + } 1.33 + 1.34 + var selection = window.getSelection(); 1.35 + function moveCaretToStartOf(aEditor) 1.36 + { 1.37 + selection.selectAllChildren(aEditor); 1.38 + selection.collapseToStart(); 1.39 + } 1.40 + 1.41 + function moveCaretToEndOf(aEditor) 1.42 + { 1.43 + selection.selectAllChildren(aEditor); 1.44 + selection.collapseToEnd(); 1.45 + } 1.46 + 1.47 + /* TestCase #1 1.48 + */ 1.49 + const kTestCase1 = 1.50 + "<p id=\"editor1\" contenteditable=\"true\">editor1</p>" + 1.51 + "<p id=\"editor2\" contenteditable=\"true\">editor2</p>" + 1.52 + "<div id=\"editor3\" contenteditable=\"true\"><div>editor3</div></div>" + 1.53 + "<p id=\"editor4\" contenteditable=\"true\">editor4</p>" + 1.54 + "non-editable text" + 1.55 + "<p id=\"editor5\" contenteditable=\"true\">editor5</p>"; 1.56 + 1.57 + const kTestCase1_editor3_deleteAtStart = 1.58 + "<p id=\"editor1\" contenteditable=\"true\">editor1</p>" + 1.59 + "<p id=\"editor2\" contenteditable=\"true\">editor2</p>" + 1.60 + "<div id=\"editor3\" contenteditable=\"true\"><div>ditor3</div></div>" + 1.61 + "<p id=\"editor4\" contenteditable=\"true\">editor4</p>" + 1.62 + "non-editable text" + 1.63 + "<p id=\"editor5\" contenteditable=\"true\">editor5</p>"; 1.64 + 1.65 + const kTestCase1_editor3_backspaceAtEnd = 1.66 + "<p id=\"editor1\" contenteditable=\"true\">editor1</p>" + 1.67 + "<p id=\"editor2\" contenteditable=\"true\">editor2</p>" + 1.68 + "<div id=\"editor3\" contenteditable=\"true\"><div>editor</div></div>" + 1.69 + "<p id=\"editor4\" contenteditable=\"true\">editor4</p>" + 1.70 + "non-editable text" + 1.71 + "<p id=\"editor5\" contenteditable=\"true\">editor5</p>"; 1.72 + 1.73 + container.innerHTML = kTestCase1; 1.74 + 1.75 + var editor1 = document.getElementById("editor1"); 1.76 + var editor2 = document.getElementById("editor2"); 1.77 + var editor3 = document.getElementById("editor3"); 1.78 + var editor4 = document.getElementById("editor4"); 1.79 + var editor5 = document.getElementById("editor5"); 1.80 + 1.81 + /* TestCase #1: 1.82 + * pressing backspace key at start should not change the content. 1.83 + */ 1.84 + editor2.focus(); 1.85 + moveCaretToStartOf(editor2); 1.86 + synthesizeKey("VK_BACK_SPACE", { }); 1.87 + is(container.innerHTML, kTestCase1, 1.88 + "Pressing backspace key at start of editor2 changes the content"); 1.89 + reset(); 1.90 + 1.91 + editor3.focus(); 1.92 + moveCaretToStartOf(editor3); 1.93 + synthesizeKey("VK_BACK_SPACE", { }); 1.94 + is(container.innerHTML, kTestCase1, 1.95 + "Pressing backspace key at start of editor3 changes the content"); 1.96 + reset(); 1.97 + 1.98 + editor4.focus(); 1.99 + moveCaretToStartOf(editor4); 1.100 + synthesizeKey("VK_BACK_SPACE", { }); 1.101 + is(container.innerHTML, kTestCase1, 1.102 + "Pressing backspace key at start of editor4 changes the content"); 1.103 + reset(); 1.104 + 1.105 + editor5.focus(); 1.106 + moveCaretToStartOf(editor5); 1.107 + synthesizeKey("VK_BACK_SPACE", { }); 1.108 + is(container.innerHTML, kTestCase1, 1.109 + "Pressing backspace key at start of editor5 changes the content"); 1.110 + reset(); 1.111 + 1.112 + /* TestCase #1: 1.113 + * pressing delete key at end should not change the content. 1.114 + */ 1.115 + editor1.focus(); 1.116 + moveCaretToEndOf(editor1); 1.117 + synthesizeKey("VK_DELETE", { }); 1.118 + is(container.innerHTML, kTestCase1, 1.119 + "Pressing delete key at end of editor1 changes the content"); 1.120 + reset(); 1.121 + 1.122 + editor2.focus(); 1.123 + moveCaretToEndOf(editor2); 1.124 + synthesizeKey("VK_DELETE", { }); 1.125 + is(container.innerHTML, kTestCase1, 1.126 + "Pressing delete key at end of editor2 changes the content"); 1.127 + reset(); 1.128 + 1.129 + editor3.focus(); 1.130 + moveCaretToEndOf(editor3); 1.131 + synthesizeKey("VK_DELETE", { }); 1.132 + // Because of a bug in nsFrameSelection::CharacterExtendForDelete, pressing Delete 1.133 + // here puts the selection in the text node inside editor3's inner div, which 1.134 + // causes us to delete the contents of that text node. This situation shouldn't 1.135 + // happen by the normal caret navigation functions that the user can invoke, so 1.136 + // we can fix it later. 1.137 + todo_is(container.innerHTML, kTestCase1, 1.138 + "Pressing delete key at end of editor3 changes the content"); 1.139 + reset(); 1.140 + 1.141 + editor4.focus(); 1.142 + moveCaretToEndOf(editor4); 1.143 + synthesizeKey("VK_DELETE", { }); 1.144 + is(container.innerHTML, kTestCase1, 1.145 + "Pressing delete key at end of editor4 changes the content"); 1.146 + reset(); 1.147 + 1.148 + /* TestCase #1: cases when the caret is not on text node. 1.149 + * - pressing delete key at start should remove the first character 1.150 + * - pressing backspace key at end should remove the first character 1.151 + * and the adjacent blocks should not be changed. 1.152 + */ 1.153 + editor3.focus(); 1.154 + moveCaretToStartOf(editor3); 1.155 + synthesizeKey("VK_DELETE", { }); 1.156 + is(container.innerHTML, kTestCase1_editor3_deleteAtStart, 1.157 + "Pressing delete key at start of editor3 changes adjacent elements" 1.158 + + " and/or does not remove the first character."); 1.159 + reset(); 1.160 + 1.161 + // Backspace doesn't work here yet. 1.162 + editor3.focus(); 1.163 + moveCaretToEndOf(editor3); 1.164 + synthesizeKey("VK_BACK_SPACE", { }); 1.165 + todo_is(container.innerHTML, kTestCase1_editor3_backspaceAtEnd, 1.166 + "Pressing backspace key at end of editor3 changes adjacent elements" 1.167 + + " and/or does not remove the last character."); 1.168 + reset(); 1.169 + // We can still check that adjacent elements are not affected. 1.170 + editor3.focus(); 1.171 + moveCaretToEndOf(editor3); 1.172 + synthesizeKey("VK_BACK_SPACE", { }); 1.173 + is(container.innerHTML, kTestCase1, 1.174 + "Pressing backspace key at end of editor3 changes the content"); 1.175 + reset(); 1.176 + 1.177 + /* TestCase #2: 1.178 + * two adjacent editable <span> in a table cell. 1.179 + */ 1.180 + const kTestCase2 = "<table><tbody><tr><td><span id=\"editor1\" contenteditable=\"true\">test</span>" + 1.181 + "<span id=\"editor2\" contenteditable=\"true\">test</span></td></tr></tbody></table>"; 1.182 + 1.183 + container.innerHTML = kTestCase2; 1.184 + editor1 = document.getElementById("editor1"); 1.185 + editor2 = document.getElementById("editor2"); 1.186 + 1.187 + editor2.focus(); 1.188 + moveCaretToStartOf(editor2); 1.189 + synthesizeKey("VK_BACK_SPACE", { }); 1.190 + is(container.innerHTML, kTestCase2, 1.191 + "Pressing backspace key at the start of editor2 changes the content for kTestCase2"); 1.192 + reset(); 1.193 + 1.194 + editor1.focus(); 1.195 + moveCaretToEndOf(editor1); 1.196 + synthesizeKey("VK_DELETE", { }); 1.197 + is(container.innerHTML, kTestCase2, 1.198 + "Pressing delete key at the end of editor1 changes the content for kTestCase2"); 1.199 + reset(); 1.200 + 1.201 + /* TestCase #3: 1.202 + * editable <span> in two adjacent table cells. 1.203 + */ 1.204 + const kTestCase3 = "<table><tbody><tr><td><span id=\"editor1\" contenteditable=\"true\">test</span></td>" + 1.205 + "<td><span id=\"editor2\" contenteditable=\"true\">test</span></td></tr></tbody></table>"; 1.206 + 1.207 + container.innerHTML = kTestCase3; 1.208 + editor1 = document.getElementById("editor1"); 1.209 + editor2 = document.getElementById("editor2"); 1.210 + 1.211 + editor2.focus(); 1.212 + moveCaretToStartOf(editor2); 1.213 + synthesizeKey("VK_BACK_SPACE", { }); 1.214 + is(container.innerHTML, kTestCase3, 1.215 + "Pressing backspace key at the start of editor2 changes the content for kTestCase3"); 1.216 + reset(); 1.217 + 1.218 + editor1.focus(); 1.219 + moveCaretToEndOf(editor1); 1.220 + synthesizeKey("VK_DELETE", { }); 1.221 + is(container.innerHTML, kTestCase3, 1.222 + "Pressing delete key at the end of editor1 changes the content for kTestCase3"); 1.223 + reset(); 1.224 + 1.225 + /* TestCase #4: 1.226 + * editable <div> in two adjacent table cells. 1.227 + */ 1.228 + const kTestCase4 = "<table><tbody><tr><td><div id=\"editor1\" contenteditable=\"true\">test</div></td>" + 1.229 + "<td><div id=\"editor2\" contenteditable=\"true\">test</div></td></tr></tbody></table>"; 1.230 + 1.231 + container.innerHTML = kTestCase4; 1.232 + editor1 = document.getElementById("editor1"); 1.233 + editor2 = document.getElementById("editor2"); 1.234 + 1.235 + editor2.focus(); 1.236 + moveCaretToStartOf(editor2); 1.237 + synthesizeKey("VK_BACK_SPACE", { }); 1.238 + is(container.innerHTML, kTestCase4, 1.239 + "Pressing backspace key at the start of editor2 changes the content for kTestCase4"); 1.240 + reset(); 1.241 + 1.242 + editor1.focus(); 1.243 + moveCaretToEndOf(editor1); 1.244 + synthesizeKey("VK_DELETE", { }); 1.245 + is(container.innerHTML, kTestCase4, 1.246 + "Pressing delete key at the end of editor1 changes the content for kTestCase4"); 1.247 + reset(); 1.248 + 1.249 + SimpleTest.finish(); 1.250 +} 1.251 + 1.252 +</script> 1.253 +</body> 1.254 + 1.255 +</html>