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.awt.XWindow;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XTextDocument;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.uno.XInterface;
33 
34 import java.io.PrintWriter;
35 
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 
41 import util.AccessibilityTools;
42 import util.SOfficeFactory;
43 import util.utils;
44 
45 
46 /**
47  * Test for object which is represented by accessible component
48  * of the URL locator combo box located in the left upper corner
49  * of a document. <p>
50  *
51  * Object implements the following interfaces :
52  * <ul>
53  *  <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
54  *  <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
55  *  <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
56  *  <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
57  *  <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
58  * </ul> <p>
59  *
60  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
61  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
62  * @see com.sun.star.accessibility.XAccessibleComponent
63  * @see com.sun.star.accessibility.XAccessibleAction
64  * @see com.sun.star.accessibility.XAccessibleContext
65  * @see ifc.accessibility._XAccessibleExtendedComponent
66  * @see ifc.accessibility._XAccessibleEventBroadcaster
67  * @see ifc.accessibility._XAccessibleComponent
68  * @see ifc.accessibility._XAccessibleAction
69  * @see ifc.accessibility._XAccessibleContext
70  */
71 public class AccessibleDropDownComboBox extends TestCase {
72     private static XTextDocument xTextDoc = null;
73 
74     /**
75      * Finds AccessibleDropDownComboBox walking through the
76      * accessible component tree of a writer document.
77      */
createTestEnvironment(TestParameters Param, PrintWriter log)78     protected TestEnvironment createTestEnvironment(TestParameters Param,
79                                                     PrintWriter log) {
80         XInterface oObj = null;
81 
82         AccessibilityTools at = new AccessibilityTools();
83 
84         XWindow xWindow = at.getCurrentContainerWindow(
85                                   (XMultiServiceFactory) Param.getMSF(),
86                                   xTextDoc);
87 
88         XAccessible xRoot = at.getAccessibleObject(xWindow);
89 
90         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.COMBO_BOX,
91                                              "", "AccessibleDropDownComboBox");
92 
93         log.println("ImplementationName " + utils.getImplName(oObj));
94 
95         TestEnvironment tEnv = new TestEnvironment(oObj);
96 
97         final XAccessibleAction editAction = (XAccessibleAction) UnoRuntime.queryInterface(
98                                                      XAccessibleAction.class,
99                                                      oObj);
100 
101         tEnv.addObjRelation("EventProducer",
102                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
103             public void fireEvent() {
104                 try {
105                     editAction.doAccessibleAction(0);
106                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
107                     e.printStackTrace();
108                 }
109             }
110         });
111 
112         return tEnv;
113     }
114 
115     /**
116      * Creates writer document.
117      */
initialize(TestParameters Param, PrintWriter log)118     protected void initialize(TestParameters Param, PrintWriter log) {
119         try {
120             SOfficeFactory SOF = SOfficeFactory.getFactory(
121                                          (XMultiServiceFactory) Param.getMSF());
122             xTextDoc = SOF.createTextDoc(null);
123         } catch (com.sun.star.uno.Exception e) {
124             throw new StatusException("Can't create document", e);
125         }
126     }
127 
128     /**
129      * Disposes writer document.
130      */
cleanup(TestParameters Param, PrintWriter log)131     protected void cleanup(TestParameters Param, PrintWriter log) {
132         util.DesktopTools.closeDoc(xTextDoc);
133     }
134 }
135 
136