blob: 4b5109cda26b2de5ee18f3e06d0c87d56d7c91f7 [file] [log] [blame]
<!DOCTYPE html> <!-- webkit-test-runner [ domPasteAllowed=false useFlexibleViewport=true ignoreSynchronousMessagingTimeouts=true ] -->
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<script src="./resources/dom-paste-helper.js"></script>
<script src="../../../resources/js-test.js"></script>
<script src="../../../resources/ui-helper.js"></script>
<style>
body {
margin: 0;
}
#copy {
width: 100%;
height: 50px;
border: 1px dashed black;
}
#editor {
width: 100%;
height: 100px;
border: 1px dashed silver;
text-align: center;
}
</style>
</head>
<body>
<div id="editor" contenteditable></div>
<iframe id="copy" src="data:text/html,<div id='copy' style='font-size: 40px; text-align: center;'>Click here to copy</div>
<script>
copy.addEventListener('click', () => {
getSelection().selectAllChildren(copy);
document.execCommand('Copy');
getSelection().removeAllRanges();
});
</script>"></iframe>
<div id="description"></div>
<div id="console"></div>
<script>
jsTestIsAsync = true;
const editor = document.getElementById("editor");
description("Verifies that a menu is shown when the page programmatically triggers paste, and that selecting Paste in the menu allows the paste to happen. To manually test, click or tap the text on the bottom, click or tap the editable area above, and then select 'Paste' in the resulting menu. The text 'Click here to copy' should be pasted <strong><em>twice</em></strong> in the editable area.");
editor.addEventListener("paste", event => shouldBeEqualToString("event.clipboardData.getData('text/plain')", "Click here to copy"));
editor.addEventListener("click", event => {
getSelection().setPosition(editor);
shouldBe("document.queryCommandSupported('Paste')", "true");
shouldBe("document.queryCommandEnabled('Paste')", "true");
shouldBe("document.execCommand('Paste')", "true");
document.execCommand('InsertParagraph');
shouldBe("document.execCommand('Paste')", "true");
shouldBeEqualToString("editor.textContent", "Click here to copyClick here to copy");
event.preventDefault();
editor.blur();
});
addEventListener("load", async () => {
if (!window.testRunner)
return;
await UIHelper.activateAt(160, 125);
await triggerPasteMenuAfterActivatingLocation(160, 50);
finishJSTest();
});
</script>
</body>
</html>