widget/tests/test_clipboard.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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"/>
    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>
    20   <!-- test code goes here -->
    21   <script class="testbody" type="application/javascript">
    22   <![CDATA[
    24   /** Test for Bug 948065 **/
    26   const Cc = Components.classes;
    27   const Ci = Components.interfaces;
    29   const kIsMac = navigator.platform.indexOf("Mac") == 0;
    31   function getLoadContext() {
    32     return window.QueryInterface(Ci.nsIInterfaceRequestor)
    33                  .getInterface(Ci.nsIWebNavigation)
    34                  .QueryInterface(Ci.nsILoadContext);
    35   }
    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   }
    60   function initAndRunTests() {
    61     let clipboard = Cc['@mozilla.org/widget/clipboard;1']
    62                     .getService(Ci.nsIClipboard);
    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.');
    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   }
    78   ]]>
    79   </script>
    80 </window>

mercurial