diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/events/test/clipboard/test_async_clipboard.xhtml | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/events/test/clipboard/test_async_clipboard.xhtml')
-rw-r--r-- | dom/events/test/clipboard/test_async_clipboard.xhtml | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/dom/events/test/clipboard/test_async_clipboard.xhtml b/dom/events/test/clipboard/test_async_clipboard.xhtml new file mode 100644 index 0000000000..787821efc3 --- /dev/null +++ b/dom/events/test/clipboard/test_async_clipboard.xhtml @@ -0,0 +1,130 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> + +<window title="Async clipboard APIs Test" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + onload="runTest();"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + +<script class="testbody" type="application/javascript"> +<![CDATA[ + + SimpleTest.waitForExplicitFinish(); + + const Services = SpecialPowers.Services; + const { AppConstants } = SpecialPowers.ChromeUtils.import( + "resource://gre/modules/AppConstants.jsm" + ); + const { PlacesUtils } = SpecialPowers.ChromeUtils.import( + "resource://gre/modules/PlacesUtils.jsm" + ); + + const kTextPlainMimeType = "text/plain"; + + function clearClipboard() { + Services.clipboard.emptyClipboard(Services.clipboard.kGlobalClipboard); + } + + async function testRead() { + let expected = "x"; + await SimpleTest.promiseClipboardChange(expected, () => { + SpecialPowers.clipboardCopyString(expected); + }, kTextPlainMimeType); + let items = await navigator.clipboard.read(); + is(items.length, 1, "read() read exactly one item"); + const actual = await items[0].getType(kTextPlainMimeType).then(blob => blob.text()); + is(actual, expected, "read() read the right thing"); + } + + async function testWrite() { + await SimpleTest.promiseClipboardChange("", () => { + clearClipboard(); + }); + + let expected = "x"; + // eslint-disable-next-line no-undef + let item = new ClipboardItem({[kTextPlainMimeType]: expected}); + await navigator.clipboard.write([item]); + let actual = SpecialPowers.getClipboardData(kTextPlainMimeType); + is(actual, expected, "write() wrote the right thing"); + } + + async function testReadText() { + let expected = "x"; + await SimpleTest.promiseClipboardChange(expected, () => { + SpecialPowers.clipboardCopyString(expected); + }, kTextPlainMimeType); + let actual = await navigator.clipboard.readText(); + is(actual, expected, "readText() read the right thing"); + } + + async function testWriteText() { + await SimpleTest.promiseClipboardChange("", () => { + clearClipboard(); + }); + + let expected = "x"; + await navigator.clipboard.writeText(expected); + let actual = SpecialPowers.getClipboardData(kTextPlainMimeType); + is(actual, expected, "writeText() wrote the right thing"); + } + + async function testNoContentsRead() { + await SimpleTest.promiseClipboardChange("", () => { + clearClipboard(); + }); + + const items = await navigator.clipboard.read(); + + // Bug 1756955: at least on Ubuntu 20.04, clearing the clipboard leads to + // one item with no types. + if (!items.length || + (items.length == 1 && !items[0].types.length)) { + ok(true, "read() read the right thing from empty clipboard"); + } else { + ok(false, "read() read the wrong thing from empty clipboard"); + } + } + + async function testNoContentsReadText() { + await SimpleTest.promiseClipboardChange("", () => { + clearClipboard(); + }); + let actual = await navigator.clipboard.readText(); + is(actual, "", "readText() read the right thing from empty clipboard"); + } + + function runTest() { + (async function() { + await SpecialPowers.pushPrefEnv({"set": [ + ["dom.events.asyncClipboard.clipboardItem", true], + ]}); + await testRead(); + await testReadText(); + await testWrite(); + await testWriteText(); + + await testNoContentsRead(); + await testNoContentsReadText(); + + SimpleTest.finish(); + })(); + } + ]]> +</script> + +<body xmlns="http://www.w3.org/1999/xhtml"> +<p id="display"> +</p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +</pre> +</body> + +</window> |