OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <div id="container"> | 4 <div id="container"> |
5 <p id="description"></p> | 5 <p id="description"></p> |
6 <p>To test manually, place the cursor at the end of 'word' and delete it complet
ely character by character. Do ctrl+z. On Mac, 'word' should be selected. On oth
er platforms 'word' should not be selected and the cursor should be placed at th
e end of 'word'.</p> | 6 <p>To test manually, place the cursor at the end of 'word' and delete it complet
ely character by character. Do ctrl+z. On Mac, 'word' should be selected. On oth
er platforms 'word' should not be selected and the cursor should be placed at th
e end of 'word'.</p> |
7 <div id="test" style="border: 2px solid red;" contenteditable >This wo<b>rd </b>
should be selected.</div> | 7 <div id="test" style="border: 2px solid red;" contenteditable >This wo<b>rd </b>
should be selected only on mac.</div> |
8 </div> | 8 </div> |
9 <div id="console"></div> | 9 <div id="console"></div> |
10 <script src="../../fast/js/resources/js-test-pre.js"></script> | 10 <script src="../../fast/js/resources/js-test-pre.js"></script> |
11 <script> | 11 <script> |
12 description('Verifies the selection behavior on undoing a text deletion.'); | 12 description('Verifies the selection behavior on undoing a text deletion.'); |
13 var sampleHTML = 'This wo<b>rd </b>should be selected.'; | 13 var sampleHTML = 'This wo<b>rd </b>should be selected only on mac.'; |
14 var selectionNode = document.getElementById('test').childNodes[1].firstChild; //
Text node 'rd ' | 14 var selectionNode = document.getElementById('test').childNodes[1].firstChild; //
Text node 'rd ' |
15 var selectionOffset = selectionNode.length - 1; | 15 var selectionOffset = selectionNode.length - 1; |
16 var endNode = document.getElementById('test').firstChild; // Text node 'This wo' | 16 var endNodeMac = document.getElementById('test').firstChild; // Text node 'This
wo' |
17 var endOffset = endNode.data.indexOf(' ') + 1; | 17 var endOffsetMac = endNodeMac.data.indexOf(' ') + 1; |
18 var selection = window.getSelection(); | 18 var selection = window.getSelection(); |
19 | 19 |
20 function $(id) { return document.getElementById(id); } | 20 function $(id) { return document.getElementById(id); } |
21 | 21 |
22 function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndN
ode, expectedEndOffset, selectedText) { | 22 function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndN
ode, expectedEndOffset, selectedText) { |
23 debug(platform); | 23 debug(platform); |
24 internals.settings.setEditingBehavior(platform); | 24 internals.settings.setEditingBehavior(platform); |
25 | 25 |
26 selection.collapse(selectionNode, selectionOffset); | 26 selection.collapse(selectionNode, selectionOffset); |
27 for (var i = 0; i < 4; i++) | 27 for (var i = 0; i < 4; i++) |
28 document.execCommand('delete'); | 28 document.execCommand('delete'); |
29 document.execCommand('undo'); | 29 document.execCommand('undo'); |
30 | 30 |
31 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data); | 31 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data); |
32 shouldBe('selection.anchorOffset', expectedStartOffset + ''); | 32 shouldBe('selection.anchorOffset', expectedStartOffset + ''); |
33 shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data); | 33 shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data); |
34 shouldBe('selection.focusOffset', expectedEndOffset + ''); | 34 shouldBe('selection.focusOffset', expectedEndOffset + ''); |
35 shouldBeEqualToString('selection.toString()', selectedText); | 35 shouldBeEqualToString('selection.toString()', selectedText); |
36 shouldBeEqualToString('$("test").innerHTML', sampleHTML); | 36 shouldBeEqualToString('$("test").innerHTML', sampleHTML); |
37 } | 37 } |
38 | 38 |
39 if (window.internals) { | 39 if (window.internals) { |
40 undoTest('mac', selectionNode, selectionOffset, endNode, endOffset, 'word'); | 40 undoTest('mac', selectionNode, selectionOffset, endNodeMac, endOffsetMac, 'w
ord'); |
41 undoTest('win', selectionNode, selectionOffset, endNode, endOffset, 'word'); | 41 undoTest('win', selectionNode, selectionOffset, selectionNode, selectionOffs
et, ''); |
42 undoTest('unix', selectionNode, selectionOffset, endNode, endOffset, 'word')
; | 42 undoTest('unix', selectionNode, selectionOffset, selectionNode, selectionOff
set, ''); |
43 undoTest('android', selectionNode, selectionOffset, endNode, endOffset, 'wor
d'); | 43 undoTest('android', selectionNode, selectionOffset, selectionNode, selection
Offset, ''); |
44 } | 44 } |
45 if (window.testRunner) | 45 if (window.testRunner) |
46 document.getElementById('container').outerHTML = ''; | 46 document.getElementById('container').outerHTML = ''; |
47 </script> | 47 </script> |
48 <script src="../../fast/js/resources/js-test-post.js"></script> | 48 <script src="../../fast/js/resources/js-test-post.js"></script> |
49 </body> | 49 </body> |
50 </html> | 50 </html> |
OLD | NEW |