2009-01-01 17:26:16 +03:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
2017-01-24 17:24:04 +03:00
|
|
|
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
2009-01-01 17:26:16 +03:00
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=466599
|
|
|
|
-->
|
|
|
|
<window title="Mozilla Bug 466599"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
onload="initAndRunTests()">
|
2019-04-16 06:59:25 +03:00
|
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
2009-01-01 17:26:16 +03:00
|
|
|
|
|
|
|
<!-- test results are displayed in the html:body -->
|
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none"></div>
|
|
|
|
<pre id="test"></pre>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
<!-- test code goes here -->
|
|
|
|
<script class="testbody" type="application/javascript">
|
|
|
|
<![CDATA[
|
|
|
|
|
|
|
|
/** Test for Bug 466599 **/
|
|
|
|
|
2012-04-17 06:14:01 +04:00
|
|
|
function getLoadContext() {
|
2018-08-01 20:07:11 +03:00
|
|
|
return window.docShell.QueryInterface(Ci.nsILoadContext);
|
2012-04-17 06:14:01 +04:00
|
|
|
}
|
|
|
|
|
2009-01-01 17:26:16 +03:00
|
|
|
function copyToClipboard(txt)
|
|
|
|
{
|
2018-02-28 20:51:33 +03:00
|
|
|
var clipid = Ci.nsIClipboard;
|
2009-01-01 17:26:16 +03:00
|
|
|
var clip =
|
2018-02-28 20:51:33 +03:00
|
|
|
Cc['@mozilla.org/widget/clipboard;1'].createInstance(clipid);
|
2009-01-01 17:26:16 +03:00
|
|
|
if (!clip)
|
|
|
|
return false;
|
|
|
|
var trans =
|
2018-02-28 20:51:33 +03:00
|
|
|
Cc['@mozilla.org/widget/transferable;1'].createInstance(Ci.nsITransferable);
|
2009-01-01 17:26:16 +03:00
|
|
|
if (!trans)
|
|
|
|
return false;
|
2012-04-17 06:14:01 +04:00
|
|
|
trans.init(getLoadContext());
|
2009-01-01 17:26:16 +03:00
|
|
|
trans.addDataFlavor('text/html');
|
|
|
|
var str =
|
2018-02-28 20:51:33 +03:00
|
|
|
Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString);
|
2009-01-01 17:26:16 +03:00
|
|
|
var copytext = txt;
|
|
|
|
str.data = copytext;
|
|
|
|
trans.setTransferData("text/html",str,copytext.length*2);
|
|
|
|
if (!clip)
|
|
|
|
return false;
|
|
|
|
clip.setData(trans,null,clipid.kGlobalClipboard);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function readFromClipboard()
|
|
|
|
{
|
2018-02-28 20:51:33 +03:00
|
|
|
var clipid = Ci.nsIClipboard;
|
2009-01-01 17:26:16 +03:00
|
|
|
var clip =
|
2018-02-28 20:51:33 +03:00
|
|
|
Cc['@mozilla.org/widget/clipboard;1'].createInstance(clipid);
|
2009-01-01 17:26:16 +03:00
|
|
|
if (!clip)
|
|
|
|
return;
|
|
|
|
var trans =
|
2018-02-28 20:51:33 +03:00
|
|
|
Cc['@mozilla.org/widget/transferable;1'].createInstance(Ci.nsITransferable);
|
2009-01-01 17:26:16 +03:00
|
|
|
if (!trans)
|
|
|
|
return;
|
2012-04-17 06:14:01 +04:00
|
|
|
trans.init(getLoadContext());
|
2009-01-01 17:26:16 +03:00
|
|
|
trans.addDataFlavor('text/html');
|
|
|
|
clip.getData(trans,clipid.kGlobalClipboard);
|
|
|
|
var str = new Object();
|
2018-11-20 19:59:56 +03:00
|
|
|
trans.getTransferData("text/html",str);
|
2009-01-01 17:26:16 +03:00
|
|
|
if (str)
|
2018-02-28 20:51:33 +03:00
|
|
|
str = str.value.QueryInterface(Ci.nsISupportsString);
|
2009-01-01 17:26:16 +03:00
|
|
|
if (str)
|
2018-11-20 19:59:56 +03:00
|
|
|
pastetext = str.data;
|
2009-01-01 17:26:16 +03:00
|
|
|
return pastetext;
|
|
|
|
}
|
|
|
|
|
|
|
|
function encodeHtmlEntities(s)
|
|
|
|
{
|
|
|
|
var result = '';
|
|
|
|
for (var i = 0; i < s.length; i++) {
|
|
|
|
var c = s.charAt(i);
|
|
|
|
result += {'<':'<', '>':'>', '&':'&', '"':'"'}[c] || c;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function initAndRunTests()
|
|
|
|
{
|
|
|
|
var source = '<p>Lorem ipsum</p>';
|
|
|
|
var expect = new RegExp('<html>.*charset=utf-8.*' + source + '.*</html>', 'im');
|
|
|
|
|
|
|
|
var result = copyToClipboard(source);
|
|
|
|
ok(result, "copied HTML data to system pasteboard");
|
|
|
|
|
|
|
|
result = readFromClipboard();
|
|
|
|
ok(expect.test(result), "data on system pasteboard is wrapped with charset metadata");
|
|
|
|
|
|
|
|
$("display").innerHTML =
|
|
|
|
'<em>source:</em> <pre>' + encodeHtmlEntities(source) + '</pre><br/>' +
|
|
|
|
'<em>result:</em> <pre>' + encodeHtmlEntities(result) + '</pre>';
|
|
|
|
}
|
|
|
|
|
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
</window>
|