Make maxlength not affect initial values or scripted sets. Bug 345267, r+sr=mats, a=dbaron

This commit is contained in:
bzbarsky@mit.edu 2007-08-21 20:22:21 -07:00
Родитель e6f02c9578
Коммит ddcdc2b80d
10 изменённых файлов: 204 добавлений и 3 удалений

Просмотреть файл

@ -42,6 +42,12 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = $(NULL)
ifdef MOZ_MOCHITEST
DIRS += test
endif
MODULE = layout
LIBRARY_NAME = gkforms_s
LIBXUL_LIBRARY = 1

Просмотреть файл

@ -2696,14 +2696,19 @@ nsTextControlFrame::SetValue(const nsAString& aValue)
flags &= ~(nsIPlaintextEditor::eEditorReadonlyMask);
editor->SetFlags(flags);
// Also don't enforce max-length here
PRInt32 savedMaxLength;
plaintextEditor->GetMaxTextLength(&savedMaxLength);
plaintextEditor->SetMaxTextLength(-1);
if (currentValue.Length() < 1)
editor->DeleteSelection(nsIEditor::eNone);
else {
nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(editor);
if (textEditor)
textEditor->InsertText(currentValue);
if (plaintextEditor)
plaintextEditor->InsertText(currentValue);
}
plaintextEditor->SetMaxTextLength(savedMaxLength);
editor->SetFlags(savedFlags);
if (selPriv)
selPriv->EndBatchChanges();

Просмотреть файл

@ -0,0 +1,51 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = layout/forms/test
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = test_bug345267.html \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

Просмотреть файл

@ -0,0 +1,93 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=345267
-->
<head>
<title>Test for Bug 345267</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/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=345267">Mozilla Bug 345267</a>
<p id="display">
<input id="d1" maxlength="3" value="abcde">
<input id="d2" maxlength="3">
<input id="d3" maxlength="3">
<input id="d4" value="abcdefghijk">
<input id="target" value="abcdefghijklm" maxlength="3">
</p>
<div id="content" style="display: none">
<input id="u1" maxlength="3" value="abcdef">
<input id="u2" maxlength="3">
<input id="u3" maxlength="3">
<input id="u4" value="abcdefghijkl">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 345267 **/
is($("d1").value, "abcde",
"Displayed initial value should not be truncated by maxlength");
is($("u1").value, "abcdef",
"Undisplayed initial value should not be truncated by maxlength");
$("d2").value = "abcdefg";
is($("d2").value, "abcdefg",
"Displayed set value should not be truncated by maxlength");
$("u2").value = "abcdefgh";
is($("u2").value, "abcdefgh",
"Undisplayed set value should not be truncated by maxlength");
$("d3").defaultValue = "abcdefghi";
is($("d3").value, "abcdefghi",
"Displayed set defaultValue should not be truncated by maxlength");
$("u3").defaultValue = "abcdefghij";
is($("u3").value, "abcdefghij",
"Undisplayed set defaultValue should not be truncated by maxlength");
$("d4").maxLength = "3";
is($("d4").value, "abcdefghijk",
"Displayed: setting maxLength should not truncate existing value");
$("u4").maxLength = "3";
is($("u4").value, "abcdefghijkl",
"Undisplayed: setting maxLength should not truncate existing value");
// Now start the editing tests
is($("target").value, "abcdefghijklm", "Test starting state incorrect");
$("target").focus();
sendKey("back_space");
is($("target").value, "abcdefghijkl", "Should only delete one char");
sendKey("back_space");
is($("target").value, "abcdefghijk", "Should only delete one char again");
(function () {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
$("target").controllers.getControllerForCommand('cmd_undo')
.doCommand('cmd_undo');
})();
is($("target").value, "abcdefghijklm",
"Should be able to undo deletion in the face of maxlength");
sendString("nopq");
is($("target").value, "abcdefghijklm",
"Typing should have no effect when already past maxlength");
$("target").value = "";
sendString("abcde");
is($("target").value, "abc", "Typing should be limited by maxlength");
$("target").value = "";
sendString("ad");
sendKey("left");
sendString("bc")
is($("target").value, "abd", "Typing should be limited by maxlength again");
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<input size="20" value="abcde">
</body>
</html>

Просмотреть файл

@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<input size="20" maxlength="2" value="abcde">
</body>
</html>

Просмотреть файл

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<body>
<input size="20" maxlength="2">
<script>
document.body.offsetWidth;
document.getElementsByTagName("input")[0].value = "abcde";
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<body>
<input size="20" value="abcde">
<script>
document.body.offsetWidth;
document.getElementsByTagName("input")[0].maxLength = "2";
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<body>
<input size="20" maxlength="2">
<script>
document.body.offsetWidth;
document.getElementsByTagName("input")[0].setAttribute("value", "abcde");
</script>
</body>
</html>

Просмотреть файл

@ -146,6 +146,10 @@ fails-if(MOZ_WIDGET_TOOLKIT=="cocoa") == 336736-1.html 336736-1-ref.html # somet
== 339289-1.html 339289-1-ref.html
== 341043-1a.html 341043-1-ref.html
!= 341043-1b.html 341043-1-ref.html
== 345267-1a.html 345267-1-ref.html
== 345267-1b.html 345267-1-ref.html
== 345267-1c.html 345267-1-ref.html
== 345267-1d.html 345267-1-ref.html
== 346774-1a.html 346774-1-ref.html
== 346774-1b.html 346774-1-ref.html
== 346774-1c.html 346774-1-ref.html