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
|
/* 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/states.js */
/* import-globals-from ../../mochitest/role.js */
loadScripts(
{ name: "states.js", dir: MOCHITESTS_DIR },
{ name: "role.js", dir: MOCHITESTS_DIR }
);
async function runTests(browser) {
let onFocus = waitForEvent(EVENT_FOCUS, "button");
await SpecialPowers.spawn(browser, [], () => {
content.document.getElementById("button").focus();
});
let button = (await onFocus).accessible;
testStates(button, STATE_FOCUSED);
// Bug 1377942 - The target of the focus event changes under different
// circumstances.
// In e10s the focus event is the new window, in non-e10s it's the doc.
onFocus = waitForEvent(EVENT_FOCUS, () => true);
let newWin = await BrowserTestUtils.openNewBrowserWindow();
// button should be blurred
await onFocus;
testStates(button, 0, 0, STATE_FOCUSED);
onFocus = waitForEvent(EVENT_FOCUS, "button");
await BrowserTestUtils.closeWindow(newWin);
testStates((await onFocus).accessible, STATE_FOCUSED);
onFocus = waitForEvent(EVENT_FOCUS, "body2");
await SpecialPowers.spawn(browser, [], () => {
content.document
.getElementById("editabledoc")
.contentWindow.document.body.focus();
});
testStates((await onFocus).accessible, STATE_FOCUSED);
onFocus = waitForEvent(EVENT_FOCUS, "body2");
newWin = await BrowserTestUtils.openNewBrowserWindow();
await BrowserTestUtils.closeWindow(newWin);
testStates((await onFocus).accessible, STATE_FOCUSED);
let onShow = waitForEvent(EVENT_SHOW, "alertdialog");
onFocus = waitForEvent(EVENT_FOCUS, "alertdialog");
await SpecialPowers.spawn(browser, [], () => {
let alertDialog = content.document.getElementById("alertdialog");
alertDialog.style.display = "block";
alertDialog.focus();
});
await onShow;
testStates((await onFocus).accessible, STATE_FOCUSED);
}
/**
* Accessible dialog focus testing
*/
addAccessibleTask(
`
<button id="button">button</button>
<iframe id="editabledoc"
src="${snippetToURL("", {
contentDocBodyAttrs: { id: "body2", contentEditable: "true" },
})}">
</iframe>
<div id="alertdialog" style="display: none" tabindex="-1" role="alertdialog" aria-labelledby="title2" aria-describedby="desc2">
<div id="title2">Blah blah</div>
<div id="desc2">Woof woof woof.</div>
<button>Close</button>
</div>`,
runTests
);
|