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
16 class save_readonly_with_password(UITestCase
):
18 #Bug 145511 - FILESAVE to PPTX as read-only with additional password protection for editing not working
19 def test_save_to_pptx(self
):
21 with
TemporaryDirectory() as tempdir
:
22 xFilePath
= os
.path
.join(tempdir
, "tdf144374-tmp.pptx")
24 with self
.ui_test
.create_doc_in_start_center("impress"):
25 xTemplateDlg
= self
.xUITest
.getTopFocusWindow()
26 xCancelBtn
= xTemplateDlg
.getChild("close")
27 self
.ui_test
.close_dialog_through_button(xCancelBtn
)
30 with self
.ui_test
.execute_dialog_through_command(".uno:Save", close_button
="") as xSaveDialog
:
31 xFileName
= xSaveDialog
.getChild("file_name")
32 xFileName
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
33 xFileName
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
34 xFileName
.executeAction("TYPE", mkPropertyValues({"TEXT": xFilePath
}))
35 xFileTypeCombo
= xSaveDialog
.getChild("file_type")
36 select_by_text(xFileTypeCombo
, "Office Open XML Presentation (.pptx)")
37 xPasswordCheckButton
= xSaveDialog
.getChild("password")
38 xPasswordCheckButton
.executeAction("CLICK", tuple())
39 xOpen
= xSaveDialog
.getChild("open")
41 with self
.ui_test
.execute_dialog_through_action(xOpen
, "CLICK", close_button
="") as xPasswordDialog
:
42 xReadonly
= xPasswordDialog
.getChild("readonly")
43 xReadonly
.executeAction("CLICK", tuple())
44 xNewPassword
= xPasswordDialog
.getChild("newpassroEntry")
45 xNewPassword
.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
46 xConfirmPassword
= xPasswordDialog
.getChild("confirmropassEntry")
47 xConfirmPassword
.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
49 xOk
= xPasswordDialog
.getChild("ok")
50 # PPTX confirmation dialog is displayed
51 with self
.ui_test
.execute_dialog_through_action(xOk
, "CLICK", close_button
="save"):
54 with self
.ui_test
.load_file(systemPathToFileUrl(xFilePath
)) as document
:
56 self
.assertTrue(document
.isReadonly())
58 # Without the fix in place, this dialog wouldn't have been displayed
59 with self
.ui_test
.execute_dialog_through_command(".uno:EditDoc") as xDialog
:
60 xPassword
= xDialog
.getChild("newpassEntry")
61 xPassword
.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
63 self
.assertFalse(document
.isReadonly())
65 def test_save_to_odp(self
):
67 with
TemporaryDirectory() as tempdir
:
68 xFilePath
= os
.path
.join(tempdir
, "readonly_with_password_tmp.odp")
70 with self
.ui_test
.create_doc_in_start_center("impress"):
71 xTemplateDlg
= self
.xUITest
.getTopFocusWindow()
72 xCancelBtn
= xTemplateDlg
.getChild("close")
73 self
.ui_test
.close_dialog_through_button(xCancelBtn
)
76 with self
.ui_test
.execute_dialog_through_command(".uno:Save", close_button
="") as xSaveDialog
:
77 xFileName
= xSaveDialog
.getChild("file_name")
78 xFileName
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
79 xFileName
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
80 xFileName
.executeAction("TYPE", mkPropertyValues({"TEXT": xFilePath
}))
81 xPasswordCheckButton
= xSaveDialog
.getChild("password")
82 xPasswordCheckButton
.executeAction("CLICK", tuple())
83 xOpen
= xSaveDialog
.getChild("open")
85 with self
.ui_test
.execute_dialog_through_action(xOpen
, "CLICK") as xPasswordDialog
:
86 xReadonly
= xPasswordDialog
.getChild("readonly")
87 xReadonly
.executeAction("CLICK", tuple())
88 xNewPassword
= xPasswordDialog
.getChild("newpassroEntry")
89 xNewPassword
.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
90 xConfirmPassword
= xPasswordDialog
.getChild("confirmropassEntry")
91 xConfirmPassword
.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
93 with self
.ui_test
.load_file(systemPathToFileUrl(xFilePath
)) as document
:
95 self
.assertTrue(document
.isReadonly())
97 with self
.ui_test
.execute_dialog_through_command(".uno:EditDoc") as xDialog
:
98 xPassword
= xDialog
.getChild("newpassEntry")
99 xPassword
.executeAction("TYPE", mkPropertyValues({"TEXT": "password"}))
101 self
.assertFalse(document
.isReadonly())
103 # vim: set shiftwidth=4 softtabstop=4 expandtab: