Get the style color and number just once
[LibreOffice.git] / sw / qa / uitest / writer_tests3 / save_readonly_with_password.py
blobf14b74046d0fe5c0be3b9995c3b4eaa95f8dd619
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 org.libreoffice.unotest import systemPathToFileUrl
12 from uitest.uihelper.common import select_by_text
13 from tempfile import TemporaryDirectory
14 import os.path
17 class save_readonly_with_password(UITestCase):
19 #Bug 144374 - Writer: FILESAVE to DOCX as read-only with additional password protection for editing not working
20 def test_save_to_docx(self):
21 with TemporaryDirectory() as tempdir:
22 xFilePath = os.path.join(tempdir, "tdf144374-tmp.docx")
24 with self.ui_test.create_doc_in_start_center("writer"):
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, "Word 2010–365 Document (.docx)")
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 # DOCX 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)) as document:
52 self.assertTrue(document.isReadonly())
54 #Without the fix in place, this dialog wouldn't have been displayed
55 with self.ui_test.execute_dialog_through_command(".uno:EditDoc") as xDialog:
56 xPassword = xDialog.getChild("newpassEntry")
57 xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
59 self.assertFalse(document.isReadonly())
61 def test_save_to_odt(self):
63 with TemporaryDirectory() as tempdir:
64 xFilePath = os.path.join(tempdir, "readonly_with_password_tmp.odt")
66 with self.ui_test.create_doc_in_start_center("writer"):
67 # Save the document
68 with self.ui_test.execute_dialog_through_command(".uno:Save", close_button="") as xSaveDialog:
69 xFileName = xSaveDialog.getChild("file_name")
70 xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
71 xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
72 xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": xFilePath}))
73 xPasswordCheckButton = xSaveDialog.getChild("password")
74 xPasswordCheckButton.executeAction("CLICK", tuple())
75 xOpen = xSaveDialog.getChild("open")
77 with self.ui_test.execute_dialog_through_action(xOpen, "CLICK") as xPasswordDialog:
78 xReadonly = xPasswordDialog.getChild("readonly")
79 xReadonly.executeAction("CLICK", tuple())
80 xNewPassword = xPasswordDialog.getChild("newpassroEntry")
81 xNewPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
82 xConfirmPassword = xPasswordDialog.getChild("confirmropassEntry")
83 xConfirmPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
85 with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as document:
87 self.assertTrue(document.isReadonly())
89 with self.ui_test.execute_dialog_through_command(".uno:EditDoc") as xDialog:
90 xPassword = xDialog.getChild("newpassEntry")
91 xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
93 self.assertFalse(document.isReadonly())
95 # vim: set shiftwidth=4 softtabstop=4 expandtab: