summaryrefslogtreecommitdiff
path: root/framework/qa/cppunit/CheckXTitle.cxx
blob: ce66c7379f02fc78cf83b7308516a098417c5c28 (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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * 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 <test/unoapi_test.hxx>

#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/XTitle.hpp>
#include <com/sun/star/frame/XDispatchHelper.hpp>
#include <com/sun/star/frame/XFrame2.hpp>
#include <com/sun/star/util/URLTransformer.hpp>

#include <comphelper/propertyvalue.hxx>
#include <comphelper/processfactory.hxx>

#include <vcl/scheduler.hxx>

using namespace ::com::sun::star;

namespace
{
// These were JUnit tests from framework/qa/complex/XTitle/CheckXTitle.java
class Test : public UnoApiTest
{
public:
    Test()
        : UnoApiTest(u"/framework/qa/cppunit/data/"_ustr)
    {
    }
};

CPPUNIT_TEST_FIXTURE(Test, checkDefaultTitle)
{
    // Cycles through default view and print preview
    // and asserts that the title doesn't change.

    // Load document
    uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(u"Hidden"_ustr,
                                                                                 false) };
    loadWithParams(u"private:factory/swriter"_ustr, aLoadArgs);

    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
    uno::Reference<frame::XController> xController(xModel->getCurrentController());
    uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);

    uno::Reference<frame::XTitle> xTitle(xFrame, css::uno::UNO_QUERY);
    OUString defaultTitle = xTitle->getTitle();

    uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(m_xContext));

    // Open print preview window and get title.
    util::URL printPreviewURL;
    printPreviewURL.Complete = u".uno::PrintPreview"_ustr;
    xParser->parseStrict(printPreviewURL);
    uno::Reference<frame::XDispatchProvider> xDispatchProvider(xModel->getCurrentController(),
                                                               uno::UNO_QUERY);
    xDispatchProvider->queryDispatch(printPreviewURL, u""_ustr, 0);
    uno::Reference<frame::XTitle> xTitle2(xFrame, css::uno::UNO_QUERY);
    Scheduler::ProcessEventsToIdle();

    // Default window title and print preview window title should be the same.
    CPPUNIT_ASSERT_EQUAL(defaultTitle, xTitle2->getTitle());

    // Close print preview window and check to see if default window title has changed
    util::URL closePreviewURL;
    closePreviewURL.Complete = u".uno::ClosePreview"_ustr;
    xParser->parseStrict(closePreviewURL);
    uno::Reference<frame::XDispatchProvider> xDispatchProvider2(xModel->getCurrentController(),
                                                                uno::UNO_QUERY);
    xDispatchProvider2->queryDispatch(closePreviewURL, u""_ustr, 0);
    uno::Reference<frame::XTitle> xTitle3(xFrame, css::uno::UNO_QUERY);
    Scheduler::ProcessEventsToIdle();

    // Default window title should be the same after closing print preview window.
    CPPUNIT_ASSERT_EQUAL(defaultTitle, xTitle3->getTitle());
}

CPPUNIT_TEST_FIXTURE(Test, checkTitleSuggestedFileName)
{
    uno::Sequence<beans::PropertyValue> aArguments
        = { comphelper::makePropertyValue(u"SuggestedSaveAsName"_ustr, u"suggestedname.odt"_ustr),
            comphelper::makePropertyValue(u"Hidden"_ustr, false) };
    loadWithParams(u"private:factory/swriter"_ustr, aArguments);
    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
    uno::Reference<frame::XController> xController(xModel->getCurrentController());
    uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);

    uno::Reference<frame::XTitle> xTitle(xFrame, css::uno::UNO_QUERY);
    OUString windowTitle = xTitle->getTitle();

    CPPUNIT_ASSERT(windowTitle.startsWith("suggestedname.odt"));
}

CPPUNIT_TEST_FIXTURE(Test, setTitleAndCheck)
{
    // Set the frame title, then cycle through default and print preview. Close the window
    // and check for infinite recursion.

    uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(u"Hidden"_ustr,
                                                                                 false) };
    loadWithParams(u"private:factory/swriter"_ustr, aLoadArgs);

    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
    uno::Reference<frame::XController> xController(xModel->getCurrentController());
    uno::Reference<frame::XFrame2> xFrame(xController->getFrame(), uno::UNO_QUERY);

    xFrame->setTitle(u"documentTitle"_ustr);

    uno::Reference<frame::XDispatchProvider> xDispatchProvider(xModel->getCurrentController(),
                                                               uno::UNO_QUERY);
    uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(m_xContext));

    util::URL printPreviewURL;
    printPreviewURL.Complete = u".uno::PrintPreview"_ustr;
    xParser->parseStrict(printPreviewURL);
    xDispatchProvider->queryDispatch(printPreviewURL, u""_ustr, 0);
    Scheduler::ProcessEventsToIdle();

    util::URL closePreviewURL;
    closePreviewURL.Complete = u".uno::ClosePreview"_ustr;
    xParser->parseStrict(closePreviewURL);
    uno::Reference<frame::XDispatchProvider> xDispatchProvider2(xModel->getCurrentController(),
                                                                uno::UNO_QUERY);
    xDispatchProvider2->queryDispatch(closePreviewURL, u""_ustr, 0);
    Scheduler::ProcessEventsToIdle();

    util::URL closeDocURL;
    closeDocURL.Complete = u".uno::CloseWin"_ustr;
    xParser->parseStrict(closeDocURL);
    uno::Reference<frame::XDispatchProvider> xDispatchProvider3(xModel->getCurrentController(),
                                                                uno::UNO_QUERY);
    uno::Reference<frame::XTitle> xTitle(xFrame, css::uno::UNO_QUERY);
    OUString windowTitle = xTitle->getTitle();

    CPPUNIT_ASSERT_EQUAL(windowTitle, u"documentTitle"_ustr);

    xDispatchProvider3->queryDispatch(closeDocURL, u""_ustr, 0);
    Scheduler::ProcessEventsToIdle();
}
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */