tdf#157003 a11y: Replace AccessibleDropDownListBox Java with C++ test

Remove the existing Java AccessibleDropDownListBox
tests and introduce a new C++/cppunit test that
takes a bit of a different approach:

Other than

    commit d2a5b4bc0b
    Date:   Tue Apr 26 16:56:56 2022 +0200

        toolkit: convert AccessibleStatusBar test to C++

        Just translate the test and add required or handy CppUnit helpers.

which basically translated the existing AccessibleStatusBar
test as is to C++/cppunit, don't do the same here,
but:

1) Move the test from toolkit to vcl, where the a11y
implementations for vcl widgets are located since

    commit 9283da8585
    Author: Michael Weghorn <m.weghorn@posteo.de>
    Date:   Tue Dec 17 12:04:04 2024 +0100

        a11y: Merge accessibility module into vcl

2) Instead of starting Writer and then searching for
the accessible object of the dropdown listbox in the
a11y tree, only create a simple dialog that contains
a dropdown listbox (VCL ListBox with WB_DROPDOWN set).
This minimizes the complexity/a11y tree to the object
of interest.

Apart from that, the general logic of what aspects are
tested is mostly unchanged, now using the C++ helpers
introduced in the above-mentioned d2a5b4bc0b
(and later commits) to test the various XAccessible* interfaces.

The XAccessibleEventBroadcaster interface is no more
explicitly tested, since the XAccessibleEventBroadcasterTester
would require an XWindow again.
However, the logic is implemented in the VCLXAccessibleComponent
subclass used by almost all widgets (vcl::Window subclasses), so
not explicitly testing it here shouldn't be a problem.

Change-Id: I61bfff515c5e9f7e2d18b9279861c09ceede403e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182986
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2025-03-15 20:23:02 -07:00
parent 2041fbab92
commit 132f22d9f6
7 changed files with 119 additions and 156 deletions

View File

@@ -1146,7 +1146,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\
qadevOOo/tests/java/mod/_toolkit/AccessibleCheckBox \
qadevOOo/tests/java/mod/_toolkit/AccessibleComboBox \
qadevOOo/tests/java/mod/_toolkit/AccessibleDropDownComboBox \
qadevOOo/tests/java/mod/_toolkit/AccessibleDropDownListBox \
qadevOOo/tests/java/mod/_toolkit/AccessibleEdit \
qadevOOo/tests/java/mod/_toolkit/AccessibleFixedText \
qadevOOo/tests/java/mod/_toolkit/AccessibleList \

View File

@@ -1,27 +0,0 @@
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleExtendedComponent";"getTitledBorderText()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleExtendedComponent";"getToolTipText()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleEventBroadcaster#optional";"addEventListener()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleEventBroadcaster#optional";"removeEventListener()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"containsPoint()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"getAccessibleAtPoint()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"getBounds()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"getLocation()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"getLocationOnScreen()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"getSize()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"grabFocus()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"getForeground()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleComponent";"getBackground()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleAction";"getAccessibleActionCount()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleAction";"doAccessibleAction()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleAction";"getAccessibleActionDescription()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleAction";"getAccessibleActionKeyBinding()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleChildCount()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleChild()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleParent()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleIndexInParent()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleRole()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleDescription()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleName()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleRelationSet()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getAccessibleStateSet()"
"AccessibleDropDownListBox";"com::sun::star::accessibility::XAccessibleContext";"getLocale()"
1 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleExtendedComponent getTitledBorderText()
2 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleExtendedComponent getToolTipText()
3 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleEventBroadcaster#optional addEventListener()
4 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleEventBroadcaster#optional removeEventListener()
5 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent containsPoint()
6 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent getAccessibleAtPoint()
7 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent getBounds()
8 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent getLocation()
9 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent getLocationOnScreen()
10 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent getSize()
11 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent grabFocus()
12 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent getForeground()
13 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleComponent getBackground()
14 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleAction getAccessibleActionCount()
15 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleAction doAccessibleAction()
16 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleAction getAccessibleActionDescription()
17 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleAction getAccessibleActionKeyBinding()
18 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleChildCount()
19 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleChild()
20 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleParent()
21 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleIndexInParent()
22 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleRole()
23 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleDescription()
24 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleName()
25 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleRelationSet()
26 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getAccessibleStateSet()
27 AccessibleDropDownListBox com::sun::star::accessibility::XAccessibleContext getLocale()

View File

@@ -1,127 +0,0 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package mod._toolkit;
import com.sun.star.accessibility.AccessibleRole;
import com.sun.star.accessibility.XAccessible;
import com.sun.star.accessibility.XAccessibleAction;
import com.sun.star.awt.XWindow;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import java.io.PrintWriter;
import lib.StatusException;
import lib.TestCase;
import lib.TestEnvironment;
import lib.TestParameters;
import util.AccessibilityTools;
import util.DesktopTools;
import util.SOfficeFactory;
import util.utils;
/**
* Test for object which is represented by style list box
* on toolbar of a document. <p>
*
* Object implements the following interfaces :
* <ul>
* <li> <code>::com::sun::star::accessibility::XAccessibleExtendedComponent</code></li>
* <li> <code>::com::sun::star::accessibility::XAccessibleEventBroadcaster</code></li>
* <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
* <li> <code>::com::sun::star::accessibility::XAccessibleAction</code></li>
* <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
* </ul> <p>
*
* @see com.sun.star.accessibility.XAccessibleExtendedComponent
* @see com.sun.star.accessibility.XAccessibleEventBroadcaster
* @see com.sun.star.accessibility.XAccessibleComponent
* @see com.sun.star.accessibility.XAccessibleAction
* @see com.sun.star.accessibility.XAccessibleContext
* @see ifc.accessibility._XAccessibleExtendedComponent
* @see ifc.accessibility._XAccessibleEventBroadcaster
* @see ifc.accessibility._XAccessibleComponent
* @see ifc.accessibility._XAccessibleAction
* @see ifc.accessibility._XAccessibleContext
*/
public class AccessibleDropDownListBox extends TestCase {
private static XTextDocument xTextDoc = null;
/**
* Finds AccessibleDropDownListBox walking through the
* accessible component tree of a writer document.
*/
@Override
protected TestEnvironment createTestEnvironment(TestParameters Param,
PrintWriter log) {
XInterface oObj = null;
util.utils.waitForEventIdle(Param.getMSF());
XWindow xWindow = AccessibilityTools.getCurrentWindow(
xTextDoc);
XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.COMBO_BOX,
"", "AccessibleDropDownListBox");
log.println("ImplementationName " + utils.getImplName(oObj));
TestEnvironment tEnv = new TestEnvironment(oObj);
final XAccessibleAction acomp = UnoRuntime.queryInterface(
XAccessibleAction.class, oObj);
tEnv.addObjRelation("EventProducer",
new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
public void fireEvent() {
try {
acomp.doAccessibleAction(0);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
throw new StatusException("Can't perform action 0", e);
}
}
});
return tEnv;
}
/**
* Creates writer document.
*/
@Override
protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
SOfficeFactory SOF = SOfficeFactory.getFactory(
Param.getMSF());
// Dock the Navigator to supply an AccessibleDropDownListBox
DesktopTools.dockNavigator(Param.getMSF());
xTextDoc = SOF.createTextDoc(null);
}
/**
* Disposes writer document.
*/
@Override
protected void cleanup(TestParameters Param, PrintWriter log) {
util.DesktopTools.closeDoc(xTextDoc);
}
}

View File

@@ -20,7 +20,6 @@
#i88332 -o toolkit.AccessibleCheckBox
#i86008 -o toolkit.AccessibleComboBox
-o toolkit.AccessibleDropDownComboBox
-o toolkit.AccessibleDropDownListBox
#i86110 -o toolkit.AccessibleEdit
-o toolkit.AccessibleFixedText
#i86110 -o toolkit.AccessibleList

View File

@@ -0,0 +1,37 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_CppunitTest_CppunitTest,vcl_a11y))
$(eval $(call gb_CppunitTest_add_exception_objects,vcl_a11y, \
vcl/qa/cppunit/a11y/widgetaccessibilitytest \
))
$(eval $(call gb_CppunitTest_use_libraries,vcl_a11y, \
sal \
cppu \
subsequenttest \
test \
vcl \
))
$(eval $(call gb_CppunitTest_use_api,vcl_a11y,\
offapi \
udkapi \
))
$(eval $(call gb_CppunitTest_use_sdk_api,vcl_a11y))
$(eval $(call gb_CppunitTest_use_rdb,vcl_a11y,services))
$(eval $(call gb_CppunitTest_use_ure,vcl_a11y))
$(eval $(call gb_CppunitTest_use_vcl,vcl_a11y))
$(eval $(call gb_CppunitTest_use_instdir_configuration,vcl_a11y))
$(eval $(call gb_CppunitTest_use_common_configuration,vcl_a11y))
# vim: set noet sw=4 ts=4:

View File

@@ -85,6 +85,7 @@ $(eval $(call gb_Module_add_targets,vcl,\
ifneq ($(ENABLE_ATSPI_TESTS),)
$(eval $(call gb_Module_add_check_targets,vcl,\
CppunitTest_vcl_a11y \
CppunitTest_vcl_gtk3_a11y \
))
endif

View File

@@ -0,0 +1,81 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#define VCL_INTERNALS
#include <com/sun/star/accessibility/XAccessibleAction.hpp>
#include <com/sun/star/accessibility/XAccessibleComponent.hpp>
#include <com/sun/star/accessibility/XAccessibleExtendedAttributes.hpp>
#include <com/sun/star/accessibility/XAccessibleExtendedComponent.hpp>
#include <test/a11y/AccessibilityTools.hxx>
#include <test/a11y/accessibletestbase.hxx>
#include <test/a11y/XAccessibleActionTester.hxx>
#include <test/a11y/XAccessibleComponentTester.hxx>
#include <test/a11y/XAccessibleContextTester.hxx>
#include <test/a11y/XAccessibleExtendedComponentTester.hxx>
#include <vcl/toolkit/dialog.hxx>
#include <vcl/toolkit/lstbox.hxx>
CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, AccessibleDropDownListBox)
{
// create and show dialog that contains a dropdown listbox
ScopedVclPtr<::Dialog> pDialog = VclPtr<::Dialog>::Create(nullptr, WB_MOVEABLE | WB_CLOSEABLE,
::Dialog::InitFlag::NoParent);
VclPtr<ListBox> pListBox = VclPtr<ListBox>::Create(pDialog, WB_DROPDOWN);
pListBox->InsertEntry(u"First Entry"_ustr);
pListBox->InsertEntry(u"Second Entry"_ustr);
pListBox->SetSizePixel(pListBox->get_preferred_size());
pListBox->Show();
pDialog->Show();
// perform various a11y checks on the dropdown listbox
css::uno::Reference<css::accessibility::XAccessible> xListBoxAcc = pListBox->GetAccessible();
CPPUNIT_ASSERT(xListBoxAcc.is());
css::uno::Reference<css::accessibility::XAccessibleContext> xContext
= xListBoxAcc->getAccessibleContext();
CPPUNIT_ASSERT(xContext.is());
CPPUNIT_ASSERT_EQUAL_MESSAGE("Drop down listbox has incorrect role",
css::accessibility::AccessibleRole::COMBO_BOX,
xContext->getAccessibleRole());
XAccessibleContextTester aContextTester(xContext);
aContextTester.testAll();
css::uno::Reference<css::accessibility::XAccessibleComponent> xAccessibleComponent(
xContext, css::uno::UNO_QUERY_THROW);
XAccessibleComponentTester aComponentTester(xAccessibleComponent);
aComponentTester.testAll();
css::uno::Reference<css::accessibility::XAccessibleExtendedComponent>
xAccessibleExtendedComponent(xContext, css::uno::UNO_QUERY_THROW);
XAccessibleExtendedComponentTester aExtendedComponentTester(xAccessibleExtendedComponent);
aExtendedComponentTester.testAll();
css::uno::Reference<css::accessibility::XAccessibleAction> xAccessibleAction(
xContext, css::uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_MESSAGE("No accessible action provided",
xAccessibleAction->getAccessibleActionCount() > 0);
XAccessibleActionTester aActionTester(xAccessibleAction);
aActionTester.testAll();
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */