4 <p>This test ensures selectstart is fired exactly once when selecting text by a mouse drag.
5 </p><span style='font-size:
50px; padding:
10px;'
>hello world
8 var span
= document
.getElementsByTagName('span')[0];
11 var selectStartCount
= 0;
12 span
.addEventListener('selectstart', function (event
) { selectStartCount
++; });
14 function expect(title
, expectedCount
, expectedType
) {
15 document
.write(title
+ ': ');
16 var actualSelectionType
= window
.getSelection().isCollapsed
? 'caret' : 'range';
18 if (selectStartCount
!= expectedCount
)
19 document
.writeln('FAIL - expected ' + expectedCount
+ ' events but got ' + selectStartCount
+ ' events');
20 else if (actualSelectionType
!= expectedType
)
21 document
.writeln('FAIL - expected selection to be ' + expectedType
+ ' but was ' + actualSelectionType
);
23 document
.writeln('PASS');
26 if (window
.testRunner
&& !window
.eventSender
)
27 document
.write('This test requires eventSender');
28 else if (window
.testRunner
) {
29 testRunner
.dumpAsText();
31 var y
= span
.offsetTop
+ span
.offsetHeight
/ 2;
32 expect('Initial state', 0, 'caret');
33 eventSender
.mouseMoveTo(span
.offsetLeft
+ 5, y
);
34 eventSender
.mouseDown();
35 expect('Mouse down', 1, 'caret');
36 eventSender
.leapForward(200);
37 eventSender
.mouseUp();
38 expect('Mouse up', 1, 'caret');
40 eventSender
.mouseMoveTo(span
.offsetLeft
+ span
.offsetWidth
- 5, y
);
41 expect('Moving to the right', 1, 'caret');
42 eventSender
.mouseDown(0, ['shiftKey']);
43 expect('Second mouse down', 2, 'range');
44 eventSender
.leapForward(200);
45 eventSender
.mouseUp();
46 expect('Second mouse up', 2, 'range');
48 document
.writeln('Done.');
49 span
.parentNode
.removeChild(span
);