2024-05-28 12:33:38 -05:00
|
|
|
/* -*- 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
|
2024-06-18 03:24:03 -05:00
|
|
|
uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(u"Hidden"_ustr,
|
|
|
|
false) };
|
|
|
|
loadWithParams(u"private:factory/swriter"_ustr, aLoadArgs);
|
2024-05-28 12:33:38 -05:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2024-07-02 04:18:04 -05:00
|
|
|
uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(m_xContext));
|
2024-05-28 12:33:38 -05:00
|
|
|
|
|
|
|
// 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);
|
2024-06-18 03:24:03 -05:00
|
|
|
xDispatchProvider->queryDispatch(printPreviewURL, u""_ustr, 0);
|
2024-05-28 12:33:38 -05:00
|
|
|
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);
|
2024-06-18 03:24:03 -05:00
|
|
|
xDispatchProvider2->queryDispatch(closePreviewURL, u""_ustr, 0);
|
2024-05-28 12:33:38 -05:00
|
|
|
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) };
|
2024-06-18 03:24:03 -05:00
|
|
|
loadWithParams(u"private:factory/swriter"_ustr, aArguments);
|
2024-05-28 12:33:38 -05:00
|
|
|
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.
|
|
|
|
|
2024-06-18 03:24:03 -05:00
|
|
|
uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(u"Hidden"_ustr,
|
|
|
|
false) };
|
|
|
|
loadWithParams(u"private:factory/swriter"_ustr, aLoadArgs);
|
2024-05-28 12:33:38 -05:00
|
|
|
|
|
|
|
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);
|
2024-07-02 04:18:04 -05:00
|
|
|
uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(m_xContext));
|
2024-05-28 12:33:38 -05:00
|
|
|
|
|
|
|
util::URL printPreviewURL;
|
|
|
|
printPreviewURL.Complete = u".uno::PrintPreview"_ustr;
|
|
|
|
xParser->parseStrict(printPreviewURL);
|
2024-06-18 03:24:03 -05:00
|
|
|
xDispatchProvider->queryDispatch(printPreviewURL, u""_ustr, 0);
|
2024-05-28 12:33:38 -05:00
|
|
|
Scheduler::ProcessEventsToIdle();
|
|
|
|
|
|
|
|
util::URL closePreviewURL;
|
|
|
|
closePreviewURL.Complete = u".uno::ClosePreview"_ustr;
|
|
|
|
xParser->parseStrict(closePreviewURL);
|
|
|
|
uno::Reference<frame::XDispatchProvider> xDispatchProvider2(xModel->getCurrentController(),
|
|
|
|
uno::UNO_QUERY);
|
2024-06-18 03:24:03 -05:00
|
|
|
xDispatchProvider2->queryDispatch(closePreviewURL, u""_ustr, 0);
|
2024-05-28 12:33:38 -05:00
|
|
|
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);
|
|
|
|
|
2024-06-18 03:24:03 -05:00
|
|
|
xDispatchProvider3->queryDispatch(closeDocURL, u""_ustr, 0);
|
2024-05-28 12:33:38 -05:00
|
|
|
Scheduler::ProcessEventsToIdle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|