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
|
<!doctype html>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
<script src="copypaste.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<div id="content">
<style>
@font-face {
font-family: Ahem;
src: url("Ahem.ttf");
}
body { font-family: Ahem; font-size: 20px; margin: 0; }
input, textarea {
font: inherit;
-moz-appearance: none;
padding: 0;
border: 0;
scrollbar-width: none;
}
</style>
<input id="disabled-input" disabled value="abcd"> efgh <br> <textarea rows=1 id="disabled-textarea" disabled>ijkl</textarea> mnop <br>
</div>
<script>
function dragSelect(e, x1, x2, x3) {
dir = x2 > x1 ? 1 : -1;
synthesizeMouse(e, x1, 5, { type: "mousedown" });
synthesizeMouse(e, x1 + dir, 5, { type: "mousemove" });
if (x3)
synthesizeMouse(e, x3, 5, { type: "mousemove" });
synthesizeMouse(e, x2 - dir, 5, { type: "mousemove" });
synthesizeMouse(e, x2, 5, { type: "mouseup" });
}
SimpleTest.waitForExplicitFinish();
waitUntilApzStable().then(async function() {
const docShell = SpecialPowers.wrap(window).docShell;
const clipboard = SpecialPowers.Services.clipboard;
function copySelectionToClipboard() {
return SimpleTest.promiseClipboardChange(
() => true,
() => {
SpecialPowers.doCommand(window, "cmd_copy");
}
);
}
function getLoadContext() {
return docShell.QueryInterface(SpecialPowers.Ci.nsILoadContext);
}
function getClipboardData(mime) {
var transferable = SpecialPowers.Cc[
"@mozilla.org/widget/transferable;1"
].createInstance(SpecialPowers.Ci.nsITransferable);
transferable.init(getLoadContext());
transferable.addDataFlavor(mime);
clipboard.getData(transferable, 1);
var data = SpecialPowers.createBlankObject();
transferable.getTransferData(mime, data);
return data;
}
function testClipboardValue(mime, expected) {
var data = SpecialPowers.wrap(getClipboardData(mime));
is(
data.value == null
? data.value
: data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data,
expected,
mime + " value in the clipboard"
);
return data.value;
}
async function runTestsOn(doc) {
for (let id of ["disabled-input", "disabled-textarea"]) {
let element = doc.getElementById(id);
dragSelect(element, 0, 60);
await copySelectionToClipboard();
testClipboardValue("text/plain", element.value.substr(0, 3));
}
}
await runTestsOn(document)
let iframe = document.createElement("iframe");
iframe.setAttribute("frameborder", "0");
iframe.srcdoc = `<!doctype html>${document.getElementById("content").outerHTML}`;
let iframeLoad = new Promise(resolve => {
iframe.addEventListener("load", resolve, { once: true });
});
document.body.appendChild(iframe);
await iframeLoad;
iframe.width = window.innerWidth;
iframe.height = window.innerHeight;
await SimpleTest.promiseFocus(iframe.contentWindow);
await runTestsOn(iframe.contentDocument);
// Add a contenteditable element to test the case where there's an HTMLEditor
// around the page.
let div = document.createElement("div");
div.setAttribute("contenteditable", "true");
document.body.appendChild(div);
await runTestsOn(document);
SimpleTest.finish();
});
</script>
|