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._svtools;
24 
25 import com.sun.star.view.XSelectionSupplier;
26 import java.awt.Robot;
27 import java.awt.event.InputEvent;
28 import java.io.PrintWriter;
29 
30 import lib.StatusException;
31 import lib.TestCase;
32 import lib.TestEnvironment;
33 import lib.TestParameters;
34 import util.AccessibilityTools;
35 import util.DesktopTools;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.accessibility.AccessibleRole;
39 import com.sun.star.accessibility.XAccessible;
40 import com.sun.star.accessibility.XAccessibleComponent;
41 import com.sun.star.awt.Point;
42 import com.sun.star.awt.XWindow;
43 import com.sun.star.beans.PropertyValue;
44 import com.sun.star.frame.XController;
45 import com.sun.star.frame.XDesktop;
46 import com.sun.star.frame.XDispatch;
47 import com.sun.star.frame.XDispatchProvider;
48 import com.sun.star.frame.XFrame;
49 import com.sun.star.frame.XModel;
50 import com.sun.star.lang.XMultiServiceFactory;
51 import com.sun.star.text.XTextDocument;
52 import com.sun.star.uno.UnoRuntime;
53 import com.sun.star.uno.XInterface;
54 import com.sun.star.util.URL;
55 
56 
57 /**
58  * Test for object that implements the following interfaces :
59  * <ul>
60  *  <li>
61  *      <code>::com::sun::star::accessibility::XAccessibleContext
62  *  </code></li>
63  *  <li>
64  *      <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
65  *  </code></li>
66  * </ul> <p>
67  *
68  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
69  * @see com.sun.star.accessibility.XAccessibleContext
70  * @see ifc.accessibility._XAccessibleEventBroadcaster
71  * @see ifc.accessibility._XAccessibleContext
72  */
73 public class AccessibleBrowseBoxHeaderBar extends TestCase {
74     static XDesktop the_Desk;
75     static XTextDocument xTextDoc;
76 
77     /**
78      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
79      */
initialize(TestParameters Param, PrintWriter log)80     protected void initialize(TestParameters Param, PrintWriter log) {
81         the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
82             DesktopTools.createDesktop(
83             (XMultiServiceFactory) Param.getMSF()));
84     }
85 
86     /**
87      * Disposes the document, if exists, created in
88      * <code>createTestEnvironment</code> method.
89      */
cleanup(TestParameters Param, PrintWriter log)90     protected void cleanup(TestParameters Param, PrintWriter log) {
91         log.println("disposing xTextDoc");
92 
93         if (xTextDoc != null) {
94             xTextDoc.dispose();
95         }
96     }
97 
98     /**
99      * Creates a text document. Opens the DataSource browser.
100      * Creates an instance of the service <code>com.sun.star.awt.Toolkit</code>
101      * and gets active top window. Then obtains an accessible object with
102      * the role <code>AccessibleRole.TABLE</code>.
103      * Object relations created :
104      * <ul>
105      *  <li> <code>'EventProducer'</code> for
106      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
107      *   </li>
108      * </ul>
109      *
110      * @param tParam test parameters
111      * @param log writer to log information while testing
112      *
113      * @see com.sun.star.awt.Toolkit
114      * @see com.sun.star.accessibility.AccessibleRole
115      * @see ifc.accessibility._XAccessibleEventBroadcaster
116      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
117      */
createTestEnvironment(TestParameters tParam, PrintWriter log)118     protected TestEnvironment createTestEnvironment(TestParameters tParam,
119         PrintWriter log) {
120         log.println("creating a test environment");
121 
122         if (xTextDoc != null) {
123             xTextDoc.dispose();
124         }
125 
126         // get a soffice factory object
127         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
128 
129         try {
130             log.println("creating a text document");
131             xTextDoc = SOF.createTextDoc(null);
132         } catch (com.sun.star.uno.Exception e) {
133             // Some exception occures.FAILED
134             e.printStackTrace(log);
135             throw new StatusException("Couldn't create document", e);
136         }
137 
138         shortWait();
139 
140         XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
141             xTextDoc);
142 
143         XController secondController = aModel1.getCurrentController();
144 
145         XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
146             XDispatchProvider.class,
147             secondController);
148 
149         XDispatch getting = null;
150 
151         log.println("opening DatasourceBrowser");
152 
153         URL the_url = new URL();
154         the_url.Complete = ".component:DB/DataSourceBrowser";
155         getting = aProv.queryDispatch(the_url, "_beamer", 12);
156 
157         //am controller ein XSelectionSupplier->mit params rufen
158         PropertyValue[] noArgs = new PropertyValue[0];
159         getting.dispatch(the_url, noArgs);
160 
161         PropertyValue[] params = new PropertyValue[3];
162         PropertyValue param1 = new PropertyValue();
163         param1.Name = "DataSourceName";
164         param1.Value = "Bibliography";
165         params[0] = param1;
166 
167         PropertyValue param2 = new PropertyValue();
168         param2.Name = "CommandType";
169         param2.Value = new Integer(com.sun.star.sdb.CommandType.TABLE);
170         params[1] = param2;
171 
172         PropertyValue param3 = new PropertyValue();
173         param3.Name = "Command";
174         param3.Value = "biblio";
175         params[2] = param3;
176 
177         shortWait();
178 
179         XFrame the_frame1 = the_Desk.getCurrentFrame();
180 
181         if (the_frame1 == null) {
182             log.println("Current frame was not found !!!");
183         }
184 
185         XFrame the_frame2 = the_frame1.findFrame("_beamer", 4);
186 
187         the_frame2.setName("DatasourceBrowser");
188 
189         XController xCont = the_frame2.getController();
190 
191         XSelectionSupplier xSelect = (XSelectionSupplier) UnoRuntime.queryInterface(
192             XSelectionSupplier.class, xCont);
193 
194         try {
195             xSelect.select(params);
196         } catch (com.sun.star.lang.IllegalArgumentException ex) {
197             throw new StatusException("Could not select Biblio-Database", ex);
198         }
199 
200         XInterface oObj = null;
201 
202         AccessibilityTools at = new AccessibilityTools();
203 
204         XWindow xWindow = secondController.getFrame().getContainerWindow();
205 
206         XAccessible xRoot = at.getAccessibleObject(xWindow);
207 
208         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE);
209 
210         at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
211         log.println("ImplementationName: " + util.utils.getImplName(oObj));
212 
213         TestEnvironment tEnv = new TestEnvironment(oObj);
214 
215         shortWait();
216 
217         XAccessibleComponent accComp = (XAccessibleComponent) UnoRuntime.queryInterface(
218             XAccessibleComponent.class,
219             oObj);
220         final Point point = accComp.getLocationOnScreen();
221 
222         shortWait();
223 
224         tEnv.addObjRelation("EventProducer",
225             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
226             public void fireEvent() {
227                 try {
228                     Robot rob = new Robot();
229                     rob.mouseMove(point.X + 5, point.Y + 5);
230                     rob.mousePress(InputEvent.BUTTON1_MASK);
231                 } catch (java.awt.AWTException e) {
232                     System.out.println("couldn't fire event");
233                 }
234             }
235         });
236 
237         return tEnv;
238     }
239 
240     /**
241      * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
242      * reset</code> call.
243      */
shortWait()244     private void shortWait() {
245         try {
246             Thread.sleep(5000);
247         } catch (InterruptedException e) {
248             System.out.println("While waiting :" + e);
249         }
250     }
251 }
252