Files
sousa-gecko/editor/libeditor/tests/test_pasteImgFromTransferable.html
T
Nika Layzell e45c9840d1 Bug 1935714 - Part 1: Improve handling of large nsStringStream streams at the API level, r=mccr8,webdriver-reviewers,necko-reviewers,valentin,extension-reviewers,devtools-reviewers,robwu,ochameau
This changes how the `nsIStringInputStream` interface is initialized in
C++ code to make it support larger stream sizes better. This involved
moving away from using nsCString in some cases, as it has a maximum
string length of approximately 2GiB.

This also required changing the signature of one of the methods making
it no longer JS-compatible. As the `setData` method was awkward to use
from JS anyway, the method was split into two (one for C++ callers, and
one for JS callers), and renamed. This required changes to the various
JS callers.

Differential Revision: https://phabricator.services.mozilla.com/D231982
2024-12-16 20:21:58 +00:00

79 lines
2.1 KiB
HTML

<!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.setByteStringData(bin);
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>