01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client.ui;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19:
20: /**
21: * Tests {@link TextArea}.
22: */
23: public class TextAreaTest extends GWTTestCase {
24:
25: public String getModuleName() {
26: return "com.google.gwt.user.User";
27: }
28:
29: /**
30: * Tests that {@link TextArea#setText(String)} appropriately converts nulls to
31: * empty strings.
32: */
33: public void testNullMeansEmptyString() {
34: TextArea area = new TextArea();
35: area.setText(null);
36: assertEquals("setText(null) should result in empty string", "",
37: area.getText());
38: }
39:
40: /**
41: * Tests that {@link TextArea#setCursorPos(int)} updates the cursor position
42: * correctly.
43: */
44: public void testMovingCursor() {
45: TextArea area = new TextArea();
46: RootPanel.get().add(area);
47: area.setText("abcd");
48: for (int i = 0; i < 4; i++) {
49: area.setCursorPos(i);
50: assertEquals(i, area.getCursorPos());
51: }
52: }
53:
54: /**
55: * Tests various text selection methods in text area.
56: */
57: public void disabledTestSelection() {
58: TextArea area = new TextArea();
59: assertEquals("", area.getSelectedText());
60: area.selectAll();
61: assertEquals(0, area.getSelectionLength());
62: try {
63: area.setSelectionRange(0, 1);
64: fail("Should have thrown IndexOutOfBoundsException");
65: } catch (IndexOutOfBoundsException e) {
66: // Expected.
67: }
68:
69: // IE bug: if not attached to dom, setSelectionRange fails.
70: RootPanel.get().add(area);
71: area.setText("a");
72:
73: area.selectAll();
74: assertEquals(1, area.getSelectionLength());
75:
76: area.setText("");
77: assertEquals(0, area.getSelectionLength());
78: area.setText("abcde");
79: area.setSelectionRange(2, 2);
80: assertEquals(2, area.getCursorPos());
81:
82: // Check for setting 0;
83: area.setSelectionRange(0, 0);
84: }
85: }
|