Add a comment to clarify what kind of inputs the class handles
[LibreOffice.git] / sw / qa / extras / accessibility / dialogs.cxx
blob1072a2c47b1f7c2f03778ae2ba787d6a43b68e0d
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>
12 #include <com/sun/star/accessibility/XAccessibleContext2.hpp>
13 #include <com/sun/star/linguistic2/LinguServiceManager.hpp>
14 #include <com/sun/star/linguistic2/XLinguServiceManager2.hpp>
15 #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
17 #include <vcl/scheduler.hxx>
19 #include <test/a11y/accessibletestbase.hxx>
20 #include <test/a11y/AccessibilityTools.hxx>
22 using namespace css;
23 using namespace css::accessibility;
25 // FIXME: dialog API doesn't work on macos yet
26 #if !defined(MACOSX)
28 CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestSpecialCharactersDialog)
30 load(u"private:factory/swriter"_ustr);
32 auto dialogWaiter = awaitDialog(u"Special Characters", [this](Dialog& dialog) {
33 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
35 CPPUNIT_ASSERT_EQUAL(
36 AccessibilityTools::getAccessibleObjectForName(
37 dialog.getAccessible(), accessibility::AccessibleRole::TEXT, u"Search:"),
38 getFocusedObject(dialog.getAccessible()));
40 // search for (c) symbol
41 dialog.postExtTextEventAsync(u"copyright"_ustr);
42 Scheduler::ProcessEventsToIdle();
44 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TABLE_CELL, u"©"));
46 /* there was a focus issue in this dialog: the table holding the characters always had the
47 * selected element as focused, even when tabbing outside.
48 * Fixed with https://gerrit.libreoffice.org/c/core/+/147660.
49 * Anyway, we still use the target element match API to also exercise it. */
50 auto xChild = AccessibilityTools::getAccessibleObjectForName(
51 dialog.getAccessible(), accessibility::AccessibleRole::PUSH_BUTTON, u"Insert");
52 CPPUNIT_ASSERT(xChild);
53 CPPUNIT_ASSERT(dialog.tabTo(xChild));
54 dialog.postKeyEventAsync(0, awt::Key::RETURN);
56 Scheduler::ProcessEventsToIdle();
57 });
59 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Special Character..."));
60 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
62 CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH>©</PARAGRAPH>"_ustr, collectText());
65 /* checks for the fix from https://gerrit.libreoffice.org/c/core/+/147660 */
66 CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, TestSpecialCharactersDialogFocus)
68 load(u"private:factory/swriter"_ustr);
70 auto dialogWaiter = awaitDialog(u"Special Characters", [](Dialog& dialog) {
71 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TABLE_CELL, u" "));
73 /* as there is a bug that focusing the character table doesn't enable the Insert button
74 * (https://bugs.documentfoundation.org/show_bug.cgi?id=153806), we move to another cell
75 * so it works. */
77 // tdf#153918: Check that '!' char has correct accessible name and insert it
78 dialog.postKeyEventAsync(0, awt::Key::RIGHT);
79 Scheduler::ProcessEventsToIdle();
80 CPPUNIT_ASSERT_EQUAL(
81 AccessibilityTools::getAccessibleObjectForName(
82 dialog.getAccessible(), accessibility::AccessibleRole::TABLE_CELL, u"!"),
83 getFocusedObject(dialog.getAccessible()));
85 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::PUSH_BUTTON, u"Insert"));
86 dialog.postKeyEventAsync(0, awt::Key::RETURN);
88 Scheduler::ProcessEventsToIdle();
89 });
91 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Special Character..."));
92 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
94 CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH>!</PARAGRAPH>"_ustr, collectText());
97 CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestHyperlinkDialog)
99 load(u"private:factory/swriter"_ustr);
101 auto dialogWaiter = awaitDialog(u"Hyperlink", [this](Dialog& dialog) {
102 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
104 // Focus the URL box (should be default, but make sure we're on it)
105 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::COMBO_BOX, u"URL:"));
106 // Fill in an address
107 dialog.postExtTextEventAsync(u"https://libreoffice.org/"_ustr);
108 // Validate the whole dialog
109 dialog.postKeyEventAsync(0, awt::Key::RETURN);
110 Scheduler::ProcessEventsToIdle();
113 // Activate the Insert->Hyperlink... menu item to open the Hyperlink dialog
114 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Hyperlink..."));
115 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
117 CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH>https://libreoffice.org/</PARAGRAPH>"_ustr, collectText());
120 CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestBookmarkDialog)
122 load(u"private:factory/swriter"_ustr);
124 auto dialogWaiter = awaitDialog(u"Bookmark", [this](Dialog& dialog) {
125 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
127 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TEXT, u"Name:"));
128 dialog.postKeyEventAsync(0, awt::Key::SELECT_ALL);
129 dialog.postKeyEventAsync(0, awt::Key::DELETE);
130 dialog.postExtTextEventAsync(u"Test Bookmark 1"_ustr);
131 // Validate the whole dialog
132 dialog.postKeyEventAsync(0, awt::Key::RETURN);
133 Scheduler::ProcessEventsToIdle();
136 // Activate the Insert->Bookmark... menu item to open the Bookmark dialog
137 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Bookmark..."));
138 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
140 CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH>#Test Bookmark 1 Bookmark </PARAGRAPH>"_ustr, collectText());
143 CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestSectionDialog)
145 load(u"private:factory/swriter"_ustr);
147 auto dialogWaiter = awaitDialog(u"Insert Section", [this](Dialog& dialog) {
148 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
150 // Validate the whole dialog
151 dialog.postKeyEventAsync(0, awt::Key::RETURN);
152 Scheduler::ProcessEventsToIdle();
155 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Section..."));
156 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
158 CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH/><PARAGRAPH/>"_ustr, collectText());
161 CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestFontworkDialog)
163 load(u"private:factory/swriter"_ustr);
165 auto dialogWaiter = awaitDialog(u"Fontwork Gallery", [this](Dialog& dialog) {
166 dumpA11YTree(dialog.getAccessible()->getAccessibleContext());
168 // Validate the whole dialog
169 dialog.postKeyEventAsync(0, awt::Key::RETURN);
170 Scheduler::ProcessEventsToIdle();
173 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Fontwork..."));
174 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
176 CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH/><SHAPE name=\"Fontwork 1\" description=\" \"><PARAGRAPH "
177 "description=\"Paragraph: 0 Simple\">Simple</PARAGRAPH></SHAPE>"_ustr,
178 collectText());
181 CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, BasicTestFrameDialog)
183 load(u"private:factory/swriter"_ustr);
185 auto dialogWaiter = awaitDialog(u"Frame", [](Dialog& dialog) {
186 // Validate the whole dialog
187 dialog.postKeyEventAsync(0, awt::Key::RETURN);
188 Scheduler::ProcessEventsToIdle();
191 CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Frame", u"Frame..."));
192 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
194 CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH/><TEXT_FRAME name=\"Frame1\"><PARAGRAPH/></TEXT_FRAME>"_ustr,
195 collectText());
198 /* Verify that UI elements in the spell check dialog have the accessible IDs
199 * set that that Orca screen reader's logic to identify them depends on,
200 * see tdf#155447 and following Orca commits:
202 * https://gitlab.gnome.org/GNOME/orca/-/commit/6221f4ecf542646a80e47ee7236380360f0e1a85
203 * https://gitlab.gnome.org/GNOME/orca/-/commit/40a2d302eb52295433fd84e6c254a7dbe5108a24
205 * (Changes should be discussed with the Orca maintainer first.)
207 * While the Orca logic depends only on case-insensitive name starting
208 * with a certain string, this test uses the full accessible ID
209 * (which matches the GtkBuilder ID in ./cui/uiconfig/ui/spellingdialog.ui)
210 * in order to identify the elements.
212 CPPUNIT_TEST_FIXTURE(test::AccessibleTestBase, SpellingDialog)
214 // spell check depends on dictionary being available, so skip test if unavailable
215 uno::Reference<linguistic2::XLinguServiceManager2> xLSM2
216 = linguistic2::LinguServiceManager::create(m_xContext);
217 uno::Reference<linguistic2::XSpellChecker1> xSpell(xLSM2->getSpellChecker(), uno::UNO_QUERY);
218 if (!xSpell.is() || !xSpell->hasLanguage(static_cast<sal_uInt16>(LANGUAGE_ENGLISH_US)))
219 return;
221 loadFromSrc(u"/sw/qa/extras/accessibility/testdocuments/tdf155705.fodt"_ustr);
223 auto dialogWaiter = awaitDialog(u"Spelling: English (USA)", [](Dialog& dialog) {
224 uno::Reference<XAccessible> xDialogAcc = dialog.getAccessible();
226 uno::Reference<XAccessibleContext2> xDialogContext(xDialogAcc->getAccessibleContext(),
227 uno::UNO_QUERY);
228 CPPUNIT_ASSERT(xDialogContext.is());
229 CPPUNIT_ASSERT_EQUAL(u"SpellingDialog"_ustr, xDialogContext->getAccessibleId());
231 uno::Reference<XAccessibleContext> xSentenceAcc
232 = AccessibilityTools::getAccessibleObjectForId(xDialogContext, u"errorsentence");
233 CPPUNIT_ASSERT(xSentenceAcc.is());
235 uno::Reference<XAccessibleContext> xSuggestionsAcc
236 = AccessibilityTools::getAccessibleObjectForId(xDialogContext, u"suggestionslb");
237 CPPUNIT_ASSERT(xSuggestionsAcc.is());
239 CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::PUSH_BUTTON, u"Close"));
240 dialog.postKeyEventAsync(0, awt::Key::RETURN);
241 Scheduler::ProcessEventsToIdle();
244 CPPUNIT_ASSERT(activateMenuItem(u"Tools", u"Spelling..."));
245 CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());
248 #endif //defined(MACOSX)
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */