bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessiblePopupMenu.java
blob1a1512e76fba25fdd589ffdd8a5fa53c72ca7aec
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod._toolkit;
20 import com.sun.star.accessibility.AccessibleRole;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleComponent;
23 import com.sun.star.accessibility.XAccessibleSelection;
24 import com.sun.star.awt.Point;
25 import com.sun.star.awt.Rectangle;
26 import com.sun.star.awt.XExtendedToolkit;
27 import com.sun.star.awt.XWindow;
28 import com.sun.star.frame.XDesktop;
29 import com.sun.star.frame.XModel;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.XTextDocument;
32 import com.sun.star.uno.UnoRuntime;
33 import com.sun.star.uno.XInterface;
35 import java.awt.Robot;
36 import java.awt.event.InputEvent;
38 import java.io.PrintWriter;
40 import lib.StatusException;
41 import lib.TestCase;
42 import lib.TestEnvironment;
43 import lib.TestParameters;
45 import util.AccessibilityTools;
46 import util.DesktopTools;
47 import util.SOfficeFactory;
50 public class AccessiblePopupMenu extends TestCase {
51 private static XTextDocument xTextDoc;
52 private static Point point;
54 /**
55 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
57 protected void initialize(TestParameters Param, PrintWriter log) {
58 UnoRuntime.queryInterface(XDesktop.class,
59 DesktopTools.createDesktop(
60 (XMultiServiceFactory) Param.getMSF()));
63 /**
64 * Disposes the document, if exists, created in
65 * <code>createTestEnvironment</code> method.
67 protected void cleanup(TestParameters Param, PrintWriter log) {
69 log.println("release the popup menu");
70 try {
71 Robot rob = new Robot();
72 int x = point.X;
73 int y = point.Y;
74 rob.mouseMove(x, y);
75 rob.mousePress(InputEvent.BUTTON1_MASK);
76 rob.mouseRelease(InputEvent.BUTTON1_MASK);
77 } catch (java.awt.AWTException e) {
78 log.println("couldn't press mouse button");
81 log.println("disposing xTextDoc");
83 if (xTextDoc != null) {
84 closeDoc();
88 /**
89 * Creates a text document.
90 * Then obtains an accessible object with
91 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
92 * <code>"Bold"</code>.
93 * Object relations created :
94 * <ul>
95 * <li> <code>'EventProducer'</code> for
96 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
97 * <li> <code>'XAccessibleText.Text'</code> for
98 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
99 * </ul>
101 * @param tParam test parameters
102 * @param log writer to log information while testing
104 * @see com.sun.star.awt.Toolkit
105 * @see com.sun.star.accessibility.AccessibleRole
106 * @see ifc.accessibility._XAccessibleEventBroadcaster
107 * @see ifc.accessibility._XAccessibleText
108 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
109 * @see com.sun.star.accessibility.XAccessibleText
111 protected TestEnvironment createTestEnvironment(TestParameters tParam,
112 PrintWriter log) {
113 log.println("creating a test environment");
115 if (xTextDoc != null) {
116 closeDoc();
119 // get a soffice factory object
120 SOfficeFactory SOF = SOfficeFactory.getFactory(
121 (XMultiServiceFactory) tParam.getMSF());
123 XInterface toolkit = null;
125 try {
126 log.println("creating a text document");
127 xTextDoc = SOF.createTextDoc(null);
128 toolkit = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
129 "com.sun.star.awt.Toolkit");
130 } catch (com.sun.star.uno.Exception e) {
131 // Some exception occurs.FAILED
132 e.printStackTrace(log);
133 throw new StatusException("Couldn't create document", e);
136 shortWait(tParam);
138 XModel aModel = UnoRuntime.queryInterface(XModel.class,
139 xTextDoc);
141 XInterface oObj = null;
143 AccessibilityTools at = new AccessibilityTools();
145 XWindow xWindow = AccessibilityTools.getCurrentWindow(
146 (XMultiServiceFactory) tParam.getMSF(),
147 aModel);
149 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
151 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
153 XAccessibleComponent window = UnoRuntime.queryInterface(
154 XAccessibleComponent.class, oObj);
156 point = window.getLocationOnScreen();
157 Rectangle rect = window.getBounds();
159 try {
160 Robot rob = new Robot();
161 int x = point.X + (rect.Width / 2);
162 int y = point.Y + (rect.Height / 2);
163 rob.mouseMove(x, y);
164 rob.mousePress(InputEvent.BUTTON3_MASK);
165 rob.mouseRelease(InputEvent.BUTTON3_MASK);
166 } catch (java.awt.AWTException e) {
167 log.println("couldn't press mouse button");
170 shortWait(tParam);
172 XExtendedToolkit tk = UnoRuntime.queryInterface(
173 XExtendedToolkit.class, toolkit);
175 try {
176 xWindow = UnoRuntime.queryInterface(XWindow.class,
177 tk.getTopWindow(0));
179 xRoot = AccessibilityTools.getAccessibleObject(xWindow);
181 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
182 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
183 log.println("Couldn't get Window");
186 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.POPUP_MENU);
188 log.println("ImplementationName: " + util.utils.getImplName(oObj));
190 TestEnvironment tEnv = new TestEnvironment(oObj);
192 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
193 new Boolean(false));
195 final XAccessibleSelection sel = UnoRuntime.queryInterface(
196 XAccessibleSelection.class,
197 oObj);
199 tEnv.addObjRelation("EventProducer",
200 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
201 public void fireEvent() {
202 try {
203 sel.selectAccessibleChild(2);
204 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
205 System.out.println("Couldn't fire event");
210 return tEnv;
213 protected void closeDoc() {
214 util.DesktopTools.closeDoc(xTextDoc);
217 private void shortWait(TestParameters tParam) {
218 util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT));