001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.awt.Window.AccessibleAWTWindow;
023:
024: import javax.accessibility.AccessibleContext;
025: import javax.accessibility.AccessibleRole;
026: import javax.accessibility.AccessibleState;
027: import javax.accessibility.AccessibleStateSet;
028:
029: import junit.framework.TestCase;
030:
031: /**
032: * AccessibleAWTWindowTest
033: */
034: public class AccessibleAWTWindowTest extends TestCase {
035:
036: private Window window;
037: AccessibleContext ac;
038: private Frame frame;
039: private Robot robot;
040:
041: @Override
042: protected void setUp() throws Exception {
043: super .setUp();
044: frame = new Frame();
045: window = new Window(frame);
046: ac = window.getAccessibleContext();
047: robot = new Robot();
048: }
049:
050: @Override
051: protected void tearDown() throws Exception {
052: super .tearDown();
053: if ((frame != null) && frame.isDisplayable()) {
054: frame.dispose();
055: }
056: }
057:
058: public final void testGetAccessibleRole() {
059: assertSame(AccessibleRole.WINDOW, ac.getAccessibleRole());
060: }
061:
062: @SuppressWarnings("deprecation")
063: public final void testGetAccessibleStateSet() {
064: frame.show();
065: window.setFocusable(true);
066: window.setVisible(true);
067: waitFocus();
068: assertTrue(window.isFocusOwner());
069: AccessibleStateSet aStateSet = ac.getAccessibleStateSet();
070: assertTrue("accessible window is active", aStateSet
071: .contains(AccessibleState.ACTIVE));
072: assertTrue("accessible window is showing", aStateSet
073: .contains(AccessibleState.SHOWING));
074: assertTrue("accessible window is focusable", aStateSet
075: .contains(AccessibleState.FOCUSABLE));
076: assertTrue("accessible window is focused", aStateSet
077: .contains(AccessibleState.FOCUSED));
078: assertFalse("accessible window is NOT resizable", aStateSet
079: .contains(AccessibleState.RESIZABLE));
080: assertTrue(frame.isActive());
081: aStateSet = frame.getAccessibleContext()
082: .getAccessibleStateSet();
083: assertFalse("accessible frame is NOT active", aStateSet
084: .contains(AccessibleState.ACTIVE));
085: }
086:
087: public final void testAccessibleAWTWindow() {
088: assertTrue(ac instanceof AccessibleAWTWindow);
089: }
090:
091: private void waitFocus() {
092: int time = 0;
093: int timeout = 32;
094: int threshold = 60000;
095: while (!window.isFocused() && (time < threshold)) {
096: robot.delay(timeout);
097: time += timeout;
098: timeout <<= 1;
099: }
100: }
101:
102: }
|