Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / selectstart-by-double-triple-clicks.html
blobc289c993dc7041597ee057183528494e09a1912a
1 <!DOCTYPE html>
2 <html>
3 <body>
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</span><pre><script>
7 var span = document.getElementsByTagName('span')[0];
8 span.focus();
10 var selectStartCount = 0;
11 span.addEventListener('selectstart', function (event) { selectStartCount++; });
13 function expect(title, expectedCount, expectedType, expectedString) {
14 document.write(title + ': ');
15 var actualSelectionType = window.getSelection().isCollapsed ? 'caret' : 'range';
16 var actualString = window.getSelection().toString().trim();
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);
22 else if (actualString && actualString != expectedString)
23 document.writeln('FAIL - expected selection to be "' + expectedString + '" but was "' + actualString + '"');
24 else
25 document.writeln('PASS');
28 if (window.testRunner && !window.eventSender)
29 document.write('This test requires eventSender');
30 else if (window.testRunner) {
31 testRunner.dumpAsText();
33 var y = span.offsetTop + span.offsetHeight / 2;
34 expect('Initial state', 0, 'caret');
35 eventSender.mouseMoveTo(span.offsetLeft + 5, y);
36 eventSender.mouseDown();
37 expect('Mouse down', 1, 'caret');
38 eventSender.leapForward(200);
39 eventSender.mouseUp();
40 expect('Mouse up', 1, 'caret');
42 eventSender.leapForward(200);
43 eventSender.mouseDown();
44 expect('Second mouse down', 2, 'range', 'hello');
45 eventSender.leapForward(200);
46 eventSender.mouseUp();
47 expect('Second mouse up', 2, 'range', 'hello');
49 eventSender.leapForward(200);
50 eventSender.mouseDown();
51 expect('Third mouse down', 3, 'range', 'hello world');
52 eventSender.leapForward(200);
53 eventSender.mouseUp();
54 expect('Third mouse up', 3, 'range', 'hello world');
56 document.writeln('Done.');
57 span.parentNode.removeChild(span);
60 </script></pre>
61 </body>
62 </html>