<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
function verifyResults(inputElement, selectedText) {
if (document.activeElement != inputElement) {
document.body.innerHTML = "FAIL (text field was not selected)";
return;
}
if (frames[0].getSelection().toString() != selectedText) {
document.body.innerHTML = "FAIL (unexpected selection)";
return;
}
document.body.innerHTML = "PASS";
}
function runTest() {
var textToSelect = "This text should be selected, but this frame shouldn't be focused.";
frame = frames[0];
frame.focus();
s = frame.getSelection();
s.collapse(frame.document.body, 0);
frame.document.execCommand("InsertText", false, textToSelect);
frame.document.execCommand("SelectAll");
var inputElement = document.getElementById("input");
inputElement.focus();
verifyResults(inputElement, textToSelect);
if (window.testRunner)
testRunner.notifyDone();
}
</script>
<p>This tests to make sure that a selection in one frame isn't cleared when focusing a node in a different frame.</p>
<iframe border="1" src="../resources/contenteditable-iframe-src.html" onload="runTest();"></iframe><br>
<input type="text" id="input" value="This text field should be focused." size="30">