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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that different paste items work in the context menu
const TEST_URL = URL_ROOT + "doc_inspector_menu.html";
const PASTE_ADJACENT_HTML_DATA = [
{
desc: "As First Child",
clipboardData: "2",
menuId: "node-menu-pastefirstchild",
},
{
desc: "As Last Child",
clipboardData: "4",
menuId: "node-menu-pastelastchild",
},
{
desc: "Before",
clipboardData: "1",
menuId: "node-menu-pastebefore",
},
{
desc: "After",
clipboardData: "<span>5</span>",
menuId: "node-menu-pasteafter",
},
];
var clipboard = require("resource://devtools/shared/platform/clipboard.js");
registerCleanupFunction(() => {
clipboard = null;
});
add_task(async function () {
const { inspector } = await openInspectorForURL(TEST_URL);
await testPasteOuterHTMLMenu();
await testPasteInnerHTMLMenu();
await testPasteAdjacentHTMLMenu();
async function testPasteOuterHTMLMenu() {
info("Testing that 'Paste Outer HTML' menu item works.");
await SimpleTest.promiseClipboardChange(
"this was pasted (outerHTML)",
() => {
clipboard.copyString("this was pasted (outerHTML)");
}
);
const outerHTMLSelector = "#paste-area h1";
const nodeFront = await getNodeFront(outerHTMLSelector, inspector);
await selectNode(nodeFront, inspector);
const allMenuItems = openContextMenuAndGetAllItems(inspector, {
target: getContainerForNodeFront(nodeFront, inspector).tagLine,
});
const onNodeReselected = inspector.markup.once("reselectedonremoved");
allMenuItems.find(item => item.id === "node-menu-pasteouterhtml").click();
info("Waiting for inspector selection to update");
await onNodeReselected;
const outerHTML = await getContentPageElementProperty("body", "outerHTML");
ok(
outerHTML.includes(clipboard.getText()),
"Clipboard content was pasted into the node's outer HTML."
);
ok(
!(await hasMatchingElementInContentPage(outerHTMLSelector)),
"The original node was removed."
);
}
async function testPasteInnerHTMLMenu() {
info("Testing that 'Paste Inner HTML' menu item works.");
await SimpleTest.promiseClipboardChange(
"this was pasted (innerHTML)",
() => {
clipboard.copyString("this was pasted (innerHTML)");
}
);
const innerHTMLSelector = "#paste-area .inner";
const getInnerHTML = () =>
getContentPageElementProperty(innerHTMLSelector, "innerHTML");
const origInnerHTML = await getInnerHTML();
const nodeFront = await getNodeFront(innerHTMLSelector, inspector);
await selectNode(nodeFront, inspector);
const allMenuItems = openContextMenuAndGetAllItems(inspector, {
target: getContainerForNodeFront(nodeFront, inspector).tagLine,
});
const onMutation = inspector.once("markupmutation");
allMenuItems.find(item => item.id === "node-menu-pasteinnerhtml").click();
info("Waiting for mutation to occur");
await onMutation;
ok(
(await getInnerHTML()) === clipboard.getText(),
"Clipboard content was pasted into the node's inner HTML."
);
ok(
await hasMatchingElementInContentPage(innerHTMLSelector),
"The original node has been preserved."
);
await undoChange(inspector);
ok(
(await getInnerHTML()) === origInnerHTML,
"Previous innerHTML has been restored after undo"
);
}
async function testPasteAdjacentHTMLMenu() {
const refSelector = "#paste-area .adjacent .ref";
const adjacentNodeSelector = "#paste-area .adjacent";
const nodeFront = await getNodeFront(refSelector, inspector);
await selectNode(nodeFront, inspector);
const markupTagLine = getContainerForNodeFront(
nodeFront,
inspector
).tagLine;
for (const { clipboardData, menuId } of PASTE_ADJACENT_HTML_DATA) {
const allMenuItems = openContextMenuAndGetAllItems(inspector, {
target: markupTagLine,
});
info(`Testing ${menuId} for ${clipboardData}`);
await SimpleTest.promiseClipboardChange(clipboardData, () => {
clipboard.copyString(clipboardData);
});
const onMutation = inspector.once("markupmutation");
allMenuItems.find(item => item.id === menuId).click();
info("Waiting for mutation to occur");
await onMutation;
}
let html = await getContentPageElementProperty(
adjacentNodeSelector,
"innerHTML"
);
ok(
html.trim() === '1<span class="ref">234</span><span>5</span>',
"The Paste as Last Child / as First Child / Before / After worked as " +
"expected"
);
await undoChange(inspector);
html = await getContentPageElementProperty(
adjacentNodeSelector,
"innerHTML"
);
ok(
html.trim() === '1<span class="ref">234</span>',
"Undo works for paste adjacent HTML"
);
}
});
|