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
132
133
134
135
136
137
138
139
|
/* eslint-disable mozilla/no-arbitrary-setTimeout */
// Test for bug 1170531
// https://bugzilla.mozilla.org/show_bug.cgi?id=1170531
add_task(async function () {
// Get a bunch of DOM nodes
let editMenu = document.getElementById("edit-menu");
let menuPopup = editMenu.menupopup;
let closeMenu = function (aCallback) {
if (Services.appinfo.OS == "Darwin") {
executeSoon(aCallback);
return;
}
menuPopup.addEventListener(
"popuphidden",
function () {
executeSoon(aCallback);
},
{ once: true }
);
executeSoon(function () {
editMenu.open = false;
});
};
let openMenu = function (aCallback) {
if (Services.appinfo.OS == "Darwin") {
goUpdateGlobalEditMenuItems();
// On OSX, we have a native menu, so it has to be updated. In single process browsers,
// this happens synchronously, but in e10s, we have to wait for the main thread
// to deal with it for us. 1 second should be plenty of time.
setTimeout(aCallback, 1000);
return;
}
menuPopup.addEventListener(
"popupshown",
function () {
executeSoon(aCallback);
},
{ once: true }
);
executeSoon(function () {
editMenu.open = true;
});
};
await BrowserTestUtils.withNewTab(
{ gBrowser, url: "about:blank" },
async function (browser) {
let menu_cut_disabled, menu_copy_disabled;
BrowserTestUtils.startLoadingURIString(
browser,
"data:text/html,<div>hello!</div>"
);
await BrowserTestUtils.browserLoaded(browser);
browser.focus();
await new Promise(resolve => waitForFocus(resolve, window));
await new Promise(resolve =>
window.requestAnimationFrame(() => executeSoon(resolve))
);
await new Promise(openMenu);
menu_cut_disabled =
menuPopup.querySelector("#menu_cut").getAttribute("disabled") == "true";
is(menu_cut_disabled, false, "menu_cut should be enabled");
menu_copy_disabled =
menuPopup.querySelector("#menu_copy").getAttribute("disabled") ==
"true";
is(menu_copy_disabled, false, "menu_copy should be enabled");
await new Promise(closeMenu);
// When there is no text selected in the contentEditable, we expect the Cut
// and Copy commands to be disabled.
BrowserTestUtils.startLoadingURIString(
browser,
"data:text/html,<div contentEditable='true'>hello!</div>"
);
await BrowserTestUtils.browserLoaded(browser);
browser.focus();
await new Promise(resolve => waitForFocus(resolve, window));
await new Promise(resolve =>
window.requestAnimationFrame(() => executeSoon(resolve))
);
await new Promise(openMenu);
menu_cut_disabled =
menuPopup.querySelector("#menu_cut").getAttribute("disabled") == "true";
is(menu_cut_disabled, true, "menu_cut should be disabled");
menu_copy_disabled =
menuPopup.querySelector("#menu_copy").getAttribute("disabled") ==
"true";
is(menu_copy_disabled, true, "menu_copy should be disabled");
await new Promise(closeMenu);
// When the text of the contentEditable is selected, the Cut and Copy commands
// should be enabled.
BrowserTestUtils.startLoadingURIString(
browser,
"data:text/html,<div contentEditable='true'>hello!</div><script>r=new Range;r.selectNodeContents(document.body.firstChild);document.getSelection().addRange(r);</script>"
);
await BrowserTestUtils.browserLoaded(browser);
browser.focus();
await new Promise(resolve => waitForFocus(resolve, window));
await new Promise(resolve =>
window.requestAnimationFrame(() => executeSoon(resolve))
);
await new Promise(openMenu);
menu_cut_disabled =
menuPopup.querySelector("#menu_cut").getAttribute("disabled") == "true";
is(menu_cut_disabled, false, "menu_cut should be enabled");
menu_copy_disabled =
menuPopup.querySelector("#menu_copy").getAttribute("disabled") ==
"true";
is(menu_copy_disabled, false, "menu_copy should be enabled");
await new Promise(closeMenu);
BrowserTestUtils.startLoadingURIString(browser, "about:preferences");
await BrowserTestUtils.browserLoaded(browser);
browser.focus();
await new Promise(resolve => waitForFocus(resolve, window));
await new Promise(resolve =>
window.requestAnimationFrame(() => executeSoon(resolve))
);
await new Promise(openMenu);
menu_cut_disabled =
menuPopup.querySelector("#menu_cut").getAttribute("disabled") == "true";
is(menu_cut_disabled, true, "menu_cut should be disabled");
menu_copy_disabled =
menuPopup.querySelector("#menu_copy").getAttribute("disabled") ==
"true";
is(menu_copy_disabled, true, "menu_copy should be disabled");
await new Promise(closeMenu);
}
);
});
|