Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / extras / accessibility / dialogs.cxx
blob7fd23ae2247d9a9d6fdd35764adbe444971960eb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <com/sun/star/awt/Key.hpp>
11 #include <com/sun/star/accessibility/AccessibleRole.hpp>
13 #include <vcl/scheduler.hxx>
15 #include <test/a11y/swaccessibletestbase.hxx>
16 #include <test/a11y/AccessibilityTools.hxx>
18 using namespace css;
20 // FIXME: dialog API doesn't work on macos yet
21 #if !defined(MACOSX)
23 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestSpecialCharactersDialog)
25 load(u"private:factory/swriter");
27 auto dialogWaiter = awaitDialog(u"Special Characters", [this](Dialog& dialog) {
28 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
30 CPPUNIT_ASSERT_EQUAL(
31 AccessibilityTools::getAccessibleObjectForName(
32 dialog.getAccessible(), accessibility::AccessibleRole::TEXT, u"Search:"),
33 getFocusedObject(dialog.getAccessible()));
35 // search for (c) symbol
36 dialog.postExtTextEventAsync(u"copyright");
37 Scheduler::ProcessEventsToIdle();
39 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TABLE_CELL, u"©"));
41 /* there was a focus issue in this dialog: the table holding the characters always had the
42 * selected element as focused, even when tabbing outside.
43 * Fixed with https://gerrit.libreoffice.org/c/core/+/147660.
44 * Anyway, we still use the target element match API to also exercise it. */
45 auto xChild = AccessibilityTools::getAccessibleObjectForName(
46 dialog.getAccessible(), accessibility::AccessibleRole::PUSH_BUTTON, u"Insert");
47 CPPUNIT_ASSERT(xChild);
48 CPPUNIT_ASSERT(dialog.tabTo(xChild));
49 dialog.postKeyEventAsync(0, awt::Key::RETURN);
51 Scheduler::ProcessEventsToIdle();
52 });
54 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Special Character..."));
55 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
57 CPPUNIT_ASSERT_EQUAL(rtl::OUString(u"<PARAGRAPH>©</PARAGRAPH>"), collectText());
60 /* checks for the fix from https://gerrit.libreoffice.org/c/core/+/147660 */
61 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestSpecialCharactersDialogFocus)
63 load(u"private:factory/swriter");
65 auto dialogWaiter = awaitDialog(u"Special Characters", [](Dialog& dialog) {
66 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TABLE_CELL, u" "));
68 /* as there is a bug that focusing the character table doesn't enable the Insert button
69 * (https://bugs.documentfoundation.org/show_bug.cgi?id=153806), we move to another cell
70 * so it works. */
72 // tdf#153918: Check that '!' char has correct accessible name and insert it
73 dialog.postKeyEventAsync(0, awt::Key::RIGHT);
74 Scheduler::ProcessEventsToIdle();
75 CPPUNIT_ASSERT_EQUAL(
76 AccessibilityTools::getAccessibleObjectForName(
77 dialog.getAccessible(), accessibility::AccessibleRole::TABLE_CELL, u"!"),
78 getFocusedObject(dialog.getAccessible()));
80 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::PUSH_BUTTON, u"Insert"));
81 dialog.postKeyEventAsync(0, awt::Key::RETURN);
83 Scheduler::ProcessEventsToIdle();
84 });
86 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Special Character..."));
87 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
89 CPPUNIT_ASSERT_EQUAL(rtl::OUString(u"<PARAGRAPH>!</PARAGRAPH>"), collectText());
92 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestHyperlinkDialog)
94 load(u"private:factory/swriter");
96 auto dialogWaiter = awaitDialog(u"Hyperlink", [this](Dialog& dialog) {
97 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
99 // Focus the URL box (should be default, but make sure we're on it)
100 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::COMBO_BOX, u"URL:"));
101 // Fill in an address
102 dialog.postExtTextEventAsync(u"https://libreoffice.org/");
103 // Validate the whole dialog
104 dialog.postKeyEventAsync(0, awt::Key::RETURN);
105 Scheduler::ProcessEventsToIdle();
108 // Activate the Insert->Hyperlink... menu item to open the Hyperlink dialog
109 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Hyperlink..."));
110 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
112 CPPUNIT_ASSERT_EQUAL(rtl::OUString("<PARAGRAPH>https://libreoffice.org/</PARAGRAPH>"),
113 collectText());
116 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestBookmarkDialog)
118 load(u"private:factory/swriter");
120 auto dialogWaiter = awaitDialog(u"Bookmark", [this](Dialog& dialog) {
121 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
123 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TEXT, u"Name:"));
124 dialog.postKeyEventAsync(0, awt::Key::SELECT_ALL);
125 dialog.postKeyEventAsync(0, awt::Key::DELETE);
126 dialog.postExtTextEventAsync(u"Test Bookmark 1");
127 // Validate the whole dialog
128 dialog.postKeyEventAsync(0, awt::Key::RETURN);
129 Scheduler::ProcessEventsToIdle();
132 // Activate the Insert->Bookmark... menu item to open the Bookmark dialog
133 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Bookmark..."));
134 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
136 CPPUNIT_ASSERT_EQUAL(rtl::OUString("<PARAGRAPH>#Test Bookmark 1 Bookmark </PARAGRAPH>"),
137 collectText());
140 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestSectionDialog)
142 load(u"private:factory/swriter");
144 auto dialogWaiter = awaitDialog(u"Insert Section", [this](Dialog& dialog) {
145 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
147 // Validate the whole dialog
148 dialog.postKeyEventAsync(0, awt::Key::RETURN);
149 Scheduler::ProcessEventsToIdle();
152 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Section..."));
153 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
155 CPPUNIT_ASSERT_EQUAL(rtl::OUString("<PARAGRAPH/><PARAGRAPH/>"), collectText());
158 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestFontworkDialog)
160 load(u"private:factory/swriter");
162 auto dialogWaiter = awaitDialog(u"Fontwork Gallery", [this](Dialog& dialog) {
163 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
165 // Validate the whole dialog
166 dialog.postKeyEventAsync(0, awt::Key::RETURN);
167 Scheduler::ProcessEventsToIdle();
170 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Fontwork..."));
171 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
173 CPPUNIT_ASSERT_EQUAL(
174 rtl::OUString("<PARAGRAPH/><SHAPE name=\"Simple\" description=\" \"><PARAGRAPH "
175 "description=\"Paragraph: 0 Simple\">Simple</PARAGRAPH></SHAPE>"),
176 collectText());
179 CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestFrameDialog)
181 load(u"private:factory/swriter");
183 auto dialogWaiter = awaitDialog(u"Frame", [](Dialog& dialog) {
184 // Validate the whole dialog
185 dialog.postKeyEventAsync(0, awt::Key::RETURN);
186 Scheduler::ProcessEventsToIdle();
189 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Frame", u"Frame..."));
190 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
192 CPPUNIT_ASSERT_EQUAL(
193 rtl::OUString("<PARAGRAPH/><TEXT_FRAME name=\"Frame1\"><PARAGRAPH/></TEXT_FRAME>"),
194 collectText());
197 #endif //defined(MACOSX)
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */