Get the style color and number just once
[LibreOffice.git] / sw / qa / uitest / navigator / tdf154521.py
blob3990a7091a1156ecac4285471d37caebcb4b7282
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 libreoffice.uno.propertyvalue import mkPropertyValues
12 from uitest.uihelper.common import get_state_as_dict
13 from com.sun.star.view import XSelectionChangeListener
14 import unohelper
16 selectionChangedResult = 0
18 class XSelectionChangeListenerExtended(unohelper.Base, XSelectionChangeListener):
19 # is invoked when a text selected, e.g. by selecting a bookmark in the Navigator
20 @classmethod
21 def selectionChanged(self, event):
22 global selectionChangedResult
23 selection = event.Source.getSelection()
24 if selection.supportsService("com.sun.star.text.TextRanges"):
25 textRange = selection[0]
26 if textRange.getString() == "foo":
27 selectionChangedResult = 1
28 else:
29 selectionChangedResult = -1
31 @classmethod
32 def disposing(self, event):
33 pass
35 class tdf154521(UITestCase):
37 def test_tdf154521(self):
38 global selectionChangedResult
39 with self.ui_test.create_doc_in_start_center("writer") as xDoc:
41 xWriterDoc = self.xUITest.getTopFocusWindow()
42 xWriterEdit = xWriterDoc.getChild("writer_edit")
44 self.xUITest.executeCommand(".uno:Sidebar")
45 xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "SwNavigatorPanel"}))
47 xNavigatorPanel = xWriterEdit.getChild("NavigatorPanel")
48 xToolBar = xNavigatorPanel.getChild("content5")
49 xToolBar.executeAction("CLICK", mkPropertyValues({"POS": "0"})) # 'root' button
51 # type "foo", and create a bookmark on it
53 self.xUITest.executeCommand(".uno:Escape")
55 xDoc.Text.insertString(xDoc.Text.getStart(), "foo", False)
56 self.xUITest.executeCommand(".uno:SelectAll")
58 with self.ui_test.execute_dialog_through_command(".uno:InsertBookmark", close_button="insert"):
59 pass
61 xWriterEdit.executeAction("FOCUS", tuple())
63 # add XSelectionChangeListener
65 xListener = XSelectionChangeListenerExtended()
66 self.assertIsNotNone(xListener)
67 xDoc.CurrentController.addSelectionChangeListener(xListener)
69 xContentTree = xNavigatorPanel.getChild("contenttree")
71 self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 1")
72 self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmark 1")
73 self.assertEqual(get_state_as_dict(xContentTree)["SelectionCount"], "1")
75 # select bookmark to trigger selectionChanged event
77 xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
79 # wait for handling the selectionChanged event
80 while selectionChangedResult == 0:
81 pass
83 # This was -1 (missing selection because of early broadcasting)
84 self.assertEqual(selectionChangedResult, 1)
86 self.xUITest.executeCommand(".uno:Sidebar")
88 def getTitle(self, document):
89 xController = document.getCurrentController()
90 xSidebar = xController.getSidebar()
91 xDecks = xSidebar.getDecks()
92 xNavigator = xDecks['NavigatorDeck']
93 xPanels = xNavigator.getPanels()
94 xPanel = xPanels['SwNavigatorPanel']
95 title = xPanel.getTitle()
96 # empty title of SwNavigatorPanel to allow to query the name of the selected bookmark
97 xPanel.setTitle("")
98 return title
100 def test_query_selected_bookmark(self):
101 global selectionChangedResult
102 with self.ui_test.create_doc_in_start_center("writer") as xDoc:
104 # click on the bookmark name in the Navigator
106 xWriterDoc = self.xUITest.getTopFocusWindow()
107 xWriterEdit = xWriterDoc.getChild("writer_edit")
109 self.xUITest.executeCommand(".uno:Sidebar")
110 xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "SwNavigatorPanel"}))
112 xNavigatorPanel = xWriterEdit.getChild("NavigatorPanel")
113 xToolBar = xNavigatorPanel.getChild("content5")
114 xToolBar.executeAction("CLICK", mkPropertyValues({"POS": "0"})) # 'root' button
116 # type "foo", and create 3 bookmarks on it
118 self.xUITest.executeCommand(".uno:Escape")
120 xDoc.Text.insertString(xDoc.Text.getStart(), "foo", False)
121 self.xUITest.executeCommand(".uno:SelectAll")
123 for i in range(3):
124 with self.ui_test.execute_dialog_through_command(".uno:InsertBookmark", close_button="insert"):
125 pass
127 # check selected bookmarks in Navigator
129 xWriterEdit.executeAction("FOCUS", tuple())
131 # disable flakey UITest
132 # xContentTree = xNavigatorPanel.getChild("contenttree")
134 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 1")
135 # self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmark 1")
136 # self.assertEqual(get_state_as_dict(xContentTree)["SelectionCount"], "1")
138 ## self.xUITest.executeCommand(".uno:Escape")
140 # # get the title of SwNavigatorPanel with emptying it to access to the selected bookmark
141 # self.assertEqual(self.getTitle(xDoc), "Navigator")
142 # # title was emptied
143 # self.assertEqual(self.getTitle(xDoc), "")
145 # # Select nested bookmark in Navigator
147 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
149 # # This jumped to Bookmark 1 after selection
150 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 1")
151 # self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmark 1")
152 # self.assertEqual(get_state_as_dict(xContentTree)["SelectionCount"], "1")
154 # # This was "Navigator"
155 # self.assertEqual(self.getTitle(xDoc), "Bookmark 1")
157 # # Try the same selection with Bookmark 2
158 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
159 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 2")
160 # self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmark 2")
161 # self.assertEqual(get_state_as_dict(xContentTree)["SelectionCount"], "1")
162 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
163 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 2")
164 # self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmark 2")
165 # self.assertEqual(get_state_as_dict(xContentTree)["SelectionCount"], "1")
167 # # This was "Navigator"
168 # self.assertEqual(self.getTitle(xDoc), "Bookmark 2")
170 # # Try the same selection with Bookmark 3
172 # # why we need this extra UP?
173 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
174 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 2")
175 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
176 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 3")
178 # self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmark 3")
179 # self.assertEqual(get_state_as_dict(xContentTree)["SelectionCount"], "1")
180 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
181 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 3")
182 # self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmark 3")
183 # self.assertEqual(get_state_as_dict(xContentTree)["SelectionCount"], "1")
185 # # This was "Navigator"
186 # self.assertEqual(self.getTitle(xDoc), "Bookmark 3")
188 # # go to the previous item
190 # # why we need this extra UP?
191 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
192 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmark 3")
193 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
194 # self.ui_test.wait_until_property_is_updated(xContentTree, "SelectEntryText", "Bookmarks")
195 # self.assertEqual(get_state_as_dict(xContentTree)["SelectEntryText"], "Bookmarks")
196 # xContentTree.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
198 # # This was "Navigator"
199 # self.assertEqual(self.getTitle(xDoc), "")
201 # self.xUITest.executeCommand(".uno:Sidebar")
203 # vim: set shiftwidth=4 softtabstop=4 expandtab: