1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package mod._toolkit;
24 
25 import com.sun.star.accessibility.AccessibleRole;
26 import com.sun.star.accessibility.XAccessible;
27 import com.sun.star.accessibility.XAccessibleAction;
28 import com.sun.star.accessibility.XAccessibleComponent;
29 import com.sun.star.awt.XWindow;
30 import com.sun.star.frame.XModel;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 
36 import java.io.PrintWriter;
37 
38 import lib.StatusException;
39 import lib.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
42 
43 import util.AccessibilityTools;
44 import util.SOfficeFactory;
45 import util.utils;
46 
47 
48 /**
49  * Test for object which is represented accessible component of
50  * menu bar of a document. <p>
51  *
52  * Object implements the following interfaces :
53  * <ul>
54  *  <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
55  *  <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
56  *  <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
57  *  <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
58  *  <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
59  * </ul> <p>
60  *
61  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
62  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
63  * @see com.sun.star.accessibility.XAccessibleComponent
64  * @see com.sun.star.accessibility.XAccessibleSelection
65  * @see com.sun.star.accessibility.XAccessibleContext
66  * @see ifc.accessibility._XAccessibleExtendedComponent
67  * @see ifc.accessibility._XAccessibleEventBroadcaster
68  * @see ifc.accessibility._XAccessibleComponent
69  * @see ifc.accessibility._XAccessibleSelection
70  * @see ifc.accessibility._XAccessibleContext
71  */
72 public class AccessibleMenuBar extends TestCase {
73     private static XTextDocument xTextDoc = null;
74     private static XAccessibleAction action = null;
75 
76     /**
77      * Finds accessible component with role <code>MENUBAR</code>
78      * walking through the accessible component tree of a document.
79      */
createTestEnvironment(TestParameters Param, PrintWriter log)80     protected TestEnvironment createTestEnvironment(TestParameters Param,
81                                                     PrintWriter log) {
82         shortWait();
83 
84         AccessibilityTools at = new AccessibilityTools();
85 
86         XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xTextDoc).
87             getCurrentController().getFrame().getContainerWindow();
88 
89         XAccessible xRoot = at.getAccessibleObject(xWindow);
90 
91 
92         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
93         XInterface oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.MENU_BAR);
94 
95         log.println("ImplementationName " + utils.getImplName(oObj));
96 
97         TestEnvironment tEnv = new TestEnvironment(oObj);
98 
99         final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface(
100                                                    XAccessibleComponent.class,
101                                                    oObj);
102 
103         tEnv.addObjRelation("EventProducer",
104                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
105             public void fireEvent() {
106                 System.out.println("Grabbing focus ... ");
107                 acomp.grabFocus();
108             }
109         });
110 
111         tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
112                             new Boolean(false));
113 
114         tEnv.addObjRelation("XAccessibleSelection.multiSelection",
115                             new Boolean(false));
116 
117         return tEnv;
118     }
119 
120     /**
121      * Creates writer document.
122      */
initialize(TestParameters Param, PrintWriter log)123     protected void initialize(TestParameters Param, PrintWriter log) {
124         try {
125             SOfficeFactory SOF = SOfficeFactory.getFactory(
126                                          (XMultiServiceFactory) Param.getMSF());
127             xTextDoc = SOF.createTextDoc(null);
128         } catch (com.sun.star.uno.Exception e) {
129             throw new StatusException("Can't create document", e);
130         }
131     }
132 
133     /**
134      * Disposes document.
135      */
cleanup(TestParameters Param, PrintWriter log)136     protected void cleanup(TestParameters Param, PrintWriter log) {
137         util.DesktopTools.closeDoc(xTextDoc);
138     }
139 
140     /**
141     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
142     * reset</code> call.
143     */
shortWait()144     private void shortWait() {
145         try {
146             Thread.sleep(500);
147         } catch (InterruptedException e) {
148             log.println("While waiting :" + e);
149         }
150     }
151 }
152