Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / uitest / writer_tests7 / tdf90401.py
blob95cc966e1dc7a689f7676d19482a02bb1df84fd0
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
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/.
10 from uitest.framework import UITestCase
11 #from uitest.uihelper.common import type_text
12 from uitest.uihelper.common import get_state_as_dict
13 from uitest.uihelper.common import get_url_for_data_file
14 from libreoffice.uno.propertyvalue import mkPropertyValues
15 from org.libreoffice.unotest import systemPathToFileUrl
16 from tempfile import TemporaryDirectory
17 import os.path
18 #Bug 90401 - remove personal info on redlines and annotations
20 class tdf90401(UITestCase):
22 def change_security_option(self, enabled):
23 with self.ui_test.execute_dialog_through_command('.uno:OptionsTreeDialog') as xDialog:
24 xPages = xDialog.getChild('pages')
25 xGenEntry = xPages.getChild('0')
26 xSecurityPage = xGenEntry.getChild('6')
27 xSecurityPage.executeAction('SELECT', tuple())
28 # Click Button Options...
29 xOptions = xDialog.getChild('options')
31 with self.ui_test.execute_blocking_action(xOptions.executeAction, args=('CLICK', ()), close_button="") as dialog:
32 xRemovePersonal = dialog.getChild('removepersonal')
33 if get_state_as_dict(xRemovePersonal)['Selected'] != enabled:
34 xRemovePersonal.executeAction('CLICK', tuple())
35 self.ui_test.wait_until_property_is_updated(xRemovePersonal, "Selected", enabled)
36 self.assertEqual(get_state_as_dict(xRemovePersonal)["Selected"], enabled)
38 xOkBtn = dialog.getChild('ok')
39 # FIXME: we can't use close_dialog_through_button here, the dialog doesn't emit the
40 # event DialogClosed after closing
41 xOkBtn.executeAction('CLICK', tuple())
43 def test_tdf90401_remove_personal_info(self):
44 # load a test document with a tracked change, and add a comment
46 with TemporaryDirectory() as tempdir:
47 try:
48 self.change_security_option("true")
50 xFilePath = os.path.join(tempdir, 'tdf90401-tmp.fodt')
52 with self.ui_test.load_file(get_url_for_data_file('redline-autocorrect.fodt')):
53 self.xUITest.executeCommand('.uno:SelectAll')
54 self.xUITest.executeCommand('.uno:InsertAnnotation')
56 # Save Copy as
57 with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="open") as xDialog:
58 xFileName = xDialog.getChild('file_name')
59 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'}))
60 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'}))
61 xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath}))
63 with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as writer_doc2:
65 # check removed personal info on comments
67 textfields = writer_doc2.getTextFields()
68 author = ""
69 year = -1
70 for textfield in textfields:
71 if textfield.supportsService("com.sun.star.text.TextField.Annotation"):
72 author = textfield.Author
73 year = textfield.Date.Year
74 # This was 'Unknown Author'
75 self.assertEqual(author, 'Author2')
76 # This was 2021
77 self.assertEqual(year, 0)
79 # check removed personal info on tracked changes
80 with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg:
81 xTreeList = xTrackDlg.getChild('writerchanges')
82 state = get_state_as_dict(xTreeList)
83 # This was 'NL\t11/03/2020 19:19:05\t', containing personal info
84 self.assertEqual(state['SelectEntryText'], 'Author1\t01/01/1970 00:00:00\t')
85 finally:
86 self.change_security_option("false")
88 def test_tdf142902_remove_personal_info_in_DOCX(self):
89 # load a test document with a tracked change, and add a comment
90 with TemporaryDirectory() as tempdir:
91 try:
92 self.change_security_option("true")
94 xFilePath = os.path.join(tempdir, 'redline-para-join-tmp.docx')
96 with self.ui_test.load_file(get_url_for_data_file('redline-para-join.docx')):
98 self.xUITest.executeCommand('.uno:SelectAll')
99 self.xUITest.executeCommand('.uno:InsertAnnotation')
101 # Save Copy as
102 with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="") as xDialog:
103 xFileName = xDialog.getChild('file_name')
104 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'}))
105 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'}))
106 xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath}))
108 xOpen = xDialog.getChild("open")
109 # DOCX confirmation dialog is displayed
110 with self.ui_test.execute_dialog_through_action(xOpen, "CLICK", close_button="save"):
111 pass
113 with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as writer_doc2:
115 # check removed personal info on comments
117 textfields = writer_doc2.getTextFields()
118 author = ""
119 year = -1
120 for textfield in textfields:
121 if textfield.supportsService("com.sun.star.text.TextField.Annotation"):
122 author = textfield.Author
123 year = textfield.Date.Year
124 # This was 'Unknown Author'
125 self.assertEqual(author, 'Author2')
126 # This was 2021
127 self.assertEqual(year, 0)
129 # check removed personal info on tracked changes
131 with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg:
132 xTreeList = xTrackDlg.getChild('writerchanges')
133 state = get_state_as_dict(xTreeList)
134 # This was 'NL\t11/03/2020 19:19:05\t', containing personal info
135 self.assertEqual(state['SelectEntryText'], 'Author1\t01/01/1970 00:00:00\t')
136 finally:
137 self.change_security_option("false")
139 # vim: set shiftwidth=4 softtabstop=4 expandtab: