summaryrefslogtreecommitdiffstats
path: root/widget/tests/test_clipboard_owner_chrome.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /widget/tests/test_clipboard_owner_chrome.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/tests/test_clipboard_owner_chrome.html')
-rw-r--r--widget/tests/test_clipboard_owner_chrome.html75
1 files changed, 75 insertions, 0 deletions
diff --git a/widget/tests/test_clipboard_owner_chrome.html b/widget/tests/test_clipboard_owner_chrome.html
new file mode 100644
index 0000000000..4759b2b14c
--- /dev/null
+++ b/widget/tests/test_clipboard_owner_chrome.html
@@ -0,0 +1,75 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1812078
+-->
+<head>
+<title>Test for Bug 1812078</title>
+<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<script src="clipboard_helper.js"></script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test"></pre>
+<script class="testbody" type="application/javascript">
+
+function testClipboardOwner(aClipboardType, aAsync) {
+ let losingOwnership = false;
+ const clipboardOwner = {
+ QueryInterface: ChromeUtils.generateQI(["nsIClipboardOwner"]),
+ // nsIClipboardOwner
+ LosingOwnership(aTransferable) {
+ losingOwnership = true;
+ },
+ };
+
+ add_task(function test_clipboard_owner() {
+ info(`Test clipboard owner for type ${aClipboardType} ${aAsync ? "async" : ""}`);
+
+ // Setup clipboard owner.
+ writeRandomStringToClipboard("text/plain", aClipboardType, clipboardOwner, aAsync);
+
+ // Test should not lose ownership.
+ clipboardTypes.forEach(function(otherType) {
+ losingOwnership = false;
+ if (aClipboardType != otherType && clipboard.isClipboardTypeSupported(otherType)) {
+ // Test setting clipboard data.
+ writeRandomStringToClipboard("text/plain", otherType);
+ ok(!losingOwnership, `Should not lose ownership while setting data to type ${otherType}`);
+
+ // Test async setting clipboard data.
+ writeRandomStringToClipboard("text/plain", otherType, null, true);
+ ok(!losingOwnership, `Should not lose ownership while async setting data to type ${otherType}`);
+ }
+ });
+
+ // Test whether should lose ownership.
+ losingOwnership = false;
+ writeRandomStringToClipboard("text/plain", aClipboardType, clipboardOwner);
+ ok(losingOwnership, `Should lose ownership while setting data to type ${aClipboardType}`);
+
+ losingOwnership = false;
+ writeRandomStringToClipboard("text/plain", aClipboardType, null, true);
+ ok(losingOwnership, `Should lose ownership while async setting data to type ${aClipboardType}`);
+
+ // Clean clipboard data.
+ cleanupAllClipboard();
+ });
+}
+
+/** Test for Bug 1812078 */
+clipboardTypes.forEach(function(testType) {
+ if (clipboard.isClipboardTypeSupported(testType)) {
+ // Test sync set clipboard data.
+ testClipboardOwner(testType, false);
+
+ // Test async set clipboard data.
+ testClipboardOwner(testType, true);
+ }
+});
+
+</script>
+</body>
+</html>