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
.XAccessibleAction
;
23 import com
.sun
.star
.accessibility
.XAccessibleContext
;
24 import com
.sun
.star
.accessibility
.XAccessibleText
;
25 import com
.sun
.star
.awt
.XExtendedToolkit
;
26 import com
.sun
.star
.awt
.XWindow
;
27 import com
.sun
.star
.lang
.XMultiServiceFactory
;
28 import com
.sun
.star
.text
.XTextDocument
;
29 import com
.sun
.star
.uno
.UnoRuntime
;
30 import com
.sun
.star
.uno
.XInterface
;
32 import java
.io
.PrintWriter
;
34 import lib
.StatusException
;
36 import lib
.TestEnvironment
;
37 import lib
.TestParameters
;
39 import util
.AccessibilityTools
;
40 import util
.SOfficeFactory
;
45 * Test for object which is represented by accessible component
46 * of a menu item in main menu of a document. <p>
48 * Object implements the following interfaces :
50 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
51 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
59 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
60 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
61 * @see com.sun.star.accessibility.XAccessibleComponent
62 * @see com.sun.star.accessibility.XAccessibleValue
63 * @see com.sun.star.accessibility.XAccessibleAction
64 * @see com.sun.star.accessibility.XAccessibleContext
65 * @see com.sun.star.accessibility.XAccessibleText
66 * @see ifc.accessibility._XAccessibleExtendedComponent
67 * @see ifc.accessibility._XAccessibleEventBroadcaster
68 * @see ifc.accessibility._XAccessibleComponent
69 * @see ifc.accessibility._XAccessibleValue
70 * @see ifc.accessibility._XAccessibleAction
71 * @see ifc.accessibility._XAccessibleContext
72 * @see ifc.accessibility._XAccessibleText
74 public class AccessibleMenuItem
extends TestCase
{
75 private static XTextDocument xTextDoc
= null;
76 private static XMultiServiceFactory msf
= null;
79 * Finds first accessible component with role <code>MENUITEM</code>
80 * walking through the accessible component tree of a document.
83 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
85 XInterface oObj
= null;
88 oObj
= (XInterface
) msf
.createInstance("com.sun.star.awt.Toolkit");
89 } catch (com
.sun
.star
.uno
.Exception e
) {
90 log
.println("Couldn't get toolkit");
91 e
.printStackTrace(log
);
92 throw new StatusException("Couldn't get toolkit", e
);
95 XExtendedToolkit tk
= UnoRuntime
.queryInterface(
96 XExtendedToolkit
.class, oObj
);
98 util
.utils
.pause(500);
100 Object atw
= tk
.getActiveTopWindow();
102 XWindow xWindow
= UnoRuntime
.queryInterface(XWindow
.class,
105 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
107 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
108 XAccessibleContext MenuBar
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
109 AccessibleRole
.MENU_BAR
);
113 XAccessible Menu
= MenuBar
.getAccessibleChild(1);
114 XAccessibleAction act
= UnoRuntime
.queryInterface(
115 XAccessibleAction
.class, Menu
);
116 act
.doAccessibleAction(0);
117 util
.utils
.pause(500);
121 oObj
= Menu
.getAccessibleContext().getAccessibleChild(11);
122 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
126 log
.println("ImplementationName " + utils
.getImplName(oObj
));
128 TestEnvironment tEnv
= new TestEnvironment(oObj
);
130 final XAccessibleAction action
= UnoRuntime
.queryInterface(
131 XAccessibleAction
.class, oObj
);
133 tEnv
.addObjRelation("EventProducer",
134 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
135 public void fireEvent() {
137 action
.doAccessibleAction(0);
138 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
143 XAccessibleText text
= UnoRuntime
.queryInterface(
144 XAccessibleText
.class, oObj
);
146 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
148 tEnv
.addObjRelation("EditOnly",
149 "Can't change or select Text in MenuBarItem");
151 tEnv
.addObjRelation("Destroy", Boolean
.TRUE
);
153 tEnv
.addObjRelation("LimitedBounds", "yes");
159 * Creates writer document.
162 protected void initialize(TestParameters Param
, PrintWriter log
) {
164 msf
= Param
.getMSF();
166 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
167 xTextDoc
= SOF
.createTextDoc(null);
168 } catch (com
.sun
.star
.uno
.Exception e
) {
169 throw new StatusException("Can't create document", e
);
177 protected void cleanup(TestParameters Param
, PrintWriter log
) {
178 util
.DesktopTools
.closeDoc(xTextDoc
);