summaryrefslogtreecommitdiffstats
path: root/sw/qa/extras/accessibility/basics.cxx
blob: 6bdd992c22d096b41b94c1c0ada61068a3c56e25 (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
/* -*- 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 <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <vcl/scheduler.hxx>

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

using namespace css;

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestBasicStructure)
{
    loadFromSrc(u"/sw/qa/python/testdocuments/xtextcontent.odt"_ustr);
    auto xContext = getDocumentAccessibleContext();
    CPPUNIT_ASSERT(xContext.is());

    dumpA11YTree(xContext);
    CPPUNIT_ASSERT_EQUAL(
        rtl::OUString("<PARAGRAPH>String1</PARAGRAPH><PARAGRAPH/><PARAGRAPH/><PARAGRAPH/>"
                      "<TABLE name=\"Table1-1\" description=\"Table1 on page 1\">"
                      "<TABLE_CELL name=\"A1\" description=\"A1\">"
                      "<PARAGRAPH>String2</PARAGRAPH>"
                      "</TABLE_CELL>"
                      "</TABLE>"
                      "<PARAGRAPH/>"
                      "<TEXT_FRAME name=\"Frame1\"><PARAGRAPH>Frame1</PARAGRAPH></TEXT_FRAME>"
                      "<TEXT_FRAME name=\"Frame2\"><PARAGRAPH>Frame2</PARAGRAPH></TEXT_FRAME>"),
        collectText(xContext));
}

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestTypeSimple)
{
    load(u"private:factory/swriter"_ustr);
    auto xContext = getDocumentAccessibleContext();
    CPPUNIT_ASSERT(xContext.is());

    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 'h', 0);
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 'e', 0);
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 'l', 0);
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 'l', 0);
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 'o', 0);
    Scheduler::ProcessEventsToIdle();

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

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestTypeMultiPara)
{
    load(u"private:factory/swriter"_ustr);
    auto xContext = getDocumentAccessibleContext();
    CPPUNIT_ASSERT(xContext.is());

    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 'A', 0);
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 'B', 0);
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 'C', 0);
    Scheduler::ProcessEventsToIdle();

    CPPUNIT_ASSERT_EQUAL(
        rtl::OUString("<PARAGRAPH>A</PARAGRAPH><PARAGRAPH>B</PARAGRAPH><PARAGRAPH>C</PARAGRAPH>"),
        collectText(xContext));
}

CPPUNIT_TEST_FIXTURE(test::SwAccessibleTestBase, TestMenuInsertPageNumber)
{
    load(u"private:factory/swriter"_ustr);
    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Field", u"Page Number"));
    CPPUNIT_ASSERT_EQUAL(rtl::OUString("<PARAGRAPH>1</PARAGRAPH>"), collectText());
}

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

    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Field", u"Page Number"));
    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Page Break"));
    // we need to move focus to the paragraph after the page break to insert the page number there
    documentPostKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::DOWN);
    CPPUNIT_ASSERT(activateMenuItem(u"Insert", u"Field", u"Page Number"));

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

CPPUNIT_PLUGIN_IMPLEMENT();

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