INPUT_MULTIPLE_FIELDS_UI: Step-up/-down of hour field should respect min/max attributes
[WebKit-https.git] / LayoutTests / fast / forms / datetimelocal-multiple-fields / datetimelocal-multiple-fields-readonly-subfield.html
1 <!DOCTYPE html>
2 <body>
3 <script src="../../js/resources/js-test-pre.js"></script>
4 <script>
5 function createInput(min, max, step, value) {
6     var input = document.createElement('input');
7     input.type = 'datetime-local';
8     if (min)
9         input.min = min;
10     if (max)
11         input.max = max;
12     if (step)
13         input.step = step;
14     if (value)
15         input.value = value;
16     return input;
17 }
18
19 // FIXME: Rename this function and the test file.
20 function isReadOnlyField(input, pseudo) {
21     var node = internals.youngestShadowRoot(input).querySelector('*[pseudo="' + pseudo + '"]');
22     if (!node)
23         testFailed('Requested node is missing.');
24     return node && node.hasAttribute('disabled');
25 }
26
27 var pseudoMinute = '-webkit-datetime-edit-minute-field';
28 var pseudoHour = '-webkit-datetime-edit-hour-field';
29 var pseudoAMPM = '-webkit-datetime-edit-ampm-field';
30 var step1day = '86400';
31 var step1min = '60';
32
33 description('Sub-fields in input[type=datetime-local] should be read-only in some cases. This requires window.internals.');
34 debug('createInput argument order: min, max, step, value');
35 debug('');
36
37 debug('Hour field:');
38 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:00", "", step1day, ""), pseudoHour)');
39 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:00", "", step1day, ""), pseudoAMPM)');
40 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:00", "", step1day, ""), pseudoMinute)');
41
42 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "", step1day, "2013-01-16T11:30"), pseudoHour)');
43 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "", step1day, "2013-01-16T11:30"), pseudoAMPM)');
44 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "", step1day, "2013-01-16T11:30"), pseudoMinute)');
45
46 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T11:30", "", step1day, "2013-01-16T12:30"), pseudoHour)');
47 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T11:30", "", step1day, "2013-01-16T12:30"), pseudoAMPM)');
48 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "", step1day, "2013-01-16T12:30"), pseudoMinute)');
49
50 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T00:00", "", step1day, "2013-01-16T12:30"), pseudoHour)');
51 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T00:00", "", step1day, "2013-01-16T12:30"), pseudoAMPM)');
52 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T00:00", "", step1day, "2013-01-16T12:30"), pseudoMinute)');
53
54 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T11:00", "2013-01-16T23:00", step1day, ""), pseudoHour)');
55 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T11:00", "2013-01-16T23:00", step1day, ""), pseudoAMPM)');
56 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:00", "2013-01-16T23:00", step1day, ""), pseudoMinute)');
57
58 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T23:00", step1day, "2013-01-16T11:30"), pseudoHour)');
59 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T23:00", step1day, "2013-01-16T11:30"), pseudoAMPM)');
60 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T23:00", step1day, "2013-01-16T11:30"), pseudoMinute)');
61
62 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T11:59", step1day, "2013-01-16T11:30"), pseudoHour)');
63 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T11:59", step1day, "2013-01-16T11:30"), pseudoAMPM)');
64 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T11:59", step1day, "2013-01-16T11:30"), pseudoMinute)');
65
66 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T11:59", step1min, ""), pseudoHour)');
67 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T11:59", step1min, ""), pseudoAMPM)');
68 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T11:30", "2013-01-16T11:59", step1min, ""), pseudoMinute)');
69
70 debug('AM/PM field:');
71 shouldBeTrue('isReadOnlyField(createInput("2013-01-16T08:00", "2013-01-16T11:00", step1min, ""), pseudoAMPM)');
72 shouldBeFalse('isReadOnlyField(createInput("2013-01-16T08:00", "2013-01-17T11:00", step1min, ""), pseudoAMPM)');
73
74 </script>
75 <script src="../../js/resources/js-test-post.js"></script>
76 </body>
77