summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_bug1286509.html
blob: 638e7fe85cd222471a6e109d4a52970dbf39a5d3 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1286509
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1286509</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1286509">Mozilla Bug 1286509</a>
<p id="display"></p>
<div id="content">
  <input type="range" id="test_input" min="0" max="10" value="5">
</div>
<pre id="test">
  <script type="application/javascript">
  /** Test for Bug 1286509 **/
  SimpleTest.waitForExplicitFinish();
  var expectedEventSequence = ['keydown', 'change', 'keyup'];
  var eventCounts = {};
  var expectedEventIdx = 0;

  function test() {
    var range = document.getElementById("test_input");
    range.focus();
    expectedEventSequence.forEach((eventName) => {
      eventCounts[eventName] = 0;
      range.addEventListener(eventName, (e) => {
        ++eventCounts[eventName];
        is(expectedEventSequence[expectedEventIdx], e.type, "Events sequence should be keydown, change, keyup");
        expectedEventIdx = (expectedEventIdx + 1) % 3;
      });
    });
    synthesizeKey("KEY_ArrowUp");
    synthesizeKey("KEY_ArrowDown");
    synthesizeKey("KEY_ArrowLeft");
    synthesizeKey("KEY_ArrowRight");
    is(eventCounts.change, 4, "Expect key up/down/left/right should trigger range input to fire change events");
    SimpleTest.finish();
  }
  addLoadEvent(test);
  </script>
</pre>
</body>
</html>