diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-11-08 13:56:08 +0100 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-11-08 16:55:08 +0100 |
commit | 39b15dc8f0adec9e856a39cf319c7c8ae6750043 (patch) | |
tree | b9633fb0c58e910e309618846a690a834e98ec42 | |
parent | 4b7316e2ff6e63bbf73e0bcf04f90b807d9829ad (diff) |
tdf#155447 a11y: Add test for accessible IDs expected by Orca
Add a new AccessibilityTools::getAccessibleObjectForId
helper that can be used in a11y tests to identify an object
by its accessible ID.
Add a test that checks that the accessible ID of the
spelling dialog matches what Orca's logic expects
in order to identify it, and that more UI elements
with expected accessible IDs exist.
This is to prevent breaking Orca logic without noticing.
Any changes affecting this test should be discussed with
the Orca maintainer first.
See the comment above the newly added test for more details
and a link to the corresponding Orca commits.
The new test initially only checks that objects with corresponding
IDs exist, could be extended to verify more of their
properties as needed.
Logic for checking availability of a dictionary, needed for
spell check was taken over from the existing tdf155705 test in
sw/qa/extras/accessibility/tdf155705.cxx, whose sample doc
is also used.
Change-Id: I0c5629272a89a4a570e080e62e99b6c105369cf9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176281
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r-- | include/test/a11y/AccessibilityTools.hxx | 8 | ||||
-rw-r--r-- | sw/qa/extras/accessibility/dialogs.cxx | 55 | ||||
-rw-r--r-- | test/source/a11y/AccessibilityTools.cxx | 17 |
3 files changed, 80 insertions, 0 deletions
diff --git a/include/test/a11y/AccessibilityTools.hxx b/include/test/a11y/AccessibilityTools.hxx index 10d67f2a5338..687275b097a7 100644 --- a/include/test/a11y/AccessibilityTools.hxx +++ b/include/test/a11y/AccessibilityTools.hxx @@ -52,6 +52,14 @@ public: const css::uno::Reference<css::accessibility::XAccessible>& xAcc, const std::function< bool(const css::uno::Reference<css::accessibility::XAccessibleContext>&)>& cPredicate); + + static css::uno::Reference<css::accessibility::XAccessibleContext> getAccessibleObjectForId( + const css::uno::Reference<css::accessibility::XAccessibleContext>& xCtx, + std::u16string_view sId); + static css::uno::Reference<css::accessibility::XAccessibleContext> + getAccessibleObjectForId(const css::uno::Reference<css::accessibility::XAccessible>& xacc, + std::u16string_view sId); + static css::uno::Reference<css::accessibility::XAccessibleContext> getAccessibleObjectForRole( const css::uno::Reference<css::accessibility::XAccessibleContext>& xCtx, sal_Int16 role); static css::uno::Reference<css::accessibility::XAccessibleContext> diff --git a/sw/qa/extras/accessibility/dialogs.cxx b/sw/qa/extras/accessibility/dialogs.cxx index 18662ce7cd9b..1072a2c47b1f 100644 --- a/sw/qa/extras/accessibility/dialogs.cxx +++ b/sw/qa/extras/accessibility/dialogs.cxx @@ -9,6 +9,10 @@ #include <com/sun/star/awt/Key.hpp> #include <com/sun/star/accessibility/AccessibleRole.hpp> +#include <com/sun/star/accessibility/XAccessibleContext2.hpp> +#include <com/sun/star/linguistic2/LinguServiceManager.hpp> +#include <com/sun/star/linguistic2/XLinguServiceManager2.hpp> +#include <com/sun/star/linguistic2/XSpellChecker1.hpp> #include <vcl/scheduler.hxx> @@ -16,6 +20,7 @@ #include <test/a11y/AccessibilityTools.hxx> using namespace css; +using namespace css::accessibility; // FIXME: dialog API doesn't work on macos yet #if !defined(MACOSX) @@ -190,6 +195,56 @@ CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestFrameDialog) collectText()); } +/* Verify that UI elements in the spell check dialog have the accessible IDs + * set that that Orca screen reader's logic to identify them depends on, + * see tdf#155447 and following Orca commits: + * + * https://gitlab.gnome.org/GNOME/orca/-/commit/6221f4ecf542646a80e47ee7236380360f0e1a85 + * https://gitlab.gnome.org/GNOME/orca/-/commit/40a2d302eb52295433fd84e6c254a7dbe5108a24 + * + * (Changes should be discussed with the Orca maintainer first.) + * + * While the Orca logic depends only on case-insensitive name starting + * with a certain string, this test uses the full accessible ID + * (which matches the GtkBuilder ID in ./cui/uiconfig/ui/spellingdialog.ui) + * in order to identify the elements. + */ +CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, SpellingDialog) +{ + // spell check depends on dictionary being available, so skip test if unavailable + uno::Reference<linguistic2::XLinguServiceManager2> xLSM2 + = linguistic2::LinguServiceManager::create(m_xContext); + uno::Reference<linguistic2::XSpellChecker1> xSpell(xLSM2->getSpellChecker(), uno::UNO_QUERY); + if (!xSpell.is() || !xSpell->hasLanguage(static_cast<sal_uInt16>(LANGUAGE_ENGLISH_US))) + return; + + loadFromSrc(u"/sw/qa/extras/accessibility/testdocuments/tdf155705.fodt"_ustr); + + auto dialogWaiter = awaitDialog(u"Spelling: English (USA)", [](Dialog& dialog) { + uno::Reference<XAccessible> xDialogAcc = dialog.getAccessible(); + + uno::Reference<XAccessibleContext2> xDialogContext(xDialogAcc->getAccessibleContext(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xDialogContext.is()); + CPPUNIT_ASSERT_EQUAL(u"SpellingDialog"_ustr, xDialogContext->getAccessibleId()); + + uno::Reference<XAccessibleContext> xSentenceAcc + = AccessibilityTools::getAccessibleObjectForId(xDialogContext, u"errorsentence"); + CPPUNIT_ASSERT(xSentenceAcc.is()); + + uno::Reference<XAccessibleContext> xSuggestionsAcc + = AccessibilityTools::getAccessibleObjectForId(xDialogContext, u"suggestionslb"); + CPPUNIT_ASSERT(xSuggestionsAcc.is()); + + CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::PUSH_BUTTON, u"Close")); + dialog.postKeyEventAsync(0, awt::Key::RETURN); + Scheduler::ProcessEventsToIdle(); + }); + + CPPUNIT_ASSERT(activateMenuItem(u"Tools", u"Spelling...")); + CPPUNIT_ASSERT(dialogWaiter->waitEndDialog()); +} + #endif //defined(MACOSX) /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/a11y/AccessibilityTools.cxx b/test/source/a11y/AccessibilityTools.cxx index e972836198c7..b91d431db9b5 100644 --- a/test/source/a11y/AccessibilityTools.cxx +++ b/test/source/a11y/AccessibilityTools.cxx @@ -70,6 +70,23 @@ AccessibilityTools::getAccessibleObjectForPredicate( return getAccessibleObjectForPredicate(xAcc->getAccessibleContext(), cPredicate); } +uno::Reference<accessibility::XAccessibleContext> AccessibilityTools::getAccessibleObjectForId( + const uno::Reference<accessibility::XAccessibleContext>& xCtx, std::u16string_view sId) +{ + return getAccessibleObjectForPredicate( + xCtx, [&](const uno::Reference<accessibility::XAccessibleContext>& xObjCtx) { + uno::Reference<accessibility::XAccessibleContext2> xContext2(xObjCtx, uno::UNO_QUERY); + return (xContext2 && xContext2->getAccessibleId() == sId); + }); +} + +css::uno::Reference<css::accessibility::XAccessibleContext> +AccessibilityTools::getAccessibleObjectForId( + const css::uno::Reference<css::accessibility::XAccessible>& xacc, const std::u16string_view sId) +{ + return getAccessibleObjectForId(xacc->getAccessibleContext(), sId); +} + uno::Reference<accessibility::XAccessibleContext> AccessibilityTools::getAccessibleObjectForRole( const uno::Reference<accessibility::XAccessibleContext>& xCtx, sal_Int16 role) { |