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.Window;
20:
21: /**
22: * TODO: document me.
23: */
24: public class AbsolutePanelTest extends GWTTestCase {
25:
26: public String getModuleName() {
27: return "com.google.gwt.user.User";
28: }
29:
30: public void testAttachDetachOrder() {
31: HasWidgetsTester.testAll(new AbsolutePanel());
32: }
33:
34: public void testPositioning() {
35: // Make an absolute panel with a label at (42, 43).
36: AbsolutePanel abs = new AbsolutePanel();
37: abs.setSize("128px", "128px");
38: Label lbl = new Label("foo");
39: abs.add(lbl, 3, 7);
40:
41: // Put the panel in a grid that will place it at (32, 32) within the grid.
42: Grid g = new Grid(2, 2);
43: g.setBorderWidth(0);
44: g.setCellPadding(0);
45: g.setCellSpacing(0);
46: g.getCellFormatter().setWidth(0, 0, "100px");
47: g.getCellFormatter().setHeight(0, 0, "200px");
48: g.setWidget(1, 1, abs);
49:
50: // Clear the margin so that absolute position is predictable.
51: Window.setMargin("0px");
52: RootPanel.get().add(g);
53:
54: // Make sure that the label's position, both relative to the absolute panel
55: // and relative to the page, is correct. It is important to test both of
56: // these, because an incorrectly constructed AbsolutePanel will lead to
57: // wacky positioning of its children.
58: int x = abs.getWidgetLeft(lbl);
59: int y = abs.getWidgetTop(lbl);
60: int absX = lbl.getAbsoluteLeft();
61: int absY = lbl.getAbsoluteTop();
62: assertEquals(x, 3);
63: assertEquals(y, 7);
64: assertEquals(absX, 3 + 100);
65: assertEquals(absY, 7 + 200);
66: }
67: }
|