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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* import-globals-from ../../mochitest/role.js */
/* import-globals-from ../../mochitest/states.js */
loadScripts(
{ name: "role.js", dir: MOCHITESTS_DIR },
{ name: "states.js", dir: MOCHITESTS_DIR }
);
ChromeUtils.defineModuleGetter(
this,
"PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm"
);
/**
* Test visited link properties.
*/
addAccessibleTask(
`
<a id="link" href="http://www.example.com/">I am a non-visited link</a><br>
`,
async (browser, accDoc) => {
let link = getNativeInterface(accDoc, "link");
let stateChanged = waitForEvent(EVENT_STATE_CHANGE, "link");
is(link.getAttributeValue("AXVisited"), 0, "Link has not been visited");
await PlacesTestUtils.addVisits(["http://www.example.com/"]);
await stateChanged;
is(link.getAttributeValue("AXVisited"), 1, "Link has been visited");
// Ensure history is cleared before running
await PlacesUtils.history.clear();
}
);
/**
* Test linked vs unlinked anchor tags
*/
addAccessibleTask(
`
<a id="link1" href="#">I am a link link</a>
<a id="link2" onclick="console.log('hi')">I am a link-ish link</a>
<a id="link3">I am a non-link link</a>
`,
async (browser, accDoc) => {
let link1 = getNativeInterface(accDoc, "link1");
is(
link1.getAttributeValue("AXRole"),
"AXLink",
"a[href] gets correct link role"
);
ok(
link1.attributeNames.includes("AXVisited"),
"Link has visited attribute"
);
ok(link1.attributeNames.includes("AXURL"), "Link has URL attribute");
let link2 = getNativeInterface(accDoc, "link2");
is(
link2.getAttributeValue("AXRole"),
"AXLink",
"a[onclick] gets correct link role"
);
ok(
link2.attributeNames.includes("AXVisited"),
"Link has visited attribute"
);
ok(link2.attributeNames.includes("AXURL"), "Link has URL attribute");
let link3 = getNativeInterface(accDoc, "link3");
is(
link3.getAttributeValue("AXRole"),
"AXGroup",
"bare <a> gets correct group role"
);
let stateChanged = waitForEvent(EVENT_STATE_CHANGE, "link1");
await SpecialPowers.spawn(browser, [], () => {
content.document.getElementById("link1").removeAttribute("href");
});
await stateChanged;
is(
link1.getAttributeValue("AXRole"),
"AXGroup",
"<a> stripped from href gets group role"
);
stateChanged = waitForEvent(EVENT_STATE_CHANGE, "link2");
await SpecialPowers.spawn(browser, [], () => {
content.document.getElementById("link2").removeAttribute("onclick");
});
await stateChanged;
is(
link2.getAttributeValue("AXRole"),
"AXGroup",
"<a> stripped from onclick gets group role"
);
stateChanged = waitForEvent(EVENT_STATE_CHANGE, "link3");
await SpecialPowers.spawn(browser, [], () => {
content.document
.getElementById("link3")
.setAttribute("href", "http://example.com");
});
await stateChanged;
is(
link3.getAttributeValue("AXRole"),
"AXLink",
"href added to bare a gets link role"
);
ok(
link3.attributeNames.includes("AXVisited"),
"Link has visited attribute"
);
ok(link3.attributeNames.includes("AXURL"), "Link has URL attribute");
}
);
|