tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleListBox.java
blobdcbef787f591906e7c890ebf8f5aed837beb9c2b
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod._toolkit;
20 import com.sun.star.accessibility.AccessibleRole;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleAction;
23 import com.sun.star.accessibility.XAccessibleComponent;
24 import com.sun.star.accessibility.XAccessibleSelection;
25 import com.sun.star.awt.XExtendedToolkit;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.frame.XController;
29 import com.sun.star.frame.XDispatch;
30 import com.sun.star.frame.XDispatchProvider;
31 import com.sun.star.frame.XModel;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 import com.sun.star.util.URL;
36 import com.sun.star.util.XURLTransformer;
38 import java.io.PrintWriter;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
43 import util.AccessibilityTools;
44 import util.SOfficeFactory;
45 import util.utils;
48 /**
49 * Test for object which is represented accessible component
50 * of 'File type' list box situated in 'Insert Hyperlink'
51 * dialog on tab 'New Document'. <p>
53 * Object implements the following interfaces :
54 * <ul>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
60 * </ul> <p>
62 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
63 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
64 * @see com.sun.star.accessibility.XAccessibleComponent
65 * @see com.sun.star.accessibility.XAccessibleSelection
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see ifc.accessibility._XAccessibleExtendedComponent
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessibleComponent
70 * @see ifc.accessibility._XAccessibleSelection
71 * @see ifc.accessibility._XAccessibleContext
73 public class AccessibleListBox extends TestCase {
74 private static XTextDocument xTextDoc = null;
75 private static XAccessibleAction action = null;
77 /**
78 * Opens 'Insert Hyperlink' dialog using document dispatch provider.
79 * Finds active top window (the dialog
80 * window) and finds button 'Close' (for closing this dialog when
81 * disposing) walking through the accessible component tree.
82 * Then the TREE component is found and the 'New Document' tab is
83 * selected to make list box visible. After that list box is obtained.
85 @Override
86 protected TestEnvironment createTestEnvironment(TestParameters Param,
87 PrintWriter log) throws Exception {
88 XInterface oObj = (XInterface) Param.getMSF().createInstance(
89 "com.sun.star.awt.Toolkit");
91 XExtendedToolkit tk = UnoRuntime.queryInterface(
92 XExtendedToolkit.class, oObj);
94 util.utils.waitForEventIdle(Param.getMSF());
96 XModel aModel1 = UnoRuntime.queryInterface(XModel.class,
97 xTextDoc);
99 XController secondController = aModel1.getCurrentController();
101 XDispatchProvider aProv = UnoRuntime.queryInterface(
102 XDispatchProvider.class,
103 secondController);
105 XURLTransformer urlTransf = null;
107 XInterface transf = (XInterface) Param.getMSF().createInstance(
108 "com.sun.star.util.URLTransformer");
109 urlTransf = UnoRuntime.queryInterface(
110 XURLTransformer.class, transf);
112 XDispatch getting = null;
113 log.println("opening HyperlinkDialog");
115 URL[] url = new URL[1];
116 url[0] = new URL();
117 url[0].Complete = ".uno:HyperlinkDialog";
118 urlTransf.parseStrict(url);
119 getting = aProv.queryDispatch(url[0], "", 0);
121 PropertyValue[] noArgs = new PropertyValue[0];
122 getting.dispatch(url[0], noArgs);
124 util.utils.waitForEventIdle(Param.getMSF());
126 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
127 tk.getActiveTopWindow());
129 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
131 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
134 // obtaining 'Close' button
135 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PUSH_BUTTON,
136 "Close");
137 action = UnoRuntime.queryInterface(
138 XAccessibleAction.class, oObj);
140 // Selecting 'New Document' tab
141 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TREE);
143 XAccessibleSelection xAccSel = UnoRuntime.queryInterface(
144 XAccessibleSelection.class,
145 oObj);
146 xAccSel.selectAccessibleChild(3);
147 util.utils.waitForEventIdle(Param.getMSF());
149 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL, "",
150 "com.sun.star.comp.toolkit.AccessibleListBox");
152 Object list = AccessibilityTools.getAccessibleObjectForRole(AccessibilityTools.SearchedAccessible,
153 AccessibleRole.LIST);
155 log.println("ImplementationName " + utils.getImplName(oObj));
157 TestEnvironment tEnv = new TestEnvironment(oObj);
159 final XAccessibleComponent acomp = UnoRuntime.queryInterface(
160 XAccessibleComponent.class,
161 list);
162 final XAccessibleComponent acomp1 = UnoRuntime.queryInterface(
163 XAccessibleComponent.class,
164 action);
166 tEnv.addObjRelation("EventProducer",
167 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
168 public void fireEvent() {
169 System.out.println("Grabbing focus ... ");
170 acomp1.grabFocus();
171 acomp.grabFocus();
175 return tEnv;
179 * Closes dialog using action of button 'Close'
181 @Override
182 protected void cleanup(TestParameters Param, PrintWriter log) {
183 log.println(" Closing dialog ... ");
185 try {
186 action.doAccessibleAction(0);
187 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
188 log.println("Couldn't close dialog");
189 } catch (com.sun.star.lang.DisposedException de) {
190 log.println("Dialog already disposed");
193 util.DesktopTools.closeDoc(xTextDoc);
197 * Creates writer document
199 @Override
200 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
201 SOfficeFactory SOF = SOfficeFactory.getFactory(
202 Param.getMSF());
203 xTextDoc = SOF.createTextDoc(null);