Fixes Issue 799. Changes TextBoxBase to normalize the behavior of setText across browsers. Calling it with null will always result in an empty string being used as the text value. Also, a test case was added for ongoing verification. Patch by: bobv Review by: knorton git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1058 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/TextBoxBase.java b/user/src/com/google/gwt/user/client/ui/TextBoxBase.java index dc91e8e..a2d92e2 100644 --- a/user/src/com/google/gwt/user/client/ui/TextBoxBase.java +++ b/user/src/com/google/gwt/user/client/ui/TextBoxBase.java
@@ -252,7 +252,7 @@ } public void setText(String text) { - DOM.setElementProperty(getElement(), "value", text); + DOM.setElementProperty(getElement(), "value", text != null ? text : ""); } /**
diff --git a/user/test/com/google/gwt/user/client/ui/TextAreaTest.java b/user/test/com/google/gwt/user/client/ui/TextAreaTest.java index aa672cc..25f045d 100644 --- a/user/test/com/google/gwt/user/client/ui/TextAreaTest.java +++ b/user/test/com/google/gwt/user/client/ui/TextAreaTest.java
@@ -18,14 +18,29 @@ import com.google.gwt.junit.client.GWTTestCase; /** - * TODO: document me. + * Tests {@link TextArea}. */ public class TextAreaTest extends GWTTestCase { public String getModuleName() { return "com.google.gwt.user.User"; } + + /** + * Tests that {@link TextArea#setText(String)} appropriately converts nulls to + * empty strings. + */ + public void testNullMeansEmptyString() { + TextArea area = new TextArea(); + area.setText(null); + assertEquals("setText(null) should result in empty string", + "", area.getText()); + } + /** + * Tests that {@link TextArea#setCursorPos(int)} updates the cursor position + * correctly. + */ public void testMovingCursor() { TextArea area = new TextArea(); RootPanel.get().add(area); @@ -36,6 +51,9 @@ } } + /** + * Tests various text selection methods in text area. + */ public void disabledTestSelection() { TextArea area = new TextArea(); assertEquals("", area.getSelectedText());