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 .
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
;
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
;
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()));
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");
71 Robot rob
= new Robot();
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) {
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 :
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>
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
,
113 log
.println("creating a test environment");
115 if (xTextDoc
!= null) {
119 // get a soffice factory object
120 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
121 (XMultiServiceFactory
) tParam
.getMSF());
123 XInterface toolkit
= null;
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
);
138 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class,
141 XInterface oObj
= null;
143 AccessibilityTools at
= new AccessibilityTools();
145 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(
146 (XMultiServiceFactory
) tParam
.getMSF(),
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();
160 Robot rob
= new Robot();
161 int x
= point
.X
+ (rect
.Width
/ 2);
162 int y
= point
.Y
+ (rect
.Height
/ 2);
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");
172 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
173 XExtendedToolkit
.class, toolkit
);
176 xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
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",
195 final XAccessibleSelection sel
= UnoRuntime
.queryInterface(
196 XAccessibleSelection
.class,
199 tEnv
.addObjRelation("EventProducer",
200 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
201 public void fireEvent() {
203 sel
.selectAccessibleChild(2);
204 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
205 System
.out
.println("Couldn't fire event");
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
));