Get the style color and number just once
[LibreOffice.git] / sw / qa / uitest / writer_tests6 / edit_file_properties_before_saving.py
blob38d5ec818a386cf5ae5bbc56b9e324742eaaae06
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/.
10 from uitest.framework import UITestCase
11 from uitest.uihelper.common import get_state_as_dict
12 from uitest.uihelper.common import type_text
13 from libreoffice.uno.propertyvalue import mkPropertyValues
14 from org.libreoffice.unotest import systemPathToFileUrl
15 from tempfile import TemporaryDirectory
16 import os.path
18 class edit_file_properties_before_saving(UITestCase):
20 def change_doc_info_setting(self, enabled):
21 with self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog") as xDialog:
22 xPages = xDialog.getChild("pages")
23 xLoadSaveEntry = xPages.getChild('1')
24 xLoadSaveEntry.executeAction("EXPAND", tuple())
25 xGeneralEntry = xLoadSaveEntry.getChild('0')
26 xGeneralEntry.executeAction("SELECT", tuple())
28 xDocInfo = xDialog.getChild("docinfo")
29 if get_state_as_dict(xDocInfo)['Selected'] != enabled:
30 xDocInfo.executeAction("CLICK", tuple())
31 self.assertEqual(enabled, get_state_as_dict(xDocInfo)['Selected'])
33 def test_tdf117895(self):
35 with TemporaryDirectory() as tempdir:
36 xFilePath = os.path.join(tempdir, "tdf117895-temp.odt")
38 try:
39 self.change_doc_info_setting("true")
41 with self.ui_test.create_doc_in_start_center("writer"):
43 # Save Copy as
44 with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="") as xDialog:
45 xFileName = xDialog.getChild('file_name')
46 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'}))
47 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'}))
48 xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath}))
50 xOpen = xDialog.getChild("open")
51 with self.ui_test.execute_dialog_through_action(xOpen, "CLICK") as xPropertiesDialog:
52 xReadOnly = xPropertiesDialog.getChild("readonly")
53 xReadOnly.executeAction("CLICK", tuple())
54 self.assertEqual("true", get_state_as_dict(xReadOnly)['Selected'])
56 with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as doc2:
57 # Without the fix in place, this test would have failed here
58 self.assertTrue(doc2.isReadonly())
59 finally:
60 # Put this setting back to false, otherwise it might affect other tests
61 self.change_doc_info_setting("false")
63 def test_tdf119206(self):
65 with TemporaryDirectory() as tempdir:
66 xFilePath = os.path.join(tempdir, "tdf119206-temp.odt")
68 try:
69 self.change_doc_info_setting("true")
71 with self.ui_test.create_doc_in_start_center("writer"):
73 xWriterDoc = self.xUITest.getTopFocusWindow()
74 xWriterEdit = xWriterDoc.getChild("writer_edit")
75 type_text(xWriterEdit, "XXXX")
77 # Close document and save
78 with self.ui_test.execute_dialog_through_command('.uno:CloseDoc', close_button="") as xConfirmationDialog:
79 xSave = xConfirmationDialog.getChild("save")
81 with self.ui_test.execute_dialog_through_action(xSave, "CLICK", close_button="") as xDialog:
82 xFileName = xDialog.getChild('file_name')
83 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'}))
84 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'}))
85 xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath}))
87 xOpen = xDialog.getChild("open")
88 with self.ui_test.execute_dialog_through_action(xOpen, "CLICK") as xPropertiesDialog:
89 # Without the fix in place, this test would have crashed here
90 xReadOnly = xPropertiesDialog.getChild("readonly")
91 xReadOnly.executeAction("CLICK", tuple())
92 self.assertEqual("true", get_state_as_dict(xReadOnly)['Selected'])
94 with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as doc2:
95 self.assertTrue(doc2.isReadonly())
97 finally:
98 # Put this setting back to false, otherwise it might affect other tests
99 self.change_doc_info_setting("false")
101 # vim: set shiftwidth=4 softtabstop=4 expandtab: