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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const PAGE = `
data:text/html,
<div>OuterText<div>
<div id="host">
<template shadowrootmode="open">
<span id="innerText">InnerText</span>
</template>
</div>
`;
/**
* Tests that right click on a cross boundary selection shows the context menu
*/
add_task(async function () {
await SpecialPowers.pushPrefEnv({
set: [["dom.shadowdom.selection_across_boundary.enabled", true]],
});
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: PAGE,
},
async function (browser) {
let contextMenu = document.getElementById("contentAreaContextMenu");
let awaitPopupShown = BrowserTestUtils.waitForEvent(
contextMenu,
"popupshown"
);
let awaitPopupHidden = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
await SpecialPowers.spawn(browser, [], () => {
let host = content.document.getElementById("host");
content.getSelection().setBaseAndExtent(
content.document.body,
0,
host.shadowRoot.getElementById("innerText").firstChild,
3 // Only select the first three characters of the inner text
);
});
await BrowserTestUtils.synthesizeMouseAtCenter(
"div", // Click on the div for OuterText
{
type: "contextmenu",
button: 2,
},
browser
);
await awaitPopupShown;
const allVisibleMenuItems = Array.from(contextMenu.children)
.filter(elem => {
return !elem.hidden;
})
.map(elem => elem.id);
ok(
allVisibleMenuItems.includes("context-copy"),
"copy button should exist"
);
contextMenu.hidePopup();
await awaitPopupHidden;
}
);
});
|