gecko-dev/content/base/test/test_bug166235.html

61 строка
2.0 KiB
HTML
Исходник Обычный вид История

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=166235
-->
<head>
<title>Test for Bug 166235</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<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>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 166235 **/
2010-05-21 20:26:33 +04:00
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const de = Components.interfaces.nsIDocumentEncoder;
var encoder = Components.classes["@mozilla.org/layout/htmlCopyEncoder;1"].createInstance(Components.interfaces.nsIDocumentEncoder);
var selection = window.getSelection();
2010-05-21 20:26:33 +04:00
// expected results for selection.toString()
var originalStrings = [
'This text should be copied.',
2010-05-21 20:26:33 +04:00
'This text should NOT be copied.',
'This text should NOT be copied.',
];
2010-05-21 20:26:33 +04:00
// expected results when selection is copied and HTML tags removed
var copiedStrings = [
'This text should be copied.',
'This text should be copied.',
'This text should be copied.'
];
for (var i = 0; i < 3; i++) {
2010-05-21 20:26:33 +04:00
var test = document.getElementById('test' + i);
selection.removeAllRanges();
selection.selectAllChildren(test);
is(selection.toString(), originalStrings [i], 'test ' + i + 'a');
selection.removeAllRanges();
selection.selectAllChildren(test);
encoder.init(document, "text/html", null);
encoder.setSelection(selection);
is(encoder.encodeToString().replace(/<[^>]*>/g, '').replace (/[\r\n]/g, ''), copiedStrings [i], 'test ' + i + 'b');
}
</script>
</pre>
</body>
</html>