WebKitTools:
[WebKit-https.git] / LayoutTests / editing / selection / move-begin-end.html
1 <html>
2     <head>
3 <script>
4 if (window.layoutTestController)
5      layoutTestController.dumpEditingCallbacks();
6 </script>
7
8         <script>
9             function runTest() {
10                 if (window.layoutTestController)
11                     layoutTestController.dumpAsText();
12                 else {
13                     log('This test must be run by DumpRenderTree!') 
14                     return;
15                 }
16
17                 var onMacPlatform = false;
18                 if (navigator.userAgent.search(/\bMac OS X\b/) != -1)
19                     onMacPlatform = true;
20                 
21                 var area = document.getElementById('area');
22                 area.focus();
23                 
24                 var sel = window.getSelection();
25                 // Position the caret at the beginning of the string.
26                 eventSender.keyDown("leftArrow");
27
28                 // Now move to the end
29                 if (onMacPlatform)
30                     eventSender.keyDown("rightArrow", ["metaKey"]);
31                 else
32                     eventSender.keyDown("end");
33
34                 if (sel.baseOffset != 9 || sel.extentOffset != 9)
35                     return;
36                 
37                 // Now move back to the beginning
38                 if (onMacPlatform)
39                     eventSender.keyDown("leftArrow", ["metaKey"]);
40                 else
41                     eventSender.keyDown("home");
42
43                 if (sel.baseOffset != 0 || sel.extentOffset != 0)
44                     return;
45
46                 // Now move to the end, selecting
47                 if (onMacPlatform)
48                     eventSender.keyDown("rightArrow", ["metaKey", "shiftKey"]);
49                 else
50                     eventSender.keyDown("end",["shiftKey"]);
51
52                 if (sel.baseOffset != 0 || sel.extentOffset != 9)
53                     return;
54
55                 // Deselect but position the caret at the end
56                 eventSender.keyDown("rightArrow");
57                 
58                 if (sel.baseOffset != 9 || sel.extentOffset != 9)
59                     return;
60                 
61                 // Now move to the beginning, selecting
62                 if (onMacPlatform)
63                     eventSender.keyDown("leftArrow", ["metaKey", "shiftKey"]);
64                 else
65                     eventSender.keyDown("home",["shiftKey"]);
66                 
67                 if (sel.baseOffset != 9 || sel.extentOffset != 0)
68                     return;
69                 
70                 document.getElementById('result').innerHTML = 'SUCCESS'
71             }
72         </script>
73     </head>
74     <body onload="runTest();">
75         <textarea id="area">Some text</textarea>
76         <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>
77         <div id="result">FAILURE</div>
78     </body>
79 </html>