1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package mod._toolkit;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRole;
26cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible;
27cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleAction;
28cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleEditableText;
29cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleText;
30cdf0e10cSrcweir import com.sun.star.awt.XExtendedToolkit;
31cdf0e10cSrcweir import com.sun.star.awt.XWindow;
32cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
33cdf0e10cSrcweir import com.sun.star.frame.XController;
34cdf0e10cSrcweir import com.sun.star.frame.XDispatch;
35cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider;
36cdf0e10cSrcweir import com.sun.star.frame.XModel;
37cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
38cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
39cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
40cdf0e10cSrcweir import com.sun.star.uno.XInterface;
41cdf0e10cSrcweir import com.sun.star.util.URL;
42cdf0e10cSrcweir import com.sun.star.util.XURLTransformer;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir import java.io.PrintWriter;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir import lib.StatusException;
47cdf0e10cSrcweir import lib.TestCase;
48cdf0e10cSrcweir import lib.TestEnvironment;
49cdf0e10cSrcweir import lib.TestParameters;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir import util.AccessibilityTools;
52cdf0e10cSrcweir import util.SOfficeFactory;
53cdf0e10cSrcweir import util.utils;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 
56cdf0e10cSrcweir /**
57cdf0e10cSrcweir  * Test for object which is represented by edit field
58cdf0e10cSrcweir  * of 'Insert Hyperlink' dialog. <p>
59cdf0e10cSrcweir  *
60cdf0e10cSrcweir  * Object implements the following interfaces :
61cdf0e10cSrcweir  * <ul>
62cdf0e10cSrcweir  *  <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
63cdf0e10cSrcweir  *  <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
64cdf0e10cSrcweir  *  <li> <code>::com::sun::star::accessibility::XAccessibleEditableText</code></li>
65cdf0e10cSrcweir  *  <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
66cdf0e10cSrcweir  *  <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
67cdf0e10cSrcweir  *  <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
68cdf0e10cSrcweir  * </ul> <p>
69cdf0e10cSrcweir  *
70cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
71cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
72cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleEditableText
73cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleComponent
74cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleContext
75cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleText
76cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleExtendedComponent
77cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleEventBroadcaster
78cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleEditableText
79cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleComponent
80cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleContext
81cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleText
82cdf0e10cSrcweir  */
83cdf0e10cSrcweir public class AccessibleEdit extends TestCase {
84cdf0e10cSrcweir     private static XTextDocument xTextDoc = null;
85cdf0e10cSrcweir     private static XAccessibleAction action = null;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     /**
88cdf0e10cSrcweir      * Opens 'Insert Hyperlink' dialog using document dispatch provider.
89cdf0e10cSrcweir      * Finds active top window (the dialog
90cdf0e10cSrcweir      * window) and finds first accessible edit field and
91cdf0e10cSrcweir      * button 'Close' (for closing this dialog when disposing)
92cdf0e10cSrcweir      * walking through the accessible component tree.
93cdf0e10cSrcweir      */
createTestEnvironment(TestParameters Param, PrintWriter log)94cdf0e10cSrcweir     protected TestEnvironment createTestEnvironment(TestParameters Param,
95cdf0e10cSrcweir                                                     PrintWriter log) {
96cdf0e10cSrcweir         XInterface oObj = null;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         try {
99cdf0e10cSrcweir             oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
100cdf0e10cSrcweir                            "com.sun.star.awt.Toolkit");
101cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
102cdf0e10cSrcweir             log.println("Couldn't get toolkit");
103cdf0e10cSrcweir             e.printStackTrace(log);
104cdf0e10cSrcweir             throw new StatusException("Couldn't get toolkit", e);
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
108cdf0e10cSrcweir                                       XExtendedToolkit.class, oObj);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
111cdf0e10cSrcweir                                                             xTextDoc);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         XController secondController = aModel1.getCurrentController();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
116cdf0e10cSrcweir                                           XDispatchProvider.class,
117cdf0e10cSrcweir                                           secondController);
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         XURLTransformer urlTransf = null;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         try {
122cdf0e10cSrcweir             XInterface transf = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
123cdf0e10cSrcweir                                         "com.sun.star.util.URLTransformer");
124cdf0e10cSrcweir             urlTransf = (XURLTransformer) UnoRuntime.queryInterface(
125cdf0e10cSrcweir                                 XURLTransformer.class, transf);
126cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
127cdf0e10cSrcweir             e.printStackTrace(log);
128cdf0e10cSrcweir             throw new StatusException("Couldn't create URLTransformer", e);
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         XDispatch getting = null;
132cdf0e10cSrcweir         log.println("opening HyperlinkDialog");
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         URL[] url = new URL[1];
135cdf0e10cSrcweir         url[0] = new URL();
136cdf0e10cSrcweir         url[0].Complete = ".uno:HyperlinkDialog";
137cdf0e10cSrcweir         urlTransf.parseStrict(url);
138cdf0e10cSrcweir         getting = aProv.queryDispatch(url[0], "", 0);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         PropertyValue[] noArgs = new PropertyValue[0];
141cdf0e10cSrcweir         getting.dispatch(url[0], noArgs);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         shortWait();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         AccessibilityTools at = new AccessibilityTools();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
148cdf0e10cSrcweir                                                               tk.getActiveTopWindow());
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         XAccessible xRoot = at.getAccessibleObject(xWindow);
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
153cdf0e10cSrcweir                                              "Close");
154cdf0e10cSrcweir         action = (XAccessibleAction) UnoRuntime.queryInterface(
155cdf0e10cSrcweir                          XAccessibleAction.class, oObj);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         log.println("ImplementationName " + utils.getImplName(oObj));
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         final XAccessibleEditableText edText = (XAccessibleEditableText) UnoRuntime.queryInterface(
164cdf0e10cSrcweir                                                        XAccessibleEditableText.class,
165cdf0e10cSrcweir                                                        oObj);
166cdf0e10cSrcweir         edText.setText("AccessibleEdit");
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         tEnv.addObjRelation("EventProducer",
169cdf0e10cSrcweir                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
170cdf0e10cSrcweir             public void fireEvent() {
171cdf0e10cSrcweir                 //                    buttonAccComp.grabFocus();
172cdf0e10cSrcweir                 //                    acomp.grabFocus();
173cdf0e10cSrcweir                 edText.setText("firing event ...");
174cdf0e10cSrcweir                 edText.setText("firing event ... 2");
175cdf0e10cSrcweir                 edText.setText("AccessibleEdit");
176cdf0e10cSrcweir             }
177cdf0e10cSrcweir         });
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         XAccessibleText text = (XAccessibleText) UnoRuntime.queryInterface(
180cdf0e10cSrcweir                                        XAccessibleText.class, oObj);
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         tEnv.addObjRelation("XAccessibleText.Text", text.getText());
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         tEnv.addObjRelation("XAccessibleEditableText.hasAttr", Boolean.FALSE);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         return tEnv;
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     /**
190cdf0e10cSrcweir      * Closes dialog using action of button 'Close'
191cdf0e10cSrcweir      */
cleanup(TestParameters Param, PrintWriter log)192cdf0e10cSrcweir     protected void cleanup(TestParameters Param, PrintWriter log) {
193cdf0e10cSrcweir         log.println("    Closing dialog ... ");
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         try {
196cdf0e10cSrcweir             action.doAccessibleAction(0);
197cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
198cdf0e10cSrcweir             log.println("Couldn't close dialog");
199cdf0e10cSrcweir         } catch (com.sun.star.lang.DisposedException de) {
200cdf0e10cSrcweir             log.println("Dialog already disposed");
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         util.DesktopTools.closeDoc(xTextDoc);
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     /**
207cdf0e10cSrcweir      * Creates writer document
208cdf0e10cSrcweir      */
initialize(TestParameters Param, PrintWriter log)209cdf0e10cSrcweir     protected void initialize(TestParameters Param, PrintWriter log) {
210cdf0e10cSrcweir         try {
211cdf0e10cSrcweir             SOfficeFactory SOF = SOfficeFactory.getFactory(
212cdf0e10cSrcweir                                          (XMultiServiceFactory) Param.getMSF());
213cdf0e10cSrcweir             xTextDoc = SOF.createTextDoc(null);
214cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
215cdf0e10cSrcweir             throw new StatusException("Can't create document", e);
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     /**
220cdf0e10cSrcweir     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
221cdf0e10cSrcweir     * reset</code> call.
222cdf0e10cSrcweir     */
shortWait()223cdf0e10cSrcweir     private void shortWait() {
224cdf0e10cSrcweir         try {
225cdf0e10cSrcweir             Thread.sleep(500);
226cdf0e10cSrcweir         } catch (InterruptedException e) {
227cdf0e10cSrcweir             log.println("While waiting :" + e);
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir     }
230*170fb961SPedro Giffuni }
231