blob: daed28f5a0f224b87b3045bf18e39a70d2300c40 [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 no callout is shown when the page programmatically triggers paste on a timer after user interaction. To test manually, click the text on the bottom to copy, and then click the editable area above to trigger two programmatic pastes with the callout bar. Check that permissions for the first programmatic paste do not affect the second programmatic paste, since it is performed on a zero-delay timer.");
async function waitForAndTapPasteMenuTwice() {
return new Promise(resolve => {
testRunner.runUIScript(`
(() => {
doneCount = 0;
function incrementProgress() {
if (++doneCount === 5)
uiController.uiScriptComplete();
}
uiController.didHideMenuCallback = incrementProgress;
uiController.didShowMenuCallback = tapPasteMenuAction;
function tapPasteMenuAction() {
const rect = uiController.rectForMenuAction("Paste");
uiController.singleTapAtPoint(rect.left + rect.width / 2, rect.top + rect.height / 2, incrementProgress);
}
uiController.singleTapAtPoint(160, 50, incrementProgress);
})()`, resolve);
});
}
function paste() {
getSelection().setPosition(editor);
shouldBe("document.execCommand('Paste')", "true");
shouldBeEqualToString("editor.textContent", "Click here to copy");
editor.textContent = "";
getSelection().removeAllRanges(editor);
}
editor.addEventListener("click", event => {
event.preventDefault();
paste();
setTimeout(paste, 0);
});
addEventListener("load", async () => {
if (!window.testRunner || !window.internals)
return;
await UIHelper.activateAt(160, 125);
await waitForAndTapPasteMenuTwice();
finishJSTest();
});
</script>
</body>
</html>