Add getModifierState to MouseEvent
[WebKit-https.git] / LayoutTests / fast / events / dblclick-event-getModifierState.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4
5 <div id="target" style="margin: 1rem; width: 100px; height: 100px; border: solid 5px red;"></div>
6 <script src="../../resources/js-test.js"></script>
7 <script>
8
9 description(`This tests mouse events sets the correct modifier key states.<br>
10 To manually test, turn on CapsLock and press Alt key and move the mosue cursor to the red box below, and then double click it.`);
11
12 jsTestIsAsync = true;
13
14 const events = [];
15 function addEvent(event) { events.push(event) };
16 let firstMousemoveEvent = null;
17
18 const target = document.getElementById('target');
19 target.addEventListener('mousedown', addEvent);
20 target.addEventListener('mouseup', addEvent);
21 target.addEventListener('click', addEvent);
22 target.addEventListener('dblclick', (event) => {
23     addEvent(event);
24     verify();
25 });
26
27 var currentEvent;
28 function verify() {
29     const eventTypes = ['mousedown', 'mouseup', 'click', 'mousedown', 'mouseup', 'click', 'dblclick'];
30     for (let i = 0; i < events.length; i++) {
31         currentEvent = events[i];
32         shouldBeEqualToString('currentEvent.type', eventTypes[i]);
33         shouldBeFalse('currentEvent.getModifierState("Control")');
34         shouldBeTrue('currentEvent.getModifierState("Alt")');
35         shouldBeFalse('currentEvent.getModifierState("Shift")');
36         shouldBeFalse('currentEvent.getModifierState("Meta")');
37         shouldBeFalse('currentEvent.getModifierState("AltGraph")');
38         shouldBeTrue('currentEvent.getModifierState("CapsLock")');
39     }
40     finishJSTest();
41 }
42
43 if (window.eventSender) {
44     eventSender.leapForward(1000); // drain dblclick timer
45
46     eventSender.mouseMoveTo(1, 1);
47     eventSender.mouseMoveTo(target.offsetLeft + target.offsetWidth / 2, target.offsetTop + target.offsetHeight / 2);
48
49     eventSender.mouseDown(0, ['altKey', 'capsLockKey']);
50     eventSender.mouseUp(0, ['altKey', 'capsLockKey']);
51     eventSender.mouseDown(0, ['altKey', 'capsLockKey']);
52     eventSender.mouseUp(0, ['altKey', 'capsLockKey']);
53 } else if (window.testRunner) {
54     testFailed('This test requires eventSender');
55     finishJSTest();
56 }
57
58 </script>
59 </body>
60 </html>