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;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19: import com.google.gwt.user.client.ui.RootPanel;
20: import com.google.gwt.user.client.ui.Label;
21:
22: /**
23: * Test Case for {@link Cookies}.
24: */
25: public class WindowTest extends GWTTestCase {
26:
27: public String getModuleName() {
28: return "com.google.gwt.user.User";
29: }
30:
31: /**
32: * Tests the ability of the Window to get the client size correctly
33: * with and without visible scroll bars.
34: */
35: public void testGetClientSize() {
36: // Get the dimensions without any scroll bars
37: Window.enableScrolling(false);
38: final int oldClientHeight = Window.getClientHeight();
39: final int oldClientWidth = Window.getClientWidth();
40: assertTrue(oldClientHeight > 0);
41: assertTrue(oldClientWidth > 0);
42:
43: // Compare to the dimensions with scroll bars
44: Window.enableScrolling(true);
45: final Label largeDOM = new Label();
46: largeDOM.setPixelSize(oldClientWidth + 100,
47: oldClientHeight + 100);
48: RootPanel.get().add(largeDOM);
49: DeferredCommand.addCommand(new Command() {
50: public void execute() {
51: int newClientHeight = Window.getClientHeight();
52: int newClientWidth = Window.getClientWidth();
53: assertTrue(newClientHeight < oldClientHeight);
54: assertTrue(newClientWidth < oldClientWidth);
55: finishTest();
56: }
57: });
58: delayTestFinish(200);
59: }
60: }
|