DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=238987
-->
<head>
  <title>Test for Bug 238987</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.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=238987">Mozilla Bug 238987</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

  /** Test for Bug 238987 **/

  var shouldStop = false;
  var modifier = 0;
  var expectedResult = "i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12";
  var forwardFocusArray = expectedResult.split(",");
  var backwardFocusArray = expectedResult.split(",");
  var forwardBlurArray = expectedResult.split(",");
  var backwardBlurArray = expectedResult.split(",");
  // Adding 3 for "begin", "end", "begin" and one for the <a> in the Mochitest template,
  var expectedWindowFocusCount = forwardFocusArray.length + backwardFocusArray.length + 4;
  // but the last blur event goes to i1, not "begin".
  var expectedWindowBlurCount = forwardFocusArray.length + backwardFocusArray.length + 3;

  // accessibility.tabfocus must be set to value 7 before running test also
  // on a mac.
  function setOrRestoreTabFocus(newValue) {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    const prefSvcContractID = "@mozilla.org/preferences-service;1";
    const prefSvcIID = Components.interfaces.nsIPrefService;
    var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
                                                     .getBranch("accessibility.");
    if (!newValue) {
      try {
        prefs.clearUserPref("tabfocus");
      } catch(ex) {}
    } else {
      prefs.setIntPref("tabfocus", newValue);
    }
  }

  function handleFocus(e) {
    if (e.target.id == "begin") {
      // if the modifier is set, the test is coming back from the end.
      if (modifier) {
        shouldStop = true;
      }
    } else if (e.target.id == "end") {
      modifier = Components.interfaces.nsIDOMNSEvent.SHIFT_MASK;
    } else if (modifier) {
      var expected = backwardFocusArray.pop();
      ok(expected == e.target.id,
         "(focus) Backward tabbing, expected [" +
         expected + "], got [" + e.target.id + "]");
    } else {
      var expected = forwardFocusArray.shift();
      ok(expected == e.target.id,
         "(focus) Forward tabbing, expected [" +
         expected + "], got [" + e.target.id + "]");
    }
  }

  function handleWindowFocus(e) {
    --expectedWindowFocusCount;
    var s = "target " + e.target;
    if ("id" in e.target) {
      s = s + ", id=\"" + e.target.id + "\"";
    }
    ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
       "|window| should not have got a focus event, " + s);
  }

  function handleBlur(e) {
    if (e.target.id == "begin" || e.target.id == "end") {
      return;
    } else if (modifier) {
      var expected = backwardBlurArray.pop();
      ok(expected == e.target.id,
         "(blur) backward tabbing, expected [" +
         expected + "], got [" + e.target.id + "]");
    } else {
      var expected = forwardBlurArray.shift();
      ok(expected == e.target.id,
         "(blur) forward tabbing, expected [" +
         expected + "], got [" + e.target.id + "]");
    }
  }

  function handleWindowBlur(e) {
    --expectedWindowBlurCount;
    var s = "target " + e.target;
    if ("id" in e.target) {
      s = s + ", id=\"" + e.target.id + "\"";
    }
    ok(e.eventPhase == Components.interfaces.nsIDOMEvent.CAPTURING_PHASE,
       "|window| should not have got a blur event, " + s);
  }

  function tab() {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
                       getInterface(Components.interfaces.nsIDOMWindowUtils);
    // Send tab key events.
    var key = Components.interfaces.nsIDOMKeyEvent.DOM_VK_TAB;
    utils.sendKeyEvent("keydown", key, 0, modifier);
    utils.sendKeyEvent("keypress", key, 0, modifier);
    utils.sendKeyEvent("keyup", key, 0, modifier);
    if (shouldStop) {
      // Did focus handling succeed
      ok(forwardFocusArray.length == 0,
         "Not all forward tabbing focus tests were run, " +
         forwardFocusArray.toString());
      ok(backwardFocusArray.length == 0,
         "Not all backward tabbing focus tests were run, " +
         backwardFocusArray.toString());
      ok(expectedWindowFocusCount == 0,
         "|window| didn't get the right amount of focus events");

       // and blur.
      ok(forwardBlurArray.length == 0,
         "Not all forward tabbing blur tests were run, " +
         forwardBlurArray.toString());
      ok(backwardBlurArray.length == 0,
         "Not all backward tabbing blur tests were run, " +
         backwardBlurArray.toString());
      ok(expectedWindowBlurCount == 0,
         "|window| didn't get the right amount of blur events");
      setOrRestoreTabFocus(0);
      SimpleTest.finish();
    } else {
      setTimeout(tab, 50);
    }
  }

  function start() {
    window.focus();
    window.addEventListener("focus", handleWindowFocus, true);
    window.addEventListener("focus", handleWindowFocus, false);
    window.addEventListener("blur", handleWindowBlur, true);
    window.addEventListener("blur", handleWindowBlur, false);
    var elements = document.getElementsByTagName("*");
    for (var i = 0; i < elements.length; ++i) {
      if (elements[i].hasAttribute("id")) {
        elements[i].addEventListener("focus", handleFocus, false);
        elements[i].addEventListener("blur", handleBlur, false);
      }
    }
    tab();
  }

  function doTest() {
    setOrRestoreTabFocus(7);
    setTimeout(start, 100);
  }

  SimpleTest.waitForExplicitFinish();
  addLoadEvent(doTest);

</script>
</pre>
  <h4 tabindex="0" id="begin">Test:</h4>
  <table>
    <tbody>
      <tr>
        <td>type="text"</td><td><input type="text"  id="i1" value=""></td>
      </tr>
      <tr>
        <td>type="button"</td><td><input type="button" id="i2" value="type='button'"></td>
      </tr>
      <tr>
        <td>type="checkbox"</td><td><input type="checkbox" id="i3" ></td>
      </tr>
      <tr>
        <td>type="radio" checked</td><td><input type="radio" id="i4" name="radio" checked>
                                         <input type="radio" id="i4b" name="radio"></td>
      </tr>
      <tr>
        <td>type="radio"</td><td><input type="radio" id="i5" name="radio2">
                                 <input type="radio" id="i6" name="radio2"></td>
      </tr>
      <tr>
        <td>type="password"</td><td><input type="password" id="i7"></td>
      </tr>
      <tr>
        <td>type="file"</td><td><input type="file" id="i8"></td>
      </tr>
      <tr>
        <td>button</td><td><button id="i9">button</button></td>
      </tr>
      <tr>
        <td>select</td><td><select id="i10"><option>select</option></select></td>
      </tr>
      <tr>
        <td>a</td><td><a href="#radio" id="i11">a link</a></td>
      </tr>
      <tr>
        <td>tabindex="0"</td><td><span tabindex="0" id="i12">span</span></td>
      </tr>
    </tbody>
  </table>
  <h4 tabindex="0" id="end">done.</h4>
</body>
</html>