Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / tests / test_pasteImgFromTransferable.html
blob2e9e2b5cca9df642b1a964396bfb8faf7afbfca9
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="/tests/SimpleTest/SimpleTest.js"></script>
5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
6 </head>
8 <body>
9 <div id="edit" contenteditable></div>
11 <script>
12 const Cc = SpecialPowers.Cc;
13 const Ci = SpecialPowers.Ci;
15 function getHTMLEditor(aWindow) {
16 let editingSession = SpecialPowers.wrap(aWindow).docShell.editingSession;
17 if (!editingSession) {
18 return null;
20 let editor = editingSession.getEditorForWindow(aWindow);
21 if (!editor) {
22 return null;
24 return editor.QueryInterface(Ci.nsIHTMLEditor);
27 const TESTS = [
29 mimeType: "image/gif",
30 base64: "R0lGODdhAQACAPABAAD/AP///ywAAAAAAQACAAACAkQKADs="
33 mimeType: "image/jpeg",
34 base64: "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxA="
37 mimeType: "image/png",
38 base64: "iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAIAAABvrngfAAAAFklEQVQImWMwjWhCQwxECoW3oCHihAB0LyYv5/oAHwAAAABJRU5ErkJggg=="
42 add_task(async function() {
43 await new Promise(resolve => SimpleTest.waitForFocus(resolve, window));
45 let edit = document.getElementById("edit");
46 edit.focus();
48 await new Promise(resolve => SimpleTest.executeSoon(resolve));
50 for (const test of TESTS) {
51 let bin = window.atob(test.base64);
52 let stringStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
53 Ci.nsIStringInputStream
55 stringStream.setData(bin, bin.length);
57 let trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(
58 Ci.nsITransferable
60 trans.init(null);
61 trans.setTransferData(test.mimeType, stringStream);
63 getHTMLEditor(window).pasteTransferable(trans);
65 is(edit.innerHTML,
66 "<img src=\"data:" + test.mimeType + ";base64," + test.base64 + "\" alt=\"\">",
67 "pastedTransferable pastes image as data URL");
68 edit.innerHTML = "";
70 });
71 </script>
72 </body>
73 </html>