4 <p>This test ensures selectstart is fired when selection is created by arrow keys.
</p>
5 If running this test manually, click on div (
"Hello World") element and try to select the text using arrow keys.
<br>
6 Expected result : SelectStart event will fire when user starts extending selection.
<br>
7 <div id=
"test" contenteditable
>Hello World
</div>
10 var selectStartCount
= 0;
11 var div
= document
.getElementById('test');
12 div
.addEventListener('selectstart', function (event
) { selectStartCount
++; });
15 if (window
.testRunner
) {
16 testRunner
.dumpAsText();
17 logResult('Initial state', 0);
19 eventSender
.keyDown("rightArrow");
20 logResult('Check (Right arrow)', 0);
22 eventSender
.keyDown("rightArrow", ["shiftKey"]);
23 logResult('Check (Right arrow + Shift)', 1);
25 if (navigator
.platform
.indexOf('Mac') == 0)
26 eventSender
.keyDown("rightArrow", ["shiftKey"], ["altKey"]);
28 eventSender
.keyDown("rightArrow", ["shiftKey"], ["ctrlKey"]);
29 logResult('Check (Right arrow + Shift + Control)', 1);
31 eventSender
.keyDown("end", ["shiftKey"]);
32 logResult('Check (End + Shift)', 1);
34 eventSender
.keyDown("home", ["shiftKey"]);
35 logResult('Check (Home + Shift)', 1);
37 eventSender
.keyDown("end", ["shiftKey"]);
38 logResult('Check (End + Shift)', 1);
40 // On Mac, home/end doesn't move caret so manually select " World".
41 if (navigator
.platform
.indexOf('Mac') == 0)
42 window
.getSelection().setBaseAndExtent(div
.firstChild
, div
.textContent
.indexOf('World'), div
.textContent
.length
);
44 eventSender
.keyDown("leftArrow");
45 logResult('Check (Left arrow)', 1);
47 if (navigator
.platform
.indexOf('Mac') == 0)
48 eventSender
.keyDown("leftArrow", ["shiftKey"], ["altKey"]);
50 eventSender
.keyDown("leftArrow", ["shiftKey"], ["ctrlKey"]);
51 logResult('Check (LeftArrow + Shift + Control)', 2);
53 eventSender
.keyDown("leftArrow", ["shiftKey"]);
54 logResult('Check (Left arrow + Shift)', 2);
56 eventSender
.keyDown("end", ["shiftKey"]);
57 logResult('Check (Home + Shift)', 2);
59 eventSender
.keyDown("home", ["ctrlKey"]);
60 logResult('Check (Home + Control)', 2);
63 document
.write("Done.")
65 function logResult(title
, expectedCount
) {
66 document
.write(title
+ ': ');
67 if (selectStartCount
!= expectedCount
)
68 document
.write('FAIL - expected ' + expectedCount
+ ' events but got ' + selectStartCount
+ ' events');
70 document
.write('PASS');
71 document
.write('<br>');