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