solenv/gbuild/UITest.mk               |    3 +
 xmlsecurity/Module_xmlsecurity.mk     |    4 ++
 xmlsecurity/UITest_xmlsecurity_gpg.mk |   20 +++++++++++
 xmlsecurity/qa/uitest/gpg/encrypt.py  |   57 ++++++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+)

New commits:
commit a7327e95cee60d59bdec1b62e144179efa9f2eb8
Author:     Moritz Duge <moritz.d...@allotropia.de>
AuthorDate: Tue May 21 17:25:09 2024 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Wed Jul 17 21:02:52 2024 +0200

    xmlsecurity: Add UItest (save GPG encrypted ODF)
    
    Change-Id: I09dd13334e0d3da5f6004312bae69b5c77120434
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167904
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/solenv/gbuild/UITest.mk b/solenv/gbuild/UITest.mk
index 7f0597f15293..300c28b350ea 100644
--- a/solenv/gbuild/UITest.mk
+++ b/solenv/gbuild/UITest.mk
@@ -41,6 +41,9 @@ gb_UITest_COMMAND = $(ICECREAM_RUN) 
$(gb_CppunitTest_coredumpctl_run) $(gb_Cppun
 
 gb_TEST_ENV_VARS += LIBO_LANG=C
 
+# GNUPGHOME is needed for tests using the LibreOffice GPG features.
+gb_TEST_ENV_VARS += GNUPGHOME="$(SRCDIR)/test/signing-keys"
+
 .PHONY : $(call gb_UITest_get_clean_target,%)
 $(call gb_UITest_get_clean_target,%) :
        $(call gb_Helper_abbreviate_dirs,\
diff --git a/xmlsecurity/Module_xmlsecurity.mk 
b/xmlsecurity/Module_xmlsecurity.mk
index f5b442683ab6..cff200f9fbe2 100644
--- a/xmlsecurity/Module_xmlsecurity.mk
+++ b/xmlsecurity/Module_xmlsecurity.mk
@@ -42,6 +42,10 @@ $(eval $(call gb_Module_add_screenshot_targets,xmlsecurity,\
     CppunitTest_xmlsecurity_dialogs_test \
 ))
 
+$(eval $(call gb_Module_add_uicheck_targets,xmlsecurity,\
+       UITest_xmlsecurity_gpg \
+))
+
 ifneq (,$(filter DESKTOP,$(BUILD_TYPE)))
 ifneq (,$(or $(ENABLE_NSS),$(filter WNT,$(OS))))
 $(eval $(call gb_Module_add_targets,xmlsecurity,\
diff --git a/xmlsecurity/UITest_xmlsecurity_gpg.mk 
b/xmlsecurity/UITest_xmlsecurity_gpg.mk
new file mode 100644
index 000000000000..1cc130e37c3c
--- /dev/null
+++ b/xmlsecurity/UITest_xmlsecurity_gpg.mk
@@ -0,0 +1,20 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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 https://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_UITest_UITest,gpg))
+
+$(eval $(call gb_UITest_add_modules,gpg,$(SRCDIR)/xmlsecurity/qa/uitest,\
+       gpg/ \
+))
+
+$(eval $(call gb_UITest_set_defs,gpg, \
+    TDOC="$(SRCDIR)/xmlsecurity/qa/uitest/data" \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/xmlsecurity/qa/uitest/gpg/encrypt.py 
b/xmlsecurity/qa/uitest/gpg/encrypt.py
new file mode 100644
index 000000000000..2425af841d6a
--- /dev/null
+++ b/xmlsecurity/qa/uitest/gpg/encrypt.py
@@ -0,0 +1,57 @@
+# -*- 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 https://mozilla.org/MPL/2.0/
+#
+
+from uitest.framework import UITestCase
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import get_state_as_dict
+
+from tempfile import TemporaryDirectory
+import os.path
+
+
+# Test for CertificateChooser using GPG.
+#
+# Requires the environment variable GNUPGHOME to be set correctly.
+# See solenv/gbuild/UITest.mk
+class GpgEncryptTest(UITestCase):
+    def test_gpg_encrypt(self):
+        # TODO: Maybe deduplicate with 
sw/qa/uitest/writer_tests8/save_with_password_test_policy.py
+        with TemporaryDirectory() as tempdir:
+            xFilePath = os.path.join(tempdir, "testfile.odt")
+            with self.ui_test.create_doc_in_start_center("writer") as document:
+                MainWindow = self.xUITest.getTopFocusWindow()
+                with self.ui_test.execute_dialog_through_command(".uno:Save", 
close_button="") 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}))
+                    gpgencrypt = xSaveDialog.getChild("gpgencrypt")
+                    gpgencrypt.executeAction("CLICK",tuple())
+                    xOpen = xSaveDialog.getChild("open")
+                    self.assertFalse(os.path.isfile(xFilePath))
+                    with self.ui_test.execute_dialog_through_action(xOpen, 
"CLICK", close_button="cancel") as xSelectCertificateDialog:
+                        signatures = 
xSelectCertificateDialog.getChild("signatures")
+                        signatures.executeAction("TYPE", 
mkPropertyValues({"KEYCODE": "DOWN"}))
+                    self.assertFalse(os.path.isfile(xFilePath))
+                with self.ui_test.execute_dialog_through_command(".uno:Save", 
close_button="") 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}))
+                    gpgencrypt = xSaveDialog.getChild("gpgencrypt")
+                    gpgencrypt.executeAction("CLICK",tuple())
+                    xOpen = xSaveDialog.getChild("open")
+                    self.assertFalse(os.path.isfile(xFilePath))
+                    with self.ui_test.execute_dialog_through_action(xOpen, 
"CLICK", close_button="ok") as xSelectCertificateDialog:
+                        signatures = 
xSelectCertificateDialog.getChild("signatures")
+                        signatures.executeAction("TYPE", 
mkPropertyValues({"KEYCODE": "DOWN"}))
+                    self.assertTrue(os.path.isfile(xFilePath))
+
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:

Reply via email to