Get the style color and number just once
[LibreOffice.git] / sw / qa / uitest / navigator / tdf134960.py
blobd60cc677bcd8330837ab23d05aa65985ab40a715
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 libreoffice.uno.propertyvalue import mkPropertyValues
11 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
13 class tdf134960_hyperlinks(UITestCase):
15 def get_item(self, xTree, name):
16 for i in xTree.getChildren():
17 xItem = xTree.getChild(i)
18 if name == get_state_as_dict(xItem)['Text']:
19 return xItem
21 def launch_sidebar(self, xWriterEdit):
23 self.xUITest.executeCommand(".uno:Sidebar")
25 xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "SwNavigatorPanel"}))
27 # wait until the navigator panel is available
28 xNavigatorPanel = self.ui_test.wait_until_child_is_available('NavigatorPanel')
30 # See the `m_aUpdateTimer.SetTimeout(200)` (to "avoid flickering of buttons")
31 # in the SwChildWinWrapper ctor in sw/source/uibase/fldui/fldwrap.cxx, where that
32 # m_aUpdateTimer is started by SwChildWinWrapper::ReInitDlg triggered from the
33 # xInsert click above.
34 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
35 xToolkit.waitUntilAllIdlesDispatched()
37 xContentTree = xNavigatorPanel.getChild("contenttree")
38 xHyperlinks = self.get_item(xContentTree, 'Hyperlinks')
39 self.assertEqual('Hyperlinks', get_state_as_dict(xHyperlinks)['Text'])
41 xHyperlinks.executeAction("EXPAND", tuple())
43 expectedHyperlinksOrder = [1, 2, 8, 9, 7, 10, 11, 3, 12, 4, 5, 6]
44 for i in range(12):
45 self.assertEqual('Hyperlink ' + str(expectedHyperlinksOrder[i]), get_state_as_dict(xHyperlinks.getChild(str(i)))['Text'])
47 xHyperlinks.executeAction("COLLAPSE", tuple())
49 self.xUITest.executeCommand(".uno:Sidebar")
51 def test_tdf134960_hyperlinks(self):
53 with self.ui_test.load_file(get_url_for_data_file("tdf134960.odt")):
54 xWriterDoc = self.xUITest.getTopFocusWindow()
55 xWriterEdit = xWriterDoc.getChild("writer_edit")
57 # Without the fix in place, this test would have failed with
58 # AssertionError: 'Hyperlink 2' != 'Hyperlink 6'
59 self.launch_sidebar(xWriterEdit)
61 def test_tdf134960_hyperlinks_with_multiple_pages(self):
63 with self.ui_test.load_file(get_url_for_data_file("tdf134960.odt")):
64 xWriterDoc = self.xUITest.getTopFocusWindow()
65 xWriterEdit = xWriterDoc.getChild("writer_edit")
67 # Insert a page break so we have different links in different pages
68 xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
69 self.xUITest.executeCommand(".uno:InsertPagebreak")
70 self.assertEqual("3", get_state_as_dict(xWriterEdit)["Pages"])
72 # Change view to 20% and 2 columns
73 with self.ui_test.execute_dialog_through_command(".uno:Zoom") as xDialog:
74 variable = xDialog.getChild("variable")
75 variable.executeAction("CLICK", tuple())
77 zoomsb = xDialog.getChild("zoomsb")
78 zoomsb.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
79 zoomsb.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
80 zoomsb.executeAction("TYPE", mkPropertyValues({"TEXT":"20"}))
82 columns = xDialog.getChild("columns")
83 columns.executeAction("CLICK", tuple())
85 columnssb = xDialog.getChild("columnssb")
86 columnssb.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
87 columnssb.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
88 columnssb.executeAction("TYPE", mkPropertyValues({"TEXT":"3"}))
90 # Without the fix in place, this test would have failed with
91 # AssertionError: 'Hyperlink 2' != 'Hyperlink 8'
92 self.launch_sidebar(xWriterEdit)
94 # vim: set shiftwidth=4 softtabstop=4 expandtab: