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;' contenteditable
>hello
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;
33 function leapForwardAndMove(x
) {
34 eventSender
.leapForward(200);
35 eventSender
.mouseMoveTo(span
.offsetLeft
+ x
, y
);
38 expect('Initial state', 0, 'caret');
39 eventSender
.dragMode
= false;
40 eventSender
.mouseMoveTo(span
.offsetLeft
+ 5, y
);
41 eventSender
.mouseDown();
42 expect('Mouse down', 1, 'caret');
44 leapForwardAndMove(5);
45 expect('Moving slightly to the right', 1, 'caret');
47 leapForwardAndMove(-5);
48 expect('Moving slightly to the left', 1, 'caret');
50 leapForwardAndMove(span
.offsetWidth
/ 2);
51 expect('Moving to the right', 1, 'range');
53 leapForwardAndMove(span
.offsetWidth
);
54 expect('Moving further to the right', 1, 'range');
56 leapForwardAndMove(0);
57 expect('Moving back to the left', 1, 'caret');
59 leapForwardAndMove(span
.offsetWidth
);
60 expect('Moving to the right again', 1, 'range');
62 eventSender
.mouseUp();
63 window
.getSelection().collapse(span
, 0);
64 eventSender
.leapForward(1000);
66 eventSender
.mouseMoveTo(span
.offsetLeft
+ span
.offsetWidth
- 5, y
);
67 eventSender
.mouseDown();
68 expect('Mouse down on the right', 2, 'caret');
70 leapForwardAndMove(span
.offsetWidth
/ 2);
71 expect('Moving to the left', 2, 'range');
73 eventSender
.mouseUp();
75 document
.writeln('Done.');
76 span
.parentNode
.removeChild(span
);