Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / number / number-validity-rangeoverflow.html
blob2d0f7f7442b9d3083b471c4734642d4d0e8e7aab
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description('This test aims to check for rangeOverflow flag with a number input field');
10 var input = document.createElement('input');
12 function checkOverflow(value, max, disabled)
14 input.value = value;
15 input.max = max;
16 input.disabled = !!disabled;
17 var overflow = input.validity.rangeOverflow;
18 var resultText = 'The value "' + input.value + '" ' +
19 (overflow ? 'overflows' : 'doesn\'t overflow') +
20 ' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
21 if (overflow)
22 testPassed(resultText);
23 else
24 testFailed(resultText);
27 function checkNotOverflow(value, max, disabled)
29 input.value = value;
30 input.max = max;
31 input.disabled = !!disabled;
32 var overflow = input.validity.rangeOverflow;
33 var resultText = 'The value "' + input.value + '" ' +
34 (overflow ? 'overflows' : 'doesn\'t overflow') +
35 ' the maximum value "' + input.max + '"' + (disabled ? ' when disabled.' : '.');
36 if (overflow)
37 testFailed(resultText);
38 else
39 testPassed(resultText);
42 debug('Type=number');
43 input.type = 'number';
44 input.min = '';
45 checkNotOverflow('99', '100'); // Very normal case.
46 checkNotOverflow('-101', '-100');
47 checkNotOverflow('99', '1E+2');
48 checkNotOverflow('0.99', '1.00');
49 checkNotOverflow('abc', '100'); // Invalid value.
50 checkNotOverflow('', '-1'); // No value.
51 checkNotOverflow('101', ''); // No max.
52 checkNotOverflow('101', 'xxx'); // Invalid max.
53 // The following case should be rangeOverflow==true ideally. But the "double" type doesn't have enough precision.
54 checkNotOverflow('0.999999999999999999999999999999999999999999', '0.999999999999999999999999999999999999999998');
56 // Overflow cases
57 checkOverflow('101', '100');
58 checkOverflow('-99', '-100');
59 checkOverflow('101', '1E+2');
60 input.min = '200'; // value < min && value > max
61 checkOverflow('101', '100');
63 // Disabled
64 checkNotOverflow('101', '1E+2', true);
65 </script>
66 </body>
67 </html>