summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/hyperlink/hyperlink.js
blob: 93caa9090cc76594c5bc978635018a99d44dc9f9 (plain)
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
/* import-globals-from ../common.js */
/* import-globals-from ../events.js */
/* import-globals-from ../states.js */

/**
 * Focus hyperlink invoker.
 *
 * @param aID             [in] hyperlink identifier
 * @param aSelectedAfter  [in] specifies if hyperlink is selected/focused after
 *                          the focus
 */
function focusLink(aID, aSelectedAfter) {
  this.node = getNode(aID);
  this.accessible = getAccessible(this.node);

  this.eventSeq = [];
  this.unexpectedEventSeq = [];

  var checker = new invokerChecker(EVENT_FOCUS, this.accessible);
  if (aSelectedAfter) {
    this.eventSeq.push(checker);
  } else {
    this.unexpectedEventSeq.push(checker);
  }

  this.invoke = function focusLink_invoke() {
    var expectedStates = aSelectedAfter ? STATE_FOCUSABLE : 0;
    var unexpectedStates =
      (!aSelectedAfter ? STATE_FOCUSABLE : 0) | STATE_FOCUSED;
    testStates(aID, expectedStates, 0, unexpectedStates, 0);

    this.node.focus();
  };

  this.finalCheck = function focusLink_finalCheck() {
    var expectedStates = aSelectedAfter ? STATE_FOCUSABLE | STATE_FOCUSED : 0;
    var unexpectedStates = !aSelectedAfter
      ? STATE_FOCUSABLE | STATE_FOCUSED
      : 0;
    testStates(aID, expectedStates, 0, unexpectedStates, 0);
  };

  this.getID = function focusLink_getID() {
    return "focus hyperlink " + prettyName(aID);
  };
}