Files
odfstudio/sw/qa/uitest/ui/frmdlg/frmdlg.py
T
Miklos Vajna 4f1121255e sw floattable, insert UI: fix default frame width when inserting a new one
Insert -> Frame -> Frame presented a dialog which stated the width of
the new frame will be 2cm, but the width was ~zero.

This is a regression from commit
9da7b1592e (sw: remove all uses of MM50
with (added) o3tl::toTwip, 2021-07-23). Previously the code worked
because the 2cm was speficified as MM50*4 (283*4=1132 twips), and we
compared this to the 2cm from the UI, which had no rounding errors
(283.46456692913387*4=1134 twips), and this 1132 vs 1134 meant the
dialog put the unchanged size to the output item set.  Now we don't have
rounding errors anymore, so we have 1134 everywhere, which means the
dialog doesn't specify a default size, but no other code would do it,
resulting in a frame with minimal width, which is clearly not wanted.

Fix the problem by checking if this will be a new frame, and if so, the
dialog should send the default size to the caller, even if the user
didn't customize the size.  This restores the lost 2cm default width
while keeping the rounding improvements.

This requires running the test in its own process, because the
measurement unit is only loaded once from the config and the rounding
error is not hit with the default inches.

Change-Id: I9a5945fdd0e5cd64ff8bd84f95f11be5277b8d18
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159050
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
2023-11-07 09:52:50 +01:00

84 lines
4.2 KiB
Python

# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
#
"""Covers sw/source/ui/frmdlg/ fixes."""
import time
from libreoffice.uno.propertyvalue import mkPropertyValues
from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict
from uitest.uihelper.common import get_url_for_data_file
class Test(UITestCase):
def test_content_control_dialog(self):
with self.ui_test.create_doc_in_start_center("writer") as xComponent:
# Given a document with a floating table:
args = {
"Columns": 1,
"Rows": 1,
}
self.xUITest.executeCommandWithParameters(".uno:InsertTable", mkPropertyValues(args))
self.xUITest.executeCommand(".uno:SelectAll")
args = {
"AnchorType": 0,
}
self.xUITest.executeCommandWithParameters(".uno:InsertFrame", mkPropertyValues(args))
# Wait until SwTextShell is replaced with SwDrawShell after 120 ms, as set in the SwView
# ctor.
time.sleep(0.2)
self.assertEqual(xComponent.TextFrames.Frame1.IsSplitAllowed, False)
# When allowing it to split on the UI:
with self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog:
xFlysplit = xDialog.getChild("flysplit")
self.assertEqual(get_state_as_dict(xFlysplit)['Visible'], "true")
self.assertEqual(get_state_as_dict(xFlysplit)['Selected'], "false")
xFlysplit.executeAction("CLICK", tuple())
# Then make sure the doc model is updated correctly:
self.assertEqual(xComponent.TextFrames.Frame1.IsSplitAllowed, True)
def test_chained_fly_split(self):
# Given a document with 2 chained fly frames:
with self.ui_test.load_file(get_url_for_data_file("chained-frames.odt")):
# When selecting the first and opening the fly frame properties dialog:
self.xUITest.executeCommand(".uno:JumpToNextFrame")
# Wait until SwTextShell is replaced with SwDrawShell after 120 ms, as set in the SwView
# ctor.
time.sleep(0.2)
with self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog:
# Then make sure that the 'split' checkbox is hidden:
xFlysplit = xDialog.getChild("flysplit")
# Without the accompanying fix in place, this test would have failed with:
# AssertionError: 'true' != 'false'
# i.e. the UI didn't hide this option, leading to some weird mix of chained shapes
# and floating tables.
self.assertEqual(get_state_as_dict(xFlysplit)['Visible'], "false")
def test_insert_frame_dialog(self):
# Change from inch to cm to hit the rounding error. 2 means Centimeter, see
# officecfg/registry/schema/org/openoffice/Office/Writer.xcs.
with self.ui_test.set_config('/org.openoffice.Office.Writer/Layout/Other/MeasureUnit', 2):
# Given a Writer document:
with self.ui_test.create_doc_in_start_center("writer") as xComponent:
# When inserting a new frame with the default width:
with self.ui_test.execute_dialog_through_command(".uno:InsertFrame") as xDialog:
xWidth = xDialog.getChild("width")
frame_width = float(get_state_as_dict(xWidth)["Value"])
# Then make sure the width is not zero:
# cm -> mm100
expected_mm100 = frame_width * 1000
# Without the accompanying fix in place, this test would have failed with:
# AssertionError: 0 != 2000.0
# i.e. the width was empty instead of the size from the UI.
self.assertEqual(xComponent.TextFrames.Frame1.Size.Width, expected_mm100)
# vim: set shiftwidth=4 softtabstop=4 expandtab: