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
13 from uitest
.uihelper
.common
import get_state_as_dict
, select_pos
14 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
16 #test Hyperlink dialog
17 class HyperlinkDialog(UITestCase
):
19 def test_hyperlink_dialog_vertical_tab(self
):
21 with self
.ui_test
.create_doc_in_start_center("writer"):
23 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog", close_button
="cancel") as xDialog
:
25 # Test the vertical tab
26 xtab
=xDialog
.getChild("tabcontrol")
27 self
.assertEqual(get_state_as_dict(xtab
)["PageCount"], "4")
30 self
.assertEqual(get_state_as_dict(xtab
)["CurrPageTitel"], "~Internet")
31 self
.assertEqual(get_state_as_dict(xtab
)["CurrPagePos"], "0")
34 self
.assertEqual(get_state_as_dict(xtab
)["CurrPageTitel"], "~Mail")
35 self
.assertEqual(get_state_as_dict(xtab
)["CurrPagePos"], "1")
38 self
.assertEqual(get_state_as_dict(xtab
)["CurrPageTitel"], "~Document")
39 self
.assertEqual(get_state_as_dict(xtab
)["CurrPagePos"], "2")
42 self
.assertEqual(get_state_as_dict(xtab
)["CurrPageTitel"], "~New Document")
43 self
.assertEqual(get_state_as_dict(xtab
)["CurrPagePos"], "3")
47 def test_insert_hyperlink(self
):
49 with self
.ui_test
.create_doc_in_start_center("writer"):
50 xMainWindow
= self
.xUITest
.getTopFocusWindow()
52 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog
:
55 xtab
=xDialog
.getChild("tabcontrol")
58 xtarget
= xDialog
.getChild("target")
59 xtarget
.executeAction("TYPE", mkPropertyValues({"TEXT": "http://www.libreoffice.org/"}))
60 self
.assertEqual(get_state_as_dict(xtarget
)["Text"], "http://www.libreoffice.org/")
62 xindication
= xDialog
.getChild("indication")
63 xindication
.executeAction("TYPE", mkPropertyValues({"TEXT": "link"}))
64 self
.assertEqual(get_state_as_dict(xindication
)["Text"], "link")
67 # Check that the link is added
68 xMainWindow
= self
.xUITest
.getTopFocusWindow()
69 xedit
= xMainWindow
.getChild("writer_edit")
70 xedit
.executeAction("SELECT", mkPropertyValues({"START_POS": "0", "END_POS": "4"}))
71 self
.assertEqual(get_state_as_dict(xedit
)["SelectedText"], "link")
74 def test_insert_hyperlink_without_scheme(self
):
76 with self
.ui_test
.create_doc_in_start_center("writer"):
77 xMainWindow
= self
.xUITest
.getTopFocusWindow()
79 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog") as xDialog
:
82 xtab
=xDialog
.getChild("tabcontrol")
85 xtarget
= xDialog
.getChild("target")
86 xtarget
.executeAction("TYPE", mkPropertyValues({"TEXT": "www.libreoffice.org:80"}))
88 # Check that the link is added with http scheme
89 xMainWindow
= self
.xUITest
.getTopFocusWindow()
90 xedit
= xMainWindow
.getChild("writer_edit")
91 xedit
.executeAction("SELECT", mkPropertyValues({"START_POS": "0", "END_POS": "29"}))
92 self
.assertEqual(get_state_as_dict(xedit
)["SelectedText"], "http://www.libreoffice.org:80")
94 def test_tdf90496(self
):
95 with self
.ui_test
.create_doc_in_start_center("writer"):
96 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog", close_button
="cancel") as xDialog
:
97 # Select a random tab to check the preselection in the hyperlink dialog
98 xTab
= xDialog
.getChild("tabcontrol")
101 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog", close_button
="cancel") as xDialog
:
102 xTab
= xDialog
.getChild("tabcontrol")
103 # Without the fix in place, this test would have failed with
104 # AssertionError: '1' != '0'
105 # i.e. the last used tab in the hyperlink dialog was not remembered
106 self
.assertEqual("1", get_state_as_dict(xTab
)["CurrPagePos"])
109 def test_tdf141166(self
):
110 # Skip this test for --with-help=html and --with-help=online, as that would fail with a
111 # DialogNotExecutedException("did not execute a dialog for a blocking action") thrown from
112 # the below execute_blocking_action call (and would leave behind the relevant HTML page
113 # opened in the user's default browser):
114 if os
.getenv('ENABLE_HTMLHELP') == 'TRUE':
116 # Skip this test for --enable-xmlhelp, as that would fail with a
117 # "uno.com.sun.star.uno.RuntimeException: Could not find child with id: cancel" thrown from
118 # the below execute_blocking_action call, as it would open the "LibreOffice Help" window
119 # instead of the apparently expected "LibreOffice Help Not Installed" dialog that has a
121 if re
.compile(r
'XMLHELP\b').search(os
.getenv('BUILD_TYPE')):
124 with self
.ui_test
.create_doc_in_start_center("writer"):
126 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog", close_button
="") as xDialog
:
127 xHelp
= xDialog
.getChild("help")
128 xHelp
.executeAction('FOCUS', tuple())
130 # Without the fix in place, this test would have crashed here
131 with self
.ui_test
.execute_blocking_action(xHelp
.executeAction
,
132 args
=("CLICK", tuple()), close_button
="cancel"):
135 # vim: set shiftwidth=4 softtabstop=4 expandtab: