diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /widget/headless/tests/test_headless_clipboard.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/headless/tests/test_headless_clipboard.js')
-rw-r--r-- | widget/headless/tests/test_headless_clipboard.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/widget/headless/tests/test_headless_clipboard.js b/widget/headless/tests/test_headless_clipboard.js new file mode 100644 index 0000000000..24fb6fc50f --- /dev/null +++ b/widget/headless/tests/test_headless_clipboard.js @@ -0,0 +1,45 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +function getString(clipboard) { + var str = ""; + + // Create transferable that will transfer the text. + var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance( + Ci.nsITransferable + ); + trans.init(null); + trans.addDataFlavor("text/unicode"); + + clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard); + + try { + var data = {}; + trans.getTransferData("text/unicode", data); + + if (data) { + data = data.value.QueryInterface(Ci.nsISupportsString); + str = data.data; + } + } catch (ex) { + // If the clipboard is empty getTransferData will throw. + } + + return str; +} + +add_task(async function test_clipboard() { + let clipboard = Services.clipboard; + + // Test copy. + const data = "random number: " + Math.random(); + let helper = Cc["@mozilla.org/widget/clipboardhelper;1"].getService( + Ci.nsIClipboardHelper + ); + helper.copyString(data); + equal(getString(clipboard), data, "Data was successfully copied."); + + clipboard.emptyClipboard(Ci.nsIClipboard.kGlobalClipboard); + equal(getString(clipboard), "", "Data was successfully cleared."); +}); |