merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _toolkit / AccessiblePopupMenu.java
blobc45a42bda0717c15a28710f63d25dc6b6c192056
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessiblePopupMenu.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._toolkit;
32 import com.sun.star.accessibility.AccessibleRole;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.accessibility.XAccessibleComponent;
35 import com.sun.star.accessibility.XAccessibleSelection;
36 import com.sun.star.awt.Point;
37 import com.sun.star.awt.Rectangle;
38 import com.sun.star.awt.XExtendedToolkit;
39 import com.sun.star.awt.XWindow;
40 import com.sun.star.frame.XDesktop;
41 import com.sun.star.frame.XModel;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
47 import java.awt.Robot;
48 import java.awt.event.InputEvent;
50 import java.io.PrintWriter;
52 import lib.StatusException;
53 import lib.TestCase;
54 import lib.TestEnvironment;
55 import lib.TestParameters;
57 import util.AccessibilityTools;
58 import util.DesktopTools;
59 import util.SOfficeFactory;
62 public class AccessiblePopupMenu extends TestCase {
63 private static XDesktop the_Desk;
64 private static XTextDocument xTextDoc;
65 private static Point point;
67 /**
68 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
70 protected void initialize(TestParameters Param, PrintWriter log) {
71 the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
72 DesktopTools.createDesktop(
73 (XMultiServiceFactory) Param.getMSF()));
76 /**
77 * Disposes the document, if exists, created in
78 * <code>createTestEnvironment</code> method.
80 protected void cleanup(TestParameters Param, PrintWriter log) {
82 log.println("release the popup menu");
83 try {
84 Robot rob = new Robot();
85 int x = point.X;
86 int y = point.Y;
87 rob.mouseMove(x, y);
88 rob.mousePress(InputEvent.BUTTON1_MASK);
89 rob.mouseRelease(InputEvent.BUTTON1_MASK);
90 } catch (java.awt.AWTException e) {
91 log.println("couldn't press mouse button");
94 log.println("disposing xTextDoc");
96 if (xTextDoc != null) {
97 closeDoc();
102 * Creates a text document.
103 * Then obtains an accessible object with
104 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
105 * <code>"Bold"</code>.
106 * Object relations created :
107 * <ul>
108 * <li> <code>'EventProducer'</code> for
109 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
110 * <li> <code>'XAccessibleText.Text'</code> for
111 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
112 * </ul>
114 * @param tParam test parameters
115 * @param log writer to log information while testing
117 * @see com.sun.star.awt.Toolkit
118 * @see com.sun.star.accessibility.AccessibleRole
119 * @see ifc.accessibility._XAccessibleEventBroadcaster
120 * @see ifc.accessibility._XAccessibleText
121 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
122 * @see com.sun.star.accessibility.XAccessibleText
124 protected TestEnvironment createTestEnvironment(TestParameters tParam,
125 PrintWriter log) {
126 log.println("creating a test environment");
128 if (xTextDoc != null) {
129 closeDoc();
132 // get a soffice factory object
133 SOfficeFactory SOF = SOfficeFactory.getFactory(
134 (XMultiServiceFactory) tParam.getMSF());
136 XInterface toolkit = null;
138 try {
139 log.println("creating a text document");
140 xTextDoc = SOF.createTextDoc(null);
141 toolkit = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
142 "com.sun.star.awt.Toolkit");
143 } catch (com.sun.star.uno.Exception e) {
144 // Some exception occures.FAILED
145 e.printStackTrace(log);
146 throw new StatusException("Couldn't create document", e);
149 shortWait(tParam);
151 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
152 xTextDoc);
154 XInterface oObj = null;
156 AccessibilityTools at = new AccessibilityTools();
158 XWindow xWindow = at.getCurrentWindow(
159 (XMultiServiceFactory) tParam.getMSF(),
160 aModel);
162 XAccessible xRoot = at.getAccessibleObject(xWindow);
164 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
166 XAccessibleComponent window = (XAccessibleComponent) UnoRuntime.queryInterface(
167 XAccessibleComponent.class, oObj);
169 point = window.getLocationOnScreen();
170 Rectangle rect = window.getBounds();
172 try {
173 Robot rob = new Robot();
174 int x = point.X + (rect.Width / 2);
175 int y = point.Y + (rect.Height / 2);
176 rob.mouseMove(x, y);
177 rob.mousePress(InputEvent.BUTTON3_MASK);
178 rob.mouseRelease(InputEvent.BUTTON3_MASK);
179 } catch (java.awt.AWTException e) {
180 log.println("couldn't press mouse button");
183 shortWait(tParam);
185 XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
186 XExtendedToolkit.class, toolkit);
188 try {
189 xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
190 tk.getTopWindow(0));
192 xRoot = at.getAccessibleObject(xWindow);
194 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
195 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
196 log.println("Couldn't get Window");
199 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.POPUP_MENU);
201 log.println("ImplementationName: " + util.utils.getImplName(oObj));
203 TestEnvironment tEnv = new TestEnvironment(oObj);
205 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
206 new Boolean(false));
208 final XAccessibleSelection sel = (XAccessibleSelection) UnoRuntime.queryInterface(
209 XAccessibleSelection.class,
210 oObj);
212 tEnv.addObjRelation("EventProducer",
213 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
214 public void fireEvent() {
215 try {
216 sel.selectAccessibleChild(2);
217 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
218 System.out.println("Couldn't fire event");
223 return tEnv;
226 protected void closeDoc() {
227 util.DesktopTools.closeDoc(xTextDoc);
230 private void shortWait(TestParameters tParam) {
231 util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT));