blob: b2d58e1ca87b113b528798d0d877440806778f35 [file] [log] [blame]
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
<html>
<head>
<meta name="viewport" content="initial-scale=1.0">
<script src="../../resources/js-test.js"></script>
<script src="../../resources/ui-helper.js"></script>
<link rel="stylesheet" href="resources/test.css">
</head>
<body>
<p id="description"></p>
<div id="test" class="test" style="width: 200px; height: 200px; border: 1px solid black" contenteditable="true">Hello from Cupertino!</div>
<p id="console"></p>
<script>
window.jsTestIsAsync = true;
description("This tests that the text insertion point is before the inserted text placeholder when it's inserted before the start of a word. This test can only be run in WebKitTestRunner or DumpRenderTree.");
async function runTest()
{
let testElement = document.getElementById("test");
if (window.testRunner)
await UIHelper.activateElementAndWaitForInputSession(testElement);
else
await UIHelper.callFunctionAndWaitForEvent(() => testElement.focus(), testElement, "focus");
let positionOfFrom = testElement.textContent.indexOf("from");
window.getSelection().setBaseAndExtent(testElement.firstChild, positionOfFrom, testElement.firstChild, positionOfFrom);
if (window.internals) {
let lineHeight = parseInt(window.getComputedStyle(testElement, null).lineHeight, 10);
internals.insertTextPlaceholder(0 /* width */, lineHeight);
}
shouldBeEqualToString("window.getSelection().type", "Caret");
shouldBe("window.getSelection().baseOffset", "'Hello'.length");
if (window.testRunner) {
// Cleanup to make the results pretty.
document.body.removeChild(testElement);
}
finishJSTest();
}
runTest();
</script>
</body>
</html>