2010-04-10 13:05:58 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=166235
|
2013-01-08 16:33:17 -08:00
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=816298
|
2010-04-10 13:05:58 -07:00
|
|
|
-->
|
|
|
|
<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>
|
2013-01-08 16:33:17 -08:00
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=166235">Mozilla Bug 166235 and Bug 816298</a>
|
2010-04-10 13:05:58 -07:00
|
|
|
<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>
|
2013-01-08 16:33:17 -08:00
|
|
|
<p id="test2">This<span style="-moz-user-select: none;"><span style="-moz-user-select: text"> text should</span> NOT</span> be copied.</p>
|
|
|
|
<p id="test3">This text should<span style="-moz-user-select: -moz-none;"> NOT</span> be copied.</p>
|
|
|
|
<p id="test4">This<span style="-moz-user-select: -moz-none;"><span style="-moz-user-select: text"> text should</span> NOT</span> be copied.</p>
|
|
|
|
<p id="test5">This<span style="-moz-user-select: all"> text<span style="-moz-user-select: none"> should</span></span> be copied.</p>
|
2010-04-10 13:05:58 -07:00
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
2010-05-24 16:24:15 -07:00
|
|
|
<textarea id="input"></textarea>
|
2010-04-10 13:05:58 -07:00
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
2013-01-08 16:33:17 -08:00
|
|
|
"use strict";
|
2010-04-10 13:05:58 -07:00
|
|
|
|
|
|
|
/** Test for Bug 166235 **/
|
2012-09-24 05:46:29 -07:00
|
|
|
var Cc = SpecialPowers.Cc;
|
|
|
|
var Ci = SpecialPowers.Ci;
|
2010-04-10 13:05:58 -07:00
|
|
|
|
2012-09-24 05:46:29 -07:00
|
|
|
var webnav = SpecialPowers.wrap(window).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(SpecialPowers.Ci.nsIWebNavigation)
|
2010-05-24 16:24:15 -07:00
|
|
|
|
2012-09-24 05:46:29 -07:00
|
|
|
var docShell = webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell);
|
2010-05-24 16:24:15 -07:00
|
|
|
|
|
|
|
var documentViewer = docShell.contentViewer
|
2012-09-24 05:46:29 -07:00
|
|
|
.QueryInterface(SpecialPowers.Ci.nsIContentViewerEdit);
|
2010-05-24 16:24:15 -07:00
|
|
|
|
2012-01-18 19:10:14 -08:00
|
|
|
var clipboard = Cc["@mozilla.org/widget/clipboard;1"]
|
2012-09-24 05:46:29 -07:00
|
|
|
.getService(SpecialPowers.Ci.nsIClipboard);
|
2010-05-24 16:24:15 -07:00
|
|
|
|
2013-02-18 21:54:23 -08:00
|
|
|
var textarea = SpecialPowers.wrap(document.getElementById('input'));
|
2010-05-24 16:24:15 -07:00
|
|
|
|
2012-04-16 19:14:01 -07:00
|
|
|
function getLoadContext() {
|
|
|
|
return SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsILoadContext);
|
|
|
|
}
|
|
|
|
|
2010-05-24 16:24:15 -07:00
|
|
|
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) {
|
2012-01-18 19:10:14 -08:00
|
|
|
var transferable = Cc['@mozilla.org/widget/transferable;1']
|
2012-09-24 05:46:29 -07:00
|
|
|
.createInstance(SpecialPowers.Ci.nsITransferable);
|
2012-04-16 19:14:01 -07:00
|
|
|
transferable.init(getLoadContext());
|
2010-05-24 16:24:15 -07:00
|
|
|
transferable.addDataFlavor(mime);
|
|
|
|
clipboard.getData(transferable, 1);
|
2013-06-04 19:56:41 -07:00
|
|
|
var data = SpecialPowers.createBlankObject();
|
2010-05-24 16:24:15 -07:00
|
|
|
transferable.getTransferData(mime, data, {}) ;
|
2013-06-04 19:56:41 -07:00
|
|
|
return SpecialPowers.wrap(data);
|
2010-05-24 16:24:15 -07:00
|
|
|
}
|
|
|
|
function testClipboardValue(mime, expected, test) {
|
|
|
|
var data = getClipboardData(mime);
|
|
|
|
is (data.value == null ? data.value :
|
2012-09-24 05:46:29 -07:00
|
|
|
data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data,
|
2010-05-24 16:24:15 -07:00
|
|
|
expected,
|
|
|
|
mime + " value in the clipboard");
|
|
|
|
return data.value;
|
|
|
|
}
|
|
|
|
function testPasteText(expected, test) {
|
|
|
|
textarea.value="";
|
|
|
|
textarea.focus();
|
2013-02-18 21:54:23 -08:00
|
|
|
textarea.editor.paste(1);
|
2010-05-24 16:24:15 -07:00
|
|
|
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()
|
2010-04-10 13:05:58 -07:00
|
|
|
var originalStrings = [
|
|
|
|
'This text should be copied.',
|
2010-05-24 16:24:15 -07:00
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.',
|
2013-01-08 16:33:17 -08:00
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.'
|
2010-05-24 16:24:15 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
// 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>',
|
2013-01-08 16:33:17 -08:00
|
|
|
'<p id=\"test2\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>',
|
|
|
|
'<p id=\"test3\">This text should be copied.</p>',
|
|
|
|
'<p id=\"test4\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>',
|
|
|
|
'<p id=\"test5\">This<span style=\"-moz-user-select: all\"> text<span style=\"-moz-user-select: none\"> should</span></span> be copied.</p>',
|
2010-05-24 16:24:15 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
// expected results for clipboard text/unicode
|
|
|
|
var clipboardUnicode = [
|
2013-01-08 16:33:17 -08:00
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.',
|
2010-05-24 16:24:15 -07:00
|
|
|
'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.',
|
2013-01-08 16:33:17 -08:00
|
|
|
'This<span style=\"-moz-user-select: none;\"><span style=\"-moz-user-select: text\"> text should</span> NOT</span> be copied.',
|
|
|
|
'This text should<span style=\"-moz-user-select: -moz-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.',
|
|
|
|
'This<span style=\"-moz-user-select: all\"> text<span style=\"-moz-user-select: none\"> should</span></span> be copied.',
|
2010-04-10 13:05:58 -07:00
|
|
|
];
|
|
|
|
|
2010-05-24 16:24:15 -07:00
|
|
|
// expected results for pasting into a TEXTAREA
|
|
|
|
var textareaStrings = [
|
2013-01-08 16:33:17 -08:00
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.',
|
2010-04-10 13:05:58 -07:00
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.',
|
|
|
|
'This text should be copied.'
|
|
|
|
];
|
|
|
|
|
2013-01-08 16:33:17 -08:00
|
|
|
for (var i = 0; i < originalStrings.length; i++) {
|
2010-05-24 16:24:15 -07:00
|
|
|
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');
|
2010-04-10 13:05:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|