summaryrefslogtreecommitdiffstats
path: root/dom/events/test/clipboard
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:35:49 +0000
commitd8bbc7858622b6d9c278469aab701ca0b609cddf (patch)
treeeff41dc61d9f714852212739e6b3738b82a2af87 /dom/events/test/clipboard
parentReleasing progress-linux version 125.0.3-1~progress7.99u1. (diff)
downloadfirefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz
firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/events/test/clipboard')
-rw-r--r--dom/events/test/clipboard/mochitest.toml7
-rw-r--r--dom/events/test/clipboard/test_async_clipboard.xhtml10
-rw-r--r--dom/events/test/clipboard/test_async_clipboard_datatransfer.html89
3 files changed, 97 insertions, 9 deletions
diff --git a/dom/events/test/clipboard/mochitest.toml b/dom/events/test/clipboard/mochitest.toml
index 7829915267..98cbd3ddb5 100644
--- a/dom/events/test/clipboard/mochitest.toml
+++ b/dom/events/test/clipboard/mochitest.toml
@@ -1,5 +1,12 @@
[DEFAULT]
+["test_async_clipboard_datatransfer.html"]
+scheme = "https"
+skip-if = [
+ "headless", # headless doesn't support custom type
+ "os == 'android'", # android doesn't support custom type
+]
+
["test_paste_image.html"]
skip-if = [
"headless", # Bug 1405869
diff --git a/dom/events/test/clipboard/test_async_clipboard.xhtml b/dom/events/test/clipboard/test_async_clipboard.xhtml
index ec54809077..8a882fd24d 100644
--- a/dom/events/test/clipboard/test_async_clipboard.xhtml
+++ b/dom/events/test/clipboard/test_async_clipboard.xhtml
@@ -74,15 +74,7 @@
});
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");
- }
+ ok(!items.length, "read() read the right thing from empty clipboard");
}
async function testNoContentsReadText() {
diff --git a/dom/events/test/clipboard/test_async_clipboard_datatransfer.html b/dom/events/test/clipboard/test_async_clipboard_datatransfer.html
new file mode 100644
index 0000000000..ab4151f4f5
--- /dev/null
+++ b/dom/events/test/clipboard/test_async_clipboard_datatransfer.html
@@ -0,0 +1,89 @@
+<html>
+<head>
+<title>Test for bug 1756955</title>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css">
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="/tests/SimpleTest/EventUtils.js"></script>
+<script>
+
+const kIsMac = navigator.platform.indexOf("Mac") > -1;
+
+async function copyByDataTransfer(aItems) {
+ const copyPromise = new Promise(resolve => {
+ document.addEventListener("copy", (e) => {
+ e.preventDefault();
+ for (const [key, value] of Object.entries(aItems)) {
+ e.clipboardData.setData(key, value);
+ }
+ resolve();
+ }, { once: true });
+ });
+ synthesizeKey(
+ "c",
+ kIsMac ? { accelKey: true } : { ctrlKey: true }
+ );
+ await copyPromise;
+}
+
+async function paste(aCallback) {
+ const pastePromise = new Promise(resolve => {
+ document.addEventListener("paste", (e) => {
+ resolve(aCallback(e.clipboardData));
+ }, { once: true });
+ });
+ synthesizeKey(
+ "v",
+ kIsMac ? { accelKey: true } : { ctrlKey: true }
+ );
+ await pastePromise;
+}
+
+add_setup(async function () {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["dom.events.asyncClipboard.readText", true],
+ ["dom.events.asyncClipboard.clipboardItem", true],
+ ],
+ });
+});
+
+add_task(async function test_mandatory_type() {
+ const items = {
+ "text/plain": "X" + Math.random(),
+ "custom/foo": "X" + Math.random(),
+ };
+ await copyByDataTransfer(items);
+ await paste(async (clipboardData) => {
+ for (const [key, value] of Object.entries(items)) {
+ is(clipboardData.getData(key), value, `Check ${key} type`);
+ }
+
+ let clipboardItems = await navigator.clipboard.read();
+ is(clipboardItems.length, 1, "Should only one clipboardItem");
+ is(clipboardItems[0].types.length, 1, "Should only one type");
+ is(await clipboardItems[0].getType("text/plain").then(blob => blob.text()),
+ items["text/plain"],
+ "Check text/plain type in clipbordItem");
+ });
+});
+
+add_task(async function test_no_mandatory_type() {
+ const items = {
+ "custom/foo": "X" + Math.random(),
+ };
+ await copyByDataTransfer(items);
+ await paste(async (clipboardData) => {
+ for (const [key, value] of Object.entries(items)) {
+ is(clipboardData.getData(key), value, `Check ${key} type`);
+ }
+
+ let clipboardItems = await navigator.clipboard.read();
+ is(clipboardItems.length, 0, "Should only have no clipboardItem");
+ });
+});
+
+</script>
+</head>
+<body>
+</body>
+</html>