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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// A test to check the 'Open Link in new tab' functionality in the
// context menu item for stylesheets (bug 992947).
const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html";
add_task(async function () {
const { panel, ui } = await openStyleEditorForURL(TESTCASE_URI);
const openLinkNewTabItem = panel.panelWindow.document.getElementById(
"context-openlinknewtab"
);
let menu = await rightClickStyleSheet(panel, ui.editors[0]);
is(
openLinkNewTabItem.getAttribute("disabled"),
"false",
"The menu item is not disabled"
);
ok(!openLinkNewTabItem.hidden, "The menu item is not hidden");
const url = TEST_BASE_HTTPS + "simple.css";
const browserWindow = Services.wm.getMostRecentWindow(
gDevTools.chromeWindowType
);
const originalOpenWebLinkIn = browserWindow.openWebLinkIn;
const tabOpenedDefer = new Promise(resolve => {
browserWindow.openWebLinkIn = newUrl => {
// Reset the actual openWebLinkIn function before proceeding.
browserWindow.openWebLinkIn = originalOpenWebLinkIn;
is(newUrl, url, "The correct tab has been opened");
resolve();
};
});
const hidden = onPopupHide(menu);
menu.activateItem(openLinkNewTabItem);
info(`Waiting for a tab to open - ${url}`);
await tabOpenedDefer;
await hidden;
menu = await rightClickInlineStyleSheet(panel, ui.editors[1]);
is(
openLinkNewTabItem.getAttribute("disabled"),
"true",
"The menu item is disabled"
);
ok(!openLinkNewTabItem.hidden, "The menu item should not be hidden");
menu.hidePopup();
menu = await rightClickNoStyleSheet(panel);
ok(openLinkNewTabItem.hidden, "The menu item should be hidden");
menu.hidePopup();
});
function onPopupShow(contextMenu) {
return new Promise(resolve => {
contextMenu.addEventListener(
"popupshown",
function () {
resolve();
},
{ once: true }
);
});
}
function onPopupHide(contextMenu) {
return new Promise(resolve => {
contextMenu.addEventListener(
"popuphidden",
function () {
resolve();
},
{ once: true }
);
});
}
function rightClickStyleSheet(panel, editor) {
const contextMenu = getContextMenuElement(panel);
return new Promise(resolve => {
onPopupShow(contextMenu).then(() => {
resolve(contextMenu);
});
EventUtils.synthesizeMouseAtCenter(
editor.summary.querySelector(".stylesheet-name"),
{ button: 2, type: "contextmenu" },
panel.panelWindow
);
});
}
function rightClickInlineStyleSheet(panel, editor) {
const contextMenu = getContextMenuElement(panel);
return new Promise(resolve => {
onPopupShow(contextMenu).then(() => {
resolve(contextMenu);
});
EventUtils.synthesizeMouseAtCenter(
editor.summary.querySelector(".stylesheet-name"),
{ button: 2, type: "contextmenu" },
panel.panelWindow
);
});
}
function rightClickNoStyleSheet(panel) {
const contextMenu = getContextMenuElement(panel);
return new Promise(resolve => {
onPopupShow(contextMenu).then(() => {
resolve(contextMenu);
});
EventUtils.synthesizeMouseAtCenter(
panel.panelWindow.document.querySelector(
"#splitview-tpl-summary-stylesheet"
),
{ button: 2, type: "contextmenu" },
panel.panelWindow
);
});
}
|