blob: 3836e795f2cf227e857d819b8e7cf82c0a4c01e3 [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 callout is shown when the page programmatically triggers paste, and that dismissing the callout prevents the paste from happening. To manually test, tap the text on the bottom, tap the editable area above, and then dismiss the resulting callout menu by scrolling or tapping elsewhere. The text 'Click here to copy' should <strong>not</strong> be pasted, and the callout bar 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 triggerPasteMenuAfterTapAt(160, 50, false);
finishJSTest();
});
</script>
</body>
</html>