function getLoadContext() {
return SpecialPowers.wrap(window).docShell
.QueryInterface(Ci.nsILoadContext);
}
function copyChildrenToClipboard(id) { textarea.blur();
clipboard.emptyClipboard(1);
window.getSelection().selectAllChildren(document.getElementById(id));
documentViewer.copySelection();
is(clipboard.hasDataMatchingFlavors(["text/plain"], 1), true);
is(clipboard.hasDataMatchingFlavors(["text/html"], 1), true);
}
function getClipboardData(mime) { var transferable = Cc['@mozilla.org/widget/transferable;1']
.createInstance(SpecialPowers.Ci.nsITransferable);
transferable.init(getLoadContext());
transferable.addDataFlavor(mime);
clipboard.getData(transferable, 1, SpecialPowers.wrap(window).browsingContext.currentWindowContext); var data = SpecialPowers.createBlankObject();
transferable.getTransferData(mime, data) ;
return SpecialPowers.wrap(data);
}
function testHtmlClipboardValue(mime, expected, test) { var expectedValue = expected;
// For Windows, navigator.platform returns "Win32".
if (navigator.platform.includes("Win")) {
expectedValue = kTextHtmlPrefixClipboardDataWindows + expected + kTextHtmlSuffixClipboardDataWindows;
}
testClipboardValue(mime, expectedValue, test);
}
function testClipboardValue(mime, expected, test) { var data = getClipboardData(mime);
is (data.value == null ? data.value :
data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data,
expected,
mime + " value in the clipboard");
return data.value;
}
function testPasteText(expected, test) { textarea.value=""; textarea.focus(); textarea.editor.paste(1);
is(textarea.value, expected, test + ": textarea paste");
}
function testInnerHTML(id, expected) { var value = document.getElementById(id).innerHTML;
is(value, expected, id + ".innerHTML");
}
// expected results for Selection.toString() var originalStrings = [ 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.'
];
// expected results for clipboard text/html var clipboardHTML = [ '
This text should be copied.
', '
This text should be copied.
', '
This text should be copied.
', '
This text should be copied.
', '
This text should be copied.
', '
This text should be copied.
',
];
// expected results for clipboard text/plain var clipboardUnicode = [ 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.'
];
// expected results for .innerHTML var innerHTMLStrings = [ 'This text should be copied.', 'This text should NOT be copied.', 'This text should NOT be copied.', 'This text should NOT be copied.', 'This text should NOT be copied.', 'This text should be copied.',
];
// expected results for pasting into a TEXTAREA var textareaStrings = [ 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.', 'This text should be copied.'
];
for (var i = 0; i < originalStrings.length; i++) { var id = 'test' + i;
copyChildrenToClipboard(id);
is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()');
testHtmlClipboardValue("text/html", clipboardHTML[i], id);
testClipboardValue("text/plain", clipboardUnicode[i], id);
testInnerHTML(id, innerHTMLStrings[i]);
testPasteText(textareaStrings[i], id + '.innerHTML');
}
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.