bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessiblePopupMenu.java
blob81da3dd50253926afc82e4eefe4a90112e5bd703
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.text.XTextDocument;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
34 import java.awt.Robot;
35 import java.awt.event.InputEvent;
37 import java.io.PrintWriter;
39 import lib.StatusException;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
44 import util.AccessibilityTools;
45 import util.DesktopTools;
46 import util.SOfficeFactory;
49 public class AccessiblePopupMenu extends TestCase {
50 private static XTextDocument xTextDoc;
51 private static Point point;
53 /**
54 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
56 @Override
57 protected void initialize(TestParameters Param, PrintWriter log) {
58 UnoRuntime.queryInterface(XDesktop.class,
59 DesktopTools.createDesktop(
60 Param.getMSF()));
63 /**
64 * Disposes the document, if exists, created in
65 * <code>createTestEnvironment</code> method.
67 @Override
68 protected void cleanup(TestParameters Param, PrintWriter log) {
70 log.println("release the popup menu");
71 try {
72 Robot rob = new Robot();
73 int x = point.X;
74 int y = point.Y;
75 rob.mouseMove(x, y);
76 rob.mousePress(InputEvent.BUTTON1_MASK);
77 rob.mouseRelease(InputEvent.BUTTON1_MASK);
78 } catch (java.awt.AWTException e) {
79 log.println("couldn't press mouse button");
82 log.println("disposing xTextDoc");
84 if (xTextDoc != null) {
85 closeDoc();
89 /**
90 * Creates a text document.
91 * Then obtains an accessible object with
92 * the role <code>AccessibleRole.PUSHBUTTON</code> and with the name
93 * <code>"Bold"</code>.
94 * Object relations created :
95 * <ul>
96 * <li> <code>'EventProducer'</code> for
97 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
98 * <li> <code>'XAccessibleText.Text'</code> for
99 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
100 * </ul>
102 * @param tParam test parameters
103 * @param log writer to log information while testing
105 * @see com.sun.star.awt.Toolkit
106 * @see com.sun.star.accessibility.AccessibleRole
107 * @see ifc.accessibility._XAccessibleEventBroadcaster
108 * @see ifc.accessibility._XAccessibleText
109 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
110 * @see com.sun.star.accessibility.XAccessibleText
112 @Override
113 protected TestEnvironment createTestEnvironment(TestParameters tParam,
114 PrintWriter log) {
115 log.println("creating a test environment");
117 if (xTextDoc != null) {
118 closeDoc();
121 // get a soffice factory object
122 SOfficeFactory SOF = SOfficeFactory.getFactory(
123 tParam.getMSF());
125 XInterface toolkit = null;
127 try {
128 log.println("creating a text document");
129 xTextDoc = SOF.createTextDoc(null);
130 toolkit = (XInterface) tParam.getMSF().createInstance(
131 "com.sun.star.awt.Toolkit");
132 } catch (com.sun.star.uno.Exception e) {
133 // Some exception occurs.FAILED
134 e.printStackTrace(log);
135 throw new StatusException("Couldn't create document", e);
138 util.utils.shortWait();
140 XModel aModel = UnoRuntime.queryInterface(XModel.class,
141 xTextDoc);
143 XInterface oObj = null;
145 XWindow xWindow = AccessibilityTools.getCurrentWindow(
146 aModel);
148 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
150 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
152 XAccessibleComponent window = UnoRuntime.queryInterface(
153 XAccessibleComponent.class, oObj);
155 point = window.getLocationOnScreen();
156 Rectangle rect = window.getBounds();
158 try {
159 Robot rob = new Robot();
160 int x = point.X + (rect.Width / 2);
161 int y = point.Y + (rect.Height / 2);
162 rob.mouseMove(x, y);
163 rob.mousePress(InputEvent.BUTTON3_MASK);
164 rob.mouseRelease(InputEvent.BUTTON3_MASK);
165 } catch (java.awt.AWTException e) {
166 log.println("couldn't press mouse button");
169 util.utils.shortWait();
171 XExtendedToolkit tk = UnoRuntime.queryInterface(
172 XExtendedToolkit.class, toolkit);
174 try {
175 xWindow = UnoRuntime.queryInterface(XWindow.class,
176 tk.getTopWindow(0));
178 xRoot = AccessibilityTools.getAccessibleObject(xWindow);
180 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
181 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
182 log.println("Couldn't get Window");
185 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.POPUP_MENU);
187 log.println("ImplementationName: " + util.utils.getImplName(oObj));
189 TestEnvironment tEnv = new TestEnvironment(oObj);
191 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
192 Boolean.FALSE);
194 final XAccessibleSelection sel = UnoRuntime.queryInterface(
195 XAccessibleSelection.class,
196 oObj);
198 tEnv.addObjRelation("EventProducer",
199 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
200 public void fireEvent() {
201 try {
202 sel.selectAccessibleChild(2);
203 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
204 System.out.println("Couldn't fire event");
209 return tEnv;
212 protected void closeDoc() {
213 util.DesktopTools.closeDoc(xTextDoc);