forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_bug166235.html
133 lines (116 loc) · 4.64 KB
/
test_bug166235.html
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=166235
-->
<head>
<title>Test for Bug 166235</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=166235">Mozilla Bug 166235</a>
<p id="test0">This text should be copied.</p>
<p id="test1">This text should<span style="-moz-user-select: none;"> NOT</span> be copied.</p>
<p id="test2">This<span style="-moz-user-select: -moz-none;"><span style="-moz-user-select: text"> text should</span> NOT</span> be copied.</p>
<div id="content" style="display: none">
</div>
<textarea id="input"></textarea>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 166235 **/
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var webnav = SpecialPowers.wrap(window).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
.getInterface(SpecialPowers.Ci.nsIWebNavigation)
var docShell = webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell);
var documentViewer = docShell.contentViewer
.QueryInterface(SpecialPowers.Ci.nsIContentViewerEdit);
var clipboard = Cc["@mozilla.org/widget/clipboard;1"]
.getService(SpecialPowers.Ci.nsIClipboard);
var textarea = SpecialPowers.wrap(document).getElementById('input');
function getLoadContext() {
return SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsILoadContext);
}
function copyChildrenToClipboard(id) {
textarea.blur();
clipboard.emptyClipboard(1);
window.getSelection().selectAllChildren(document.getElementById(id));
documentViewer.copySelection();
is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), true);
is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true);
}
function getClipboardData(mime) {
var transferable = Cc['@mozilla.org/widget/transferable;1']
.createInstance(SpecialPowers.Ci.nsITransferable);
transferable.init(getLoadContext());
transferable.addDataFlavor(mime);
clipboard.getData(transferable, 1);
var data = SpecialPowers.wrap({});
transferable.getTransferData(mime, data, {}) ;
return data;
}
function testClipboardValue(mime, expected, test) {
var data = getClipboardData(mime);
is (data.value == null ? data.value :
data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data,
expected,
mime + " value in the clipboard");
return data.value;
}
function testPasteText(expected, test) {
textarea.value="";
textarea.focus();
textarea.QueryInterface(SpecialPowers.Ci.nsIDOMNSEditableElement)
.editor.paste(1);
is(textarea.value, expected, test + ": textarea paste");
}
function testInnerHTML(id, expected) {
var value = document.getElementById(id).innerHTML;
is(value, expected, id + ".innerHTML");
}
// expected results for Selection.toString()
var originalStrings = [
'This text should be copied.',
'This text should be copied.',
'This text should be copied.',
];
// expected results for clipboard text/html
var clipboardHTML = [
'<p id=\"test0\">This text should be copied.</p>',
'<p id=\"test1\">This text should be copied.</p>',
'<p id=\"test2\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>'
];
// expected results for clipboard text/unicode
var clipboardUnicode = [
'This text should be copied.',
'This text should be copied.',
'This text should be copied.'
];
// expected results for .innerHTML
var innerHTMLStrings = [
'This text should be copied.',
'This text should<span style=\"-moz-user-select: none;\"> NOT</span> be copied.',
'This<span style=\"-moz-user-select: -moz-none;\"><span style=\"-moz-user-select: text\"> text should</span> NOT</span> be copied.'
];
// expected results for pasting into a TEXTAREA
var textareaStrings = [
'This text should be copied.',
'This text should be copied.',
'This text should be copied.'
];
for (var i = 0; i < 3; i++) {
var id = 'test' + i;
copyChildrenToClipboard(id);
is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()');
testClipboardValue("text/html", clipboardHTML[i], id);
testClipboardValue("text/unicode", clipboardUnicode[i], id);
testInnerHTML(id, innerHTMLStrings[i]);
testPasteText(textareaStrings[i], id + '.innerHTML');
}
</script>
</pre>
</body>
</html>