accessible/tests/mochitest/events/test_aria_statechange.html
author Mark Banner <standard8@mozilla.com>
Fri, 19 Oct 2018 12:55:39 +0000
changeset 490493 edc4ae8f78e2fb02647d7cd85cb19830a17dcd1d
parent 414423 46fa29da7f94fb72a4afbfa39a0e811d19b224da
permissions -rw-r--r--
Bug 1486741 - Enable ESLint rule comma-dangle for all of mozilla-central (automatic fixes). r=mossop Differential Revision: https://phabricator.services.mozilla.com/D8389

<html>

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

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

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

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

  <script type="application/javascript">


    /**
     * Do tests.
     */
    var gQueue = null;

    // gA11yEventDumpID = "eventdump"; // debugging
    // gA11yEventDumpToConsole = true; // debugging

    function expandNode(aID, aIsExpanded) {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new expandedStateChecker(aIsExpanded, this.DOMNode),
      ];

      this.invoke = function expandNode_invoke() {
        this.DOMNode.setAttribute("aria-expanded",
                                  (aIsExpanded ? "true" : "false"));
      };

      this.getID = function expandNode_getID() {
        return prettyName(aID) + " aria-expanded changed to '" + aIsExpanded + "'";
      };
    }

    function busyify(aID, aIsBusy) {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new stateChangeChecker(STATE_BUSY, kOrdinalState, aIsBusy, this.DOMNode),
      ];

      this.invoke = function busyify_invoke() {
        this.DOMNode.setAttribute("aria-busy", (aIsBusy ? "true" : "false"));
      };

      this.getID = function busyify_getID() {
        return prettyName(aID) + " aria-busy changed to '" + aIsBusy + "'";
      };
    }

    function makeCurrent(aID, aIsCurrent, aValue) {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new stateChangeChecker(EXT_STATE_CURRENT, true, aIsCurrent, this.DOMNode),
      ];

      this.invoke = function makeCurrent_invoke() {
        this.DOMNode.setAttribute("aria-current", aValue);
      };

      this.getID = function makeCurrent_getID() {
        return prettyName(aID) + " aria-current changed to " + aValue;
      };
    }

    function setAttrOfMixedType(aID, aAttr, aState, aValue) {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new stateChangeChecker(aState, kOrdinalState,
                               aValue == "true", this.DOMNode),
      ];

      if (hasState(aID, STATE_MIXED) || aValue == "mixed") {
        this.eventSeq.push(
          new stateChangeChecker(STATE_MIXED, kOrdinalState,
                                 aValue == "mixed", this.DOMNode)
        );
      }

      this.invoke = function setAttrOfMixedType_invoke() {
        this.DOMNode.setAttribute(aAttr, aValue);
      };

      this.getID = function setAttrOfMixedType_getID() {
        return prettyName(aID) + " " + aAttr + " changed to '" + aValue + "'";
      };
    }

    function setPressed(aID, aValue) {
      this.__proto__ =
        new setAttrOfMixedType(aID, "aria-pressed", STATE_PRESSED, aValue);
    }

    function setChecked(aID, aValue) {
      this.__proto__ =
        new setAttrOfMixedType(aID, "aria-checked", STATE_CHECKED, aValue);
    }

    function buildQueueForAttr(aList, aQueue, aID, aInvokerFunc) {
      for (var i = 0; i < aList.length; i++) {
        for (var j = i + 1; j < aList.length; j++) {
          // XXX: changes from/to "undefined"/"" shouldn't fire state change
          // events, bug 472142.
          aQueue.push(new aInvokerFunc(aID, aList[i]));
          aQueue.push(new aInvokerFunc(aID, aList[j]));
        }
      }
    }

    function buildQueueForAttrOfMixedType(aQueue, aID, aInvokerFunc) {
      var list = [ "", "undefined", "false", "true", "mixed" ];
      buildQueueForAttr(list, aQueue, aID, aInvokerFunc);
    }

    function buildQueueForAttrOfBoolType(aQueue, aID, aInvokerFunc) {
      var list = [ "", "undefined", "false", "true" ];
      buildQueueForAttr(list, aQueue, aID, aInvokerFunc);
    }

    function doTests() {
      gQueue = new eventQueue();

      gQueue.push(new expandNode("section", true));
      gQueue.push(new expandNode("section", false));
      gQueue.push(new expandNode("div", true));
      gQueue.push(new expandNode("div", false));

      gQueue.push(new busyify("aria_doc", true));
      gQueue.push(new busyify("aria_doc", false));

      buildQueueForAttrOfMixedType(gQueue, "pressable", setPressed);
      buildQueueForAttrOfMixedType(gQueue, "pressable_native", setPressed);
      buildQueueForAttrOfMixedType(gQueue, "checkable", setChecked);
      buildQueueForAttrOfBoolType(gQueue, "checkableBool", setChecked);

      gQueue.push(new makeCurrent("current_page_1", false, "false"));
      gQueue.push(new makeCurrent("current_page_2", true, "page"));
      gQueue.push(new makeCurrent("current_page_2", false, "false"));
      gQueue.push(new makeCurrent("current_page_3", true, "true"));
      gQueue.push(new makeCurrent("current_page_3", false, ""));

      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=551684"
     title="No statechange event for aria-expanded on native HTML elements, is fired on ARIA widgets">
    Mozilla Bug 551684
  </a><br>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=648133"
     title="fire state change event for aria-busy">
    Mozilla Bug 648133
  </a><br>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=467143"
     title="mixed state change event is fired for focused accessible only">
    Mozilla Bug 467143
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=989958"
     title="Pressed state is not exposed on a button element with aria-pressed attribute">
    Mozilla Bug 989958
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=1136563"
     title="Support ARIA 1.1 switch role">
    Mozilla Bug 1136563
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=1355921"
     title="Elements with a defined, non-false value for aria-current should expose ATK_STATE_ACTIVE">
    Mozilla Bug 1355921
  </a>

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

  <!-- aria-expanded -->
  <div id="section" role="section" aria-expanded="false">expandable section</div>
  <div id="div" aria-expanded="false">expandable native div</div>

  <!-- aria-busy -->
  <div id="aria_doc" role="document" tabindex="0">A document</div>

  <!-- aria-pressed -->
  <div id="pressable" role="button"></div>
  <button id="pressable_native"></button>

  <!-- aria-checked -->
  <div id="checkable" role="checkbox"></div>
  <div id="checkableBool" role="switch"></div>

  <!-- aria-current -->
  <div id="current_page_1" role="link" aria-current="page">1</div>
  <div id="current_page_2" role="link" aria-current="false">2</div>
  <div id="current_page_3" role="link">3</div>
</body>
</html>