diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /editor/libeditor/tests/test_pasteImgFromTransferable.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'editor/libeditor/tests/test_pasteImgFromTransferable.html')
-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> |