tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleMenuItem.java
blob0e9fa36ead5352de027eb32cbea9c985c8713b5a
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.XAccessibleContext;
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.lang.XMultiServiceFactory;
28 import com.sun.star.text.XTextDocument;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
32 import java.io.PrintWriter;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 import util.AccessibilityTools;
38 import util.SOfficeFactory;
39 import util.utils;
42 /**
43 * Test for object which is represented by accessible component
44 * of a menu item in main menu of a document. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
49 * <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
50 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
51 * <li> <code>::com::sun::star::accessibility::XAccessibleValue</code></li>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleText</code></li>
55 * </ul> <p>
57 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
58 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
59 * @see com.sun.star.accessibility.XAccessibleComponent
60 * @see com.sun.star.accessibility.XAccessibleValue
61 * @see com.sun.star.accessibility.XAccessibleAction
62 * @see com.sun.star.accessibility.XAccessibleContext
63 * @see com.sun.star.accessibility.XAccessibleText
64 * @see ifc.accessibility._XAccessibleExtendedComponent
65 * @see ifc.accessibility._XAccessibleEventBroadcaster
66 * @see ifc.accessibility._XAccessibleComponent
67 * @see ifc.accessibility._XAccessibleValue
68 * @see ifc.accessibility._XAccessibleAction
69 * @see ifc.accessibility._XAccessibleContext
70 * @see ifc.accessibility._XAccessibleText
72 public class AccessibleMenuItem extends TestCase {
73 private static XTextDocument xTextDoc = null;
74 private static XMultiServiceFactory msf = null;
76 /**
77 * Finds first accessible component with role <code>MENUITEM</code>
78 * walking through the accessible component tree of a document.
80 @Override
81 protected TestEnvironment createTestEnvironment(TestParameters Param,
82 PrintWriter log) throws Exception {
83 XInterface oObj = (XInterface) msf.createInstance("com.sun.star.awt.Toolkit");
85 XExtendedToolkit tk = UnoRuntime.queryInterface(
86 XExtendedToolkit.class, oObj);
88 util.utils.waitForEventIdle(Param.getMSF());
90 Object atw = tk.getActiveTopWindow();
92 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
93 atw);
95 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
97 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
98 XAccessibleContext MenuBar = AccessibilityTools.getAccessibleObjectForRole(xRoot,
99 AccessibleRole.MENU_BAR);
101 try {
102 //activate Edit-Menu
103 XAccessible Menu = MenuBar.getAccessibleChild(1);
104 XAccessibleAction act = UnoRuntime.queryInterface(
105 XAccessibleAction.class, Menu);
106 act.doAccessibleAction(0);
107 util.utils.waitForEventIdle(Param.getMSF());
109 //get a menu-item
110 oObj = Menu.getAccessibleContext().getAccessibleChild(11);
111 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
115 log.println("ImplementationName " + utils.getImplName(oObj));
117 TestEnvironment tEnv = new TestEnvironment(oObj);
119 final XAccessibleAction action = UnoRuntime.queryInterface(
120 XAccessibleAction.class, oObj);
122 tEnv.addObjRelation("EventProducer",
123 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
124 public void fireEvent() {
125 try {
126 action.doAccessibleAction(0);
127 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
132 XAccessibleText text = UnoRuntime.queryInterface(
133 XAccessibleText.class, oObj);
135 tEnv.addObjRelation("XAccessibleText.Text", text.getText());
137 tEnv.addObjRelation("EditOnly",
138 "Can't change or select Text in MenuBarItem");
140 tEnv.addObjRelation("Destroy", Boolean.TRUE);
142 tEnv.addObjRelation("LimitedBounds", "yes");
144 return tEnv;
148 * Creates writer document.
150 @Override
151 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
152 msf = Param.getMSF();
154 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
155 xTextDoc = SOF.createTextDoc(null);
159 * Disposes document.
161 @Override
162 protected void cleanup(TestParameters Param, PrintWriter log) {
163 util.DesktopTools.closeDoc(xTextDoc);