diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /editor/libeditor/tests/test_pasteImgFromTransferable.html | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | editor/libeditor/tests/test_pasteImgFromTransferable.html | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_pasteImgFromTransferable.html b/editor/libeditor/tests/test_pasteImgFromTransferable.html new file mode 100644 index 0000000000..a45bb5b574 --- /dev/null +++ b/editor/libeditor/tests/test_pasteImgFromTransferable.html @@ -0,0 +1,78 @@ +<!DOCTYPE html> +<html> +<head> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> + +<body> +<div id="edit" contenteditable></div> + +<script> +const Cc = SpecialPowers.Cc; +const Ci = SpecialPowers.Ci; + +function getHTMLEditor(aWindow) { + let editingSession = SpecialPowers.wrap(aWindow).docShell.editingSession; + if (!editingSession) { + return null; + } + let editor = editingSession.getEditorForWindow(aWindow); + if (!editor) { + return null; + } + return editor.QueryInterface(Ci.nsIHTMLEditor); +} + +const TESTS = [ + { + mimeType: "image/gif", + base64: "R0lGODdhAQACAPABAAD/AP///ywAAAAAAQACAAACAkQKADs=" + }, + { + mimeType: "image/jpeg", + base64: "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxA=" + }, + { + mimeType: "image/png", + base64: "iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAIAAABvrngfAAAAFklEQVQImWMwjWhCQwxECoW3oCHihAB0LyYv5/oAHwAAAABJRU5ErkJggg==" + }, +]; + +add_task(async function() { + await new Promise(resolve => SimpleTest.waitForFocus(resolve, window)); + + let edit = document.getElementById("edit"); + edit.focus(); + + await new Promise(resolve => SimpleTest.executeSoon(resolve)); + + for (const test of TESTS) { + let bin = window.atob(test.base64); + let stringStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance( + Ci.nsIStringInputStream + ); + stringStream.setData(bin, bin.length); + + let trans = Cc["@mozilla.org/widget/transferable;1"].createInstance( + Ci.nsITransferable + ); + trans.init(null); + trans.setTransferData(test.mimeType, stringStream); + + let evt = new Promise(resolve => + edit.addEventListener("input", resolve, {once: true})); + + getHTMLEditor(window).pasteTransferable(trans); + + await evt; + + is(edit.innerHTML, + "<img src=\"data:" + test.mimeType + ";base64," + test.base64 + "\" alt=\"\">", + "pastedTransferable pastes image as data URL"); + edit.innerHTML = ""; + } +}); +</script> +</body> +</html> |