summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-mouse-events.html
blob: 7f5ae99fc86d60afbb23f4d73579229a3d287392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/ahem.js"></script>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<p>
Please run this with DRT or WTR.
</p>
Test following mouse actions:
<ul>
    <li>Mouse click to focus each of sub-fields</li>
    <li>Mouse click on the spin button to update each of sub-fields</li>
</ul>
<input id="input" type="date" style="font-family:ahem; font-size:16px;">
<div id="console"></div>
<script>
function keyDown(key, modifiers)
{
    if (!window.eventSender)
        return;
    eventSender.keyDown(key, modifiers);
}

function mouseClickOn(x, y)
{
    if (!window.eventSender)
        return;
    eventSender.mouseMoveTo(x + input.offsetLeft, y + input.offsetTop);
    eventSender.mouseDown();
    eventSender.mouseUp();
}

onload = function() {
    description('Multiple fields UI of date input type with mouse events');
    var input = document.getElementById('input');

    input.value = '2345-07-19';
    var center = input.offsetHeight / 2;
    var spinButtonOffset = 26;
    var clearButtonOffset = 41;

    debug('==> Focus on the month field.');
    mouseClickOn(12, center);
    keyDown('upArrow');
    shouldBeEqualToString('input.value', '2345-08-19');
    mouseClickOn(input.offsetWidth - spinButtonOffset, center - 1);
    shouldBeEqualToString('input.value', '2345-09-19');
    mouseClickOn(input.offsetWidth - spinButtonOffset, center + 1);
    shouldBeEqualToString('input.value', '2345-08-19');
    shouldBeZero('window.getSelection().rangeCount'); // No text selection.

    debug('');
    debug('==> Focus on the day field.');
    mouseClickOn(60, center);
    keyDown('upArrow');
    shouldBeEqualToString('input.value', '2345-08-20');
    mouseClickOn(input.offsetWidth - spinButtonOffset, center - 1);
    shouldBeEqualToString('input.value', '2345-08-21');
    mouseClickOn(input.offsetWidth - spinButtonOffset, center + 1);
    shouldBeEqualToString('input.value', '2345-08-20');
    shouldBeZero('window.getSelection().rangeCount'); // No text selection.

    debug('');
    debug('==> Focus on the year field.');
    mouseClickOn(input.offsetWidth - 115, center);
    keyDown('upArrow');
    shouldBeEqualToString('input.value', '2346-08-20');
    mouseClickOn(input.offsetWidth - spinButtonOffset, center - 1);
    shouldBeEqualToString('input.value', '2347-08-20');
    mouseClickOn(input.offsetWidth - spinButtonOffset, center + 1);
    shouldBeEqualToString('input.value', '2346-08-20');
    shouldBeZero('window.getSelection().rangeCount'); // No text selection.

    debug('');
    debug('==> Click on a disabled field.');
    input.disabled = true;
    mouseClickOn(12, center);
    keyDown('upArrow');
    shouldBeEqualToString('input.value', '2346-08-20');
    input.disabled = false;

    debug('');
    debug('==> Click on a read-only field.');
    input.readOnly = true;
    mouseClickOn(12, center);
    keyDown('upArrow');
    shouldBeEqualToString('input.value', '2346-08-20');
    input.readOnly = false;

    debug('');
    debug('==> Click on clear button.');
    input.readOnly = true;
    mouseClickOn(input.offsetWidth - clearButtonOffset, center);
    shouldBeEqualToString('input.value', '2346-08-20');
    input.disabled = true;
    input.readOnly = false;
    mouseClickOn(input.offsetWidth - clearButtonOffset, center);
    shouldBeEqualToString('input.value', '2346-08-20');
    input.disabled = false;
    mouseClickOn(input.offsetWidth - clearButtonOffset, center);
    shouldBeEqualToString('input.value', '');

    debug('');
};
</script>
</body>
</html>