This patch makes PasswordTextBox  inherit from TextBox and adds some unit tests around this change.

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1870 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/PasswordTextBox.java b/user/src/com/google/gwt/user/client/ui/PasswordTextBox.java
index f074bcc..b670cab 100644
--- a/user/src/com/google/gwt/user/client/ui/PasswordTextBox.java
+++ b/user/src/com/google/gwt/user/client/ui/PasswordTextBox.java
@@ -34,7 +34,7 @@
  * <h3>Example</h3> {@example com.google.gwt.examples.TextBoxExample}
  * </p>
  */
-public class PasswordTextBox extends TextBoxBase {
+public class PasswordTextBox extends TextBox {
 
   /**
    * Creates an empty password text box.
diff --git a/user/test/com/google/gwt/user/client/ui/PasswordTextBoxTest.java b/user/test/com/google/gwt/user/client/ui/PasswordTextBoxTest.java
new file mode 100644
index 0000000..1386e13
--- /dev/null
+++ b/user/test/com/google/gwt/user/client/ui/PasswordTextBoxTest.java
@@ -0,0 +1,27 @@
+/*

+ * Copyright 2007 Google Inc.

+ * 

+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0

+ * 

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

+ * License for the specific language governing permissions and limitations under

+ * the License.

+ */

+package com.google.gwt.user.client.ui;

+

+/**

+ * Tests {@link PasswordTextBox}.

+ */

+public class PasswordTextBoxTest extends TextBoxTest {

+

+  @Override

+  protected TextBox createTextBoxBase() {

+    return new PasswordTextBox();

+  }

+}

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 25f045d..a8a984a 100644
--- a/user/test/com/google/gwt/user/client/ui/TextAreaTest.java
+++ b/user/test/com/google/gwt/user/client/ui/TextAreaTest.java
@@ -13,73 +13,18 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
+
 package com.google.gwt.user.client.ui;
 
-import com.google.gwt.junit.client.GWTTestCase;
 
 /**
- * Tests {@link TextArea}.
+ * Tests a {@link TextArea}.
  */
-public class TextAreaTest extends GWTTestCase {
+public class TextAreaTest extends TextBoxBaseTestBase {
 
-  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());
+  @Override
+  protected TextBoxBase createTextBoxBase() {
+    return new TextArea();
   }
 
-  /**
-   * Tests that {@link TextArea#setCursorPos(int)} updates the cursor position
-   * correctly.
-   */
-  public void testMovingCursor() {
-    TextArea area = new TextArea();
-    RootPanel.get().add(area);
-    area.setText("abcd");
-    for (int i = 0; i < 4; i++) {
-      area.setCursorPos(i);
-      assertEquals(i, area.getCursorPos());
-    }
-  }
-
-  /**
-   * Tests various text selection methods in text area.
-   */
-  public void disabledTestSelection() {
-    TextArea area = new TextArea();
-    assertEquals("", area.getSelectedText());
-    area.selectAll();
-    assertEquals(0, area.getSelectionLength());
-    try {
-      area.setSelectionRange(0, 1);
-      fail("Should have thrown IndexOutOfBoundsException");
-    } catch (IndexOutOfBoundsException e) {
-      // Expected.
-    }
-
-    // IE bug: if not attached to dom, setSelectionRange fails.
-    RootPanel.get().add(area);
-    area.setText("a");
-
-    area.selectAll();
-    assertEquals(1, area.getSelectionLength());
-
-    area.setText("");
-    assertEquals(0, area.getSelectionLength());
-    area.setText("abcde");
-    area.setSelectionRange(2, 2);
-    assertEquals(2, area.getCursorPos());
-
-    // Check for setting 0;
-    area.setSelectionRange(0, 0);
-  }
 }
diff --git a/user/test/com/google/gwt/user/client/ui/TextBoxBaseTestBase.java b/user/test/com/google/gwt/user/client/ui/TextBoxBaseTestBase.java
new file mode 100644
index 0000000..c17295f
--- /dev/null
+++ b/user/test/com/google/gwt/user/client/ui/TextBoxBaseTestBase.java
@@ -0,0 +1,88 @@
+/*

+ * Copyright 2007 Google Inc.

+ * 

+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0

+ * 

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

+ * License for the specific language governing permissions and limitations under

+ * the License.

+ */

+package com.google.gwt.user.client.ui;

+

+import com.google.gwt.junit.client.GWTTestCase;

+

+/**

+ * Abstract base test for {@link TextBox}, {@link TextArea}, and

+ * {@link PasswordTextBox}.

+ */

+public abstract class TextBoxBaseTestBase extends GWTTestCase {

+

+  public String getModuleName() {

+    return "com.google.gwt.user.User";

+  }

+

+  protected abstract TextBoxBase createTextBoxBase();

+

+  /**

+   * Tests that {@link TextArea#setText(String)} appropriately converts nulls to

+   * empty strings.

+   */

+  public void testNullMeansEmptyString() {

+    TextBoxBase area = createTextBoxBase();

+    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() {

+    TextBoxBase area = createTextBoxBase();

+    RootPanel.get().add(area);

+    area.setText("abcd");

+    for (int i = 0; i < 4; i++) {

+      area.setCursorPos(i);

+      assertEquals(i, area.getCursorPos());

+    }

+  }

+

+  /**

+   * Tests various text selection methods in text area.

+   */

+  public void disabledTestSelection() {

+    TextBoxBase area = createTextBoxBase();

+    assertEquals("", area.getSelectedText());

+    area.selectAll();

+    assertEquals(0, area.getSelectionLength());

+    try {

+      area.setSelectionRange(0, 1);

+      fail("Should have thrown IndexOutOfBoundsException");

+    } catch (IndexOutOfBoundsException e) {

+      // Expected.

+    }

+

+    // IE bug: if not attached to dom, setSelectionRange fails.

+    RootPanel.get().add(area);

+    area.setText("a");

+

+    area.selectAll();

+    assertEquals(1, area.getSelectionLength());

+

+    area.setText("");

+    assertEquals(0, area.getSelectionLength());

+    area.setText("abcde");

+    area.setSelectionRange(2, 2);

+    assertEquals(2, area.getCursorPos());

+

+    // Check for setting 0;

+    area.setSelectionRange(0, 0);

+  }

+}

diff --git a/user/test/com/google/gwt/user/client/ui/TextBoxTest.java b/user/test/com/google/gwt/user/client/ui/TextBoxTest.java
new file mode 100644
index 0000000..129a8a9
--- /dev/null
+++ b/user/test/com/google/gwt/user/client/ui/TextBoxTest.java
@@ -0,0 +1,47 @@
+/*

+ * Copyright 2007 Google Inc.

+ * 

+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0

+ * 

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

+ * License for the specific language governing permissions and limitations under

+ * the License.

+ */

+package com.google.gwt.user.client.ui;

+

+/**

+ * Testing TextBox.

+ */

+public class TextBoxTest extends TextBoxBaseTestBase {

+

+  @Override

+  protected TextBox createTextBoxBase() {

+    return new TextBox();

+  }

+

+  public void testMaxLength() {

+    TextBox b = createTextBoxBase();

+    b.setMaxLength(5);

+    assertEquals(5, b.getMaxLength());

+    // As our setText does not honor max length, no way to text it in the wild

+    // here.

+  }

+ 

+  public void testMinLength() {

+    TextBox b = createTextBoxBase();

+    b.setVisibleLength(5);

+

+    // Make sure maxLength is independent from visible length.

+    b.setMaxLength(10);

+    assertEquals(10, b.getMaxLength());

+

+    // Now check visible length.

+    assertEquals(5, b.getVisibleLength());

+  }

+}