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 after 'o' in 'word' and delete it characte
r by character. Do ctrl+z. On Mac, 'word' should be selected. On other platforms
'word' should not be selected and the cursor should be placed after 'o' in 'wor
d'.</p> | 6 <p>To test manually, place the cursor after 'o' in 'word' and delete it characte
r by character. Do ctrl+z. On Mac, 'word' should be selected. On other platforms
'word' should not be selected and the cursor should be placed after 'o' in 'wor
d'.</p> |
7 <div id="test" style="border: 2px solid red;" contenteditable>This wo<b>rd </b>s
hould be selected.</div> | 7 <div id="test" style="border: 2px solid red;" contenteditable>This wo<b>rd </b>s
hould 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').firstChild; // Text node 'Th
is wo' | 14 var selectionNode = document.getElementById('test').firstChild; // Text node 'Th
is wo' |
15 var selectionOffset = selectionNode.length; | 15 var selectionOffset = selectionNode.length; |
16 var endNode = document.getElementById('test').childNodes[1].firstChild; // Text
node 'rd ' | 16 var endNodeMac = document.getElementById('test').childNodes[1].firstChild; // Te
xt node 'rd ' |
17 var endOffset = endNode.length - 1; | 17 var endOffsetMac = endNodeMac.length - 1; |
18 var startOffset = selectionNode.data.indexOf(' ')+1; | 18 var startOffsetMac = selectionNode.data.indexOf(' ')+1; |
19 var selection = window.getSelection(); | 19 var selection = window.getSelection(); |
20 | 20 |
21 function $(id) { return document.getElementById(id); } | 21 function $(id) { return document.getElementById(id); } |
22 | 22 |
23 function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndN
ode, expectedEndOffset, selectedText) { | 23 function undoTest(platform, expectedStartNode, expectedStartOffset, expectedEndN
ode, expectedEndOffset, selectedText) { |
24 debug(platform); | 24 debug(platform); |
25 internals.settings.setEditingBehavior(platform); | 25 internals.settings.setEditingBehavior(platform); |
26 | 26 |
27 selection.collapse(selectionNode, selectionOffset); | 27 selection.collapse(selectionNode, selectionOffset); |
28 for (var i = 0; i < 2; i++) | 28 for (var i = 0; i < 2; i++) |
29 document.execCommand('delete'); | 29 document.execCommand('delete'); |
30 for (var i = 0; i < 2; i++) | 30 for (var i = 0; i < 2; i++) |
31 document.execCommand('forwarddelete'); | 31 document.execCommand('forwarddelete'); |
32 document.execCommand('undo'); | 32 document.execCommand('undo'); |
33 | 33 |
34 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data); | 34 shouldBeEqualToString('selection.anchorNode.data', expectedStartNode.data); |
35 shouldBe('selection.anchorOffset', expectedStartOffset + ''); | 35 shouldBe('selection.anchorOffset', expectedStartOffset + ''); |
36 shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data); | 36 shouldBeEqualToString('selection.focusNode.data', expectedEndNode.data); |
37 shouldBe('selection.focusOffset', expectedEndOffset + ''); | 37 shouldBe('selection.focusOffset', expectedEndOffset + ''); |
38 shouldBeEqualToString('selection.toString()', selectedText); | 38 shouldBeEqualToString('selection.toString()', selectedText); |
39 shouldBeEqualToString('$("test").innerHTML', sampleHTML); | 39 shouldBeEqualToString('$("test").innerHTML', sampleHTML); |
40 } | 40 } |
41 | 41 |
42 if (window.internals) { | 42 if (window.internals) { |
43 undoTest('mac', selectionNode, startOffset, endNode, endOffset, 'word'); | 43 undoTest('mac', selectionNode, startOffsetMac, endNodeMac, endOffsetMac, 'wo
rd'); |
44 undoTest('win', selectionNode, startOffset, endNode, endOffset, 'word'); | 44 undoTest('win', selectionNode, selectionOffset, selectionNode, selectionOffs
et, ''); |
45 undoTest('unix', selectionNode, startOffset, endNode, endOffset, 'word'); | 45 undoTest('unix', selectionNode, selectionOffset, selectionNode, selectionOff
set, ''); |
46 undoTest('android', selectionNode, startOffset, endNode, endOffset, 'word'); | 46 undoTest('android', selectionNode, selectionOffset, selectionNode, selection
Offset, ''); |
47 } | 47 } |
48 if (window.testRunner) | 48 if (window.testRunner) |
49 document.getElementById('container').outerHTML = ''; | 49 document.getElementById('container').outerHTML = ''; |
50 </script> | 50 </script> |
51 <script src="../../fast/js/resources/js-test-post.js"></script> | 51 <script src="../../fast/js/resources/js-test-post.js"></script> |
52 </body> | 52 </body> |
53 </html> | 53 </html> |
OLD | NEW |