| 1 |
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- |
| 2 |
# |
| 3 |
# This file is part of the LibreOffice project. |
| 4 |
# |
| 5 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
# |
| 9 |
|
| 10 |
"""Covers sw/source/ui/frmdlg/ fixes.""" |
| 11 |
|
| 12 |
import time |
| 13 |
from libreoffice.uno.propertyvalue import mkPropertyValues |
| 14 |
from uitest.framework import UITestCase |
| 15 |
from uitest.uihelper.common import get_state_as_dict |
| 16 |
from uitest.uihelper.common import get_url_for_data_file |
| 17 |
|
| 18 |
|
| 19 |
class Test(UITestCase): |
| 20 |
def test_uno_frame_dialog(self): |
| 21 |
with self.ui_test.create_doc_in_start_center("writer") as xComponent: |
| 22 |
# Given a document with a floating table: |
| 23 |
args = { |
| 24 |
"Columns": 1, |
| 25 |
"Rows": 1, |
| 26 |
} |
| 27 |
self.xUITest.executeCommandWithParameters(".uno:InsertTable", mkPropertyValues(args)) |
| 28 |
self.xUITest.executeCommand(".uno:SelectAll") |
| 29 |
args = { |
| 30 |
"AnchorType": 0, |
| 31 |
} |
| 32 |
self.xUITest.executeCommandWithParameters(".uno:InsertFrame", mkPropertyValues(args)) |
| 33 |
# Wait until SwTextShell is replaced with SwDrawShell after 120 ms, as set in the SwView |
| 34 |
# ctor. |
| 35 |
time.sleep(0.2) |
| 36 |
self.assertEqual(xComponent.TextFrames.Frame1.IsSplitAllowed, False) |
| 37 |
|
| 38 |
# When allowing it to split on the UI: |
| 39 |
with self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog: |
| 40 |
xFlysplit = xDialog.getChild("flysplit") |
| 41 |
self.assertEqual(get_state_as_dict(xFlysplit)['Visible'], "true") |
| 42 |
self.assertEqual(get_state_as_dict(xFlysplit)['Selected'], "false") |
| 43 |
xFlysplit.executeAction("CLICK", tuple()) |
| 44 |
|
| 45 |
# Then make sure the doc model is updated correctly: |
| 46 |
self.assertEqual(xComponent.TextFrames.Frame1.IsSplitAllowed, True) |
| 47 |
|
| 48 |
def test_chained_fly_split(self): |
| 49 |
# Given a document with 2 chained fly frames: |
| 50 |
with self.ui_test.load_file(get_url_for_data_file("chained-frames.odt")): |
| 51 |
# When selecting the first and opening the fly frame properties dialog: |
| 52 |
self.xUITest.executeCommand(".uno:JumpToNextFrame") |
| 53 |
# Wait until SwTextShell is replaced with SwDrawShell after 120 ms, as set in the SwView |
| 54 |
# ctor. |
| 55 |
time.sleep(0.2) |
| 56 |
with self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog: |
| 57 |
# Then make sure that the 'split' checkbox is hidden: |
| 58 |
xFlysplit = xDialog.getChild("flysplit") |
| 59 |
# Without the accompanying fix in place, this test would have failed with: |
| 60 |
# AssertionError: 'true' != 'false' |
| 61 |
# i.e. the UI didn't hide this option, leading to some weird mix of chained shapes |
| 62 |
# and floating tables. |
| 63 |
self.assertEqual(get_state_as_dict(xFlysplit)['Visible'], "false") |
| 64 |
|
| 65 |
def test_insert_frame_dialog(self): |
| 66 |
# Change from inch to cm to hit the rounding error. 2 means Centimeter, see |
| 67 |
# officecfg/registry/schema/org/openoffice/Office/Writer.xcs. |
| 68 |
with self.ui_test.set_config('/org.openoffice.Office.Writer/Layout/Other/MeasureUnit', 2): |
| 69 |
# Given a Writer document: |
| 70 |
with self.ui_test.create_doc_in_start_center("writer") as xComponent: |
| 71 |
# When inserting a new frame with the default width: |
| 72 |
with self.ui_test.execute_dialog_through_command(".uno:InsertFrame") as xDialog: |
| 73 |
xWidth = xDialog.getChild("width") |
| 74 |
frame_width = float(get_state_as_dict(xWidth)["Value"]) |
| 75 |
# Then make sure the width is not zero: |
| 76 |
# cm -> mm100 |
| 77 |
expected_mm100 = frame_width * 1000 |
| 78 |
# Without the accompanying fix in place, this test would have failed with: |
| 79 |
# AssertionError: 0 != 2000.0 |
| 80 |
# i.e. the width was empty instead of the size from the UI. |
| 81 |
self.assertEqual(xComponent.TextFrames.Frame1.Size.Width, expected_mm100) |
| 82 |
|
| 83 |
def test_insert_floating_table(self): |
| 84 |
with self.ui_test.create_doc_in_start_center("writer") as xComponent: |
| 85 |
# Given a Writer document with a selected (inline) table: |
| 86 |
args = { |
| 87 |
"Columns": 1, |
| 88 |
"Rows": 1, |
| 89 |
} |
| 90 |
self.xUITest.executeCommandWithParameters(".uno:InsertTable", mkPropertyValues(args)) |
| 91 |
self.xUITest.executeCommand(".uno:SelectAll") |
| 92 |
# When converting it to a split fly: |
| 93 |
with self.ui_test.execute_dialog_through_command(".uno:InsertFrame") as xDialog: |
| 94 |
xFlySplit = xDialog.getChild("flysplit") |
| 95 |
fly_split_visible = get_state_as_dict(xFlySplit)["Visible"] == "true" |
| 96 |
# Then make sure the inserted fly can be marked as "split allowed": |
| 97 |
# Without the accompanying fix in place, this test would have failed, the fly had to be |
| 98 |
# inserted first, only then it could be marked as "split allowed". |
| 99 |
self.assertEqual(fly_split_visible, True) |
| 100 |
|
| 101 |
# Without the accompanying fix in place, this test would have failed with: |
| 102 |
# AssertionError: 2 != 0 |
| 103 |
# i.e. the frame had a border by default when the table already had its own border. |
| 104 |
self.assertEqual(xComponent.TextFrames.Frame1.LeftBorder.LineWidth, 0) |
| 105 |
|
| 106 |
def test_insert_simple_frame(self): |
| 107 |
# Given a Writer document: |
| 108 |
with self.ui_test.create_doc_in_start_center("writer"): |
| 109 |
# When inserting a simple text frame (not a floating table): |
| 110 |
with self.ui_test.execute_dialog_through_command(".uno:InsertFrame") as xDialog: |
| 111 |
to_char = xDialog.getChild("tochar") |
| 112 |
to_char_enabled = get_state_as_dict(to_char)["Checked"] == "true" |
| 113 |
# Then make sure the anchor type is to-char, matching the default anchor for images: |
| 114 |
# This failed, text frames defaulted to to-para, images defaulted to to-char, which was |
| 115 |
# inconsistent. |
| 116 |
self.assertTrue(to_char_enabled) |
| 117 |
|
| 118 |
def test_floattable_in_shape_text(self): |
| 119 |
with self.ui_test.set_config('/org.openoffice.Office.Writer/Cursor/Option/SelectPastedAnchoredObject', True): |
| 120 |
with self.ui_test.load_file(get_url_for_data_file("floattable-in-shape-text.docx")) as xComponent: |
| 121 |
# Given a table in a frame, anchored in shape text (TextBox case): |
| 122 |
self.xUITest.executeCommand(".uno:SelectAll") |
| 123 |
# Insert frame around the selected table: |
| 124 |
args = { |
| 125 |
"AnchorType": 0, |
| 126 |
} |
| 127 |
self.xUITest.executeCommandWithParameters(".uno:InsertFrame", mkPropertyValues(args)) |
| 128 |
# Cut it from the body text: |
| 129 |
self.xUITest.executeCommand(".uno:Cut") |
| 130 |
# Select the shape: |
| 131 |
xComponent.CurrentController.select(xComponent.DrawPage[0]) |
| 132 |
xWriterDoc = self.xUITest.getTopFocusWindow() |
| 133 |
xWriterEdit = xWriterDoc.getChild("writer_edit") |
| 134 |
# Begin text edit on the shape: |
| 135 |
xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"F2"})) |
| 136 |
# Paste it into the shape text: |
| 137 |
self.xUITest.executeCommand(".uno:Paste") |
| 138 |
|
| 139 |
# When editing that frame: |
| 140 |
visible = "true" |
| 141 |
with self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog: |
| 142 |
xFlysplit = xDialog.getChild("flysplit") |
| 143 |
visible = get_state_as_dict(xFlysplit)['Visible'] |
| 144 |
|
| 145 |
# Then make sure that the option allow split is hidden: |
| 146 |
# Without the accompanying fix in place, this test would have failed with: |
| 147 |
# AssertionError: 'true' != 'false' |
| 148 |
# - true |
| 149 |
# + false |
| 150 |
# i.e. the UI allowed creating split floating tables in shape text, which is unnecessary |
| 151 |
# complexity. |
| 152 |
self.assertEqual(visible, "false") |
| 153 |
|
| 154 |
def test_keep_aspect_ratio_init(self): |
| 155 |
# Change from inch to pt to hit the rounding error. 6 means Point, see |
| 156 |
# officecfg/registry/schema/org/openoffice/Office/Writer.xcs. |
| 157 |
with self.ui_test.set_config('/org.openoffice.Office.Writer/Layout/Other/MeasureUnit', 6): |
| 158 |
# Given a document with an image, width is relative: |
| 159 |
with self.ui_test.load_file(get_url_for_data_file("keep-aspect-ratio.odt")) as xComponent: |
| 160 |
xComponent.CurrentController.select(xComponent.DrawPage[0]) |
| 161 |
# Wait until SwTextShell is replaced with SwDrawShell after 120 ms, as set in the SwView |
| 162 |
# ctor. |
| 163 |
time.sleep(0.2) |
| 164 |
# When opening the image properties dialog: |
| 165 |
with self.ui_test.execute_dialog_through_command(".uno:FrameDialog") as xDialog: |
| 166 |
xWidth = xDialog.getChild("width") |
| 167 |
frame_width = get_state_as_dict(xWidth)["Value"] |
| 168 |
# Then make sure the width is 48%: |
| 169 |
# Without the accompanying fix in place, this test would have failed with: |
| 170 |
# AssertionError: '5' != '48' |
| 171 |
# i.e. the reported size was close to zero instead of ~half of the page width. |
| 172 |
self.assertEqual(frame_width, "48") |
| 173 |
|
| 174 |
# vim: set shiftwidth=4 softtabstop=4 expandtab: |