summaryrefslogtreecommitdiffstats
path: root/sw/qa/uitest/writer_tests7/tdf128744.py
blob: 34201e8586757af93f5557a235668470df4c5ddd (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
# -*- 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 libreoffice.uno.propertyvalue import mkPropertyValues
from uitest.uihelper.common import get_state_as_dict
from uitest.uihelper.common import select_pos
from uitest.uihelper.common import get_url_for_data_file

class tdf128744(UITestCase):

   def test_tdf128744(self):
        # load the sample file
        with self.ui_test.load_file(get_url_for_data_file("tdf128744.docx")):

            # first try to unprotect Record Changes with an invalid password

            with self.ui_test.execute_dialog_through_command(".uno:SetDocumentProperties") as xDialog:
                xRecordChangesCheckbox = xDialog.getChild("recordchanges")
                self.assertEqual(get_state_as_dict(xRecordChangesCheckbox)["Selected"], "true")
                xTabs = xDialog.getChild("tabcontrol")
                select_pos(xTabs, "3")     #tab Security
                xProtectBtn = xDialog.getChild("protect")

                # No close_button: click on the "Ok" inside to check the "Invalid password" infobox
                with self.ui_test.execute_blocking_action(xProtectBtn.executeAction, args=('CLICK', ()), close_button="") as xPasswordDialog:
                    self.assertEqual(get_state_as_dict(xPasswordDialog)["DisplayText"], "Enter Password")
                    xPassword = xPasswordDialog.getChild("pass1ed")
                    xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "bad password"}))
                    print(xPasswordDialog.getChildren())
                    xOkBtn = xPasswordDialog.getChild("ok")
                    with self.ui_test.execute_blocking_action(xOkBtn.executeAction, args=('CLICK', ())) as xInfoBox:
                        # "Invalid password" infobox
                        self.assertEqual(get_state_as_dict(xInfoBox)["DisplayText"], 'Information')

            # now open the dialog again and read the properties, Record Changes checkbox is still enabled
            with self.ui_test.execute_dialog_through_command(".uno:SetDocumentProperties", close_button="cancel") as xDialog:
                xRecordChangesCheckbox = xDialog.getChild("recordchanges")
                self.assertEqual(get_state_as_dict(xRecordChangesCheckbox)["Selected"], "true")
                xResetBtn = xDialog.getChild("reset")
                xResetBtn.executeAction("CLICK", tuple())

            # unprotect Record Changes with the valid password "test"

            with self.ui_test.execute_dialog_through_command(".uno:SetDocumentProperties") as xDialog:
                xRecordChangesCheckbox = xDialog.getChild("recordchanges")
                self.assertEqual(get_state_as_dict(xRecordChangesCheckbox)["Selected"], "true")
                xTabs = xDialog.getChild("tabcontrol")
                select_pos(xTabs, "3")     #tab Security
                xProtectBtn = xDialog.getChild("protect")

                with self.ui_test.execute_blocking_action(xProtectBtn.executeAction, args=('CLICK', ())) as xPasswordDialog:
                    self.assertEqual(get_state_as_dict(xPasswordDialog)["DisplayText"], "Enter Password")
                    xPassword = xPasswordDialog.getChild("pass1ed")
                    # give the correct password
                    xPassword.executeAction("TYPE", mkPropertyValues({"TEXT": "test"}))

            # now open the dialog again and read the properties, Record Changes checkbox is disabled now
            with self.ui_test.execute_dialog_through_command(".uno:SetDocumentProperties", close_button="cancel") as xDialog:
                xRecordChangesCheckbox = xDialog.getChild("recordchanges")
                self.assertEqual(get_state_as_dict(xRecordChangesCheckbox)["Selected"], "false")
                xResetBtn = xDialog.getChild("reset")
                xResetBtn.executeAction("CLICK", tuple())

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