LibreOffice Module test (master) 1
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
test::AccessibleTestBase Class Reference

#include <accessibletestbase.hxx>

Inheritance diagram for test::AccessibleTestBase:
[legend]
Collaboration diagram for test::AccessibleTestBase:
[legend]

Classes

class  Dialog
 
class  DialogWaiter
 

Public Member Functions

virtual void setUp () override
 
virtual void tearDown () override
 
- Public Member Functions inherited from test::BootstrapFixture
 DECL_DLLPRIVATE_STATIC_LINK (BootstrapFixture, ImplInitFilterHdl, ConvertData &, bool)
 
 BootstrapFixture (bool bAssertOnDialog=true, bool bNeedUCB=true)
 
virtual ~BootstrapFixture () override
 
virtual void setUp () override
 
void validate (const OUString &rURL, ValidationFormat) const
 
- Public Member Functions inherited from test::BootstrapFixtureBase
 BootstrapFixtureBase ()
 
virtual ~BootstrapFixtureBase () override
 
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext () const
 
const css::uno::Reference< css::lang::XMultiServiceFactory > & getMultiServiceFactory () const
 
virtual void setUp () override
 
virtual void tearDown () override
 

Protected Member Functions

virtual void load (const rtl::OUString &sURL)
 
virtual void loadFromSrc (const rtl::OUString &sSrcPath)
 
void close ()
 
css::uno::Reference< css::accessibility::XAccessibleContext > getWindowAccessibleContext ()
 
virtual css::uno::Reference< css::accessibility::XAccessibleContext > getDocumentAccessibleContext ()
 
void documentPostKeyEvent (int nType, int nCharCode, int nKeyCode)
 
virtual std::deque< css::uno::Reference< css::accessibility::XAccessibleContext > > getAllChildren (const css::uno::Reference< css::accessibility::XAccessibleContext > &xContext)
 Tries to list all children of an accessible. More...
 
void dumpA11YTree (const css::uno::Reference< css::accessibility::XAccessibleContext > &xContext, const int depth=0)
 Prints the tree of accessible objects starting at xContext to stdout. More...
 
css::uno::Reference< css::accessibility::XAccessibleContext > getItemFromName (const css::uno::Reference< css::accessibility::XAccessibleContext > &xMenuCtx, std::u16string_view name)
 
bool activateMenuItem (const css::uno::Reference< css::accessibility::XAccessibleAction > &xAction)
 
bool activateMenuItem (const css::uno::Reference< css::accessibility::XAccessibleContext > &xCtx)
 
template<typename... Ts>
css::uno::Reference< css::accessibility::XAccessibleContext > getItemFromName (const css::uno::Reference< css::accessibility::XAccessibleContext > &xMenuCtx, std::u16string_view name, Ts... names)
 
template<typename... Ts>
bool activateMenuItem (const css::uno::Reference< css::accessibility::XAccessibleContext > &xMenuCtx, Ts... names)
 
template<typename... Ts>
bool activateMenuItem (Ts... names)
 

Static Protected Member Functions

static bool isDocumentRole (const sal_Int16 role)
 
static css::uno::Reference< css::accessibility::XAccessibleContext > getFirstRelationTargetOfType (const css::uno::Reference< css::accessibility::XAccessibleContext > &xContext, sal_Int16 relationType)
 
static css::uno::Reference< css::accessibility::XAccessibleContext > getFocusedObject (const css::uno::Reference< css::accessibility::XAccessibleContext > &xCtx)
 Gets the focused accessible object at xAcc level or below. More...
 
static css::uno::Reference< css::accessibility::XAccessibleContext > getFocusedObject (const css::uno::Reference< css::accessibility::XAccessible > &xAcc)
 
static css::uno::Reference< css::accessibility::XAccessibleContext > tabTo (const css::uno::Reference< css::accessibility::XAccessible > &xRoot, const sal_Int16 role, const std::u16string_view name, const EventPosterHelperBase *pEventPosterHelper=nullptr)
 Navigates through focusable elements using the Tab keyboard shortcut. More...
 
static bool tabTo (const css::uno::Reference< css::accessibility::XAccessible > &xRoot, const css::uno::Reference< css::accessibility::XAccessibleContext > &xChild, const EventPosterHelperBase *pEventPosterHelper=nullptr)
 
static std::shared_ptr< DialogWaiterawaitDialog (const std::u16string_view name, std::function< void(Dialog &)> callback, bool bAutoClose=true)
 Helper to call user code when a given dialog opens. More...
 
- Static Protected Member Functions inherited from test::BootstrapFixture
static bool IsDefaultDPI ()
 
static std::pair< double, double > getDPIScaling ()
 

Protected Attributes

css::uno::Reference< css::frame::XDesktop2 > mxDesktop
 
css::uno::Reference< css::lang::XComponent > mxDocument
 
css::uno::Reference< css::awt::XWindow > mxWindow
 
- Protected Attributes inherited from test::BootstrapFixture
css::uno::Reference< css::uno::XComponentContext > mxComponentContext
 
- Protected Attributes inherited from test::BootstrapFixtureBase
Directories m_directories
 
css::uno::Reference< css::uno::XComponentContext > m_xContext
 
css::uno::Reference< css::lang::XMultiServiceFactory > m_xSFactory
 
css::uno::Reference< css::lang::XMultiComponentFactory > m_xFactory
 

Additional Inherited Members

- Static Public Member Functions inherited from test::BootstrapFixture
static sal_uInt16 getDefaultDeviceBitCount ()
 

Detailed Description

Definition at line 38 of file accessibletestbase.hxx.

Member Function Documentation

◆ activateMenuItem() [1/4]

bool test::AccessibleTestBase::activateMenuItem ( const css::uno::Reference< css::accessibility::XAccessibleAction > &  xAction)
protected

◆ activateMenuItem() [2/4]

bool test::AccessibleTestBase::activateMenuItem ( const css::uno::Reference< css::accessibility::XAccessibleContext > &  xCtx)
inlineprotected

Definition at line 91 of file accessibletestbase.hxx.

◆ activateMenuItem() [3/4]

template<typename... Ts>
bool test::AccessibleTestBase::activateMenuItem ( const css::uno::Reference< css::accessibility::XAccessibleContext > &  xMenuCtx,
Ts...  names 
)
inlineprotected

Definition at line 117 of file accessibletestbase.hxx.

◆ activateMenuItem() [4/4]

template<typename... Ts>
bool test::AccessibleTestBase::activateMenuItem ( Ts...  names)
inlineprotected

◆ awaitDialog()

std::shared_ptr< test::AccessibleTestBase::DialogWaiter > test::AccessibleTestBase::awaitDialog ( const std::u16string_view  name,
std::function< void(Dialog &)>  callback,
bool  bAutoClose = true 
)
staticprotected

Helper to call user code when a given dialog opens.

Parameters
nameThe title of the dialog window to wait for
callbackThe user code to run when the given dialog opens
bAutoCloseWhether to automatically cancel the dialog after the user code finished, if the dialog is still there. You should leave this to true unless you know exactly what you are doing, see below.
Returns
A DialogWaiter wrapper on which call waitEndDialog() after having triggered the dialog in some way.

This function makes it fairly easy and safe to execute code once a dialog pops up:

auto waiter = awaitDialog(u"Special Characters", [this](Dialog &dialog) {
// for example, something like this:
// something();
// CPPUNIT_ASSERT(dialog.tabTo(...));
// CPPUNIT_ASSERT(somethingElse);
// dialog.postKeyEventAsync(0, awt::Key::RETURN);
});
CPPUNIT_ASSERT(activateMenuItem(u"Some menu", u"Some Item Triggering a Dialog..."));
CPPUNIT_ASSERT(waiter->waitEndDialog());
bool activateMenuItem(const css::uno::Reference< css::accessibility::XAccessibleAction > &xAction)
static std::shared_ptr< DialogWaiter > awaitDialog(const std::u16string_view name, std::function< void(Dialog &)> callback, bool bAutoClose=true)
Helper to call user code when a given dialog opens.
Note
The user code might actually be executed before DialogWaiter::waitEndDialog() is called. It is actually likely to be called at the time the call that triggers the dialog happens. However, as letting an exception slip in a event handler is likely to cause problems, exceptions are forwarded to the DialogWaiter::waitEndDialog() call. However, note that you cannot rely on something like this:
int foo = 0;
auto waiter = awaitDialog(u"Some Dialog", [&foo](Dialog&) {
CPPUNIT_ASSERT_EQUAL(1, foo);
});
CPPUNIT_ASSERT(activateMenuItem(u"Some menu", u"Some Item Triggering a Dialog..."));
foo = 1; // here, the callback likely already ran as a result of the
// Scheduler::ProcessEventsToIdle() call that activateMenuItem() did.
CPPUNIT_ASSERT(waiter->waitEndDialog());
Warning
You should almost certainly always leave bAutoClose to true. If it is set to false, you have to take extreme care:
  • The dialog will not be canceled if the user code raises an exception.
  • If the dialog is run through Dialog::Execute(), control won't return to the test body until the dialog is closed. This means that the only ways to execute code until then is a separate thread or via code dispatched by the main loop. Thus, you have to make sure you DO close the dialog some way or another yourself in order for the test code to terminate at some point.
  • If the dialog doesn't use Dialog::Execute() but is rather similar to a second separate window (e.g. non-modal), you might still have to close the dialog before closing the test document is possible without a CloseVetoException – which might badly break the test run.

Definition at line 393 of file accessibletestbase.cxx.

References Timer::ClearInvokeHandler(), Application::GetDialogCancelMode(), Application::GetVCLToolkit(), Task::IsActive(), LINK, msName, name, Application::SetDialogCancelMode(), Timer::SetInvokeHandler(), Task::SetPriority(), Timer::SetTimeout(), Timer::Start(), Task::Stop(), windowActivated(), windowClosed(), windowClosing(), windowDeactivated(), windowMinimized(), windowNormalized(), windowOpened(), and Application::Yield().

◆ close()

void test::AccessibleTestBase::close ( )
protected

Definition at line 49 of file accessibletestbase.cxx.

Referenced by test::AccessibleTestBase::Dialog::~Dialog().

◆ documentPostKeyEvent()

void test::AccessibleTestBase::documentPostKeyEvent ( int  nType,
int  nCharCode,
int  nKeyCode 
)
inlineprotected

Definition at line 54 of file accessibletestbase.hxx.

References nType.

◆ dumpA11YTree()

void test::AccessibleTestBase::dumpA11YTree ( const css::uno::Reference< css::accessibility::XAccessibleContext > &  xContext,
const int  depth = 0 
)
protected

Prints the tree of accessible objects starting at xContext to stdout.

Definition at line 155 of file accessibletestbase.cxx.

References AccessibilityTools::debugString(), AccessibilityTools::getRelationTypeName(), i, and Scheduler::ProcessEventsToIdle().

◆ getAllChildren()

std::deque< uno::Reference< accessibility::XAccessibleContext > > test::AccessibleTestBase::getAllChildren ( const css::uno::Reference< css::accessibility::XAccessibleContext > &  xContext)
protectedvirtual

Tries to list all children of an accessible.

Parameters
xContextAn XAccessibleContext object
Returns
The list of all children (but no more than AccessibilityTools::MAX_CHILDREN)

This fetches children of xContext. This would ideally just be the same than iterating over children the regular way up to AccessibilityTools::MAX_CHILDREN, but unfortunately some components (Writer, Impress, ...) do not provide all their children the regular way and require specifics to include them.

There is no guarantee on which children are returned if there are more than AccessibilityTools::MAX_CHILDREN – yet they will always be the same in a given context.

Reimplemented in test::SwAccessibleTestBase.

Definition at line 139 of file accessibletestbase.cxx.

References i, and AccessibilityTools::MAX_CHILDREN.

Referenced by test::SwAccessibleTestBase::getAllChildren().

◆ getDocumentAccessibleContext()

uno::Reference< accessibility::XAccessibleContext > test::AccessibleTestBase::getDocumentAccessibleContext ( )
protectedvirtual

◆ getFirstRelationTargetOfType()

uno::Reference< accessibility::XAccessibleContext > test::AccessibleTestBase::getFirstRelationTargetOfType ( const css::uno::Reference< css::accessibility::XAccessibleContext > &  xContext,
sal_Int16  relationType 
)
staticprotected

Definition at line 112 of file accessibletestbase.cxx.

References i.

Referenced by test::SwAccessibleTestBase::getPreviousFlowingSibling().

◆ getFocusedObject() [1/2]

static css::uno::Reference< css::accessibility::XAccessibleContext > test::AccessibleTestBase::getFocusedObject ( const css::uno::Reference< css::accessibility::XAccessible > &  xAcc)
inlinestaticprotected

Definition at line 150 of file accessibletestbase.hxx.

◆ getFocusedObject() [2/2]

static css::uno::Reference< css::accessibility::XAccessibleContext > test::AccessibleTestBase::getFocusedObject ( const css::uno::Reference< css::accessibility::XAccessibleContext > &  xCtx)
staticprotected

Gets the focused accessible object at xAcc level or below.

Parameters
xAccAn accessible object
Returns
The accessible context of the focused object, or nullptr

Finds the accessible object context at or under xAcc that has the focused state (and is showing). Normally only one such object should exist in a given hierarchy, but in all cases this function will return the first one found.

See also
AccessibilityTools::getAccessibleObjectForPredicate()

◆ getItemFromName() [1/2]

css::uno::Reference< css::accessibility::XAccessibleContext > test::AccessibleTestBase::getItemFromName ( const css::uno::Reference< css::accessibility::XAccessibleContext > &  xMenuCtx,
std::u16string_view  name 
)
protected

◆ getItemFromName() [2/2]

template<typename... Ts>
css::uno::Reference< css::accessibility::XAccessibleContext > test::AccessibleTestBase::getItemFromName ( const css::uno::Reference< css::accessibility::XAccessibleContext > &  xMenuCtx,
std::u16string_view  name,
Ts...  names 
)
inlineprotected

Definition at line 104 of file accessibletestbase.hxx.

References name.

◆ getWindowAccessibleContext()

uno::Reference< accessibility::XAccessibleContext > test::AccessibleTestBase::getWindowAccessibleContext ( )
protected

Definition at line 81 of file accessibletestbase.cxx.

◆ isDocumentRole()

bool test::AccessibleTestBase::isDocumentRole ( const sal_Int16  role)
staticprotected

Definition at line 88 of file accessibletestbase.cxx.

◆ load()

void test::AccessibleTestBase::load ( const rtl::OUString &  sURL)
protectedvirtual

Definition at line 61 of file accessibletestbase.cxx.

References close, and xModel.

◆ loadFromSrc()

void test::AccessibleTestBase::loadFromSrc ( const rtl::OUString &  sSrcPath)
protectedvirtual

Definition at line 75 of file accessibletestbase.cxx.

◆ setUp()

void test::AccessibleTestBase::setUp ( )
overridevirtual

◆ tabTo() [1/2]

static bool test::AccessibleTestBase::tabTo ( const css::uno::Reference< css::accessibility::XAccessible > &  xRoot,
const css::uno::Reference< css::accessibility::XAccessibleContext > &  xChild,
const EventPosterHelperBase pEventPosterHelper = nullptr 
)
staticprotected

◆ tabTo() [2/2]

static css::uno::Reference< css::accessibility::XAccessibleContext > test::AccessibleTestBase::tabTo ( const css::uno::Reference< css::accessibility::XAccessible > &  xRoot,
const sal_Int16  role,
const std::u16string_view  name,
const EventPosterHelperBase pEventPosterHelper = nullptr 
)
staticprotected

Navigates through focusable elements using the Tab keyboard shortcut.

Parameters
xRootThe root element to look for focused elements in.
roleThe accessible role of the element to tab to.
nameThe accessible name of the element to tab to.
pEventPosterHelperPointer to a EventPosterHelper instance, or nullptr to obtain it from xRoot.
Returns
The element tabbed to, or nullptr if not found.

Navigates through focusable elements in the top level containing xRoot using the Tab keyboard key until the focused elements matches role and name.

Note that usually xRoot should be the toplevel accessible, or at least contain all focusable elements within that window. It is however not a requirement, but only elements actually inside it will be candidate for a match, and thus if focus goes outside it, it might lead to not finding the target element.

If pEventPosterHelper is nullptr, this function will try to construct one from xRoot.

See also
EventPosterHelper.

Referenced by test::AccessibleTestBase::Dialog::tabTo().

◆ tearDown()

void test::AccessibleTestBase::tearDown ( )
overridevirtual

Reimplemented from test::BootstrapFixtureBase.

Definition at line 59 of file accessibletestbase.cxx.

References close.

Member Data Documentation

◆ mxDesktop

css::uno::Reference<css::frame::XDesktop2> test::AccessibleTestBase::mxDesktop
protected

Definition at line 41 of file accessibletestbase.hxx.

Referenced by setUp().

◆ mxDocument

css::uno::Reference<css::lang::XComponent> test::AccessibleTestBase::mxDocument
protected

Definition at line 42 of file accessibletestbase.hxx.

◆ mxWindow

css::uno::Reference<css::awt::XWindow> test::AccessibleTestBase::mxWindow
protected

Definition at line 43 of file accessibletestbase.hxx.


The documentation for this class was generated from the following files: