diff options
author | Colomban Wendling <cwendling@hypra.fr> | 2022-10-19 18:31:43 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2023-01-25 08:22:01 +0000 |
commit | 293db294e3408eda3f3133925fd307011b13c8d8 (patch) | |
tree | aeea87728ca2d6b3607ce80f2abc769376c3e11e /test/source | |
parent | d183daea1abbd7b564d083298874dd7c40d5a5b3 (diff) |
test: Add AccessibilityTools::nameEquals()
Some accessible names contain a suffix when OSL_DEBUG_LEVEL > 0, which
makes it tricky to compare to a known value. To fix that, introduce a
helper that knows how and when to deal with the suffix properly that
can then be used to easily check accessible names.
As we already have a similar, yet private, helper for menu items on
Windows (that include the keybinding label as a suffix), merge the two
together in a unified solution for comparing names.
Change-Id: I7e67edbc7817218ef3e097062d25888172056c21
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142257
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'test/source')
-rw-r--r-- | test/source/a11y/AccessibilityTools.cxx | 41 | ||||
-rw-r--r-- | test/source/a11y/accessibletestbase.cxx | 28 |
2 files changed, 42 insertions, 27 deletions
diff --git a/test/source/a11y/AccessibilityTools.cxx b/test/source/a11y/AccessibilityTools.cxx index 7a89ac2ac80f..8afc1687c889 100644 --- a/test/source/a11y/AccessibilityTools.cxx +++ b/test/source/a11y/AccessibilityTools.cxx @@ -27,8 +27,10 @@ #include <com/sun/star/accessibility/XAccessibleContext.hpp> #include <sal/log.hxx> +#include <toolkit/awt/vclxaccessiblecomponent.hxx> #include <vcl/scheduler.hxx> #include <vcl/timer.hxx> +#include <vcl/window.hxx> using namespace css; @@ -136,6 +138,45 @@ bool AccessibilityTools::equals(const uno::Reference<accessibility::XAccessibleC return equals(xctx1->getAccessibleParent(), xctx2->getAccessibleParent()); } +bool AccessibilityTools::nameEquals(const uno::Reference<accessibility::XAccessibleContext>& xCtx, + const std::u16string_view name) +{ + auto ctxName = xCtx->getAccessibleName(); + OUString rest; + + if (!ctxName.startsWith(name, &rest)) + return false; + if (rest == u"") + return true; + +#if defined(_WIN32) + // see OAccessibleMenuItemComponent::GetAccessibleName(): + // on Win32, ignore a \tSHORTCUT suffix on a menu item + switch (xCtx->getAccessibleRole()) + { + case accessibility::AccessibleRole::MENU_ITEM: + case accessibility::AccessibleRole::RADIO_MENU_ITEM: + case accessibility::AccessibleRole::CHECK_MENU_ITEM: + return rest[0] == '\t'; + + default: + break; + } +#endif + +#if OSL_DEBUG_LEVEL > 0 + // see VCLXAccessibleComponent::getAccessibleName() + auto pVCLXAccessibleComponent = dynamic_cast<VCLXAccessibleComponent*>(xCtx.get()); + if (pVCLXAccessibleComponent) + { + auto windowType = pVCLXAccessibleComponent->GetWindow()->GetType(); + if (rest == u" (Type = " + OUString::number(static_cast<sal_Int32>(windowType)) + ")") + return true; + } +#endif + return false; +} + static OUString unknownName(const sal_Int64 value) { return "unknown (" + OUString::number(value) + ")"; diff --git a/test/source/a11y/accessibletestbase.cxx b/test/source/a11y/accessibletestbase.cxx index 64151644348c..e7732e0d6a7d 100644 --- a/test/source/a11y/accessibletestbase.cxx +++ b/test/source/a11y/accessibletestbase.cxx @@ -193,32 +193,6 @@ void test::AccessibleTestBase::dumpA11YTree( } } -/* see OAccessibleMenuItemComponent::GetAccessibleName() */ -static bool accessibleNameMatches(const uno::Reference<accessibility::XAccessibleContext>& xContext, - std::u16string_view name) -{ - const OUString actualName = xContext->getAccessibleName(); - - if (actualName == name) - return true; - -#if defined(_WIN32) - /* on Win32, ignore a \tSHORTCUT suffix on a menu item */ - switch (xContext->getAccessibleRole()) - { - case accessibility::AccessibleRole::MENU_ITEM: - case accessibility::AccessibleRole::RADIO_MENU_ITEM: - case accessibility::AccessibleRole::CHECK_MENU_ITEM: - return actualName.startsWith(name) && actualName[name.length()] == '\t'; - - default: - break; - } -#endif - - return false; -} - /** Gets a child by name (usually in a menu) */ uno::Reference<accessibility::XAccessibleContext> test::AccessibleTestBase::getItemFromName( const uno::Reference<accessibility::XAccessibleContext>& xMenuCtx, std::u16string_view name) @@ -230,7 +204,7 @@ uno::Reference<accessibility::XAccessibleContext> test::AccessibleTestBase::getI for (sal_Int64 i = 0; i < childCount && i < AccessibilityTools::MAX_CHILDREN; i++) { auto item = xMenuCtx->getAccessibleChild(i)->getAccessibleContext(); - if (accessibleNameMatches(item, name)) + if (AccessibilityTools::nameEquals(item, name)) { std::cout << "-> found " << AccessibilityTools::debugString(item) << std::endl; return item; |