summaryrefslogtreecommitdiffstats
path: root/sw/qa/extras/accessibility/dialogs.cxx
blob: a14eed6bdba3bd22862eed733af52bda6cbe41de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <com/sun/star/awt/Key.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>

#include <vcl/scheduler.hxx>

#include <test/a11y/swaccessibletestbase.hxx>
#include <test/a11y/AccessibilityTools.hxx>

using namespace css;

// FIXME: dialog API doesn't work on macos yet
#if !defined(MACOSX)

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestSpecialCharactersDialog)
{
    load(u"private:factory/swriter"_ustr);

    auto dialogWaiter = awaitDialog(u"Special Characters", [this](Dialog& dialog) {
        dumpA11YTree(dialog.getAccessible()->getAccessibleContext());

        CPPUNIT_ASSERT_EQUAL(
            AccessibilityTools::getAccessibleObjectForName(
                dialog.getAccessible(), accessibility::AccessibleRole::TEXT, u"Search:"),
            getFocusedObject(dialog.getAccessible()));

        // search for (c) symbol
        dialog.postExtTextEventAsync(u"copyright"_ustr);
        Scheduler::ProcessEventsToIdle();

        CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TABLE_CELL, u"©"));

        /* there was a focus issue in this dialog: the table holding the characters always had the
         * selected element as focused, even when tabbing outside.
         * Fixed with https://gerrit.libreoffice.org/c/core/+/147660.
         * Anyway, we still use the target element match API to also exercise it. */
        auto xChild = AccessibilityTools::getAccessibleObjectForName(
            dialog.getAccessible(), accessibility::AccessibleRole::PUSH_BUTTON, u"Insert");
        CPPUNIT_ASSERT(xChild);
        CPPUNIT_ASSERT(dialog.tabTo(xChild));
        dialog.postKeyEventAsync(0, awt::Key::RETURN);

        Scheduler::ProcessEventsToIdle();
    });

    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Special Character..."));
    CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());

    CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH>©</PARAGRAPH>"_ustr, collectText());
}

/* checks for the fix from https://gerrit.libreoffice.org/c/core/+/147660 */
CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestSpecialCharactersDialogFocus)
{
    load(u"private:factory/swriter"_ustr);

    auto dialogWaiter = awaitDialog(u"Special Characters", [](Dialog& dialog) {
        CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TABLE_CELL, u" "));

        /* as there is a bug that focusing the character table doesn't enable the Insert button
         * (https://bugs.documentfoundation.org/show_bug.cgi?id=153806), we move to another cell
         * so it works. */

        // tdf#153918: Check that '!' char has correct accessible name and insert it
        dialog.postKeyEventAsync(0, awt::Key::RIGHT);
        Scheduler::ProcessEventsToIdle();
        CPPUNIT_ASSERT_EQUAL(
            AccessibilityTools::getAccessibleObjectForName(
                dialog.getAccessible(), accessibility::AccessibleRole::TABLE_CELL, u"!"),
            getFocusedObject(dialog.getAccessible()));

        CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::PUSH_BUTTON, u"Insert"));
        dialog.postKeyEventAsync(0, awt::Key::RETURN);

        Scheduler::ProcessEventsToIdle();
    });

    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Special Character..."));
    CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());

    CPPUNIT_ASSERT_EQUAL(u"<PARAGRAPH>!</PARAGRAPH>"_ustr, collectText());
}

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestHyperlinkDialog)
{
    load(u"private:factory/swriter"_ustr);

    auto dialogWaiter = awaitDialog(u"Hyperlink", [this](Dialog& dialog) {
        dumpA11YTree(dialog.getAccessible()->getAccessibleContext());

        // Focus the URL box (should be default, but make sure we're on it)
        CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::COMBO_BOX, u"URL:"));
        // Fill in an address
        dialog.postExtTextEventAsync(u"https://libreoffice.org/"_ustr);
        // Validate the whole dialog
        dialog.postKeyEventAsync(0, awt::Key::RETURN);
        Scheduler::ProcessEventsToIdle();
    });

    // Activate the Insert->Hyperlink... menu item to open the Hyperlink dialog
    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Hyperlink..."));
    CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());

    CPPUNIT_ASSERT_EQUAL(rtl::OUString("<PARAGRAPH>https://libreoffice.org/</PARAGRAPH>"),
                         collectText());
}

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestBookmarkDialog)
{
    load(u"private:factory/swriter"_ustr);

    auto dialogWaiter = awaitDialog(u"Bookmark", [this](Dialog& dialog) {
        dumpA11YTree(dialog.getAccessible()->getAccessibleContext());

        CPPUNIT_ASSERT(dialog.tabTo(accessibility::AccessibleRole::TEXT, u"Name:"));
        dialog.postKeyEventAsync(0, awt::Key::SELECT_ALL);
        dialog.postKeyEventAsync(0, awt::Key::DELETE);
        dialog.postExtTextEventAsync(u"Test Bookmark 1"_ustr);
        // Validate the whole dialog
        dialog.postKeyEventAsync(0, awt::Key::RETURN);
        Scheduler::ProcessEventsToIdle();
    });

    // Activate the Insert->Bookmark... menu item to open the Bookmark dialog
    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Bookmark..."));
    CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());

    CPPUNIT_ASSERT_EQUAL(rtl::OUString("<PARAGRAPH>#Test Bookmark 1 Bookmark </PARAGRAPH>"),
                         collectText());
}

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestSectionDialog)
{
    load(u"private:factory/swriter"_ustr);

    auto dialogWaiter = awaitDialog(u"Insert Section", [this](Dialog& dialog) {
        dumpA11YTree(dialog.getAccessible()->getAccessibleContext());

        // Validate the whole dialog
        dialog.postKeyEventAsync(0, awt::Key::RETURN);
        Scheduler::ProcessEventsToIdle();
    });

    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Section..."));
    CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());

    CPPUNIT_ASSERT_EQUAL(rtl::OUString("<PARAGRAPH/><PARAGRAPH/>"), collectText());
}

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestFontworkDialog)
{
    load(u"private:factory/swriter"_ustr);

    auto dialogWaiter = awaitDialog(u"Fontwork Gallery", [this](Dialog& dialog) {
        dumpA11YTree(dialog.getAccessible()->getAccessibleContext());

        // Validate the whole dialog
        dialog.postKeyEventAsync(0, awt::Key::RETURN);
        Scheduler::ProcessEventsToIdle();
    });

    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Fontwork..."));
    CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());

    CPPUNIT_ASSERT_EQUAL(
        rtl::OUString("<PARAGRAPH/><SHAPE name=\"Simple\" description=\" \"><PARAGRAPH "
                      "description=\"Paragraph: 0 Simple\">Simple</PARAGRAPH></SHAPE>"),
        collectText());
}

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, BasicTestFrameDialog)
{
    load(u"private:factory/swriter"_ustr);

    auto dialogWaiter = awaitDialog(u"Frame", [](Dialog& dialog) {
        // Validate the whole dialog
        dialog.postKeyEventAsync(0, awt::Key::RETURN);
        Scheduler::ProcessEventsToIdle();
    });

    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Frame", u"Frame..."));
    CPPUNIT_ASSERT(dialogWaiter->waitEndDialog());

    CPPUNIT_ASSERT_EQUAL(
        rtl::OUString("<PARAGRAPH/><TEXT_FRAME name=\"Frame1\"><PARAGRAPH/></TEXT_FRAME>"),
        collectText());
}

#endif //defined(MACOSX)

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */