tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / forms / script-tests / ValidityState-typeMismatch-number.js
1 description('This test aims to check for typeMismatch flag with type=number input fields');
2
3 var i = document.createElement('input');
4 i.type = 'number';
5
6 function check(value, disabled)
7 {
8     i.value = value;
9     i.disabled = !!disabled;
10     var mismatch = i.validity.typeMismatch;
11     var resultText = '"' + value + '" is ' + (mismatch ? 'an invalid' : 'a valid') + ' number' + (disabled ? ' when disabled.' : '.');
12     if (!mismatch)
13         testPassed(resultText);
14     else
15         testFailed(resultText);
16 }
17
18 function checkSanitization(value, expectedValue)
19 {
20     i.value = value;
21     if (i.validity.typeMismatch) {
22         testFailed('"' + value + '" made typeMismatch true.');
23     } else if (i.value != expectedValue) {
24         testFailed('"' + value + '" was sanitized to "' + i.value + '". It should be ' + expectedValue);
25     } else {
26         testPassed('"' + value + '" was sanitized to "' + i.value + '".');
27     }
28 }
29
30 // Valid values
31 check('0');
32 check('10');
33 check('01');
34 check('0.2');
35 check('.2');
36 check('-0');
37 check('-1.2');
38 check('1.2E10');
39 check('1.2E-10');
40 check('1.2E+10');
41 check('12345678901234567890123456789012345678901234567890');
42 check('0.12345678901234567890123456789012345678901234567890');
43
44 // Invalid values
45 checkSanitization('abc', '');
46 checkSanitization('0xff', '');
47
48 checkSanitization('+1', '');
49 checkSanitization(' 10', '');
50 checkSanitization('10 ', '');
51 checkSanitization('1,2', '');
52 checkSanitization('1E', '');
53 checkSanitization('NaN', '');
54 checkSanitization('nan', '');
55 checkSanitization('Inf', '');
56 checkSanitization('inf', '');
57 checkSanitization('Infinity', '');
58 checkSanitization('infinity', '');
59
60 // Assume empty string as valid.
61 check('');
62
63 // Huge exponent.
64 checkSanitization('1.2E65535', '');
65
66 // The spec doesn't allow, but our implementation does.
67 check('1.');
68 check('1.2e10');
69
70 // Disabled
71 check('invalid', true);