/* 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.defineESModuleGetters(this, {
PlacesTestUtils: "resource://testing-common/PlacesTestUtils.sys.mjs",
});
/**
* Test visited link properties.
*/
addAccessibleTask(
`
I am a non-visited link
`,
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");
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
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();
}
);
function waitForLinkedChange(id, isEnabled) {
return waitForEvent(EVENT_STATE_CHANGE, e => {
e.QueryInterface(nsIAccessibleStateChangeEvent);
return (
e.state == STATE_LINKED &&
!e.isExtraState &&
isEnabled == e.isEnabled &&
id == getAccessibleDOMNodeID(e.accessible)
);
});
}
/**
* Test linked vs unlinked anchor tags
*/
addAccessibleTask(
`
I am a link link
I am a link-ish link
I am a non-link link
`,
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 gets correct group role"
);
let stateChanged = waitForLinkedChange("link1", false);
await SpecialPowers.spawn(browser, [], () => {
content.document.getElementById("link1").removeAttribute("href");
});
await stateChanged;
is(
link1.getAttributeValue("AXRole"),
"AXGroup",
" stripped from href gets group role"
);
stateChanged = waitForLinkedChange("link2", false);
await SpecialPowers.spawn(browser, [], () => {
content.document.getElementById("link2").removeAttribute("onclick");
});
await stateChanged;
is(
link2.getAttributeValue("AXRole"),
"AXGroup",
" stripped from onclick gets group role"
);
stateChanged = waitForLinkedChange("link3", true);
await SpecialPowers.spawn(browser, [], () => {
content.document
.getElementById("link3")
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
.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");
}
);
/**
* Test anchors and linked ui elements attr
*/
addAccessibleTask(
`
I am a link
I am a link with an empty anchor
I am a link with no corresponding element
I am a link with a corresponding element
I jump to an empty element
I jump to a named element
I jump to an empty named element