Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: headless
- Manifest: dom/base/test/mochitest.toml
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test pasting <svg><image href></title>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
const kPasteTargetId = "pasteTarget";
const kTestContentId = "testContent";
function selectSVG() {
const testContent = document.getElementById(kTestContentId);
document.getSelection().selectAllChildren(testContent);
}
async function copyToClipboard() {
function validatorFn(aData) {
const testContent = document.getElementById(kTestContentId);
let expectedData = testContent.outerHTML;
if (navigator.platform.includes(kPlatformWindows)) {
expectedData = kTextHtmlPrefixClipboardDataWindows +
expectedData + kTextHtmlSuffixClipboardDataWindows;
}
return SimpleTest.stripLinebreaksAndWhitespaceAfterTags(aData) ==
SimpleTest.stripLinebreaksAndWhitespaceAfterTags(expectedData);
}
function setupFn() {
synthesizeKey("c", { accelKey: true } /* aEvent */);
}
const flavor = "text/html";
await SimpleTest.promiseClipboardChange(validatorFn, setupFn, flavor);
}
async function pasteTo(aTargetElement) {
document.getSelection().selectAllChildren(aTargetElement);
const promiseInputEvent = new Promise(resolve => {
document.addEventListener("input", resolve,
{ once: true } /* options */);
synthesizeKey("v", { accelKey: true } /* aEvent */);
});
await promiseInputEvent;
}
async function runTest() {
selectSVG();
await copyToClipboard();
// Get the test-content before pasting, because pasting will duplicate
// ids.
const expectedPastedInnerHTML =
SimpleTest.stripLinebreaksAndWhitespaceAfterTags(
document.getElementById(kTestContentId).outerHTML);
const pasteTargetElement = document.getElementById(kPasteTargetId);
await pasteTo(pasteTargetElement);
const pastedInnerHTMLWithoutLinebreaksAndWhitespaceAfterTags =
SimpleTest.stripLinebreaksAndWhitespaceAfterTags(
pasteTargetElement.innerHTML);
is(pastedInnerHTMLWithoutLinebreaksAndWhitespaceAfterTags,
expectedPastedInnerHTML,
"Pasted HTML is as expected.");
SimpleTest.finish()
}
function onLoad() {
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTest);
};
</script>
</head>
<body onload="onLoad()">
<h6>
</h6>
<div id="testContent">
foo
<svg>
<image
height="200" width="200">
</image>
</svg>
bar
</div>
<div contenteditable id="pasteTarget"/>
</body>
</html>