blob: 8bc83cf5802ce38dfefa4465d1e2dfa28b04dd95 [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 dismissing the menu prevents the paste from happening. To manually test, click or tap the text on the bottom, click or tap the editable area above, and then dismiss the resulting menu by interacting elsewhere. The text 'Click here to copy' should <strong>not</strong> be pasted, and the menu should disappear.");
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')", "false");
shouldBe("document.execCommand('Paste')", "false");
shouldBeEqualToString("editor.textContent", "");
event.preventDefault();
editor.blur();
});
addEventListener("load", async () => {
if (!window.testRunner)
return;
await UIHelper.activateAt(160, 125);
await triggerPasteMenuAfterActivatingLocation(160, 50, false);
finishJSTest();
});
</script>
</body>
</html>