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"])
108 def test_tdf146576_propose_clipboard_content(self
):
109 with self
.ui_test
.create_doc_in_start_center("writer"):
110 xWriterDoc
= self
.xUITest
.getTopFocusWindow()
111 xWriterEdit
= xWriterDoc
.getChild("writer_edit")
115 ("http://www.libreoffice.org", "http://www.libreoffice.org/"),
116 (" http://www.libreoffice.org ", "http://www.libreoffice.org/")
120 for sampleURL
, expectedURL
in sampleURLs
:
121 self
.xUITest
.executeCommand(".uno:SelectAll")
122 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"TEXT": sampleURL
}))
124 # Copy URL and open the hyperlink dialog
125 self
.xUITest
.executeCommand(".uno:SelectAll")
126 self
.xUITest
.executeCommand(".uno:Copy")
127 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog", close_button
="cancel") as xDialog
:
128 xTab
= xDialog
.getChild("tabcontrol")
129 select_pos(xTab
, "0")
130 # Check if the content of the clipboard is proposed as expected
131 xTarget
= xDialog
.getChild("target")
132 self
.assertEqual(get_state_as_dict(xTarget
)["Text"].lower(), expectedURL
)
134 def test_tdf162753_propose_clipboard_content_internet(self
):
135 with self
.ui_test
.create_doc_in_start_center("writer"):
136 # Insert a sample URL
137 xWriterDoc
= self
.xUITest
.getTopFocusWindow()
138 xWriterEdit
= xWriterDoc
.getChild("writer_edit")
139 xWriterEdit
.executeAction("TYPE", mkPropertyValues({"TEXT": "http://www.libreoffice.org"}))
141 # Copy URL and open the hyperlink dialog
142 self
.xUITest
.executeCommand(".uno:SelectAll")
143 self
.xUITest
.executeCommand(".uno:Copy")
144 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog", close_button
="cancel") as xDialog
:
145 xTab
= xDialog
.getChild("tabcontrol")
146 select_pos(xTab
, "0")
147 # Check if the content of the clipboard is proposed as URL in the hyperlink dialog
148 xTarget
= xDialog
.getChild("target")
149 self
.assertEqual(get_state_as_dict(xTarget
)["Text"].lower(), "http://www.libreoffice.org/")
150 select_pos(xTab
, "2")
151 # Select document dialog and check if the content of the clipboard is not proposed as URL
152 xPath
= xDialog
.getChild("path")
153 self
.assertEqual(get_state_as_dict(xPath
)["Text"], "")
154 # Select internet dialog and check if the content of the clipboard is again proposed as URL
155 select_pos(xTab
, "0")
156 xTarget
= xDialog
.getChild("target")
157 self
.assertEqual(get_state_as_dict(xTarget
)["Text"].lower(), "http://www.libreoffice.org/")
159 def test_tdf141166(self
):
160 # Skip this test for --with-help=html and --with-help=online, as that would fail with a
161 # DialogNotExecutedException("did not execute a dialog for a blocking action") thrown from
162 # the below execute_blocking_action call (and would leave behind the relevant HTML page
163 # opened in the user's default browser):
164 if os
.getenv('ENABLE_HTMLHELP') == 'TRUE':
166 # Skip this test for --enable-xmlhelp, as that would fail with a
167 # "uno.com.sun.star.uno.RuntimeException: Could not find child with id: cancel" thrown from
168 # the below execute_blocking_action call, as it would open the "LibreOffice Help" window
169 # instead of the apparently expected "LibreOffice Help Not Installed" dialog that has a
171 if re
.compile(r
'XMLHELP\b').search(os
.getenv('BUILD_TYPE')):
174 with self
.ui_test
.create_doc_in_start_center("writer"):
176 with self
.ui_test
.execute_dialog_through_command(".uno:HyperlinkDialog", close_button
="") as xDialog
:
177 xHelp
= xDialog
.getChild("help")
178 xHelp
.executeAction('FOCUS', tuple())
180 # Without the fix in place, this test would have crashed here
181 with self
.ui_test
.execute_blocking_action(xHelp
.executeAction
,
182 args
=("CLICK", tuple()), close_button
="cancel"):
185 # vim: set shiftwidth=4 softtabstop=4 expandtab: