[Libreoffice-commits] core.git: sw/qa sw/source
Xisco Fauli (via logerrit)
logerrit at kemper.freedesktop.org
Wed Dec 23 18:42:35 UTC 2020
sw/qa/uitest/data/tdf136578.odt |binary
sw/qa/uitest/writer_tests4/tdf136578.py | 38 ++++++++++++++++++++++++++++++++
sw/source/uibase/docvw/PageBreakWin.cxx | 23 +++++++++++++++----
sw/source/uibase/inc/PageBreakWin.hxx | 3 ++
sw/source/uibase/inc/uiobject.hxx | 22 ++++++++++++++++++
sw/source/uibase/uitest/uiobject.cxx | 25 +++++++++++++++++++++
6 files changed, 106 insertions(+), 5 deletions(-)
New commits:
commit d42c73d0bc064633a51db8c1d5fa9e2f60cba5e8
Author: Xisco Fauli <xiscofauli at libreoffice.org>
AuthorDate: Tue Dec 22 00:38:03 2020 +0100
Commit: Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Wed Dec 23 19:41:52 2020 +0100
tdf#136578: uitest: add wrapper for PageBreakWin
Change-Id: I1536f2f03da9ec64627bd1e2e1776cf130717aff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108143
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>
diff --git a/sw/qa/uitest/data/tdf136578.odt b/sw/qa/uitest/data/tdf136578.odt
new file mode 100644
index 000000000000..15a1269c9e89
Binary files /dev/null and b/sw/qa/uitest/data/tdf136578.odt differ
diff --git a/sw/qa/uitest/writer_tests4/tdf136578.py b/sw/qa/uitest/writer_tests4/tdf136578.py
new file mode 100644
index 000000000000..ae609f30becb
--- /dev/null
+++ b/sw/qa/uitest/writer_tests4/tdf136578.py
@@ -0,0 +1,38 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# 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/.
+#
+from uitest.framework import UITestCase
+import org.libreoffice.unotest
+import pathlib
+
+def get_url_for_data_file(file_name):
+ return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
+class tdf136578(UITestCase):
+
+ def test_tdf136578(self):
+
+ self.ui_test.load_file(get_url_for_data_file("tdf136578.odt"))
+
+ xWriterDoc = self.xUITest.getTopFocusWindow()
+ xWriterEdit = xWriterDoc.getChild("writer_edit")
+
+ document = self.ui_test.get_component()
+
+ self.assertEqual(document.CurrentController.PageCount, 2)
+
+ self.ui_test.wait_until_child_is_available(xWriterEdit, 'PageBreak')
+ xPageBreak = xWriterEdit.getChild('PageBreak')
+
+ xPageBreak.executeAction("DELETE", tuple())
+
+ # Without the fix in place, this test would have failed with
+ # AssertionError: 1 != 2
+ self.assertEqual(document.CurrentController.PageCount, 1)
+
+ self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/uibase/docvw/PageBreakWin.cxx b/sw/source/uibase/docvw/PageBreakWin.cxx
index 2bd4eaa8abc7..34db213d8e15 100644
--- a/sw/source/uibase/docvw/PageBreakWin.cxx
+++ b/sw/source/uibase/docvw/PageBreakWin.cxx
@@ -27,6 +27,7 @@
#include <strings.hrc>
#include <tabfrm.hxx>
#include <uiitems.hxx>
+#include <uiobject.hxx>
#include <view.hxx>
#include <viewopt.hxx>
#include <wrtsh.hxx>
@@ -105,6 +106,8 @@ SwPageBreakWin::SwPageBreakWin( SwEditWin* pEditWin, const SwFrame *pFrame ) :
m_nDelayAppearing( 0 ),
m_bDestroyed( false )
{
+ set_id("PageBreak"); // for uitest
+
m_xMenuButton->connect_toggled(LINK(this, SwPageBreakWin, ToggleHdl));
m_xMenuButton->connect_selected(LINK(this, SwPageBreakWin, SelectHdl));
m_xMenuButton->set_accessible_name(SwResId(STR_PAGE_BREAK_BUTTON));
@@ -239,6 +242,16 @@ IMPL_LINK(SwPageBreakWin, SelectHdl, const OString&, rIdent, void)
{
SwFrameControlPtr pThis = GetEditWin()->GetFrameControlsManager( ).GetControl( FrameControlType::PageBreak, GetFrame() );
+ execute(rIdent);
+
+ // Only fade if there is more than this temporary shared pointer:
+ // The main reference has been deleted due to a page break removal
+ if ( pThis.use_count() > 1 )
+ Fade( false );
+}
+
+void SwPageBreakWin::execute(std::string_view rIdent)
+{
// Is there a PageBefore break on this page?
SwContentFrame *pCnt = const_cast<SwContentFrame*>(GetPageFrame()->FindFirstBodyContent());
SvxBreak eBreak = lcl_GetBreakItem( pCnt );
@@ -333,11 +346,6 @@ IMPL_LINK(SwPageBreakWin, SelectHdl, const OString&, rIdent, void)
rNd.GetDoc().GetIDocumentUndoRedo( ).EndUndo( SwUndoId::UI_DELETE_PAGE_BREAK, nullptr );
}
-
- // Only fade if there is more than this temporary shared pointer:
- // The main reference has been deleted due to a page break removal
- if ( pThis.use_count() > 1 )
- Fade( false );
}
void SwPageBreakWin::UpdatePosition(const std::optional<Point>& xEvtPt)
@@ -479,4 +487,9 @@ IMPL_LINK_NOARG(SwPageBreakWin, FadeHandler, Timer *, void)
m_aFadeTimer.Start();
}
+FactoryFunction SwPageBreakWin::GetUITestFactory() const
+{
+ return PageBreakUIObject::create;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/PageBreakWin.hxx b/sw/source/uibase/inc/PageBreakWin.hxx
index 90f0d9afe562..c5cc9cd7774e 100644
--- a/sw/source/uibase/inc/PageBreakWin.hxx
+++ b/sw/source/uibase/inc/PageBreakWin.hxx
@@ -39,6 +39,7 @@ public:
virtual ~SwPageBreakWin() override;
virtual void dispose() override;
+ void execute(std::string_view rIdent);
void UpdatePosition(const std::optional<Point>& xEvtPt = std::optional<Point>());
virtual void ShowAll( bool bShow ) override;
@@ -48,6 +49,8 @@ public:
void Fade( bool bFadeIn );
+ virtual FactoryFunction GetUITestFactory() const override;
+
private:
DECL_LINK( FadeHandler, Timer *, void );
/// Hide the button when the menu is toggled closed, e.g by clicking outside
diff --git a/sw/source/uibase/inc/uiobject.hxx b/sw/source/uibase/inc/uiobject.hxx
index 944384a595e7..b671365c3403 100644
--- a/sw/source/uibase/inc/uiobject.hxx
+++ b/sw/source/uibase/inc/uiobject.hxx
@@ -14,6 +14,7 @@
#include <vcl/uitest/uiobject.hxx>
#include "edtwin.hxx"
+#include "PageBreakWin.hxx"
#include "navipi.hxx"
#include <AnnotationWin.hxx>
@@ -83,6 +84,27 @@ protected:
};
+class PageBreakUIObject : public WindowUIObject
+{
+public:
+
+ PageBreakUIObject(const VclPtr<SwPageBreakWin>& xEditWin);
+
+ virtual void execute(const OUString& rAction,
+ const StringMap& rParameters) override;
+
+ static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
+
+protected:
+
+ virtual OUString get_name() const override;
+
+private:
+
+ VclPtr<SwPageBreakWin> mxPageBreakUIObject;
+
+};
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uitest/uiobject.cxx b/sw/source/uibase/uitest/uiobject.cxx
index 44b995dcf588..fc62fa157cf1 100644
--- a/sw/source/uibase/uitest/uiobject.cxx
+++ b/sw/source/uibase/uitest/uiobject.cxx
@@ -255,6 +255,31 @@ OUString CommentUIObject::get_name() const
return "CommentUIObject";
}
+PageBreakUIObject::PageBreakUIObject(const VclPtr<SwPageBreakWin>& xPageBreakUIObject):
+ WindowUIObject(xPageBreakUIObject),
+ mxPageBreakUIObject(xPageBreakUIObject)
+{
+}
+void PageBreakUIObject::execute(const OUString& rAction,
+ const StringMap& rParameters)
+{
+ if (rAction == "DELETE" || rAction == "EDIT")
+ mxPageBreakUIObject->execute(rAction.toAsciiLowerCase().toUtf8());
+ else
+ WindowUIObject::execute(rAction, rParameters);
+}
+
+std::unique_ptr<UIObject> PageBreakUIObject::create(vcl::Window* pWindow)
+{
+ SwPageBreakWin* pPageBreakWin = dynamic_cast<SwPageBreakWin*>(pWindow);
+ assert(pPageBreakWin);
+ return std::unique_ptr<UIObject>(new PageBreakUIObject(pPageBreakWin));
+}
+
+OUString PageBreakUIObject::get_name() const
+{
+ return "PageBreakUIObject";
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list