From 015da04a8f3e1368c6b9668ca22d7e320e1ecae6 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 22 Mar 2023 11:34:54 +0100 Subject: [PATCH] sw floattable: fix current page number when editing document with a split fly UITest_writer_tests6's tdf124675.tdf124675.test_tdf124675_crash_moving_SwTextFrame_previous_page failed in the SW_FORCE_FLY_SPLIT=1 case, since the current page after typing was 3, not 2. It seems this change is wanted, since the total page count increases by 2, so it's consistent that the current page increases similarly with typing. Also, repeating the UITest in Word (after positioning the cursor at the top paragraph in the document) also produces page 3 as the current page. Fix the problem by locally enabling split flys for this test and then we can assert that we match Word. This requires a new context manager, but that set_config() is really similar to other context managers in the class that return no value. The original purpose of the test was to make sure we don't crash, anyway. Change-Id: Id0dfde23a8726c8799950a6e4fdd1d85f135eafc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149315 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/uitest/writer_tests6/tdf124675.py | 27 +++++++++++++------------ uitest/uitest/test.py | 13 ++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/sw/qa/uitest/writer_tests6/tdf124675.py b/sw/qa/uitest/writer_tests6/tdf124675.py index 40eb2987e260..93bae8ea9284 100644 --- a/sw/qa/uitest/writer_tests6/tdf124675.py +++ b/sw/qa/uitest/writer_tests6/tdf124675.py @@ -14,23 +14,24 @@ from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file class tdf124675(UITestCase): def test_tdf124675_crash_moving_SwTextFrame_previous_page(self): - with self.ui_test.load_file(get_url_for_data_file("tdf124675.docx")) as writer_doc: - xWriterDoc = self.xUITest.getTopFocusWindow() - xWriterEdit = xWriterDoc.getChild("writer_edit") + with self.ui_test.set_config('/org.openoffice.Office.Writer/Filter/Import/DOCX/ImportFloatingTableAsSplitFly', True): + with self.ui_test.load_file(get_url_for_data_file("tdf124675.docx")) as writer_doc: + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") - self.assertEqual(writer_doc.CurrentController.PageCount, 2) - self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1") + self.assertEqual(writer_doc.CurrentController.PageCount, 2) + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1") - for i in range(52): - xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) + for i in range(52): + xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"})) - self.assertEqual(writer_doc.CurrentController.PageCount, 4) - self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "2") + self.assertEqual(writer_doc.CurrentController.PageCount, 4) + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "3") - for i in range(52): - self.xUITest.executeCommand(".uno:Undo") + for i in range(52): + self.xUITest.executeCommand(".uno:Undo") - self.assertEqual(writer_doc.CurrentController.PageCount, 2) - self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1") + self.assertEqual(writer_doc.CurrentController.PageCount, 2) + self.assertEqual(get_state_as_dict(xWriterEdit)["CurrentPage"], "1") # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py index 207969d5213b..23ca7f39bc4e 100644 --- a/uitest/uitest/test.py +++ b/uitest/uitest/test.py @@ -100,6 +100,19 @@ class UITest(object): finally: self.close_doc() + # Resets the setting to the old value at exit + @contextmanager + def set_config(self, path, new_value): + xChanges = self._xContext.ServiceManager.createInstanceWithArgumentsAndContext('com.sun.star.configuration.ReadWriteAccess', ("",), self._xContext) + try: + old_value = xChanges.getByHierarchicalName(path) + xChanges.replaceByHierarchicalName(path, new_value) + xChanges.commitChanges() + yield + finally: + xChanges.replaceByHierarchicalName(path, old_value) + xChanges.commitChanges() + # Calls UITest.close_doc at exit @contextmanager def load_empty_file(self, app):