001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.client.ui;
017:
018: import com.google.gwt.junit.client.GWTTestCase;
019: import com.google.gwt.user.client.Timer;
020:
021: /**
022: * Tests the {@link RichTextArea} widget.
023: */
024: public class RichTextAreaTest extends GWTTestCase {
025:
026: public String getModuleName() {
027: return "com.google.gwt.user.User";
028: }
029:
030: /**
031: * Test that removing and re-adding an RTA doesn't destroy its contents (Only
032: * IE actually preserves dynamically-created iframe contents across DOM
033: * removal/re-adding).
034: */
035: public void testAddEditRemoveAdd() {
036: final RichTextArea area = new RichTextArea();
037: RootPanel.get().add(area);
038: area.setHTML("foo");
039:
040: // This has to be done on a timer because the rta can take some time to
041: // finish initializing (on some browsers).
042: this .delayTestFinish(1000);
043: new Timer() {
044: public void run() {
045: RootPanel.get().remove(area);
046: RootPanel.get().add(area);
047:
048: // It's ok (and important) to check the HTML immediately after re-adding
049: // the rta.
050: assertEquals("foo", area.getHTML());
051: finishTest();
052: }
053: }.schedule(500);
054: }
055:
056: /**
057: * Test that a delayed set of HTML is reflected. Some platforms have timing
058: * subtleties that need to be tested.
059: */
060: public void testSetHTMLAfterInit() {
061: final RichTextArea richTextArea = new RichTextArea();
062: RootPanel.get().add(richTextArea);
063: new Timer() {
064: public void run() {
065: richTextArea.setHTML("<b>foo</b>");
066: assertEquals("<b>foo</b>", richTextArea.getHTML()
067: .toLowerCase());
068: finishTest();
069: }
070: }.schedule(200);
071: delayTestFinish(1000);
072: }
073:
074: /**
075: * Test that an immediate set of HTML is reflected immediately and after a
076: * delay. Some platforms have timing subtleties that need to be tested.
077: */
078: public void testSetHTMLBeforeInit() {
079: final RichTextArea richTextArea = new RichTextArea();
080: RootPanel.get().add(richTextArea);
081: richTextArea.setHTML("<b>foo</b>");
082: assertEquals("<b>foo</b>", richTextArea.getHTML().toLowerCase());
083: new Timer() {
084: public void run() {
085: assertEquals("<b>foo</b>", richTextArea.getHTML()
086: .toLowerCase());
087: finishTest();
088: }
089: }.schedule(200);
090: delayTestFinish(1000);
091: }
092:
093: /**
094: * Test that delayed set of text is reflected. Some platforms have timing
095: * subtleties that need to be tested.
096: */
097: public void testSetTextAfterInit() {
098: final RichTextArea richTextArea = new RichTextArea();
099: RootPanel.get().add(richTextArea);
100: new Timer() {
101: public void run() {
102: richTextArea.setText("foo");
103: assertEquals("foo", richTextArea.getText());
104: finishTest();
105: }
106: }.schedule(200);
107: delayTestFinish(1000);
108: }
109:
110: /**
111: * Test that an immediate set of text is reflected immediately and after a
112: * delay. Some platforms have timing subtleties that need to be tested.
113: */
114: public void testSetTextBeforeInit() {
115: final RichTextArea richTextArea = new RichTextArea();
116: RootPanel.get().add(richTextArea);
117: richTextArea.setText("foo");
118: assertEquals("foo", richTextArea.getText());
119: new Timer() {
120: public void run() {
121: assertEquals("foo", richTextArea.getText());
122: finishTest();
123: }
124: }.schedule(200);
125: delayTestFinish(1000);
126: }
127: }
|