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
.XModel
;
29 import com
.sun
.star
.text
.XTextDocument
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
31 import com
.sun
.star
.uno
.XInterface
;
33 import java
.awt
.Robot
;
34 import java
.awt
.event
.InputEvent
;
35 import java
.io
.PrintWriter
;
38 import lib
.TestEnvironment
;
39 import lib
.TestParameters
;
40 import util
.AccessibilityTools
;
41 import util
.SOfficeFactory
;
43 public class AccessiblePopupMenu
extends TestCase
{
44 private static XTextDocument xTextDoc
;
45 private static Point point
;
48 * Disposes the document, if exists, created in
49 * <code>createTestEnvironment</code> method.
52 protected void cleanup(TestParameters Param
, PrintWriter log
) {
54 log
.println("release the popup menu");
56 Robot rob
= new Robot();
60 rob
.mousePress(InputEvent
.BUTTON1_MASK
);
61 rob
.mouseRelease(InputEvent
.BUTTON1_MASK
);
62 } catch (java
.awt
.AWTException e
) {
63 log
.println("couldn't press mouse button");
66 log
.println("disposing xTextDoc");
68 if (xTextDoc
!= null) {
74 * Creates a text document. Then obtains an accessible object with the role
75 * <code>AccessibleRole.PUSHBUTTON</code> and with the name
76 * <code>"Bold"</code>. Object relations created :
78 * <li> <code>'EventProducer'</code> for
79 * {@link ifc.accessibility._XAccessibleEventBroadcaster}</li>
80 * <li> <code>'XAccessibleText.Text'</code> for
81 * {@link ifc.accessibility._XAccessibleText}: the name of button</li>
87 * writer to log information while testing
89 * @see com.sun.star.awt.Toolkit
90 * @see com.sun.star.accessibility.AccessibleRole
91 * @see ifc.accessibility._XAccessibleEventBroadcaster
92 * @see ifc.accessibility._XAccessibleText
93 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
94 * @see com.sun.star.accessibility.XAccessibleText
97 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
98 PrintWriter log
) throws Exception
{
99 log
.println("creating a test environment");
101 if (xTextDoc
!= null) {
105 // get a soffice factory object
106 SOfficeFactory SOF
= SOfficeFactory
.getFactory(tParam
.getMSF());
108 XInterface toolkit
= null;
110 log
.println("creating a text document");
111 xTextDoc
= SOF
.createTextDoc(null);
112 toolkit
= (XInterface
) tParam
.getMSF().createInstance(
113 "com.sun.star.awt.Toolkit");
115 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
);
117 XInterface oObj
= null;
119 XWindow xWindow
= AccessibilityTools
.getCurrentWindow(aModel
);
121 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
123 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
124 AccessibleRole
.PANEL
);
126 XAccessibleComponent window
= UnoRuntime
.queryInterface(
127 XAccessibleComponent
.class, oObj
);
129 point
= window
.getLocationOnScreen();
130 Rectangle rect
= window
.getBounds();
133 Robot rob
= new Robot();
134 int x
= point
.X
+ (rect
.Width
/ 2);
135 int y
= point
.Y
+ (rect
.Height
/ 2);
137 rob
.mousePress(InputEvent
.BUTTON3_MASK
);
138 rob
.mouseRelease(InputEvent
.BUTTON3_MASK
);
139 } catch (java
.awt
.AWTException e
) {
140 log
.println("couldn't press mouse button");
143 util
.utils
.shortWait();
145 XExtendedToolkit tk
= UnoRuntime
.queryInterface(XExtendedToolkit
.class,
149 xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
152 xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
154 AccessibilityTools
.printAccessibleTree(log
, xRoot
,
155 tParam
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
156 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
157 log
.println("Couldn't get Window");
160 oObj
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
161 AccessibleRole
.POPUP_MENU
);
163 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
165 TestEnvironment tEnv
= new TestEnvironment(oObj
);
167 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
170 final XAccessibleSelection sel
= UnoRuntime
.queryInterface(
171 XAccessibleSelection
.class, oObj
);
175 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
176 public void fireEvent() {
178 sel
.selectAccessibleChild(2);
179 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
180 System
.out
.println("Couldn't fire event");
188 protected void closeDoc() {
189 util
.DesktopTools
.closeDoc(xTextDoc
);