From 3cf9ebf5841d363da85e700fe7acc4ebe5be52ca Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Mon, 26 May 2025 08:26:37 +0200 Subject: [PATCH] [API CHANGE] uitest: Add API to get XUIObject for specific XWindow Add a XUITest::getWindow method that allows to get the XUIObject for a given XWindow. The XUITest interface is internal/unpublished API used for UI tests. The newly introduced method will be used in an upcoming commit in sw/qa/uitest/table/tdf146145.py to port that test away from depending on a11y implementation details that are about to change. Change-Id: I6fcbee3ce894ad82ec42fa034b85544b50408779 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185773 Tested-by: Jenkins Reviewed-by: Michael Weghorn --- offapi/com/sun/star/ui/test/XUITest.idl | 6 ++++++ vcl/source/uitest/uno/uitest_uno.cxx | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/offapi/com/sun/star/ui/test/XUITest.idl b/offapi/com/sun/star/ui/test/XUITest.idl index 201791d88df4..e4fd1d30aa19 100644 --- a/offapi/com/sun/star/ui/test/XUITest.idl +++ b/offapi/com/sun/star/ui/test/XUITest.idl @@ -21,6 +21,12 @@ interface XUITest XUIObject getTopFocusWindow(); XUIObject getFloatWindow(); + + /** Get the XUIObject for the given window. + + @since LibreOffice 25.8 + */ + XUIObject getWindow([in] ::com::sun::star::awt::XWindow xWindow); }; }; }; }; }; }; diff --git a/vcl/source/uitest/uno/uitest_uno.cxx b/vcl/source/uitest/uno/uitest_uno.cxx index a96371daba38..c49422877e8a 100644 --- a/vcl/source/uitest/uno/uitest_uno.cxx +++ b/vcl/source/uitest/uno/uitest_uno.cxx @@ -17,6 +17,7 @@ #include #include +#include #include #include "uiobject_uno.hxx" @@ -44,6 +45,9 @@ public: css::uno::Reference SAL_CALL getFloatWindow() override; + css::uno::Reference + SAL_CALL getWindow(const css::uno::Reference& xWindow) override; + OUString SAL_CALL getImplementationName() override; sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; @@ -94,6 +98,20 @@ css::uno::Reference SAL_CALL UITestUnoObj::getFloatWin return new UIObjectUnoObj(std::move(pObj)); } +css::uno::Reference + SAL_CALL UITestUnoObj::getWindow(const css::uno::Reference<::css::awt::XWindow>& xWindow) +{ + if (!xWindow.is()) + return {}; + + UnoWrapperBase* pWrapper = UnoWrapperBase::GetUnoWrapper(); + assert(pWrapper); + VclPtr pWindow = pWrapper->GetWindow(xWindow); + assert(pWindow); + + return new UIObjectUnoObj(pWindow->GetUITestFactory()(pWindow)); +} + OUString SAL_CALL UITestUnoObj::getImplementationName() { return u"org.libreoffice.uitest.UITest"_ustr;