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.
83 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
85 XMultiServiceFactory msf
= (XMultiServiceFactory
) Param
.getMSF();
88 SOfficeFactory SOF
= SOfficeFactory
.getFactory(msf
);
89 xTextDoc
= SOF
.createTextDoc(null);
90 } catch (com
.sun
.star
.uno
.Exception e
) {
91 throw new StatusException("Can't create document", e
);
96 XWindow xWindow
= UnoRuntime
.queryInterface(XModel
.class, xTextDoc
).
97 getCurrentController().getFrame().getContainerWindow();
99 AccessibilityTools at
= new AccessibilityTools();
101 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(xWindow
);
103 AccessibilityTools
.printAccessibleTree(log
, xRoot
, Param
.getBool(util
.PropertyName
.DEBUG_IS_ACTIVE
));
104 XAccessibleContext menubar
= AccessibilityTools
.getAccessibleObjectForRole(xRoot
,
105 AccessibleRole
.MENU_BAR
);
106 XInterface oObj
= null;
110 oObj
= menubar
.getAccessibleChild(2);
111 menu2
= menubar
.getAccessibleChild(1);
112 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
115 log
.println("ImplementationName " + utils
.getImplName(oObj
));
117 TestEnvironment tEnv
= new TestEnvironment(oObj
);
119 final XAccessibleAction act1
= UnoRuntime
.queryInterface(
120 XAccessibleAction
.class, oObj
);
121 final XAccessibleAction act2
= UnoRuntime
.queryInterface(
122 XAccessibleAction
.class, menu2
);
124 tEnv
.addObjRelation("EventProducer",
125 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer() {
126 public void fireEvent() {
128 act2
.doAccessibleAction(0);
132 } catch (InterruptedException e
) {
135 act1
.doAccessibleAction(0);
136 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
141 XAccessibleText text
= UnoRuntime
.queryInterface(
142 XAccessibleText
.class, oObj
);
144 tEnv
.addObjRelation("XAccessibleText.Text", text
.getText());
146 tEnv
.addObjRelation("EditOnly", "Can't change or select Text in Menu");
148 tEnv
.addObjRelation("LimitedBounds", "yes");
150 tEnv
.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
153 tEnv
.addObjRelation("XAccessibleSelection.multiSelection",
159 protected void cleanup(TestParameters Param
, PrintWriter log
) {
161 util
.DesktopTools
.closeDoc(xTextDoc
);
162 } catch (com
.sun
.star
.lang
.DisposedException e
) {
163 log
.println("Object already disposed");
168 * Creates a new writer document
170 protected void initialize(TestParameters Param
, PrintWriter log
) {
174 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
177 private void shortWait() {
180 } catch (InterruptedException e
) {
181 log
.println("While waiting :" + e
);