summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_copyimage.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 /dom/base/test/test_copyimage.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 'dom/base/test/test_copyimage.html')
-rw-r--r--dom/base/test/test_copyimage.html87
1 files changed, 87 insertions, 0 deletions
diff --git a/dom/base/test/test_copyimage.html b/dom/base/test/test_copyimage.html
new file mode 100644
index 0000000000..2bb384f8f2
--- /dev/null
+++ b/dom/base/test/test_copyimage.html
@@ -0,0 +1,87 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=518249
+https://bugzilla.mozilla.org/show_bug.cgi?id=952456
+-->
+<head>
+ <title>Test for copy image</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=518249">Mozilla Bug 518249</a>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=952456">Mozilla Bug 952456</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+function testCopyImage () {
+ var Ci = SpecialPowers.Ci;
+ var Cc = SpecialPowers.Cc;
+ var clipboard = SpecialPowers.Services.clipboard;
+
+ function getClipboardData(mime) {
+ var transferable = Cc['@mozilla.org/widget/transferable;1']
+ .createInstance(Ci.nsITransferable);
+ var loadingContext = SpecialPowers.wrap(window).docShell
+ .QueryInterface(Ci.nsILoadContext);
+ transferable.init(loadingContext);
+ transferable.addDataFlavor(mime);
+ clipboard.getData(transferable, 1, SpecialPowers.wrap(window).browsingContext.currentWindowContext);
+ var data = SpecialPowers.createBlankObject();
+ transferable.getTransferData(mime, data);
+ return data;
+ }
+
+ function testClipboardValue(mime, expected) {
+ var data = SpecialPowers.wrap(getClipboardData(mime));
+ var str = data.value == null ? data.value :
+ data.value.QueryInterface(Ci.nsISupportsString).data;
+ is(str, expected, "clipboard has correct [" + mime + "] content")
+ }
+
+ //--------- Prepare data and copy it.
+
+ // Select the node.
+ var node = document.getElementById('logo');
+
+ // Set node and copy image.
+ var docShell = SpecialPowers.wrap(window).docShell;
+ var documentViewer = docShell.docViewer
+ .QueryInterface(Ci.nsIDocumentViewerEdit);
+ documentViewer.setCommandNode(node);
+ documentViewer.copyImage(documentViewer.COPY_IMAGE_ALL);
+
+ //--------- Let's check the content of the clipboard now.
+
+ // Does the clipboard contain text/plain data ?
+ ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard), "clipboard contains unicode text");
+ // Does the clipboard contain text/html data ?
+ ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), "clipboard contains html text");
+ // Does the clipboard contain image data ?
+ ok(clipboard.hasDataMatchingFlavors(["image/png"], clipboard.kGlobalClipboard), "clipboard contains image");
+
+ // Is the text/plain data correct ?
+ testClipboardValue('text/plain', 'about:logo');
+ // Is the text/html data correct ?
+ var expected = '<img id="logo" src="about:logo">';
+ if (navigator.platform.includes("Win")) {
+ expected = kTextHtmlPrefixClipboardDataWindows + expected + kTextHtmlSuffixClipboardDataWindows;
+ }
+ testClipboardValue('text/html', expected);
+
+ SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+addLoadEvent(testCopyImage);
+</script>
+</pre>
+<div>
+ <img id="logo" src="about:logo">
+</div>
+</body>
+</html>