widget/tests/test_clipboard.xul

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial