Bug 948065 - Mochitest for nsIClipboard. r=ehsan
authorJan Jongboom <janjongboom@gmail.com>
Wed, 05 Mar 2014 14:18:37 -0500
changeset 189288 b8e76bcb90879cd2ed69c8bab74afeda24f0829d
parent 189287 b9f4ce275fddf8a302dc2aa1a55bebcd7dcc0e21
child 189289 23bebfef70a2ca7ec9db6e60df7152b280670865
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs948065
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 948065 - Mochitest for nsIClipboard. r=ehsan
widget/tests/chrome.ini
widget/tests/test_clipboard.xul
--- a/widget/tests/chrome.ini
+++ b/widget/tests/chrome.ini
@@ -21,16 +21,17 @@ support-files = window_wheeltransaction.
 support-files = window_imestate_iframes.html
 [test_plugin_scroll_consistency.html]
 [test_composition_text_querycontent.xul]
 support-files = window_composition_text_querycontent.xul
 [test_input_events_on_deactive_window.xul]
 [test_position_on_resize.xul]
 [test_sizemode_events.xul]
 [test_bug760802.xul]
+[test_clipboard.xul]
 
 # Cocoa
 [test_native_menus.xul]
 skip-if = toolkit != "cocoa"
 support-files = native_menus_window.xul
 [test_native_mouse_mac.xul]
 skip-if = toolkit != "cocoa"
 support-files = native_mouse_mac_window.xul
new file mode 100644
--- /dev/null
+++ b/widget/tests/test_clipboard.xul
@@ -0,0 +1,80 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=948065
+-->
+<window title="Mozilla Bug 948065"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        onload="initAndRunTests()">
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+    <p id="display"></p>
+    <div id="content" style="display: none"></div>
+    <pre id="test"></pre>
+  </body>
+
+  <!-- test code goes here -->
+  <script class="testbody" type="application/javascript">
+  <![CDATA[
+
+  /** Test for Bug 948065 **/
+
+  const Cc = Components.classes;
+  const Ci = Components.interfaces;
+
+  const kIsMac = navigator.platform.indexOf("Mac") == 0;
+
+  function getLoadContext() {
+    return window.QueryInterface(Ci.nsIInterfaceRequestor)
+                 .getInterface(Ci.nsIWebNavigation)
+                 .QueryInterface(Ci.nsILoadContext);
+  }
+
+  // Get clipboard data to paste.
+  function paste(clipboard) {
+    let trans = Cc['@mozilla.org/widget/transferable;1']
+                .createInstance(Ci.nsITransferable);
+    trans.init(getLoadContext());
+    trans.addDataFlavor("text/unicode");
+    clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
+    let str = {};
+    let length = {};
+    try {
+      trans.getTransferData('text/unicode', str, length);
+    } catch (e) {
+      str = '';
+    }
+    if (str) {
+      str = str.value.QueryInterface(Ci.nsISupportsString);
+      if (str) {
+        str = str.data.substring(0, length.value / 2);
+      }
+    }
+    return str;
+  }
+
+  function initAndRunTests() {
+    let clipboard = Cc['@mozilla.org/widget/clipboard;1']
+                    .getService(Ci.nsIClipboard);
+
+    // Test copy.
+    const data = "random number: " + Math.random();
+    let helper = Cc['@mozilla.org/widget/clipboardhelper;1']
+                 .getService(Ci.nsIClipboardHelper);
+    helper.copyString(data, document);
+    is(paste(clipboard), data, 'Data was successfully copied.');
+
+    // Test emptyClipboard, disabled for OSX because bug 666254
+    if (!kIsMac) {
+      clipboard.emptyClipboard(Ci.nsIClipboard.kGlobalClipboard);
+      is(paste(clipboard), '', 'Data was successfully cleared.');
+    }
+  }
+
+  ]]>
+  </script>
+</window>