sc/qa/uitest/calc_tests7/save_readonly_with_password.py |   91 ++++++++++++++++
 1 file changed, 91 insertions(+)

New commits:
commit 1e562859d597e2523159d93d04e205017da092f4
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri Oct 29 17:36:40 2021 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Sat Oct 30 00:07:13 2021 +0200

    sc: uitest: test "save to ODS/XLSX as read-only with password protection"
    
    Similar to the UItest added in 1b53c1dfc76f08ca7df40a0673aa50eca700d072
    < tdf#144374 DOCX: export the password for editing > for the DOCX format
    
    Change-Id: I4e9349044355107bbf015fc821e330dfb8005922
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124443
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/uitest/calc_tests7/save_readonly_with_password.py 
b/sc/qa/uitest/calc_tests7/save_readonly_with_password.py
new file mode 100644
index 000000000000..c930b3ece9cd
--- /dev/null
+++ b/sc/qa/uitest/calc_tests7/save_readonly_with_password.py
@@ -0,0 +1,91 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# 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/.
+#
+from uitest.framework import UITestCase
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from org.libreoffice.unotest import systemPathToFileUrl
+from uitest.uihelper.common import select_by_text
+from tempfile import TemporaryDirectory
+import os.path
+
+class save_readonly_with_password(UITestCase):
+
+   def test_save_to_xlsx(self):
+
+        with TemporaryDirectory() as tempdir:
+            xFilePath = os.path.join(tempdir, 
"readonly_with_password_tmp.xlsx")
+
+            with self.ui_test.create_doc_in_start_center("calc"):
+                # Save the document
+                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}))
+                    xFileTypeCombo = xSaveDialog.getChild("file_type")
+                    select_by_text(xFileTypeCombo, "Excel 2007–365 (.xlsx)")
+                    xPasswordCheckButton = xSaveDialog.getChild("password")
+                    xPasswordCheckButton.executeAction("CLICK", tuple())
+                    xOpen = xSaveDialog.getChild("open")
+
+                    with self.ui_test.execute_dialog_through_action(xOpen, 
"CLICK") as xPasswordDialog:
+                        xReadonly = xPasswordDialog.getChild("readonly")
+                        xReadonly.executeAction("CLICK", tuple())
+                        xNewPassword = 
xPasswordDialog.getChild("newpassroEntry")
+                        xNewPassword.executeAction("TYPE", 
mkPropertyValues({"TEXT": "password"}))
+                        xConfirmPassword = 
xPasswordDialog.getChild("confirmropassEntry")
+                        xConfirmPassword.executeAction("TYPE", 
mkPropertyValues({"TEXT": "password"}))
+
+                # XLSX confirmation dialog is displayed
+                xWarnDialog = self.xUITest.getTopFocusWindow()
+                xSave = xWarnDialog.getChild("save")
+                self.ui_test.close_dialog_through_button(xSave)
+
+            with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as 
document:
+
+                self.assertTrue(document.isReadonly())
+
+                with 
self.ui_test.execute_dialog_through_command(".uno:EditDoc") as xDialog:
+                    xPassword = xDialog.getChild("newpassEntry")
+                    xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": 
"password"}))
+
+                self.assertFalse(document.isReadonly())
+
+   def test_save_to_ods(self):
+
+        with TemporaryDirectory() as tempdir:
+            xFilePath = os.path.join(tempdir, "readonly_with_password_tmp.ods")
+
+            with self.ui_test.create_doc_in_start_center("calc"):
+                # Save the document
+                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}))
+                    xPasswordCheckButton = xSaveDialog.getChild("password")
+                    xPasswordCheckButton.executeAction("CLICK", tuple())
+                    xOpen = xSaveDialog.getChild("open")
+
+                    with self.ui_test.execute_dialog_through_action(xOpen, 
"CLICK") as xPasswordDialog:
+                        xReadonly = xPasswordDialog.getChild("readonly")
+                        xReadonly.executeAction("CLICK", tuple())
+                        xNewPassword = 
xPasswordDialog.getChild("newpassroEntry")
+                        xNewPassword.executeAction("TYPE", 
mkPropertyValues({"TEXT": "password"}))
+                        xConfirmPassword = 
xPasswordDialog.getChild("confirmropassEntry")
+                        xConfirmPassword.executeAction("TYPE", 
mkPropertyValues({"TEXT": "password"}))
+
+            with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as 
document:
+
+                self.assertTrue(document.isReadonly())
+
+                with 
self.ui_test.execute_dialog_through_command(".uno:EditDoc") as xDialog:
+                    xPassword = xDialog.getChild("newpassEntry")
+                    xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": 
"password"}))
+
+                self.assertFalse(document.isReadonly())
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:

Reply via email to