Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / protect / protectSheet.py
blob4b65e3b9e0ee2e1cf57b9155576b084552a3ffc0
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 uitest.uihelper.calc import enter_text_to_cell
11 from uitest.uihelper.common import get_state_as_dict
13 from libreoffice.calc.document import get_cell_by_position
14 from libreoffice.uno.propertyvalue import mkPropertyValues
17 class protectSheet(UITestCase):
18 def test_protect_sheet(self):
19 with self.ui_test.create_doc_in_start_center("calc") as document:
20 xCalcDoc = self.xUITest.getTopFocusWindow()
21 gridwin = xCalcDoc.getChild("grid_window")
22 #enter password - lock
23 with self.ui_test.execute_dialog_through_command(".uno:Protect") as xDialog:
24 xprotect = xDialog.getChild("protect")
25 xpassword1 = xDialog.getChild("password1")
26 xpassword2 = xDialog.getChild("password2")
28 if (get_state_as_dict(xprotect)["Selected"]) == "false":
29 xprotect.executeAction("CLICK", tuple())
30 xpassword1.executeAction("TYPE", mkPropertyValues({"TEXT":"aa"}))
31 xpassword2.executeAction("TYPE", mkPropertyValues({"TEXT":"aa"}))
33 #Unlock
35 with self.ui_test.execute_dialog_through_command(".uno:Protect") as xDialog:
36 xpass1ed = xDialog.getChild("pass1ed")
38 xpass1ed.executeAction("TYPE", mkPropertyValues({"TEXT":"aa"}))
40 #Verify - the sheet is unlocked
41 enter_text_to_cell(gridwin, "B2", "A")
42 self.assertEqual(get_cell_by_position(document, 0, 1, 1).getString(), "A")
44 # test cancel button
45 with self.ui_test.execute_dialog_through_command(".uno:Protect", close_button="cancel"):
46 pass
48 enter_text_to_cell(gridwin, "B2", "B")
49 self.assertEqual(get_cell_by_position(document, 0, 1, 1).getString(), "B")
52 # vim: set shiftwidth=4 softtabstop=4 expandtab: