|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
|
4 <!-- |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=948065 |
|
6 --> |
|
7 <window title="Mozilla Bug 948065" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
9 onload="initAndRunTests()"> |
|
10 <script type="application/javascript" |
|
11 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
12 |
|
13 <!-- test results are displayed in the html:body --> |
|
14 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
15 <p id="display"></p> |
|
16 <div id="content" style="display: none"></div> |
|
17 <pre id="test"></pre> |
|
18 </body> |
|
19 |
|
20 <!-- test code goes here --> |
|
21 <script class="testbody" type="application/javascript"> |
|
22 <![CDATA[ |
|
23 |
|
24 /** Test for Bug 948065 **/ |
|
25 |
|
26 const Cc = Components.classes; |
|
27 const Ci = Components.interfaces; |
|
28 |
|
29 const kIsMac = navigator.platform.indexOf("Mac") == 0; |
|
30 |
|
31 function getLoadContext() { |
|
32 return window.QueryInterface(Ci.nsIInterfaceRequestor) |
|
33 .getInterface(Ci.nsIWebNavigation) |
|
34 .QueryInterface(Ci.nsILoadContext); |
|
35 } |
|
36 |
|
37 // Get clipboard data to paste. |
|
38 function paste(clipboard) { |
|
39 let trans = Cc['@mozilla.org/widget/transferable;1'] |
|
40 .createInstance(Ci.nsITransferable); |
|
41 trans.init(getLoadContext()); |
|
42 trans.addDataFlavor("text/unicode"); |
|
43 clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard); |
|
44 let str = {}; |
|
45 let length = {}; |
|
46 try { |
|
47 trans.getTransferData('text/unicode', str, length); |
|
48 } catch (e) { |
|
49 str = ''; |
|
50 } |
|
51 if (str) { |
|
52 str = str.value.QueryInterface(Ci.nsISupportsString); |
|
53 if (str) { |
|
54 str = str.data.substring(0, length.value / 2); |
|
55 } |
|
56 } |
|
57 return str; |
|
58 } |
|
59 |
|
60 function initAndRunTests() { |
|
61 let clipboard = Cc['@mozilla.org/widget/clipboard;1'] |
|
62 .getService(Ci.nsIClipboard); |
|
63 |
|
64 // Test copy. |
|
65 const data = "random number: " + Math.random(); |
|
66 let helper = Cc['@mozilla.org/widget/clipboardhelper;1'] |
|
67 .getService(Ci.nsIClipboardHelper); |
|
68 helper.copyString(data, document); |
|
69 is(paste(clipboard), data, 'Data was successfully copied.'); |
|
70 |
|
71 // Test emptyClipboard, disabled for OSX because bug 666254 |
|
72 if (!kIsMac) { |
|
73 clipboard.emptyClipboard(Ci.nsIClipboard.kGlobalClipboard); |
|
74 is(paste(clipboard), '', 'Data was successfully cleared.'); |
|
75 } |
|
76 } |
|
77 |
|
78 ]]> |
|
79 </script> |
|
80 </window> |