|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=166235 |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=816298 |
|
6 --> |
|
7 <head> |
|
8 <title>Test for Bug 166235</title> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=166235">Mozilla Bug 166235 and Bug 816298</a> |
|
14 <p id="test0">This text should be copied.</p> |
|
15 <p id="test1">This text should<span style="-moz-user-select: none;"> NOT</span> be copied.</p> |
|
16 <p id="test2">This<span style="-moz-user-select: none;"><span style="-moz-user-select: text"> text should</span> NOT</span> be copied.</p> |
|
17 <p id="test3">This text should<span style="-moz-user-select: -moz-none;"> NOT</span> be copied.</p> |
|
18 <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> |
|
19 <p id="test5">This<span style="-moz-user-select: all"> text<span style="-moz-user-select: none"> should</span></span> be copied.</p> |
|
20 <div id="content" style="display: none"> |
|
21 |
|
22 </div> |
|
23 <textarea id="input"></textarea> |
|
24 <pre id="test"> |
|
25 <script type="application/javascript"> |
|
26 "use strict"; |
|
27 |
|
28 /** Test for Bug 166235 **/ |
|
29 var Cc = SpecialPowers.Cc; |
|
30 var Ci = SpecialPowers.Ci; |
|
31 |
|
32 var webnav = SpecialPowers.wrap(window).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) |
|
33 .getInterface(SpecialPowers.Ci.nsIWebNavigation) |
|
34 |
|
35 var docShell = webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell); |
|
36 |
|
37 var documentViewer = docShell.contentViewer |
|
38 .QueryInterface(SpecialPowers.Ci.nsIContentViewerEdit); |
|
39 |
|
40 var clipboard = Cc["@mozilla.org/widget/clipboard;1"] |
|
41 .getService(SpecialPowers.Ci.nsIClipboard); |
|
42 |
|
43 var textarea = SpecialPowers.wrap(document.getElementById('input')); |
|
44 |
|
45 function getLoadContext() { |
|
46 return SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor) |
|
47 .getInterface(Ci.nsIWebNavigation) |
|
48 .QueryInterface(Ci.nsILoadContext); |
|
49 } |
|
50 |
|
51 function copyChildrenToClipboard(id) { |
|
52 textarea.blur(); |
|
53 clipboard.emptyClipboard(1); |
|
54 window.getSelection().selectAllChildren(document.getElementById(id)); |
|
55 documentViewer.copySelection(); |
|
56 |
|
57 is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), true); |
|
58 is(clipboard.hasDataMatchingFlavors(["text/html"], 1,1), true); |
|
59 } |
|
60 function getClipboardData(mime) { |
|
61 var transferable = Cc['@mozilla.org/widget/transferable;1'] |
|
62 .createInstance(SpecialPowers.Ci.nsITransferable); |
|
63 transferable.init(getLoadContext()); |
|
64 transferable.addDataFlavor(mime); |
|
65 clipboard.getData(transferable, 1); |
|
66 var data = SpecialPowers.createBlankObject(); |
|
67 transferable.getTransferData(mime, data, {}) ; |
|
68 return SpecialPowers.wrap(data); |
|
69 } |
|
70 function testClipboardValue(mime, expected, test) { |
|
71 var data = getClipboardData(mime); |
|
72 is (data.value == null ? data.value : |
|
73 data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data, |
|
74 expected, |
|
75 mime + " value in the clipboard"); |
|
76 return data.value; |
|
77 } |
|
78 function testPasteText(expected, test) { |
|
79 textarea.value=""; |
|
80 textarea.focus(); |
|
81 textarea.editor.paste(1); |
|
82 is(textarea.value, expected, test + ": textarea paste"); |
|
83 } |
|
84 function testInnerHTML(id, expected) { |
|
85 var value = document.getElementById(id).innerHTML; |
|
86 is(value, expected, id + ".innerHTML"); |
|
87 } |
|
88 |
|
89 // expected results for Selection.toString() |
|
90 var originalStrings = [ |
|
91 'This text should be copied.', |
|
92 'This text should be copied.', |
|
93 'This text should be copied.', |
|
94 'This text should be copied.', |
|
95 'This text should be copied.', |
|
96 'This text should be copied.' |
|
97 ]; |
|
98 |
|
99 // expected results for clipboard text/html |
|
100 var clipboardHTML = [ |
|
101 '<p id=\"test0\">This text should be copied.</p>', |
|
102 '<p id=\"test1\">This text should be copied.</p>', |
|
103 '<p id=\"test2\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>', |
|
104 '<p id=\"test3\">This text should be copied.</p>', |
|
105 '<p id=\"test4\">This<span style=\"-moz-user-select: text\"> text should</span> be copied.</p>', |
|
106 '<p id=\"test5\">This<span style=\"-moz-user-select: all\"> text<span style=\"-moz-user-select: none\"> should</span></span> be copied.</p>', |
|
107 ]; |
|
108 |
|
109 // expected results for clipboard text/unicode |
|
110 var clipboardUnicode = [ |
|
111 'This text should be copied.', |
|
112 'This text should be copied.', |
|
113 'This text should be copied.', |
|
114 'This text should be copied.', |
|
115 'This text should be copied.', |
|
116 'This text should be copied.' |
|
117 ]; |
|
118 |
|
119 // expected results for .innerHTML |
|
120 var innerHTMLStrings = [ |
|
121 'This text should be copied.', |
|
122 'This text should<span style=\"-moz-user-select: none;\"> NOT</span> be copied.', |
|
123 'This<span style=\"-moz-user-select: none;\"><span style=\"-moz-user-select: text\"> text should</span> NOT</span> be copied.', |
|
124 'This text should<span style=\"-moz-user-select: -moz-none;\"> NOT</span> be copied.', |
|
125 'This<span style=\"-moz-user-select: -moz-none;\"><span style=\"-moz-user-select: text\"> text should</span> NOT</span> be copied.', |
|
126 'This<span style=\"-moz-user-select: all\"> text<span style=\"-moz-user-select: none\"> should</span></span> be copied.', |
|
127 ]; |
|
128 |
|
129 // expected results for pasting into a TEXTAREA |
|
130 var textareaStrings = [ |
|
131 'This text should be copied.', |
|
132 'This text should be copied.', |
|
133 'This text should be copied.', |
|
134 'This text should be copied.', |
|
135 'This text should be copied.', |
|
136 'This text should be copied.' |
|
137 ]; |
|
138 |
|
139 for (var i = 0; i < originalStrings.length; i++) { |
|
140 var id = 'test' + i; |
|
141 copyChildrenToClipboard(id); |
|
142 is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()'); |
|
143 testClipboardValue("text/html", clipboardHTML[i], id); |
|
144 testClipboardValue("text/unicode", clipboardUnicode[i], id); |
|
145 testInnerHTML(id, innerHTMLStrings[i]); |
|
146 testPasteText(textareaStrings[i], id + '.innerHTML'); |
|
147 } |
|
148 |
|
149 </script> |
|
150 </pre> |
|
151 </body> |
|
152 </html> |