Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / calc_tests7 / save_readonly_with_password.py
blobc7d2f829e32cb418f0b765a878c75e030024e936
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/.
9 from uitest.framework import UITestCase
10 from libreoffice.uno.propertyvalue import mkPropertyValues
11 from com.sun.star.beans import PropertyValue
12 from org.libreoffice.unotest import systemPathToFileUrl
13 from uitest.uihelper.common import select_by_text
14 from tempfile import TemporaryDirectory
15 import os.path
17 class save_readonly_with_password(UITestCase):
19 def test_save_to_xlsx(self):
21 with TemporaryDirectory() as tempdir:
22 xFilePath = os.path.join(tempdir, "readonly_with_password_tmp.xlsx")
24 with self.ui_test.create_doc_in_start_center("calc"):
25 # Save the document
26 with self.ui_test.execute_dialog_through_command(".uno:Save", close_button="") as xSaveDialog:
27 xFileName = xSaveDialog.getChild("file_name")
28 xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
29 xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
30 xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": xFilePath}))
31 xFileTypeCombo = xSaveDialog.getChild("file_type")
32 select_by_text(xFileTypeCombo, "Excel 2007–365 (.xlsx)")
33 xPasswordCheckButton = xSaveDialog.getChild("password")
34 xPasswordCheckButton.executeAction("CLICK", tuple())
35 xOpen = xSaveDialog.getChild("open")
37 with self.ui_test.execute_dialog_through_action(xOpen, "CLICK", close_button="") as xPasswordDialog:
38 xReadonly = xPasswordDialog.getChild("readonly")
39 xReadonly.executeAction("CLICK", tuple())
40 xNewPassword = xPasswordDialog.getChild("newpassroEntry")
41 xNewPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
42 xConfirmPassword = xPasswordDialog.getChild("confirmropassEntry")
43 xConfirmPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
45 xOk = xPasswordDialog.getChild("ok")
46 # XLSX confirmation dialog is displayed
47 with self.ui_test.execute_dialog_through_action(xOk, "CLICK", close_button="save"):
48 pass
50 with self.ui_test.load_file(systemPathToFileUrl(xFilePath), [PropertyValue(Name="Silent", Value=True)]) as document:
51 self.assertTrue(document.isReadonly())
53 with self.ui_test.execute_dialog_through_command(".uno:EditDoc") as xDialog:
54 xPassword = xDialog.getChild("newpassEntry")
55 xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
57 self.assertFalse(document.isReadonly())
59 def test_save_to_ods(self):
61 with TemporaryDirectory() as tempdir:
62 xFilePath = os.path.join(tempdir, "readonly_with_password_tmp.ods")
64 with self.ui_test.create_doc_in_start_center("calc"):
65 # Save the document
66 with self.ui_test.execute_dialog_through_command(".uno:Save", close_button="") as xSaveDialog:
67 xFileName = xSaveDialog.getChild("file_name")
68 xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
69 xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
70 xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": xFilePath}))
71 xPasswordCheckButton = xSaveDialog.getChild("password")
72 xPasswordCheckButton.executeAction("CLICK", tuple())
73 xOpen = xSaveDialog.getChild("open")
75 with self.ui_test.execute_dialog_through_action(xOpen, "CLICK") as xPasswordDialog:
76 xReadonly = xPasswordDialog.getChild("readonly")
77 xReadonly.executeAction("CLICK", tuple())
78 xNewPassword = xPasswordDialog.getChild("newpassroEntry")
79 xNewPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
80 xConfirmPassword = xPasswordDialog.getChild("confirmropassEntry")
81 xConfirmPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
83 with self.ui_test.load_file(systemPathToFileUrl(xFilePath), [PropertyValue(Name="Silent", Value=True)]) as document:
85 self.assertTrue(document.isReadonly())
87 with self.ui_test.execute_dialog_through_command(".uno:EditDoc") as xDialog:
88 xPassword = xDialog.getChild("newpassEntry")
89 xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
91 self.assertFalse(document.isReadonly())
93 # vim: set shiftwidth=4 softtabstop=4 expandtab: