Bug 620936 - setSelectionRange should not fail with offsets larger than the value of the editable field; r=roc a=blocking-betaN+

This commit is contained in:
Ehsan Akhgari 2011-01-05 20:55:31 -05:00
parent bef69aac9c
commit 56697d99dc
3 changed files with 38 additions and 1 deletions

View File

@ -1102,7 +1102,7 @@ nsTextControlFrame::OffsetToDOMPoint(PRInt32 aOffset,
} else {
// Otherwise, set the selection on the textnode itself.
NS_IF_ADDREF(*aResult = firstNode);
*aPosition = aOffset;
*aPosition = PR_MIN(aOffset, textLength);
}
} else {
NS_IF_ADDREF(*aResult = rootNode);

View File

@ -75,6 +75,7 @@ _TEST_FILES = test_bug231389.html \
test_bug572406.html \
test_bug572649.html \
test_bug36619.html \
test_bug620936.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,36 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=620936
-->
<head>
<title>Test for Bug 620936</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=620936">Mozilla Bug 620936</a>
<p id="display"></p>
<div id="content">
<input value="foo">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 620936 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
var i = document.querySelector("input");
i.focus();
i.setSelectionRange(100, 100);
is(i.selectionStart, 3, "The selection should be set to the end of the text");
is(i.selectionEnd, 3, "The selection should be set to the end of the text");
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>