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
126
127
128
129
130
131
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_ROOT_CHROME = getRootDirectory(gTestPath);
const TEST_DIALOG_PATH = TEST_ROOT_CHROME + "subdialog.xhtml";
/**
* Tests that tab dialogs are focused when switching tabs.
*/
add_task(async function test_tabdialogbox_tab_switch_focus() {
// Open 3 tabs
let tabPromises = [];
for (let i = 0; i < 3; i += 1) {
tabPromises.push(
BrowserTestUtils.openNewForegroundTab(
gBrowser,
"http://example.com",
true
)
);
}
// Wait for tabs to be ready
let tabs = await Promise.all(tabPromises);
// Open subdialog in first two tabs
let dialogs = [];
for (let i = 0; i < 2; i += 1) {
let dialogBox = gBrowser.getTabDialogBox(tabs[i].linkedBrowser);
dialogBox.open(TEST_DIALOG_PATH);
dialogs.push(dialogBox.getTabDialogManager()._topDialog);
}
// Wait for dialogs to be ready
await Promise.all([dialogs[0]._dialogReady, dialogs[1]._dialogReady]);
// Switch to first tab which has dialog
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
// The textbox in the dialogs content window should be focused
let dialogTextbox = dialogs[0]._frame.contentDocument.querySelector(
"#textbox"
);
is(Services.focus.focusedElement, dialogTextbox, "Dialog textbox is focused");
// Switch to second tab which has dialog
await BrowserTestUtils.switchTab(gBrowser, tabs[1]);
// The textbox in the dialogs content window should be focused
let dialogTextbox2 = dialogs[1]._frame.contentDocument.querySelector(
"#textbox"
);
is(
Services.focus.focusedElement,
dialogTextbox2,
"Dialog2 textbox is focused"
);
// Switch to third tab which does not have a dialog
await BrowserTestUtils.switchTab(gBrowser, tabs[2]);
// Test that content is focused
is(
Services.focus.focusedElement,
tabs[2].linkedBrowser,
"Top level browser is focused"
);
// Cleanup
tabs.forEach(tab => {
BrowserTestUtils.removeTab(tab);
});
});
/**
* Tests that other dialogs are still visible if one dialog is hidden.
*/
add_task(async function test_tabdialogbox_tab_switch_hidden() {
// Open 2 tabs
let tabPromises = [];
for (let i = 0; i < 2; i += 1) {
tabPromises.push(
BrowserTestUtils.openNewForegroundTab(
gBrowser,
"http://example.com",
true
)
);
}
// Wait for tabs to be ready
let tabs = await Promise.all(tabPromises);
// Open subdialog in tabs
let dialogs = [];
let dialogBox, dialogBoxManager, browser;
for (let i = 0; i < 2; i += 1) {
dialogBox = gBrowser.getTabDialogBox(tabs[i].linkedBrowser);
browser = tabs[i].linkedBrowser;
dialogBox.open(TEST_DIALOG_PATH);
dialogBoxManager = dialogBox.getTabDialogManager();
dialogs.push(dialogBoxManager._topDialog);
}
// Wait for dialogs to be ready
await Promise.all([dialogs[0]._dialogReady, dialogs[1]._dialogReady]);
// Hide the top dialog
dialogBoxManager.hideDialog(browser);
ok(
BrowserTestUtils.is_hidden(dialogBoxManager._dialogStack),
"Dialog stack is hidden"
);
// Switch to first tab
await BrowserTestUtils.switchTab(gBrowser, tabs[0]);
// Check the dialog stack is showing in first tab
dialogBoxManager = gBrowser
.getTabDialogBox(tabs[0].linkedBrowser)
.getTabDialogManager();
is(dialogBoxManager._dialogStack.hidden, false, "Dialog stack is showing");
// Cleanup
tabs.forEach(tab => {
BrowserTestUtils.removeTab(tab);
});
});
|