diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-02-13 12:04:53 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-02-13 13:13:27 +0000 |
commit | 32267c54d7430886e643b297b5e03f5fbf08cf19 (patch) | |
tree | 8704e8e1f1fa71d9b40e9a1c866e85d9527d6f1a /sw/qa/uitest | |
parent | 4beaa92bc2c91e7ff84b044469d376216efec2fe (diff) |
sw: use try/finally to reset the changes in OptionsTreeDialog
Otherwise it might affect other tests if it hits an assert
Change-Id: I16b818edc0f4414937f28b8459d06712c7db9eac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146896
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sw/qa/uitest')
-rw-r--r-- | sw/qa/uitest/writer_tests7/tdf90401.py | 238 |
1 files changed, 111 insertions, 127 deletions
diff --git a/sw/qa/uitest/writer_tests7/tdf90401.py b/sw/qa/uitest/writer_tests7/tdf90401.py index 15c1f3c31c12..95cc966e1dc7 100644 --- a/sw/qa/uitest/writer_tests7/tdf90401.py +++ b/sw/qa/uitest/writer_tests7/tdf90401.py @@ -19,137 +19,121 @@ import os.path class tdf90401(UITestCase): - def test_tdf90401_remove_personal_info(self): - + def change_security_option(self, enabled): + with self.ui_test.execute_dialog_through_command('.uno:OptionsTreeDialog') as xDialog: + xPages = xDialog.getChild('pages') + xGenEntry = xPages.getChild('0') + xSecurityPage = xGenEntry.getChild('6') + xSecurityPage.executeAction('SELECT', tuple()) + # Click Button Options... + xOptions = xDialog.getChild('options') + + with self.ui_test.execute_blocking_action(xOptions.executeAction, args=('CLICK', ()), close_button="") as dialog: + xRemovePersonal = dialog.getChild('removepersonal') + if get_state_as_dict(xRemovePersonal)['Selected'] != enabled: + xRemovePersonal.executeAction('CLICK', tuple()) + self.ui_test.wait_until_property_is_updated(xRemovePersonal, "Selected", enabled) + self.assertEqual(get_state_as_dict(xRemovePersonal)["Selected"], enabled) + + xOkBtn = dialog.getChild('ok') + # FIXME: we can't use close_dialog_through_button here, the dialog doesn't emit the + # event DialogClosed after closing + xOkBtn.executeAction('CLICK', tuple()) + + def test_tdf90401_remove_personal_info(self): # load a test document with a tracked change, and add a comment with TemporaryDirectory() as tempdir: - xFilePath = os.path.join(tempdir, 'tdf90401-tmp.fodt') - - with self.ui_test.load_file(get_url_for_data_file('redline-autocorrect.fodt')): - - self.xUITest.executeCommand('.uno:SelectAll') - self.xUITest.executeCommand('.uno:InsertAnnotation') - - # enable remove personal info security option - - with self.ui_test.execute_dialog_through_command('.uno:OptionsTreeDialog') as xDialog: - xPages = xDialog.getChild('pages') - xGenEntry = xPages.getChild('0') - xSecurityPage = xGenEntry.getChild('6') - xSecurityPage.executeAction('SELECT', tuple()) - # Click Button Options... - xOptions = xDialog.getChild('options') - - with self.ui_test.execute_blocking_action(xOptions.executeAction, args=('CLICK', ()), close_button="") as dialog: - xRemovePersonal = dialog.getChild('removepersonal') - if get_state_as_dict(xRemovePersonal)['Selected'] == "false": - xRemovePersonal.executeAction('CLICK', tuple()) - self.ui_test.wait_until_property_is_updated(xRemovePersonal, "Selected", "true") - self.assertEqual(get_state_as_dict(xRemovePersonal)["Selected"], "true") - - xOkBtn = dialog.getChild('ok') - # FIXME: we can't use close_dialog_through_button here, the dialog doesn't emit the - # event DialogClosed after closing - xOkBtn.executeAction('CLICK', tuple()) - - # Save Copy as - with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="open") as xDialog: - xFileName = xDialog.getChild('file_name') - xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'})) - xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'})) - xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath})) - - with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as writer_doc2: - - # check removed personal info on comments - - textfields = writer_doc2.getTextFields() - author = "" - year = -1 - for textfield in textfields: - if textfield.supportsService("com.sun.star.text.TextField.Annotation"): - author = textfield.Author - year = textfield.Date.Year - # This was 'Unknown Author' - self.assertEqual(author, 'Author2') - # This was 2021 - self.assertEqual(year, 0) - - # check removed personal info on tracked changes - with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg: - xTreeList = xTrackDlg.getChild('writerchanges') - state = get_state_as_dict(xTreeList) - # This was 'NL\t11/03/2020 19:19:05\t', containing personal info - self.assertEqual(state['SelectEntryText'], 'Author1\t01/01/1970 00:00:00\t') - - def test_tdf142902_remove_personal_info_in_DOCX(self): - + try: + self.change_security_option("true") + + xFilePath = os.path.join(tempdir, 'tdf90401-tmp.fodt') + + with self.ui_test.load_file(get_url_for_data_file('redline-autocorrect.fodt')): + self.xUITest.executeCommand('.uno:SelectAll') + self.xUITest.executeCommand('.uno:InsertAnnotation') + + # Save Copy as + with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="open") as xDialog: + xFileName = xDialog.getChild('file_name') + xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'})) + xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'})) + xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath})) + + with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as writer_doc2: + + # check removed personal info on comments + + textfields = writer_doc2.getTextFields() + author = "" + year = -1 + for textfield in textfields: + if textfield.supportsService("com.sun.star.text.TextField.Annotation"): + author = textfield.Author + year = textfield.Date.Year + # This was 'Unknown Author' + self.assertEqual(author, 'Author2') + # This was 2021 + self.assertEqual(year, 0) + + # check removed personal info on tracked changes + with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg: + xTreeList = xTrackDlg.getChild('writerchanges') + state = get_state_as_dict(xTreeList) + # This was 'NL\t11/03/2020 19:19:05\t', containing personal info + self.assertEqual(state['SelectEntryText'], 'Author1\t01/01/1970 00:00:00\t') + finally: + self.change_security_option("false") + + def test_tdf142902_remove_personal_info_in_DOCX(self): # load a test document with a tracked change, and add a comment with TemporaryDirectory() as tempdir: - xFilePath = os.path.join(tempdir, 'redline-para-join-tmp.docx') - - with self.ui_test.load_file(get_url_for_data_file('redline-para-join.docx')): - - self.xUITest.executeCommand('.uno:SelectAll') - self.xUITest.executeCommand('.uno:InsertAnnotation') - - # enable remove personal info security option - - with self.ui_test.execute_dialog_through_command('.uno:OptionsTreeDialog') as xDialog: - xPages = xDialog.getChild('pages') - xGenEntry = xPages.getChild('0') - xSecurityPage = xGenEntry.getChild('6') - xSecurityPage.executeAction('SELECT', tuple()) - # Click Button Options... - xOptions = xDialog.getChild('options') - - with self.ui_test.execute_blocking_action(xOptions.executeAction, args=('CLICK', ()), close_button="") as dialog: - xRemovePersonal = dialog.getChild('removepersonal') - if get_state_as_dict(xRemovePersonal)['Selected'] == "false": - xRemovePersonal.executeAction('CLICK', tuple()) - self.ui_test.wait_until_property_is_updated(xRemovePersonal, "Selected", "true") - self.assertEqual(get_state_as_dict(xRemovePersonal)["Selected"], "true") - - xOkBtn = dialog.getChild('ok') - # FIXME: we can't use close_dialog_through_button here, the dialog doesn't emit the - # event DialogClosed after closing - xOkBtn.executeAction('CLICK', tuple()) - - # Save Copy as - with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="") as xDialog: - xFileName = xDialog.getChild('file_name') - xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'})) - xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'})) - xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath})) - - xOpen = xDialog.getChild("open") - # DOCX confirmation dialog is displayed - with self.ui_test.execute_dialog_through_action(xOpen, "CLICK", close_button="save"): - pass - - with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as writer_doc2: - - # check removed personal info on comments - - textfields = writer_doc2.getTextFields() - author = "" - year = -1 - for textfield in textfields: - if textfield.supportsService("com.sun.star.text.TextField.Annotation"): - author = textfield.Author - year = textfield.Date.Year - # This was 'Unknown Author' - self.assertEqual(author, 'Author2') - # This was 2021 - self.assertEqual(year, 0) - - # check removed personal info on tracked changes - - with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg: - xTreeList = xTrackDlg.getChild('writerchanges') - state = get_state_as_dict(xTreeList) - # This was 'NL\t11/03/2020 19:19:05\t', containing personal info - self.assertEqual(state['SelectEntryText'], 'Author1\t01/01/1970 00:00:00\t') + try: + self.change_security_option("true") + + xFilePath = os.path.join(tempdir, 'redline-para-join-tmp.docx') + + with self.ui_test.load_file(get_url_for_data_file('redline-para-join.docx')): + + self.xUITest.executeCommand('.uno:SelectAll') + self.xUITest.executeCommand('.uno:InsertAnnotation') + + # Save Copy as + with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="") as xDialog: + xFileName = xDialog.getChild('file_name') + xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'})) + xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'})) + xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath})) + + xOpen = xDialog.getChild("open") + # DOCX confirmation dialog is displayed + with self.ui_test.execute_dialog_through_action(xOpen, "CLICK", close_button="save"): + pass + + with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as writer_doc2: + + # check removed personal info on comments + + textfields = writer_doc2.getTextFields() + author = "" + year = -1 + for textfield in textfields: + if textfield.supportsService("com.sun.star.text.TextField.Annotation"): + author = textfield.Author + year = textfield.Date.Year + # This was 'Unknown Author' + self.assertEqual(author, 'Author2') + # This was 2021 + self.assertEqual(year, 0) + + # check removed personal info on tracked changes + + with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg: + xTreeList = xTrackDlg.getChild('writerchanges') + state = get_state_as_dict(xTreeList) + # This was 'NL\t11/03/2020 19:19:05\t', containing personal info + self.assertEqual(state['SelectEntryText'], 'Author1\t01/01/1970 00:00:00\t') + finally: + self.change_security_option("false") # vim: set shiftwidth=4 softtabstop=4 expandtab: |