accessible/tests/mochitest/events/test_statechange.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/tests/mochitest/events/test_statechange.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,287 @@
     1.4 +<html>
     1.5 +
     1.6 +<head>
     1.7 +  <title>Accessible state change event testing</title>
     1.8 +
     1.9 +  <link rel="stylesheet" type="text/css"
    1.10 +        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.11 +
    1.12 +  <script type="application/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +
    1.15 +  <script type="application/javascript"
    1.16 +          src="../common.js"></script>
    1.17 +  <script type="application/javascript"
    1.18 +          src="../events.js"></script>
    1.19 +  <script type="application/javascript"
    1.20 +          src="../role.js"></script>
    1.21 +  <script type="application/javascript"
    1.22 +          src="../states.js"></script>
    1.23 +
    1.24 +  <script type="application/javascript">
    1.25 +    ////////////////////////////////////////////////////////////////////////////
    1.26 +    // Invokers
    1.27 +
    1.28 +    function makeEditableDoc(aDocNode, aIsEnabled)
    1.29 +    {
    1.30 +      this.DOMNode = aDocNode;
    1.31 +
    1.32 +      this.invoke = function editabledoc_invoke() {
    1.33 +        // Note: this should fire an EVENT_STATE_CHANGE
    1.34 +        this.DOMNode.designMode = 'on';
    1.35 +      };
    1.36 +
    1.37 +      this.check = function editabledoc_check(aEvent) {
    1.38 +
    1.39 +        testStates(aDocNode, 0, EXT_STATE_EDITABLE);
    1.40 +
    1.41 +        var event = null;
    1.42 +        try {
    1.43 +          var event = aEvent.QueryInterface(nsIAccessibleStateChangeEvent);
    1.44 +        } catch (e) {
    1.45 +          ok(false, "State change event was expected");
    1.46 +        }
    1.47 +
    1.48 +        if (!event) { return; }
    1.49 +
    1.50 +        ok(event.isExtraState, "Extra state change was expected");
    1.51 +        is(event.state, EXT_STATE_EDITABLE, "Wrong state of statechange event");
    1.52 +        ok(event.isEnabled, "Expected editable state to be enabled");
    1.53 +      }
    1.54 +
    1.55 +      this.getID = function editabledoc_getID() {
    1.56 +        return prettyName(aDocNode) + " editable state changed";
    1.57 +      };
    1.58 +    }
    1.59 +
    1.60 +    function invalidInput(aNodeOrID)
    1.61 +    {
    1.62 +      this.DOMNode = getNode(aNodeOrID);
    1.63 +
    1.64 +      this.invoke = function invalidInput_invoke() {
    1.65 +        // Note: this should fire an EVENT_STATE_CHANGE
    1.66 +        this.DOMNode.value = "I am not an email";
    1.67 +      };
    1.68 +
    1.69 +      this.check = function invalidInput_check() {
    1.70 +        testStates(aNodeOrID, STATE_INVALID);
    1.71 +      };
    1.72 +
    1.73 +      this.getID = function invalidInput_getID() {
    1.74 +        return prettyName(aNodeOrID) + " became invalid";
    1.75 +      };
    1.76 +    }
    1.77 +
    1.78 +    function changeCheckInput(aID, aIsChecked)
    1.79 +    {
    1.80 +      this.DOMNode = getNode(aID);
    1.81 +
    1.82 +      this.eventSeq = [
    1.83 +        new stateChangeChecker(STATE_CHECKED, false, aIsChecked, this.DOMNode)
    1.84 +      ];
    1.85 +
    1.86 +      this.invoke = function changeCheckInput_invoke()
    1.87 +      {
    1.88 +        this.DOMNode.checked = aIsChecked;
    1.89 +      }
    1.90 +
    1.91 +      this.getID = function changeCheckInput_getID()
    1.92 +      {
    1.93 +        return "change checked state to '" + aIsChecked + "' for " +
    1.94 +          prettyName(aID);
    1.95 +      }
    1.96 +    }
    1.97 +
    1.98 +    function stateChangeOnFileInput(aID, aAttr, aValue,
    1.99 +                                    aState, aIsExtraState, aIsEnabled)
   1.100 +    {
   1.101 +      this.fileControlNode = getNode(aID);
   1.102 +      this.fileControl = getAccessible(this.fileControlNode);
   1.103 +      this.browseButton = this.fileControl.firstChild;
   1.104 +      // No state change events on the label.
   1.105 +
   1.106 +      this.invoke = function stateChangeOnFileInput_invoke()
   1.107 +      {
   1.108 +        this.fileControlNode.setAttribute(aAttr, aValue);
   1.109 +      }
   1.110 +
   1.111 +      this.eventSeq = [
   1.112 +        new stateChangeChecker(aState, aIsExtraState, aIsEnabled, this.fileControl),
   1.113 +        new stateChangeChecker(aState, aIsExtraState, aIsEnabled, this.browseButton)
   1.114 +      ];
   1.115 +
   1.116 +      this.getID = function stateChangeOnFileInput_getID()
   1.117 +      {
   1.118 +        return "inherited state change on file input on attribute '" + aAttr + "' change";
   1.119 +      }
   1.120 +    }
   1.121 +
   1.122 +    function dupeStateChange(aID, aAttr, aValue,
   1.123 +                             aState, aIsExtraState, aIsEnabled)
   1.124 +    {
   1.125 +      this.eventSeq = [
   1.126 +        new stateChangeChecker(aState, aIsExtraState, aIsEnabled, getNode(aID))
   1.127 +      ];
   1.128 +
   1.129 +      this.invoke = function dupeStateChange_invoke()
   1.130 +      {
   1.131 +        getNode(aID).setAttribute(aAttr, aValue);
   1.132 +        getNode(aID).setAttribute(aAttr, aValue);
   1.133 +      }
   1.134 +
   1.135 +      this.getID = function dupeStateChange_getID()
   1.136 +      {
   1.137 +        return "duped state change events";
   1.138 +      }
   1.139 +    }
   1.140 +
   1.141 +    function oppositeStateChange(aID, aAttr, aState, aIsExtraState)
   1.142 +    {
   1.143 +      this.eventSeq = [ ];
   1.144 +      this.unexpectedEventSeq = [
   1.145 +        new stateChangeChecker(aState, aIsExtraState, false, getNode(aID)),
   1.146 +        new stateChangeChecker(aState, aIsExtraState, true, getNode(aID))
   1.147 +      ];
   1.148 +
   1.149 +      this.invoke = function oppositeStateChange_invoke()
   1.150 +      {
   1.151 +        getNode(aID).setAttribute(aAttr, "false");
   1.152 +        getNode(aID).setAttribute(aAttr, "true");
   1.153 +      }
   1.154 +
   1.155 +      this.getID = function oppositeStateChange_getID()
   1.156 +      {
   1.157 +        return "opposite state change events";
   1.158 +      }
   1.159 +    }
   1.160 +
   1.161 +    /**
   1.162 +     * Change concomitant ARIA and native attribute at once.
   1.163 +     */
   1.164 +    function echoingStateChange(aID, aARIAAttr, aAttr, aValue,
   1.165 +                               aState, aIsExtraState, aIsEnabled)
   1.166 +    {
   1.167 +      this.eventSeq = [
   1.168 +        new stateChangeChecker(aState, aIsExtraState, aIsEnabled, getNode(aID))
   1.169 +      ];
   1.170 +
   1.171 +      this.invoke = function echoingStateChange_invoke()
   1.172 +      {
   1.173 +        if (aValue == null) {
   1.174 +          getNode(aID).removeAttribute(aARIAAttr);
   1.175 +          getNode(aID).removeAttribute(aAttr);
   1.176 +
   1.177 +        } else {
   1.178 +          getNode(aID).setAttribute(aARIAAttr, aValue);
   1.179 +          getNode(aID).setAttribute(aAttr, aValue);
   1.180 +        }
   1.181 +      }
   1.182 +
   1.183 +      this.getID = function echoingStateChange_getID()
   1.184 +      {
   1.185 +        return "enchoing ARIA and native attributes change";
   1.186 +      }
   1.187 +    }
   1.188 +
   1.189 +    ////////////////////////////////////////////////////////////////////////////
   1.190 +    // Do tests
   1.191 +
   1.192 +    var gQueue = null;
   1.193 +
   1.194 +    // var gA11yEventDumpID = "eventdump"; // debug stuff
   1.195 +    //gA11yEventDumpToConsole = true; // debug stuff
   1.196 +
   1.197 +    function doTests()
   1.198 +    {
   1.199 +      gQueue = new eventQueue(nsIAccessibleEvent.EVENT_STATE_CHANGE);
   1.200 +
   1.201 +      // Test delayed editable state change
   1.202 +      var doc = document.getElementById("iframe").contentDocument;
   1.203 +      gQueue.push(new makeEditableDoc(doc));
   1.204 +
   1.205 +      // invalid state change
   1.206 +      gQueue.push(new invalidInput("email"));
   1.207 +
   1.208 +      // checked state change
   1.209 +      gQueue.push(new changeCheckInput("checkbox", true));
   1.210 +      gQueue.push(new changeCheckInput("checkbox", false));
   1.211 +      gQueue.push(new changeCheckInput("radio", true));
   1.212 +      gQueue.push(new changeCheckInput("radio", false));
   1.213 +
   1.214 +      // file input inherited state changes
   1.215 +      gQueue.push(new stateChangeOnFileInput("file", "aria-busy", "true",
   1.216 +                                             STATE_BUSY, false, true));
   1.217 +      gQueue.push(new stateChangeOnFileInput("file", "aria-required", "true",
   1.218 +                                             STATE_REQUIRED, false, true));
   1.219 +      gQueue.push(new stateChangeOnFileInput("file", "aria-invalid", "true",
   1.220 +                                             STATE_INVALID, false, true));
   1.221 +
   1.222 +      gQueue.push(new dupeStateChange("div", "aria-busy", "true",
   1.223 +                                      STATE_BUSY, false, true));
   1.224 +      gQueue.push(new oppositeStateChange("div", "aria-busy",
   1.225 +                                          STATE_BUSY, false));
   1.226 +
   1.227 +      gQueue.push(new echoingStateChange("text1", "aria-disabled", "disabled", "true",
   1.228 +                                         EXT_STATE_ENABLED, true, false));
   1.229 +      gQueue.push(new echoingStateChange("text1", "aria-disabled", "disabled", null,
   1.230 +                                         EXT_STATE_ENABLED, true, true));
   1.231 +
   1.232 +      gQueue.invoke(); // Will call SimpleTest.finish();
   1.233 +    }
   1.234 +
   1.235 +    SimpleTest.waitForExplicitFinish();
   1.236 +    addA11yLoadEvent(doTests);
   1.237 +  </script>
   1.238 +</head>
   1.239 +
   1.240 +<body>
   1.241 +
   1.242 +  <a target="_blank"
   1.243 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=564471"
   1.244 +     title="Make state change events async">
   1.245 +    Bug 564471
   1.246 +  </a>
   1.247 +  <a target="_blank"
   1.248 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=555728"
   1.249 +     title="Fire a11y event based on HTML5 constraint validation">
   1.250 +    Bug 555728
   1.251 +  </a>
   1.252 +  <a target="_blank"
   1.253 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=699017"
   1.254 +     title="File input control should be propogate states to descendants">
   1.255 +    Bug 699017
   1.256 +  </a>
   1.257 +  <a target="_blank"
   1.258 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=788389"
   1.259 +     title="Fire statechange event whenever checked state is changed not depending on focused state">
   1.260 +    Bug 788389
   1.261 +  </a>
   1.262 +  <a target="_blank"
   1.263 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=926812"
   1.264 +     title="State change event not fired when both disabled and aria-disabled are toggled">
   1.265 +    Bug 926812
   1.266 +  </a>
   1.267 +
   1.268 +  <p id="display"></p>
   1.269 +  <div id="content" style="display: none"></div>
   1.270 +  <pre id="test">
   1.271 +  </pre>
   1.272 +
   1.273 +  <div id="testContainer">
   1.274 +    <iframe id="iframe"></iframe>
   1.275 +  </div>
   1.276 +
   1.277 +  <input id="email" type='email'>
   1.278 +
   1.279 +  <input id="checkbox" type="checkbox">
   1.280 +  <input id="radio" type="radio">
   1.281 +
   1.282 +  <input id="file" type="file">
   1.283 +
   1.284 +  <div id="div"></div>
   1.285 +
   1.286 +  <input id="text1">
   1.287 +
   1.288 +  <div id="eventdump"></div>
   1.289 +</body>
   1.290 +</html>

mercurial