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.DOM;
020:
021: /**
022: * Tests both {@link HorizontalSplitPanel} and {@link VerticalSplitPanel}.
023: */
024: public class SplitPanelTest extends GWTTestCase {
025:
026: private static Widget createMockWidget() {
027: final Label label = new Label();
028: label.setText("Testing 1, 2, 3");
029: DOM.setStyleAttribute(label.getElement(), "fontSize", "72pt");
030: return label;
031: }
032:
033: public String getModuleName() {
034: return "com.google.gwt.user.User";
035: }
036:
037: public void testHorizontalAttachDetachOrder() {
038: HasWidgetsTester.testAll(new HorizontalSplitPanel());
039: }
040:
041: /**
042: * Tests creation, widget assignment, null assignment for
043: * {@link HorizontalSplitPanel}.
044: */
045: public void testHorizontalSplitPanelCreate() {
046: final HorizontalSplitPanel panel = new HorizontalSplitPanel();
047: final Widget widgetA = createMockWidget();
048: final Widget widgetB = createMockWidget();
049:
050: // Intentionally add before setting widgets.
051:
052: RootPanel.get().add(panel);
053:
054: panel.setHeight("100px");
055: panel.setWidth("100px");
056:
057: // Ensure position can be set before widgets are added.
058: panel.setSplitPosition("20px");
059:
060: panel.setRightWidget(widgetB);
061: panel.setLeftWidget(widgetA);
062:
063: assertTrue(panel.getRightWidget() == widgetB);
064: assertTrue(panel.getLeftWidget() == widgetA);
065:
066: panel.setLeftWidget(null);
067: panel.setRightWidget(null);
068:
069: assertTrue(panel.getRightWidget() == null);
070: assertTrue(panel.getLeftWidget() == null);
071:
072: panel.setLeftWidget(widgetB);
073: panel.setRightWidget(widgetA);
074:
075: assertTrue(panel.getLeftWidget() == widgetB);
076: assertTrue(panel.getRightWidget() == widgetA);
077:
078: // Ensure we ended up at the right size.
079: assertEquals(100, panel.getOffsetWidth());
080: assertEquals(100, panel.getOffsetHeight());
081: }
082:
083: public void testVerticalAttachDetachOrder() {
084: HasWidgetsTester.testAll(new VerticalSplitPanel());
085: }
086:
087: /**
088: * Tests creation, widget assignment, null assignment for
089: * {@link VerticalSplitPanel}.
090: */
091: public void testVerticalSplitPanelCreate() {
092:
093: final VerticalSplitPanel panel = new VerticalSplitPanel();
094: final Widget widgetA = createMockWidget();
095: final Widget widgetB = createMockWidget();
096:
097: // Intentionally add before setting widgets.
098: RootPanel.get().add(panel);
099:
100: panel.setHeight("100px");
101: panel.setWidth("100px");
102: // Ensure position can be set before widgets are added.
103: panel.setSplitPosition("20px");
104:
105: panel.setBottomWidget(widgetB);
106: panel.setTopWidget(widgetA);
107:
108: assertTrue(panel.getBottomWidget() == widgetB);
109: assertTrue(panel.getTopWidget() == widgetA);
110:
111: panel.setTopWidget(null);
112: panel.setBottomWidget(null);
113:
114: assertTrue(panel.getTopWidget() == null);
115: assertTrue(panel.getBottomWidget() == null);
116:
117: panel.setTopWidget(widgetB);
118: panel.setBottomWidget(widgetA);
119:
120: assertTrue(panel.getTopWidget() == widgetB);
121: assertTrue(panel.getBottomWidget() == widgetA);
122:
123: // Ensure we ended up at the right size.
124: assertEquals(100, panel.getOffsetWidth());
125: assertEquals(100, panel.getOffsetHeight());
126: }
127: }
|