Get the style color and number just once
[LibreOffice.git] / sw / qa / uitest / writer_tests7 / tdf90401.py
blob6c29269a58805e8f301c5893c5852ef878fc757f
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 xTreeList.getChild('0').executeAction("SELECT", tuple())
83 state = get_state_as_dict(xTreeList)
84 # This was 'NL\t11/03/2020 19:19:05\t', containing personal info
85 self.assertEqual(state['SelectEntryText'], 'Author1\t01/01/1970 00:00:00\t')
86 finally:
87 self.change_security_option("false")
89 def test_tdf142902_remove_personal_info_in_DOCX(self):
90 # load a test document with a tracked change, and add a comment
91 with TemporaryDirectory() as tempdir:
92 try:
93 self.change_security_option("true")
95 xFilePath = os.path.join(tempdir, 'redline-para-join-tmp.docx')
97 with self.ui_test.load_file(get_url_for_data_file('redline-para-join.docx')):
99 self.xUITest.executeCommand('.uno:SelectAll')
100 self.xUITest.executeCommand('.uno:InsertAnnotation')
102 # Save Copy as
103 with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="") as xDialog:
104 xFileName = xDialog.getChild('file_name')
105 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'}))
106 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'}))
107 xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath}))
109 xOpen = xDialog.getChild("open")
110 # DOCX confirmation dialog is displayed
111 with self.ui_test.execute_dialog_through_action(xOpen, "CLICK", close_button="save"):
112 pass
114 with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as writer_doc2:
116 # check removed personal info on comments
118 textfields = writer_doc2.getTextFields()
119 author = ""
120 year = -1
121 for textfield in textfields:
122 if textfield.supportsService("com.sun.star.text.TextField.Annotation"):
123 author = textfield.Author
124 year = textfield.Date.Year
125 # This was 'Unknown Author'
126 self.assertEqual(author, 'Author2')
127 # This was 2021
128 self.assertEqual(year, 0)
130 # check removed personal info on tracked changes
132 with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg:
133 xTreeList = xTrackDlg.getChild('writerchanges')
134 xTreeList.getChild('0').executeAction("SELECT", tuple())
135 state = get_state_as_dict(xTreeList)
136 # This was 'NL\t11/03/2020 19:19:05\t', containing personal info
137 self.assertEqual(state['SelectEntryText'], 'Author1\t01/01/1970 00:00:00\t')
138 finally:
139 self.change_security_option("false")
141 # vim: set shiftwidth=4 softtabstop=4 expandtab: