tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleButton.java
blob299e366dcd78efd37b459a0769e208300e432de9
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.XAccessibleText;
25 import com.sun.star.awt.XExtendedToolkit;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.frame.XController;
28 import com.sun.star.frame.XDispatch;
29 import com.sun.star.frame.XDispatchProvider;
30 import com.sun.star.frame.XModel;
31 import com.sun.star.lang.XMultiServiceFactory;
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.TestEnvironment;
41 import lib.TestParameters;
42 import util.AccessibilityTools;
43 import util.SOfficeFactory;
44 import util.utils;
46 /**
47 * Object implements the following interfaces :
48 * <ul>
49 * <li>
50 * <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
51 * <li>
52 * <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
56 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
58 * </ul>
59 * <p>
61 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
63 * @see com.sun.star.accessibility.XAccessibleComponent
64 * @see com.sun.star.accessibility.XAccessibleValue
65 * @see com.sun.star.accessibility.XAccessibleAction
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see com.sun.star.accessibility.XAccessibleText
68 * @see ifc.accessibility._XAccessibleExtendedComponent
69 * @see ifc.accessibility._XAccessibleEventBroadcaster
70 * @see ifc.accessibility._XAccessibleComponent
71 * @see ifc.accessibility._XAccessibleValue
72 * @see ifc.accessibility._XAccessibleAction
73 * @see ifc.accessibility._XAccessibleContext
74 * @see ifc.accessibility._XAccessibleText
76 public class AccessibleButton extends lib.TestCase {
77 private static XTextDocument xTextDoc = null;
78 private static XAccessibleAction action = null;
80 /**
81 * Opens 'Printer Settings' dialog using document dispatch provider running
82 * in a separate thread. Finds active top window (the dialog window) and
83 * finds accessible button 'OK' walking through the accessible component
84 * tree.
86 @Override
87 protected TestEnvironment createTestEnvironment(TestParameters Param,
88 PrintWriter log) throws Exception {
89 XInterface oObj = null;
90 XMultiServiceFactory msf = Param.getMSF();
92 oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
94 XExtendedToolkit tk = UnoRuntime.queryInterface(XExtendedToolkit.class,
95 oObj);
97 util.utils.waitForEventIdle(Param.getMSF());
99 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
101 XController xController = aModel.getCurrentController();
103 // Opening PrinterSetupDialog
104 String aSlotID = ".uno:Zoom";
105 XDispatchProvider xDispProv = UnoRuntime.queryInterface(
106 XDispatchProvider.class, xController);
107 XURLTransformer xParser = UnoRuntime.queryInterface(
108 XURLTransformer.class,
109 msf.createInstance("com.sun.star.util.URLTransformer"));
111 // Because it's an in/out parameter
112 // we must use an array of URL objects.
113 URL[] aParseURL = new URL[] { new URL() };
114 aParseURL[0].Complete = aSlotID;
115 xParser.parseStrict(aParseURL);
117 XDispatch xDispatcher = xDispProv.queryDispatch(aParseURL[0], "", 0);
118 if (xDispatcher != null) {
119 xDispatcher.dispatch(aParseURL[0], null);
122 util.utils.waitForEventIdle(msf);
124 Object atw = tk.getActiveTopWindow();
126 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, atw);
128 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
130 AccessibilityTools.printAccessibleTree(log, xRoot,
131 Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
132 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
133 AccessibleRole.PUSH_BUTTON, "Cancel");
135 log.println("ImplementationName " + utils.getImplName(oObj));
137 TestEnvironment tEnv = new TestEnvironment(oObj);
139 action = UnoRuntime.queryInterface(XAccessibleAction.class, oObj);
141 final XAccessibleComponent acomp = UnoRuntime.queryInterface(
142 XAccessibleComponent.class, oObj);
144 tEnv.addObjRelation(
145 "EventProducer",
146 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
147 public void fireEvent() {
148 System.out.println("Grabbing focus ... ");
149 acomp.grabFocus();
153 XAccessibleText text = UnoRuntime.queryInterface(XAccessibleText.class,
154 oObj);
156 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
158 tEnv.addObjRelation("EditOnly",
159 "This method isn't supported in this component");
161 tEnv.addObjRelation("LimitedBounds", "yes");
163 return tEnv;
167 * Closes the dialog using accessible button 'OK' found in
168 * <code>createTestEnvironment()</code>.
170 @Override
171 protected void cleanup(TestParameters Param, PrintWriter log) {
172 log.println(" disposing xTextDoc ");
174 try {
175 action.doAccessibleAction(0);
176 } catch (com.sun.star.lang.IndexOutOfBoundsException ioe) {
177 log.println("Couldn't close dialog");
178 } catch (com.sun.star.lang.DisposedException de) {
179 log.println("Dialog already disposed");
182 util.DesktopTools.closeDoc(xTextDoc);
186 * Opens new writer document.
188 @Override
189 protected void initialize(TestParameters Param, PrintWriter log)
190 throws Exception {
191 SOfficeFactory SOF = SOfficeFactory.getFactory(Param.getMSF());
192 xTextDoc = SOF.createTextDoc(null);