layout/forms/test/test_bug411236.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/forms/test/test_bug411236.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=411236
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 411236</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=411236">Mozilla Bug 411236</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content">
    1.18 +  <input type="file" onfocus="window.oTarget = event.originalTarget;"
    1.19 +         onclick="window.fileInputGotClick = true; return false;"
    1.20 +         id="fileinput">
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +
    1.25 +/** Test for Bug 411236 **/
    1.26 +
    1.27 +window.oTarget = null;
    1.28 +window.fileInputGotClick = false;
    1.29 +
    1.30 +function tab() {
    1.31 +  var utils = SpecialPowers.DOMWindowUtils;
    1.32 +  // Send tab key events.
    1.33 +  var key = SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_TAB;
    1.34 +  utils.sendKeyEvent("keydown", key, 0, 0);
    1.35 +  utils.sendKeyEvent("keypress", key, 0, 0);
    1.36 +  utils.sendKeyEvent("keyup", key, 0, 0);
    1.37 +}
    1.38 +
    1.39 +function test() {
    1.40 +  // Try to find the 'Browse...' using tabbing.
    1.41 +  var i = 0;
    1.42 +  while (!window.oTarget && i < 100) {
    1.43 +    ++i;
    1.44 +    tab();
    1.45 +  }
    1.46 +
    1.47 +  if (i >= 100) {
    1.48 +    ok(false, "Couldn't find an input element!");
    1.49 +    SimpleTest.finish();
    1.50 +    return;
    1.51 +  }
    1.52 +
    1.53 +  ok(window.oTarget instanceof HTMLButtonElement, "Should have focused an input element!")
    1.54 +  ok(SpecialPowers.wrap(window.oTarget).type == "button", "Should have focused 'Browse...' button!");
    1.55 +  var e = document.createEvent("mouseevents");
    1.56 +  e.initMouseEvent("click", true, true, window, 0, 1, 1, 1, 1,
    1.57 +                    false, false, false, false, 0, null);
    1.58 +  SpecialPowers.wrap(window.oTarget).dispatchEvent(e);
    1.59 +  ok(window.fileInputGotClick,
    1.60 +     "File input should have got a click event, but not open the file dialog.");
    1.61 +  SimpleTest.finish();
    1.62 +}
    1.63 +
    1.64 +function beginTest() {
    1.65 +  // accessibility.tabfocus must be set to value 7 before running test also
    1.66 +  // on a mac.
    1.67 +  SpecialPowers.pushPrefEnv({"set": [["accessibility.tabfocus", 7]]}, do_test);
    1.68 +}
    1.69 +
    1.70 +function do_test() {
    1.71 +  window.focus();
    1.72 +  document.getElementById('fileinput').focus();
    1.73 +  setTimeout(test, 100);
    1.74 +}
    1.75 +
    1.76 +SimpleTest.waitForExplicitFinish();
    1.77 +addLoadEvent(beginTest);
    1.78 +
    1.79 +</script>
    1.80 +</pre>
    1.81 +</body>
    1.82 +</html>

mercurial