1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug166235.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,152 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=166235 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=816298 1.9 +--> 1.10 +<head> 1.11 + <title>Test for Bug 166235</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=166235">Mozilla Bug 166235 and Bug 816298</a> 1.17 +<p id="test0">This text should be copied.</p> 1.18 +<p id="test1">This text should<span style="-moz-user-select: none;"> NOT</span> be copied.</p> 1.19 +<p id="test2">This<span style="-moz-user-select: none;"><span style="-moz-user-select: text"> text should</span> NOT</span> be copied.</p> 1.20 +<p id="test3">This text should<span style="-moz-user-select: -moz-none;"> NOT</span> be copied.</p> 1.21 +<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> 1.22 +<p id="test5">This<span style="-moz-user-select: all"> text<span style="-moz-user-select: none"> should</span></span> be copied.</p> 1.23 +<div id="content" style="display: none"> 1.24 + 1.25 +</div> 1.26 +<textarea id="input"></textarea> 1.27 +<pre id="test"> 1.28 +<script type="application/javascript"> 1.29 + "use strict"; 1.30 + 1.31 +/** Test for Bug 166235 **/ 1.32 + var Cc = SpecialPowers.Cc; 1.33 + var Ci = SpecialPowers.Ci; 1.34 + 1.35 + var webnav = SpecialPowers.wrap(window).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) 1.36 + .getInterface(SpecialPowers.Ci.nsIWebNavigation) 1.37 + 1.38 + var docShell = webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell); 1.39 + 1.40 + var documentViewer = docShell.contentViewer 1.41 + .QueryInterface(SpecialPowers.Ci.nsIContentViewerEdit); 1.42 + 1.43 + var clipboard = Cc["@mozilla.org/widget/clipboard;1"] 1.44 + .getService(SpecialPowers.Ci.nsIClipboard); 1.45 + 1.46 + var textarea = SpecialPowers.wrap(document.getElementById('input')); 1.47 + 1.48 + function getLoadContext() { 1.49 + return SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor) 1.50 + .getInterface(Ci.nsIWebNavigation) 1.51 + .QueryInterface(Ci.nsILoadContext); 1.52 + } 1.53 + 1.54 + function copyChildrenToClipboard(id) { 1.55 + textarea.blur(); 1.56 + clipboard.emptyClipboard(1); 1.57 + window.getSelection().selectAllChildren(document.getElementById(id)); 1.58 + documentViewer.copySelection(); 1.59 + 1.60 + is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), true); 1.61 + is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true); 1.62 + } 1.63 + function getClipboardData(mime) { 1.64 + var transferable = Cc['@mozilla.org/widget/transferable;1'] 1.65 + .createInstance(SpecialPowers.Ci.nsITransferable); 1.66 + transferable.init(getLoadContext()); 1.67 + transferable.addDataFlavor(mime); 1.68 + clipboard.getData(transferable, 1); 1.69 + var data = SpecialPowers.createBlankObject(); 1.70 + transferable.getTransferData(mime, data, {}) ; 1.71 + return SpecialPowers.wrap(data); 1.72 + } 1.73 + function testClipboardValue(mime, expected, test) { 1.74 + var data = getClipboardData(mime); 1.75 + is (data.value == null ? data.value : 1.76 + data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data, 1.77 + expected, 1.78 + mime + " value in the clipboard"); 1.79 + return data.value; 1.80 + } 1.81 + function testPasteText(expected, test) { 1.82 + textarea.value=""; 1.83 + textarea.focus(); 1.84 + textarea.editor.paste(1); 1.85 + is(textarea.value, expected, test + ": textarea paste"); 1.86 + } 1.87 + function testInnerHTML(id, expected) { 1.88 + var value = document.getElementById(id).innerHTML; 1.89 + is(value, expected, id + ".innerHTML"); 1.90 + } 1.91 + 1.92 +// expected results for Selection.toString() 1.93 +var originalStrings = [ 1.94 + 'This text should be copied.', 1.95 + 'This text should be copied.', 1.96 + 'This text should be copied.', 1.97 + 'This text should be copied.', 1.98 + 'This text should be copied.', 1.99 + 'This text should be copied.' 1.100 +]; 1.101 + 1.102 +// expected results for clipboard text/html 1.103 +var clipboardHTML = [ 1.104 + '<p id=\"test0\">This text should be copied.</p>', 1.105 + '<p id=\"test1\">This text should be copied.</p>', 1.106 + '<p id=\"test2\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>', 1.107 + '<p id=\"test3\">This text should be copied.</p>', 1.108 + '<p id=\"test4\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>', 1.109 + '<p id=\"test5\">This<span style=\"-moz-user-select: all\"> text<span style=\"-moz-user-select: none\"> should</span></span> be copied.</p>', 1.110 +]; 1.111 + 1.112 +// expected results for clipboard text/unicode 1.113 +var clipboardUnicode = [ 1.114 + 'This text should be copied.', 1.115 + 'This text should be copied.', 1.116 + 'This text should be copied.', 1.117 + 'This text should be copied.', 1.118 + 'This text should be copied.', 1.119 + 'This text should be copied.' 1.120 +]; 1.121 + 1.122 +// expected results for .innerHTML 1.123 +var innerHTMLStrings = [ 1.124 + 'This text should be copied.', 1.125 + 'This text should<span style=\"-moz-user-select: none;\"> NOT</span> be copied.', 1.126 + 'This<span style=\"-moz-user-select: none;\"><span style=\"-moz-user-select: text\"> text should</span> NOT</span> be copied.', 1.127 + 'This text should<span style=\"-moz-user-select: -moz-none;\"> NOT</span> be copied.', 1.128 + 'This<span style=\"-moz-user-select: -moz-none;\"><span style=\"-moz-user-select: text\"> text should</span> NOT</span> be copied.', 1.129 + 'This<span style=\"-moz-user-select: all\"> text<span style=\"-moz-user-select: none\"> should</span></span> be copied.', 1.130 +]; 1.131 + 1.132 +// expected results for pasting into a TEXTAREA 1.133 +var textareaStrings = [ 1.134 + 'This text should be copied.', 1.135 + 'This text should be copied.', 1.136 + 'This text should be copied.', 1.137 + 'This text should be copied.', 1.138 + 'This text should be copied.', 1.139 + 'This text should be copied.' 1.140 +]; 1.141 + 1.142 +for (var i = 0; i < originalStrings.length; i++) { 1.143 + var id = 'test' + i; 1.144 + copyChildrenToClipboard(id); 1.145 + is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()'); 1.146 + testClipboardValue("text/html", clipboardHTML[i], id); 1.147 + testClipboardValue("text/unicode", clipboardUnicode[i], id); 1.148 + testInnerHTML(id, innerHTMLStrings[i]); 1.149 + testPasteText(textareaStrings[i], id + '.innerHTML'); 1.150 +} 1.151 + 1.152 +</script> 1.153 +</pre> 1.154 +</body> 1.155 +</html>