function copyImage(aImageId) {
// selection of the node var node = document.getElementById(aImageId); var docShell = SpecialPowers.wrap(window).docShell;
// let's copy the node var documentViewer = docShell.docViewer
.QueryInterface(SpecialPowers.Ci.nsIDocumentViewerEdit);
documentViewer.setCommandNode(node);
documentViewer.copyImage(documentViewer.COPY_IMAGE_ALL);
}
async function doTest(imageAsFileEnabled) {
await SpecialPowers.pushPrefEnv({
set: [["clipboard.imageAsFile.enabled", imageAsFileEnabled]],
});
copyImage('image');
//--------- now check the content of the clipboard var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"]
.getService(SpecialPowers.Ci.nsIClipboard);
// 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");
async function onPaste(e, imageAsFileEnabled) { var imageTester = new ImageTester;
testFiles(e, imageTester, imageAsFileEnabled);
testItems(e, imageTester);
await imageTester.test();
}
function testItems(e, imageTester) { var items = e.clipboardData.items;
is(items, e.clipboardData.items, "Getting @items twice should return the same object"); var haveFiles = false;
ok(items instanceof DataTransferItemList, "@items implements DataTransferItemList");
ok(items.length, "@items is not empty");
for (var i = 0; i < items.length; i++) { var item = items[i];
ok(item instanceof DataTransferItem, "each element of @items must implement DataTransferItem");
if (item.kind == "file") { var file = item.getAsFile();
ok(file instanceof File, ".getAsFile() returns a File object");
ok(file.size > 0, "Files shouldn't have size 0");
imageTester.add(file);
}
}
}
function testFiles(e, imageTester, imageAsFileEnabled) { var files = e.clipboardData.files;
is(files, e.clipboardData.files, "Getting the files array twice should return the same array");
is(files.length, 1, "There should be one file in the clipboard");
for (var i = 0; i < files.length; i++) { var file = files[i];
ok(file instanceof File, ".files should contain only File objects");
ok(file.size > 0, "This file shouldn't have size 0");
if (navigator.platform.includes("Win") && imageAsFileEnabled) {
ok(file.name.startsWith("Untitled") && file.name.endsWith(".png"),
`Check filename, got "${file.name}"`);
} else {
is(file.name, "image.png", "Check filename");
}
testSlice(file);
imageTester.add(file);
// Adding the same image again so we can test concurrency
imageTester.add(file);
}
}
function testSlice(aFile) { var blob = aFile.slice();
ok(blob instanceof Blob, ".slice returns a blob");
is(blob.size, aFile.size, "the blob has the same size");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.