1# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
2#
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6#
7
8from uitest.framework import UITestCase
9from libreoffice.uno.propertyvalue import mkPropertyValues
10from uitest.uihelper.common import get_state_as_dict, select_pos
11from com.sun.star.drawing.FillStyle import SOLID
12import importlib
13
14class TestClass(UITestCase):
15    def test_master_page_background(self):
16        self.ui_test.create_doc_in_start_center("writer")
17        document = self.ui_test.get_component()
18
19        # set margins and fill color
20        self.ui_test.execute_dialog_through_command(".uno:PageDialog")
21        DrawPageDialog = self.xUITest.getTopFocusWindow()
22        xTabs = DrawPageDialog.getChild("tabcontrol")
23        select_pos(xTabs, "1")
24        checkBackgroundFullSize = DrawPageDialog.getChild("checkBackgroundFullSize")
25        self.assertEqual(get_state_as_dict(checkBackgroundFullSize)["Selected"], "true")
26        spinMargLeft = DrawPageDialog.getChild("spinMargLeft")
27        for _ in range(20):
28            spinMargLeft.executeAction("UP",tuple())
29        spinMargRight = DrawPageDialog.getChild("spinMargRight")
30        for _ in range(15):
31            spinMargRight.executeAction("UP",tuple())
32        spinMargTop = DrawPageDialog.getChild("spinMargTop")
33        for _ in range(10):
34            spinMargTop.executeAction("UP",tuple())
35        spinMargBot = DrawPageDialog.getChild("spinMargBot")
36        for _ in range(5):
37            spinMargBot.executeAction("UP",tuple())
38        xTabs = DrawPageDialog.getChild("tabcontrol")
39        select_pos(xTabs, "2")
40        btncolor = DrawPageDialog.getChild("btncolor")
41        btncolor.executeAction("CLICK",tuple())
42        ok = DrawPageDialog.getChild("ok")
43        self.ui_test.close_dialog_through_button(ok)
44
45        xStyle = document.StyleFamilies["PageStyles"]["Standard"]
46
47        self.assertEqual(xStyle.FillStyle, SOLID)
48        self.assertEqual(xStyle.LeftMargin, 2997)
49        self.assertEqual(xStyle.RightMargin, 2743)
50        self.assertEqual(xStyle.TopMargin, 2489)
51        self.assertEqual(xStyle.BottomMargin, 2235)
52        self.assertEqual(xStyle.BackgroundFullSize, True)
53
54        # uncheck it
55        self.ui_test.execute_dialog_through_command(".uno:PageDialog")
56        DrawPageDialog = self.xUITest.getTopFocusWindow()
57        xTabs = DrawPageDialog.getChild("tabcontrol")
58        select_pos(xTabs, "1")
59        checkBackgroundFullSize = DrawPageDialog.getChild("checkBackgroundFullSize")
60        self.assertEqual(get_state_as_dict(checkBackgroundFullSize)["Selected"], "true")
61        checkBackgroundFullSize.executeAction("CLICK",tuple())
62        ok = DrawPageDialog.getChild("ok")
63        self.ui_test.close_dialog_through_button(ok)
64
65        self.assertEqual(xStyle.FillStyle, SOLID)
66        self.assertEqual(xStyle.LeftMargin, 2997)
67        self.assertEqual(xStyle.RightMargin, 2743)
68        self.assertEqual(xStyle.TopMargin, 2489)
69        self.assertEqual(xStyle.BottomMargin, 2235)
70        self.assertEqual(xStyle.BackgroundFullSize, False)
71
72        # check it again
73        self.ui_test.execute_dialog_through_command(".uno:PageDialog")
74        DrawPageDialog = self.xUITest.getTopFocusWindow()
75        xTabs = DrawPageDialog.getChild("tabcontrol")
76        select_pos(xTabs, "1")
77        checkBackgroundFullSize = DrawPageDialog.getChild("checkBackgroundFullSize")
78        self.assertEqual(get_state_as_dict(checkBackgroundFullSize)["Selected"], "false")
79        checkBackgroundFullSize.executeAction("CLICK",tuple())
80        ok = DrawPageDialog.getChild("ok")
81        self.ui_test.close_dialog_through_button(ok)
82
83        self.assertEqual(xStyle.FillStyle, SOLID)
84        self.assertEqual(xStyle.LeftMargin, 2997)
85        self.assertEqual(xStyle.RightMargin, 2743)
86        self.assertEqual(xStyle.TopMargin, 2489)
87        self.assertEqual(xStyle.BottomMargin, 2235)
88        self.assertEqual(xStyle.BackgroundFullSize, True)
89
90        self.ui_test.close_doc()
91
92# vim: set shiftwidth=4 softtabstop=4 expandtab:
93