summaryrefslogtreecommitdiffstats
path: root/layout/forms/test/test_bug903715.html
blob: b887b2cd01441ff92b92393aa63489186f52e97a (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
78
79
80
81
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=903715
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 903715</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=903715">Mozilla Bug 903715</a>
<p id="display"></p>
<div id="content">
  <form id="form" action="/">
    <select id="select" name="select">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
      <option>6</option>
      <option>7</option>
      <option>8</option>
      <option>9</option>
    </select>
    <input id="input-text" name="text" value="some text">
    <input id="input-submit" type="submit">
  </form>
</div>
<pre id="test">
</pre>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
SimpleTest.waitForFocus(runTests, window);

function runTests()
{
  var form = document.getElementById("form");
  form.addEventListener("keypress", function (aEvent) {
    ok(false, "keypress event shouldn't be fired when the preceding keydown event caused closing the dropdown of the select element");
  }, true);
  form.addEventListener("submit", function (aEvent) {
    ok(false, "submit shouldn't be performed by the Enter key press on the select element");
    aEvent.preventDefault();
  }, true);
  var select = document.getElementById("select");
  select.addEventListener("change", function (aEvent) {
    var input = document.getElementById("input-text");
    input.focus();
    input.select();
  });

  select.focus();

  select.addEventListener("popupshowing", function (aEvent) {
    setTimeout(function () {
      synthesizeKey("KEY_ArrowDown");
      select.addEventListener("popuphiding", function (aEventInner) {
        setTimeout(function () {
          // Enter key should cause closing the dropdown of the select element
          // and keypress event shouldn't be fired on the input element because
          // which shouldn't cause sumbmitting the form contents.
          ok(true, "Test passes if there is no error");
          SimpleTest.finish();
        }, 100);
      });
      // Close dropdown.
      synthesizeKey("KEY_Enter");
    }, 100);
  });

  // Open dropdown.
  synthesizeKey("KEY_ArrowDown", { altKey: true });
}
</script>
</body>
</html>