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.

Mercurial (b6d82b1a6b02)

VCS Links

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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
<html>

<head>
  <title>Accessible state change event testing</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../events.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../states.js"></script>

  <script type="application/javascript">
    // //////////////////////////////////////////////////////////////////////////
    // Invokers

    function makeEditableDoc(aDocNode, aIsEnabled) {
      this.DOMNode = aDocNode;

      this.invoke = function editabledoc_invoke() {
        // Note: this should fire an EVENT_STATE_CHANGE
        this.DOMNode.designMode = "on";
      };

      this.check = function editabledoc_check(aEvent) {
        testStates(aDocNode, 0, EXT_STATE_EDITABLE);

        let event = null;
        try {
          event = aEvent.QueryInterface(nsIAccessibleStateChangeEvent);
        } catch (e) {
          ok(false, "State change event was expected");
        }

        if (!event) { return; }

        ok(event.isExtraState, "Extra state change was expected");
        is(event.state, EXT_STATE_EDITABLE, "Wrong state of statechange event");
        ok(event.isEnabled, "Expected editable state to be enabled");
      };

      this.getID = function editabledoc_getID() {
        return prettyName(aDocNode) + " editable state changed";
      };
    }

    function invalidInput(aNodeOrID) {
      this.DOMNode = getNode(aNodeOrID);

      this.invoke = function invalidInput_invoke() {
        // Note: this should fire an EVENT_STATE_CHANGE
        this.DOMNode.value = "I am not an email";
      };

      this.check = function invalidInput_check() {
        testStates(aNodeOrID, STATE_INVALID);
      };

      this.getID = function invalidInput_getID() {
        return prettyName(aNodeOrID) + " became invalid";
      };
    }

    function changeCheckInput(aID, aIsChecked) {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new stateChangeChecker(STATE_CHECKED, false, aIsChecked, this.DOMNode),
      ];

      this.invoke = function changeCheckInput_invoke() {
        this.DOMNode.checked = aIsChecked;
      };

      this.getID = function changeCheckInput_getID() {
        return "change checked state to '" + aIsChecked + "' for " +
          prettyName(aID);
      };
    }

    function stateChangeOnFileInput(aID, aAttr, aValue,
                                    aState, aIsExtraState, aIsEnabled) {
      this.fileControlNode = getNode(aID);
      this.fileControl = getAccessible(this.fileControlNode);
      this.browseButton = this.fileControl.firstChild;
      // No state change events on the label.

      this.invoke = function stateChangeOnFileInput_invoke() {
        this.fileControlNode.setAttribute(aAttr, aValue);
      };

      this.eventSeq = [
        new stateChangeChecker(aState, aIsExtraState, aIsEnabled, this.fileControl),
        new stateChangeChecker(aState, aIsExtraState, aIsEnabled, this.browseButton),
      ];

      this.getID = function stateChangeOnFileInput_getID() {
        return "inherited state change on file input on attribute '" + aAttr + "' change";
      };
    }

    function dupeStateChange(aID, aAttr, aValue,
                             aState, aIsExtraState, aIsEnabled) {
      this.eventSeq = [
        new stateChangeChecker(aState, aIsExtraState, aIsEnabled, getNode(aID)),
      ];

      this.invoke = function dupeStateChange_invoke() {
        getNode(aID).setAttribute(aAttr, aValue);
        getNode(aID).setAttribute(aAttr, aValue);
      };

      this.getID = function dupeStateChange_getID() {
        return "duped state change events";
      };
    }

    function oppositeStateChange(aID, aAttr, aState, aIsExtraState) {
      this.eventSeq = [ ];
      this.unexpectedEventSeq = [
        new stateChangeChecker(aState, aIsExtraState, false, getNode(aID)),
        new stateChangeChecker(aState, aIsExtraState, true, getNode(aID)),
      ];

      this.invoke = function oppositeStateChange_invoke() {
        getNode(aID).setAttribute(aAttr, "false");
        getNode(aID).setAttribute(aAttr, "true");
      };

      this.getID = function oppositeStateChange_getID() {
        return "opposite state change events";
      };
    }

    /**
     * Change concomitant ARIA and native attribute at once.
     */
    function echoingStateChange(aID, aARIAAttr, aAttr, aValue,
                               aState, aIsExtraState, aIsEnabled) {
      this.eventSeq = [
        new stateChangeChecker(aState, aIsExtraState, aIsEnabled, getNode(aID)),
      ];

      this.invoke = function echoingStateChange_invoke() {
        if (aValue == null) {
          getNode(aID).removeAttribute(aARIAAttr);
          getNode(aID).removeAttribute(aAttr);
        } else {
          getNode(aID).setAttribute(aARIAAttr, aValue);
          getNode(aID).setAttribute(aAttr, aValue);
        }
      };

      this.getID = function echoingStateChange_getID() {
        return "enchoing ARIA and native attributes change";
      };
    }

    // //////////////////////////////////////////////////////////////////////////
    // Do tests

    var gQueue = null;

    // var gA11yEventDumpID = "eventdump"; // debug stuff
    // gA11yEventDumpToConsole = true; // debug stuff

    function doTests() {
      gQueue = new eventQueue(nsIAccessibleEvent.EVENT_STATE_CHANGE);

      // Test delayed editable state change
      var doc = document.getElementById("iframe").contentDocument;
      gQueue.push(new makeEditableDoc(doc));

      // invalid state change
      gQueue.push(new invalidInput("email"));

      // checked state change
      gQueue.push(new changeCheckInput("checkbox", true));
      gQueue.push(new changeCheckInput("checkbox", false));
      gQueue.push(new changeCheckInput("radio", true));
      gQueue.push(new changeCheckInput("radio", false));

      // file input inherited state changes
      gQueue.push(new stateChangeOnFileInput("file", "aria-busy", "true",
                                             STATE_BUSY, false, true));
      gQueue.push(new stateChangeOnFileInput("file", "aria-required", "true",
                                             STATE_REQUIRED, false, true));
      gQueue.push(new stateChangeOnFileInput("file", "aria-invalid", "true",
                                             STATE_INVALID, false, true));

      gQueue.push(new dupeStateChange("div", "aria-busy", "true",
                                      STATE_BUSY, false, true));
      gQueue.push(new oppositeStateChange("div", "aria-busy",
                                          STATE_BUSY, false));

      gQueue.push(new echoingStateChange("text1", "aria-disabled", "disabled", "true",
                                         EXT_STATE_ENABLED, true, false));
      gQueue.push(new echoingStateChange("text1", "aria-disabled", "disabled", null,
                                         EXT_STATE_ENABLED, true, true));

      gQueue.invoke(); // Will call SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTests);
  </script>
</head>

<body>

  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=564471"
     title="Make state change events async">
    Bug 564471
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=555728"
     title="Fire a11y event based on HTML5 constraint validation">
    Bug 555728
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=699017"
     title="File input control should be propogate states to descendants">
    Bug 699017
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=788389"
     title="Fire statechange event whenever checked state is changed not depending on focused state">
    Bug 788389
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=926812"
     title="State change event not fired when both disabled and aria-disabled are toggled">
    Bug 926812
  </a>

  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>

  <div id="testContainer">
    <iframe id="iframe"></iframe>
  </div>

  <input id="email" type='email'>

  <input id="checkbox" type="checkbox">
  <input id="radio" type="radio">

  <input id="file" type="file">

  <div id="div"></div>

  <input id="text1">

  <div id="eventdump"></div>
</body>
</html>