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: import com.google.gwt.user.client.DOM;
20: import com.google.gwt.user.client.Element;
21:
22: /**
23: * TODO: document me.
24: */
25: public class LinearPanelTest extends GWTTestCase {
26:
27: public String getModuleName() {
28: return "com.google.gwt.user.User";
29: }
30:
31: public void testHorizontalAddRemove() {
32: HorizontalPanel hp = new HorizontalPanel();
33: RootPanel.get().add(hp);
34:
35: HTML[] stuff = new HTML[3];
36: stuff[0] = new HTML("foo");
37: stuff[1] = new HTML("bar");
38: stuff[2] = new HTML("baz");
39:
40: // Ensure that we can add & remove cleanly.
41: hp.add(stuff[0]);
42: hp.add(stuff[1]);
43: hp.add(stuff[2]);
44:
45: assertTrue(hp.getWidgetCount() == 3);
46: hp.remove(stuff[1]);
47: assertTrue(hp.getWidgetCount() == 2);
48: assertTrue(hp.getWidget(0) == stuff[0]);
49: assertTrue(hp.getWidget(1) == stuff[2]);
50:
51: // Make sure the table structure is still correct (no stuff left hanging
52: // around).
53: Element elem = hp.getElement();
54: Element body = DOM.getFirstChild(elem);
55: Element tr = DOM.getFirstChild(body);
56: assertTrue(DOM.getChildCount(tr) == 2);
57: }
58:
59: public void testVerticalAddRemove() {
60: VerticalPanel hp = new VerticalPanel();
61: RootPanel.get().add(hp);
62:
63: HTML[] stuff = new HTML[3];
64: stuff[0] = new HTML("foo");
65: stuff[1] = new HTML("bar");
66: stuff[2] = new HTML("baz");
67:
68: // Ensure that we can add & remove cleanly.
69: hp.add(stuff[0]);
70: hp.add(stuff[1]);
71: hp.add(stuff[2]);
72:
73: assertTrue(hp.getWidgetCount() == 3);
74: hp.remove(stuff[1]);
75: assertTrue(hp.getWidgetCount() == 2);
76: assertTrue(hp.getWidget(0) == stuff[0]);
77: assertTrue(hp.getWidget(1) == stuff[2]);
78:
79: // Make sure the table structure is still correct (no stuff left hanging
80: // around).
81: Element elem = hp.getElement();
82: Element body = DOM.getFirstChild(elem);
83: assertTrue(DOM.getChildCount(body) == 2);
84: }
85: }
|