summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_number_l10n.html
blob: c8202028edc41d1406708cc95d3d6ea2d6510e60 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=844744
-->
<head>
  <title>Test localization of number control input</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="test_input_number_data.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <meta charset="UTF-8">
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=844744">Mozilla Bug 844744</a>
<p id="display"></p>
<div id="content">
  <input id="input" type="number" step="any">
</div>
<pre id="test">
<script type="application/javascript">

/**
 * Test for Bug 844744
 * This test checks that localized input that is typed into <input type=number>
 * is correctly handled.
 **/
SimpleTest.waitForExplicitFinish();

SimpleTest.waitForFocus(function() {
  startTests();
  SimpleTest.finish();
});

var elem;

function runTest(test) {
  elem.lang = test.langTag;
  elem.value = 0;
  elem.focus();
  elem.select();
  sendString(test.inputWithGrouping);
  is(elem.value, "", "Test " + test.desc + " ('" + test.langTag +
                     "') localization with grouping separator");
  elem.value = 0;
  elem.select();
  sendString(test.inputWithoutGrouping);
  is(elem.valueAsNumber, test.value, "Test " + test.desc + " ('" + test.langTag +
                                     "') localization without grouping separator");
  is(elem.value, String(test.value), "Test " + test.desc + " ('" + test.langTag +
                                     "') localization without grouping separator as string");
}

function runInvalidInputTest(test) {
  elem.lang = test.langTag;
  elem.value = 0;
  elem.focus();
  elem.select();
  sendString(test.input);
  is(elem.value, "", "Test " + test.desc + " ('" + test.langTag +
                             "') with invalid input: " + test.input);
}

function startTests() {
  elem = document.getElementById("input");
  for (var test of tests) {
    runTest(test, elem);
  }
  for (var test of invalidTests) {
    runInvalidInputTest(test, elem);
  }
}

</script>
</pre>
</body>
</html>