4 <p>This test ensures selectstart event fires when selection is created by arrow key and script can prevent the selection change.</p>
5 If running this test manually, click on the div ("Hello World") and try to select the text using arrow keys.<br>
6 Expected result: SelectStart event will fire when user starts extending the selection, but due to script preventDefault it prevents the selection change.<br>
7 <div contenteditable>Hello World</div>
11 var selectStartCount = 0;
12 var div = document.getElementsByTagName('div')[0];
13 div.addEventListener('selectstart', function (event) { event.preventDefault(); selectStartCount++; });
15 window.getSelection().setPosition(div.firstChild, 1);
17 if (window.testRunner) {
18 testRunner.dumpAsText();
19 eventSender.keyDown("rightArrow", ["shiftKey"]);
20 logResult("Check Right arrow + Shift", 1);
22 eventSender.keyDown("rightArrow", ["shiftKey"], ["ctrlKey"]);
23 logResult("Check Right arrow + Shift + Control", 2);
25 eventSender.keyDown("end", ["shiftKey"]);
26 logResult("Check End + Shift", 3);
29 function logResult(title, expectedCount) {
30 var range = window.getSelection().getRangeAt(0);
31 document.write(title + ': ');
32 if (selectStartCount != expectedCount)
33 document.write('FAIL - expected ' + expectedCount + ' events but got ' + selectStartCount + ' events');
34 else if (range.startOffset != 1 || range.endOffset != 1)
35 document.write('FAIL - selection changed');
37 document.write('PASS');
38 document.write('<br>');