Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / move-begin-end.html
blob293e4632424403a16c337f96df1711266ba93020
1 <script>
2 if (window.testRunner) {
3 testRunner.dumpEditingCallbacks();
4 testRunner.dumpAsText();
7 var sel = window.getSelection();
9 function logResult(str) {
10 if (str != 'SUCCESS')
11 str += ' baseOffset: ' + sel.baseOffset + ' extentOffset: ' + sel.extentOffset;
12 document.getElementById('result').innerHTML = str;
15 function runTest() {
16 if (!window.testRunner) {
17 log('This test must be run by DumpRenderTree!')
18 return;
21 var onMacPlatform = navigator.userAgent.search(/\bMac OS X\b/) != -1;
23 var area = document.getElementById('area');
24 area.focus();
26 // Now move to the end
27 if (onMacPlatform)
28 eventSender.keyDown("rightArrow", ["metaKey"]);
29 else
30 eventSender.keyDown("end");
32 if (sel.baseOffset != 9 || sel.extentOffset != 9) {
33 logResult("Selection should be at the end.");
34 return;
37 // Now move back to the beginning
38 if (onMacPlatform)
39 eventSender.keyDown("leftArrow", ["metaKey"]);
40 else
41 eventSender.keyDown("home");
43 if (sel.baseOffset != 0 || sel.extentOffset != 0) {
44 logResult("Selection should be at the beginning.");
45 return;
48 // Now move to the end, selecting
49 if (onMacPlatform)
50 eventSender.keyDown("rightArrow", ["metaKey", "shiftKey"]);
51 else
52 eventSender.keyDown("end",["shiftKey"]);
54 if (sel.baseOffset != 0 || sel.extentOffset != 9) {
55 logResult("Selection should contain the whole line and have forward directionality.");
56 return;
59 // Deselect but position the caret at the end
60 eventSender.keyDown("rightArrow");
62 if (sel.baseOffset != 9 || sel.extentOffset != 9) {
63 logResult("Selection should be at the end.");
64 return;
67 // Now move to the beginning, selecting
68 if (onMacPlatform)
69 eventSender.keyDown("leftArrow", ["metaKey", "shiftKey"]);
70 else
71 eventSender.keyDown("home",["shiftKey"]);
73 if (sel.baseOffset != 9 || sel.extentOffset != 0) {
74 logResult("Selection should contain the whole line and have backward directionality.");
75 return;
78 logResult('SUCCESS');
80 </script>
81 <body onload="runTest();">
82 <div contenteditable id="area">Some text</div>
83 <div>This tests that moving the caret and selecting using Command+Left/Right arrows work correctly. If this text is successful, the text "SUCCESS" will be shown below.</div>
84 <div id="result">FAILURE</div>
85 </body>