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.XAccessibleComponent;
29cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext;
30cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleSelection;
31cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleValue;
32cdf0e10cSrcweir import com.sun.star.awt.XExtendedToolkit;
33cdf0e10cSrcweir import com.sun.star.awt.XWindow;
34cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
35cdf0e10cSrcweir import com.sun.star.frame.XController;
36cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
37cdf0e10cSrcweir import com.sun.star.frame.XDispatch;
38cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider;
39cdf0e10cSrcweir import com.sun.star.frame.XModel;
40cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
41cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
42cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
43cdf0e10cSrcweir import com.sun.star.uno.XInterface;
44cdf0e10cSrcweir import com.sun.star.util.URL;
45cdf0e10cSrcweir import com.sun.star.util.XURLTransformer;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir import java.io.PrintWriter;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir import lib.StatusException;
50cdf0e10cSrcweir import lib.TestCase;
51cdf0e10cSrcweir import lib.TestEnvironment;
52cdf0e10cSrcweir import lib.TestParameters;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir import util.AccessibilityTools;
55cdf0e10cSrcweir import util.DesktopTools;
56cdf0e10cSrcweir import util.SOfficeFactory;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir /**
60cdf0e10cSrcweir  * Test for object that implements the following interfaces :
61cdf0e10cSrcweir  * <ul>
62cdf0e10cSrcweir  *  <li><code>
63cdf0e10cSrcweir  *  ::com::sun::star::accessibility::XAccessibleContext</code></li>
64cdf0e10cSrcweir  *  <li><code>
65cdf0e10cSrcweir  *  ::com::sun::star::accessibility::XAccessibleEventBroadcaster
66cdf0e10cSrcweir  *  </code></li>
67cdf0e10cSrcweir  *  <li><code>
68cdf0e10cSrcweir  *  ::com::sun::star::accessibility::XAccessibleComponent</code></li>
69cdf0e10cSrcweir  *  <li><code>
70cdf0e10cSrcweir  *  ::com::sun::star::accessibility::XAccessibleExtendedComponent
71cdf0e10cSrcweir  *  </code></li>
72cdf0e10cSrcweir  *  <li><code>
73cdf0e10cSrcweir  *  ::com::sun::star::accessibility::XAccessibleValue</code></li>
74cdf0e10cSrcweir  *  <li><code>
75cdf0e10cSrcweir  *  ::com::sun::star::accessibility::XAccessibleText</code></li>
76cdf0e10cSrcweir  * </ul> <p>
77cdf0e10cSrcweir  *
78cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
79cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleContext
80cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleComponent
81cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleExtendedComponent
82cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleValue
83cdf0e10cSrcweir  * @see com.sun.star.accessibility.XAccessibleText
84cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleEventBroadcaster
85cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleContext
86cdf0e10cSrcweir  * @see ifc.accessibility._XAccessibleComponent
87e6b649b5SPedro Giffuni  * @see ifc.accessibility._XAccessibleExtendedComponent
88e6b649b5SPedro Giffuni  * @see ifc.accessibility._XAccessibleValue
89e6b649b5SPedro Giffuni  * @see ifc.accessibility._XAccessibleText
90cdf0e10cSrcweir  */
91cdf0e10cSrcweir public class AccessibleRadioButton extends TestCase {
92cdf0e10cSrcweir     private static XDesktop the_Desk;
93cdf0e10cSrcweir     private static XTextDocument xTextDoc;
94cdf0e10cSrcweir     private static XAccessibleAction accCloseButton;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     /**
98cdf0e10cSrcweir      * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
99cdf0e10cSrcweir      */
initialize(TestParameters Param, PrintWriter log)100cdf0e10cSrcweir     protected void initialize(TestParameters Param, PrintWriter log) {
101cdf0e10cSrcweir         the_Desk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,
102cdf0e10cSrcweir                                                         DesktopTools.createDesktop(
103cdf0e10cSrcweir                                                                 (XMultiServiceFactory) Param.getMSF()));
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     /**
107cdf0e10cSrcweir      * Closes a Hyperlink dialog, disposes the document, if exists, created in
108cdf0e10cSrcweir      * <code>createTestEnvironment</code> method.
109cdf0e10cSrcweir      */
cleanup(TestParameters Param, PrintWriter log)110cdf0e10cSrcweir     protected void cleanup(TestParameters Param, PrintWriter log) {
111cdf0e10cSrcweir         try {
112cdf0e10cSrcweir             if (accCloseButton != null) {
113cdf0e10cSrcweir                 log.println("closing HyperlinkDialog");
114cdf0e10cSrcweir                 accCloseButton.doAccessibleAction(0);
115cdf0e10cSrcweir             }
116cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
117cdf0e10cSrcweir             e.printStackTrace(log);
118cdf0e10cSrcweir         } catch (com.sun.star.lang.DisposedException de) {
119cdf0e10cSrcweir             log.println("Already disposed");
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         log.println("disposing xTextDoc");
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         if (xTextDoc != null) {
125cdf0e10cSrcweir             closeDoc();
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     /**
130cdf0e10cSrcweir      * Creates a text document, opens a hypelink dialog, selects a first item
131cdf0e10cSrcweir      * in IconChoiceCtrl.
132cdf0e10cSrcweir      * Then obtains an accessible object with
133cdf0e10cSrcweir      * the role <code>AccessibleRole.RADIOBUTTON</code> with the name <code>
134cdf0e10cSrcweir      * "Internet"</code>.
135cdf0e10cSrcweir      * Object relations created :
136cdf0e10cSrcweir      * <ul>
137cdf0e10cSrcweir      *  <li> <code>'EventProducer'</code> for
138cdf0e10cSrcweir      *      {@link ifc.accessibility._XAccessibleEventBroadcaster}:
139cdf0e10cSrcweir      *      grabs focus </li>
140cdf0e10cSrcweir      *  <li> <code>'XAccessibleText.Text'</code> for
141cdf0e10cSrcweir      *      {@link ifc.accessibility._XAccessibleText}:
142cdf0e10cSrcweir      *      the text of the component </li>
143cdf0e10cSrcweir      *  <li> <code>'XAccessibleValue.anotherFromGroup'</code> for
144cdf0e10cSrcweir      *      {@link ifc.accessibility._XAccessibleValue}:
145cdf0e10cSrcweir      *       <code>'FTP'</code> button </li>
146cdf0e10cSrcweir      * </ul>
147cdf0e10cSrcweir      *
148cdf0e10cSrcweir      * @param tParam test parameters
149cdf0e10cSrcweir      * @param log writer to log information while testing
150cdf0e10cSrcweir      *
151cdf0e10cSrcweir      * @see com.sun.star.awt.Toolkit
152cdf0e10cSrcweir      * @see com.sun.star.accessibility.AccessibleRole
153cdf0e10cSrcweir      * @see ifc.accessibility._XAccessibleEventBroadcaster
154cdf0e10cSrcweir      * @see ifc.accessibility._XAccessibleText
155cdf0e10cSrcweir      * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
156cdf0e10cSrcweir      * @see com.sun.star.accessibility.XAccessibleText
157cdf0e10cSrcweir      */
createTestEnvironment(TestParameters tParam, PrintWriter log)158cdf0e10cSrcweir     protected TestEnvironment createTestEnvironment(TestParameters tParam,
159cdf0e10cSrcweir                                                     PrintWriter log) {
160cdf0e10cSrcweir         log.println("creating a test environment");
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         // get a soffice factory object
163cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(
164cdf0e10cSrcweir                                      (XMultiServiceFactory) tParam.getMSF());
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         try {
167cdf0e10cSrcweir             log.println("creating a text document");
168cdf0e10cSrcweir             xTextDoc = SOF.createTextDoc(null);
169cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
170*30acf5e8Spfg             // Some exception occured.FAILED
171cdf0e10cSrcweir             e.printStackTrace(log);
172cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         util.utils.shortWait(2000);
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         XModel aModel1 = (XModel) UnoRuntime.queryInterface(XModel.class,
178cdf0e10cSrcweir                                                             xTextDoc);
179cdf0e10cSrcweir 
180cdf0e10cSrcweir         XController secondController = aModel1.getCurrentController();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         XDispatchProvider aProv = (XDispatchProvider) UnoRuntime.queryInterface(
183cdf0e10cSrcweir                                           XDispatchProvider.class,
184cdf0e10cSrcweir                                           secondController);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         XURLTransformer urlTransf = null;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         try {
189cdf0e10cSrcweir             XInterface transf = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
190cdf0e10cSrcweir                                         "com.sun.star.util.URLTransformer");
191cdf0e10cSrcweir             urlTransf = (XURLTransformer) UnoRuntime.queryInterface(
192cdf0e10cSrcweir                                 XURLTransformer.class, transf);
193cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
194cdf0e10cSrcweir             e.printStackTrace(log);
195cdf0e10cSrcweir             throw new StatusException("Couldn't create URLTransformer", e);
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         XDispatch getting = null;
199cdf0e10cSrcweir         log.println("opening HyperlinkDialog");
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         URL[] url = new URL[1];
202cdf0e10cSrcweir         url[0] = new URL();
203cdf0e10cSrcweir         url[0].Complete = ".uno:HyperlinkDialog";
204cdf0e10cSrcweir         urlTransf.parseStrict(url);
205cdf0e10cSrcweir         getting = aProv.queryDispatch(url[0], "", 0);
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         PropertyValue[] noArgs = new PropertyValue[0];
208cdf0e10cSrcweir         getting.dispatch(url[0], noArgs);
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         util.utils.shortWait(2000);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         XInterface oObj = null;
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         try {
215cdf0e10cSrcweir             oObj = (XInterface) ((XMultiServiceFactory) tParam.getMSF()).createInstance(
216cdf0e10cSrcweir                            "com.sun.star.awt.Toolkit");
217cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
218cdf0e10cSrcweir             log.println("Couldn't get toolkit");
219cdf0e10cSrcweir             e.printStackTrace(log);
220cdf0e10cSrcweir             throw new StatusException("Couldn't get toolkit", e);
221cdf0e10cSrcweir         }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         XExtendedToolkit tk = (XExtendedToolkit) UnoRuntime.queryInterface(
224cdf0e10cSrcweir                                       XExtendedToolkit.class, oObj);
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         AccessibilityTools at = new AccessibilityTools();
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         util.utils.shortWait(2000);
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class,
231cdf0e10cSrcweir                                                               tk.getActiveTopWindow());
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         XAccessible xRoot = at.getAccessibleObject(xWindow);
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         XAccessibleContext iconChoiceCtrl = at.getAccessibleObjectForRole(
236cdf0e10cSrcweir                                                     xRoot, AccessibleRole.TREE,
237cdf0e10cSrcweir                                                     "IconChoiceControl");
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         XAccessibleSelection sel = (XAccessibleSelection) UnoRuntime.queryInterface(
240cdf0e10cSrcweir                                            XAccessibleSelection.class,
241cdf0e10cSrcweir                                            iconChoiceCtrl);
242cdf0e10cSrcweir 
243cdf0e10cSrcweir         try {
244cdf0e10cSrcweir             sel.selectAccessibleChild(0);
245cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
246cdf0e10cSrcweir             log.println("Unexpected exception");
247cdf0e10cSrcweir             e.printStackTrace(log);
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         at.printAccessibleTree(log,xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
251cdf0e10cSrcweir 
252cdf0e10cSrcweir         oObj = at.getAccessibleObjectForRole(xRoot,
253cdf0e10cSrcweir                                              AccessibleRole.RADIO_BUTTON,
254cdf0e10cSrcweir                                              "Web");
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         XAccessibleContext anotherButton = at.getAccessibleObjectForRole(xRoot,
257cdf0e10cSrcweir                                                                          AccessibleRole.RADIO_BUTTON,
258cdf0e10cSrcweir                                                                          "FTP");
259cdf0e10cSrcweir 
260cdf0e10cSrcweir         XAccessibleContext closeButton = at.getAccessibleObjectForRole(xRoot,
261cdf0e10cSrcweir                                                                        AccessibleRole.PUSH_BUTTON,
262cdf0e10cSrcweir                                                                        "Close");
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         accCloseButton = (XAccessibleAction) UnoRuntime.queryInterface(
266cdf0e10cSrcweir                                  XAccessibleAction.class, closeButton);
267cdf0e10cSrcweir 
268cdf0e10cSrcweir         log.println("ImplementationName: " + util.utils.getImplName(oObj));
269cdf0e10cSrcweir 
270cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj);
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         tEnv.addObjRelation("EditOnly",
273cdf0e10cSrcweir                             "This method isn't supported in this component");
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         tEnv.addObjRelation("LimitedBounds", "yes");
276cdf0e10cSrcweir 
277cdf0e10cSrcweir         final XAccessibleComponent acomp = (XAccessibleComponent) UnoRuntime.queryInterface(
278cdf0e10cSrcweir                                                    XAccessibleComponent.class,
279cdf0e10cSrcweir                                                    oObj);
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         tEnv.addObjRelation("EventProducer",
282cdf0e10cSrcweir                             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
283cdf0e10cSrcweir             public void fireEvent() {
284cdf0e10cSrcweir                 acomp.grabFocus();
285cdf0e10cSrcweir             }
286cdf0e10cSrcweir         });
287cdf0e10cSrcweir 
288cdf0e10cSrcweir         tEnv.addObjRelation("XAccessibleText.Text", "Web");
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         tEnv.addObjRelation("EditOnly",
291cdf0e10cSrcweir                             "Can't change or select Text in AccessibleRadioButton");
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         XAccessibleValue anotherButtonValue = (XAccessibleValue) UnoRuntime.queryInterface(
294cdf0e10cSrcweir                                                       XAccessibleValue.class,
295cdf0e10cSrcweir                                                       anotherButton);
296cdf0e10cSrcweir 
297cdf0e10cSrcweir         tEnv.addObjRelation("XAccessibleValue.anotherFromGroup",
298cdf0e10cSrcweir                             anotherButtonValue);
299cdf0e10cSrcweir 
300cdf0e10cSrcweir         return tEnv;
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
closeDoc()303cdf0e10cSrcweir     protected void closeDoc() {
304cdf0e10cSrcweir         util.DesktopTools.closeDoc(xTextDoc);
305cdf0e10cSrcweir     }
306cdf0e10cSrcweir }
307