summaryrefslogtreecommitdiff
path: root/sw/qa/uitest/writer_tests6/edit_file_properties_before_saving.py
blob: 0df0dc504dde813145d811624b1c68a898b770b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# 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 uitest.uihelper.common import get_state_as_dict
from uitest.uihelper.common import type_text
from libreoffice.uno.propertyvalue import mkPropertyValues
from org.libreoffice.unotest import systemPathToFileUrl
from tempfile import TemporaryDirectory
import os.path

class edit_file_properties_before_saving(UITestCase):

    def change_doc_info_setting(self, enabled):
        with self.ui_test.execute_dialog_through_command(".uno:OptionsTreeDialog") as xDialog:
            xPages = xDialog.getChild("pages")
            xLoadSaveEntry = xPages.getChild('1')
            xLoadSaveEntry.executeAction("EXPAND", tuple())
            xGeneralEntry = xLoadSaveEntry.getChild('0')
            xGeneralEntry.executeAction("SELECT", tuple())

            xDocInfo = xDialog.getChild("docinfo")
            if get_state_as_dict(xDocInfo)['Selected'] != enabled:
                xDocInfo.executeAction("CLICK", tuple())
            self.assertEqual(enabled, get_state_as_dict(xDocInfo)['Selected'])

    def test_tdf117895(self):

        with TemporaryDirectory() as tempdir:
            xFilePath = os.path.join(tempdir, "tdf117895-temp.odt")

            with self.ui_test.create_doc_in_start_center("writer"):

                try:
                    self.change_doc_info_setting("true")

                    # Save Copy as
                    with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="") as xDialog:
                        xFileName = xDialog.getChild('file_name')
                        xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'}))
                        xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'}))
                        xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath}))

                        xOpen = xDialog.getChild("open")
                        with self.ui_test.execute_dialog_through_action(xOpen, "CLICK") as xPropertiesDialog:
                            xReadOnly = xPropertiesDialog.getChild("readonly")
                            xReadOnly.executeAction("CLICK", tuple())
                            self.assertEqual("true", get_state_as_dict(xReadOnly)['Selected'])
                finally:
                    # Put this setting back to false, otherwise it might affect other tests
                    self.change_doc_info_setting("false")

            self.ui_test.wait_until_file_is_available(xFilePath)

            with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as doc2:
                # Without the fix in place, this test would have failed here
                self.assertTrue(doc2.isReadonly())

    def test_tdf119206(self):

        with TemporaryDirectory() as tempdir:
            xFilePath = os.path.join(tempdir, "tdf119206-temp.odt")

            with self.ui_test.create_doc_in_start_center("writer"):

                try:
                    self.change_doc_info_setting("true")

                    xWriterDoc = self.xUITest.getTopFocusWindow()
                    xWriterEdit = xWriterDoc.getChild("writer_edit")
                    type_text(xWriterEdit, "XXXX")

                    # Close document and save
                    with self.ui_test.execute_dialog_through_command('.uno:CloseDoc', close_button="") as xConfirmationDialog:
                        xSave = xConfirmationDialog.getChild("save")

                        with self.ui_test.execute_dialog_through_action(xSave, "CLICK", close_button="") as xDialog:
                            xFileName = xDialog.getChild('file_name')
                            xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'}))
                            xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'}))
                            xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath}))

                            xOpen = xDialog.getChild("open")
                            with self.ui_test.execute_dialog_through_action(xOpen, "CLICK") as xPropertiesDialog:
                                # Without the fix in place, this test would have crashed here
                                xReadOnly = xPropertiesDialog.getChild("readonly")
                                xReadOnly.executeAction("CLICK", tuple())
                                self.assertEqual("true", get_state_as_dict(xReadOnly)['Selected'])
                finally:
                    # Put this setting back to false, otherwise it might affect other tests
                    self.change_doc_info_setting("false")

            self.ui_test.wait_until_file_is_available(xFilePath)

            with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as doc2:
                self.assertTrue(doc2.isReadonly())

# vim: set shiftwidth=4 softtabstop=4 expandtab: