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
.XWindow
;
26 import com
.sun
.star
.frame
.XModel
;
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 accessible component of
46 * main menu of a document. <p>
48 * Object implements the following interfaces :
50 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
51 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
60 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
61 * @see com.sun.star.accessibility.XAccessibleAction
62 * @see com.sun.star.accessibility.XAccessibleSelection
63 * @see com.sun.star.accessibility.XAccessibleValue
64 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
65 * @see com.sun.star.accessibility.XAccessibleComponent
66 * @see com.sun.star.accessibility.XAccessibleText
67 * @see com.sun.star.accessibility.XAccessibleContext
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessibleAction
70 * @see ifc.accessibility._XAccessibleSelection
71 * @see ifc.accessibility._XAccessibleValue
72 * @see ifc.accessibility._XAccessibleExtendedComponent
73 * @see ifc.accessibility._XAccessibleComponent
74 * @see ifc.accessibility._XAccessibleText
75 * @see ifc.accessibility._XAccessibleContext
77 public class AccessibleMenu
extends TestCase
{
78 private static XTextDocument xTextDoc
= null;
80 * Finds accessible component with role <code>MENU</code>
81 * walking through the accessible component tree of a document.
84 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
86 XMultiServiceFactory msf
= Param
.getMSF();
89 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
90 xTextDoc
= SOF
.createTextDoc(null);
91 } catch (com
.sun
.star
.uno
.Exception e
) {
92 throw new StatusException("Can't create document", e
);
95 util
.utils
.pause(500);
97 XWindow xWindow
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
).
98 getCurrentController().getFrame().getContainerWindow();
100 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
102 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
103 XAccessibleContext menubar
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
104 AccessibleRole
.MENU_BAR
);
105 XInterface oObj
= null;
109 oObj
= menubar
.getAccessibleChild(2);
110 menu2
= menubar
.getAccessibleChild(1);
111 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
114 log
.println("ImplementationName " + utils
.getImplName(oObj
));
116 TestEnvironment tEnv
= new TestEnvironment(oObj
);
118 final XAccessibleAction act1
= UnoRuntime
.queryInterface(
119 XAccessibleAction
.class, oObj
);
120 final XAccessibleAction act2
= UnoRuntime
.queryInterface(
121 XAccessibleAction
.class, menu2
);
123 tEnv
.addObjRelation("EventProducer",
124 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
125 public void fireEvent() {
127 act2
.doAccessibleAction(0);
129 util
.utils
.pause(500);
131 act1
.doAccessibleAction(0);
132 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
137 XAccessibleText text
= UnoRuntime
.queryInterface(
138 XAccessibleText
.class, oObj
);
140 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
142 tEnv
.addObjRelation("EditOnly", "Can't change or select Text in Menu");
144 tEnv
.addObjRelation("LimitedBounds", "yes");
146 tEnv
.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
149 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
156 protected void cleanup(TestParameters Param
, PrintWriter log
) {
158 util
.DesktopTools
.closeDoc(xTextDoc
);
159 } catch (com
.sun
.star
.lang
.DisposedException e
) {
160 log
.println("Object already disposed");
165 * Creates a new writer document
168 protected void initialize(TestParameters Param
, PrintWriter log
) {