1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
# -*- 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/.
#
# tests for tracked changes ; tdf912270
from uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file, type_text, select_by_text
from libreoffice.uno.propertyvalue import mkPropertyValues
from tempfile import TemporaryDirectory
from org.libreoffice.unotest import systemPathToFileUrl
import os.path
class trackedchanges(UITestCase):
def test_tdf91270(self):
with self.ui_test.create_doc_in_start_center("writer") as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
type_text(xWriterEdit, "Test")
self.xUITest.executeCommand(".uno:TrackChanges")
self.xUITest.executeCommand(".uno:SelectAll") #select whole text
self.xUITest.executeCommand(".uno:Cut") #cut text
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close"):
pass
def test_tracked_changes_accept(self):
with self.ui_test.create_doc_in_start_center("writer") as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, "Test LibreOffice")
self.xUITest.executeCommand(".uno:ShowTrackedChanges")
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
xAccBtn = xTrackDlg.getChild("accept")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(document.Text.String[0:16], "Test LibreOffice")
def test_tracked_changes_acceptall(self):
with self.ui_test.create_doc_in_start_center("writer") as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, "Test LibreOffice")
self.xUITest.executeCommand(".uno:ShowTrackedChanges")
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
xAccBtn = xTrackDlg.getChild("acceptall")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(document.Text.String[0:16], "Test LibreOffice")
def test_tracked_changes_reject(self):
with self.ui_test.create_doc_in_start_center("writer") as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, "Test LibreOffice")
self.xUITest.executeCommand(".uno:ShowTrackedChanges")
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
xRejBtn = xTrackDlg.getChild("reject")
xRejBtn.executeAction("CLICK", tuple())
self.assertEqual(document.Text.String[0:1], "")
def test_tracked_changes_rejectall(self):
with self.ui_test.create_doc_in_start_center("writer") as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, "Test LibreOffice")
self.xUITest.executeCommand(".uno:ShowTrackedChanges")
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
xAccBtn = xTrackDlg.getChild("rejectall")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(document.Text.String[0:1], "")
def test_tracked_changes_zprev_next(self):
with self.ui_test.create_doc_in_start_center("writer") as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, "Test LibreOffice")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, " Test2")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, " Test3")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, " Test4")
self.xUITest.executeCommand(".uno:TrackChanges")
type_text(xWriterEdit, " Test5")
self.xUITest.executeCommand(".uno:PreviousTrackedChange")
self.xUITest.executeCommand(".uno:RejectTrackedChange")
self.assertEqual(document.Text.String[0:37], "Test LibreOffice Test2 Test3 Test4")
self.xUITest.executeCommand(".uno:PreviousTrackedChange")
self.xUITest.executeCommand(".uno:PreviousTrackedChange")
self.xUITest.executeCommand(".uno:AcceptTrackedChange")
self.assertEqual(document.Text.String[0:37], "Test LibreOffice Test2 Test3 Test4")
self.xUITest.executeCommand(".uno:NextTrackedChange")
self.xUITest.executeCommand(".uno:RejectTrackedChange")
self.assertEqual(document.Text.String[0:30], "Test LibreOffice Test2 Test4")
def test_list_of_changes(self):
with self.ui_test.load_file(get_url_for_data_file("trackedChanges.odt")) as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
listText = [
"Unknown Author\t01/24/2020 16:19:32\t",
"Unknown Author\t01/24/2020 16:19:35\t",
"Unknown Author\t01/24/2020 16:19:39\t",
"Unknown Author\t01/24/2020 16:19:39\t",
"Xisco Fauli\t01/27/2020 17:42:55\t"]
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild("writerchanges")
resultsAccept = [
"The tennis ball is a small ball. The baskedtball is much bigger.",
"The tennis ball is a small ball. The baskedtball is much bigger.",
"The tennis ball is a small ball. The baskedtball is much bigger.",
"The tennis ball is a small ball. The basketball is much bigger.",
"The tennis ball is a small ball. The basketball is much bigger.",
"The tennis ball is a small ball. The basketball is much bigger."]
for i in range(len(listText)):
self.assertEqual(document.Text.String.strip(), resultsAccept[i])
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], listText[i] )
xAccBtn = xTrackDlg.getChild("accept")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(document.Text.String.strip(), resultsAccept[5])
#List is empty
self.assertFalse('0' in changesList.getChildren())
for i in reversed(range(len(listText))):
xUndoBtn = xTrackDlg.getChild("undo")
xUndoBtn.executeAction("CLICK", tuple())
self.assertEqual(document.Text.String.strip(), resultsAccept[i])
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], listText[i] )
resultsReject = [
"The tennis ball is a small ball. The baskedtball is much bigger.",
"The tenis ball is a small ball. The baskedtball is much bigger.",
"The tenis ball is a small bal. The baskedtball is much bigger.",
"The tenis ball is a small bal. The baskedtball is much bigger.",
"The tenis ball is a small bal. The baskedball is much bigger.",
"The tenis ball is a small bal. The baskedball is much biger."]
for i in range(len(listText)):
self.assertEqual(document.Text.String.strip(), resultsReject[i])
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], listText[i] )
xAccBtn = xTrackDlg.getChild("reject")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(document.Text.String.strip(), resultsReject[5])
#List is empty
self.assertFalse('0' in changesList.getChildren())
for i in reversed(range(len(listText))):
xUndoBtn = xTrackDlg.getChild("undo")
xUndoBtn.executeAction("CLICK", tuple())
self.assertEqual(document.Text.String.strip(), resultsReject[i])
self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], listText[i] )
def test_tdf135018(self):
with self.ui_test.load_file(get_url_for_data_file("tdf135018.odt")) as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
self.assertEqual(5, document.CurrentController.PageCount)
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild("writerchanges")
self.assertEqual(111, len(changesList.getChildren()))
# Without the fix in place, it would have crashed here
xAccBtn = xTrackDlg.getChild("acceptall")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(0, len(changesList.getChildren()))
xUndoBtn = xTrackDlg.getChild("undo")
xUndoBtn.executeAction("CLICK", tuple())
self.assertEqual(111, len(changesList.getChildren()))
# Check the changes are shown after opening the Manage Tracked Changes dialog
self.assertGreater(document.CurrentController.PageCount, 5)
def test_tdf144270_tracked_table_rows(self):
with self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
tables = document.getTextTables()
self.assertEqual(3, len(tables))
# Accept
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild("writerchanges")
# This was 14 (every cell is a different change instead of counting rows or tables)
# Now: 4 changes (2 deleted/inserted rows and 2 deleted/inserted tables)
self.assertEqual(4, len(changesList.getChildren()))
# Without the fix in place, it would have crashed here
for i in (3, 2, 1, 0):
xAccBtn = xTrackDlg.getChild("accept")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(i, len(changesList.getChildren()))
tables = document.getTextTables()
self.assertEqual(2, len(tables))
for i in range(1, 5):
xUndoBtn = xTrackDlg.getChild("undo")
xUndoBtn.executeAction("CLICK", tuple())
self.assertEqual(i, len(changesList.getChildren()))
tables = document.getTextTables()
self.assertEqual(3, len(tables))
# Accept All
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild("writerchanges")
# This was 14 (every cell is a different change instead of counting rows or tables)
# Now: 4 changes (2 deleted/inserted rows and 2 deleted/inserted tables)
self.assertEqual(4, len(changesList.getChildren()))
xAccBtn = xTrackDlg.getChild("acceptall")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(0, len(changesList.getChildren()))
tables = document.getTextTables()
self.assertEqual(2, len(tables))
xUndoBtn = xTrackDlg.getChild("undo")
xUndoBtn.executeAction("CLICK", tuple())
self.assertEqual(4, len(changesList.getChildren()))
tables = document.getTextTables()
self.assertEqual(3, len(tables))
# goto to the start of the document to reject from the first tracked table row change
self.xUITest.executeCommand(".uno:GoToStartOfDoc")
# Reject
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild("writerchanges")
# This was 14 (every cell is a different change instead of counting rows or tables)
# Now: 4 changes (2 deleted/inserted rows and 2 deleted/inserted tables)
self.assertEqual(4, len(changesList.getChildren()))
# Without the fix in place, it would have crashed here
for i in (3, 2, 1, 0):
xAccBtn = xTrackDlg.getChild("reject")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(i, len(changesList.getChildren()))
tables = document.getTextTables()
self.assertEqual(2, len(tables))
for i in range(1, 5):
xUndoBtn = xTrackDlg.getChild("undo")
xUndoBtn.executeAction("CLICK", tuple())
self.assertEqual(i, len(changesList.getChildren()))
tables = document.getTextTables()
self.assertEqual(3, len(tables))
# Reject All
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild("writerchanges")
# This was 14 (every cell is a different change instead of counting rows or tables)
# Now: 4 changes (2 deleted/inserted rows and 2 deleted/inserted tables)
self.assertEqual(4, len(changesList.getChildren()))
xAccBtn = xTrackDlg.getChild("rejectall")
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(0, len(changesList.getChildren()))
tables = document.getTextTables()
self.assertEqual(2, len(tables))
xUndoBtn = xTrackDlg.getChild("undo")
xUndoBtn.executeAction("CLICK", tuple())
self.assertEqual(4, len(changesList.getChildren()))
tables = document.getTextTables()
self.assertEqual(3, len(tables))
def test_tdf148032(self):
with self.ui_test.load_file(get_url_for_data_file("trackedChanges.odt")) as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
# adding new Comment
self.xUITest.executeCommand(".uno:InsertAnnotation")
# wait until the comment is available
xComment1 = self.ui_test.wait_until_child_is_available('Comment1')
xEditView1 = xComment1.getChild("editview")
xEditView1.executeAction("TYPE", mkPropertyValues({"TEXT": "This is the First Comment"}))
self.assertEqual(get_state_as_dict(xComment1)["Text"], "This is the First Comment" )
self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" )
self.assertEqual(get_state_as_dict(xComment1)["Author"], "Unknown Author" )
self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" )
xComment1.executeAction("LEAVE", mkPropertyValues({}))
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild("writerchanges")
self.assertEqual(6, len(changesList.getChildren()))
xChild = changesList.getChild(0)
# This was False (missing comment)
self.assertEqual(True, get_state_as_dict(xChild)["Text"].endswith('\tComment added'))
def test_tdf147179(self):
with self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as document:
xWriterDoc = self.xUITest.getTopFocusWindow()
xWriterEdit = xWriterDoc.getChild("writer_edit")
tables = document.getTextTables()
self.assertEqual(3, len(tables))
# Select text of the tracked row, not only text of its first cell
with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild("writerchanges")
# select second tracked table row in tree list
changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
while get_state_as_dict(xWriterEdit)["SelectedText"] != 'klj':
xToolkit.processEventsToIdle()
# this was "j" (only text of the first cell was selected, not text of the row)
self.assertEqual(get_state_as_dict(xWriterEdit)["SelectedText"], "klj" )
# select first tracked table row in tree list
changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
while get_state_as_dict(xWriterEdit)["SelectedText"] != 'bca':
xToolkit.processEventsToIdle()
# this was "a" (only text of the first cell was selected, not text of the row)
self.assertEqual(get_state_as_dict(xWriterEdit)["SelectedText"], "bca" )
def test_RedlineSuccessorData(self):
with TemporaryDirectory() as tempdir:
xFilePath = os.path.join(tempdir, "redlinesuccessordata-temp.odt")
with self.ui_test.load_file(get_url_for_data_file("redlinesuccessordata.docx")) as document:
# check tracked deletion in tracked insertion
with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild('writerchanges')
# four children, but only three visible
state = get_state_as_dict(changesList)
self.assertEqual(state['Children'], '4')
self.assertEqual(state['VisibleCount'], '3')
# select tracked deletion with RedlineSuccessorData in tree list
changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
state = get_state_as_dict(changesList)
self.assertEqual(state['SelectEntryText'], 'Kelemen Gábor 2\t05/19/2021 12:35:00\t')
self.assertEqual(get_state_as_dict(changesList.getChild(1))['Children'], '1')
self.assertEqual(get_state_as_dict(changesList.getChild(1))['VisibleChildCount'], '0')
# open tree node with the tracked insertion: four visible children
changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RIGHT"}))
state = get_state_as_dict(changesList)
self.assertEqual(state['Children'], '4')
self.assertEqual(state['VisibleCount'], '4')
self.assertEqual(get_state_as_dict(changesList.getChild(1))['Children'], '1')
self.assertEqual(get_state_as_dict(changesList.getChild(1))['VisibleChildCount'], '1')
# select tracked insertion in tree list
changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
state = get_state_as_dict(changesList)
self.assertEqual(state['SelectEntryText'], 'First Person\t10/21/2012 23:45:00\t')
# Save the DOCX document as ODT with a tracked deletion in a tracked insertion
with self.ui_test.execute_dialog_through_command(".uno:SaveAs", close_button="open") as xSaveDialog:
xFileName = xSaveDialog.getChild("file_name")
xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": xFilePath}))
xFileTypeCombo = xSaveDialog.getChild("file_type")
select_by_text(xFileTypeCombo, "ODF Text Document (.odt)")
self.ui_test.wait_until_file_is_available(xFilePath)
# load the temporary file, and check ODF roundtrip of the tracked deletion in a tracked insertion
with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as document:
# check tracked deletion in tracked insertion
with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg:
changesList = xTrackDlg.getChild('writerchanges')
# four children, but only three visible
state = get_state_as_dict(changesList)
self.assertEqual(state['Children'], '4')
self.assertEqual(state['VisibleCount'], '3')
# select tracked deletion with RedlineSuccessorData in tree list
changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
state = get_state_as_dict(changesList)
self.assertEqual(state['SelectEntryText'], 'Kelemen Gábor 2\t05/19/2021 12:35:00\t')
self.assertEqual(get_state_as_dict(changesList.getChild(1))['Children'], '1')
self.assertEqual(get_state_as_dict(changesList.getChild(1))['VisibleChildCount'], '0')
# open tree node with the tracked insertion: four visible children
changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RIGHT"}))
state = get_state_as_dict(changesList)
self.assertEqual(state['Children'], '4')
self.assertEqual(state['VisibleCount'], '4')
self.assertEqual(get_state_as_dict(changesList.getChild(1))['Children'], '1')
self.assertEqual(get_state_as_dict(changesList.getChild(1))['VisibleChildCount'], '1')
# select tracked insertion in tree list
changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
state = get_state_as_dict(changesList)
self.assertEqual(state['SelectEntryText'], 'First Person\t10/21/2012 23:45:00\t')
# reject all
xAccBtn = xTrackDlg.getChild("rejectall")
xAccBtn.executeAction("CLICK", tuple())
# FIXME why we need double rejectall (dialog-only)?
xAccBtn.executeAction("CLICK", tuple())
self.assertEqual(0, len(changesList.getChildren()))
# This was false, because of not rejected tracked deletion
# of the text "inserts": "Document text inserts document"...
self.assertTrue(document.getText().getString().startswith('Document text document text'))
# vim: set shiftwidth=4 softtabstop=4 expandtab:
|