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: import com.google.gwt.user.client.Window;
22:
23: /**
24: * TODO: document me.
25: */
26: public class PopupTest extends GWTTestCase {
27:
28: /**
29: * Expose otherwise private or protected methods.
30: */
31: private class TestablePopupPanel extends PopupPanel {
32: public Element getContainerElement() {
33: return super .getContainerElement();
34: }
35: }
36:
37: public String getModuleName() {
38: return "com.google.gwt.user.User";
39: }
40:
41: public void testPopup() {
42: // Get rid of window margins so we can test absolute position.
43: Window.setMargin("0px");
44:
45: PopupPanel popup = new PopupPanel();
46: Label lbl = new Label("foo");
47:
48: // Make sure that setting the popup's size & position works _before_
49: // setting its widget.
50: popup.setSize("384px", "128px");
51: popup.setPopupPosition(128, 64);
52: popup.setWidget(lbl);
53: popup.show();
54:
55: assertEquals(384, popup.getOffsetWidth());
56: assertEquals(128, popup.getOffsetHeight());
57: assertEquals(128, popup.getPopupLeft());
58: assertEquals(64, popup.getPopupTop());
59:
60: // Make sure that the popup returns to the correct position
61: // after hiding and showing it.
62: popup.hide();
63: popup.show();
64: assertEquals(128, popup.getPopupLeft());
65: assertEquals(64, popup.getPopupTop());
66:
67: // Make sure that setting the popup's size & position works _after_
68: // setting its widget (and that clearing its size properly resizes it to
69: // its widget's size).
70: popup.setSize("", "");
71: popup.setPopupPosition(16, 16);
72:
73: assertEquals(lbl.getOffsetWidth(), popup.getOffsetWidth());
74: assertEquals(lbl.getOffsetHeight(), popup.getOffsetHeight());
75: assertEquals(16, popup.getAbsoluteLeft());
76: assertEquals(16, popup.getAbsoluteTop());
77:
78: // Ensure that hiding the popup fires the appropriate events.
79: delayTestFinish(1000);
80: popup.addPopupListener(new PopupListener() {
81: public void onPopupClosed(PopupPanel sender,
82: boolean autoClosed) {
83: finishTest();
84: }
85: });
86: popup.hide();
87: }
88:
89: public void testSeparateContainers() {
90: TestablePopupPanel p1 = new TestablePopupPanel();
91: TestablePopupPanel p2 = new TestablePopupPanel();
92: assertTrue(p1.getContainerElement() != null);
93: assertTrue(p2.getContainerElement() != null);
94: assertFalse(DOM.compare(p1.getContainerElement(), p2
95: .getContainerElement()));
96: }
97: }
|