Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / uitest / writer_tests3 / hyperlinkdialog.py
blob6390310810d55c5864818268f5e736921361f3ec
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 import os
12 import re
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")
29 select_pos(xtab, "0")
30 self.assertEqual(get_state_as_dict(xtab)["CurrPageTitel"], "~Internet")
31 self.assertEqual(get_state_as_dict(xtab)["CurrPagePos"], "0")
33 select_pos(xtab, "1")
34 self.assertEqual(get_state_as_dict(xtab)["CurrPageTitel"], "~Mail")
35 self.assertEqual(get_state_as_dict(xtab)["CurrPagePos"], "1")
37 select_pos(xtab, "2")
38 self.assertEqual(get_state_as_dict(xtab)["CurrPageTitel"], "~Document")
39 self.assertEqual(get_state_as_dict(xtab)["CurrPagePos"], "2")
41 select_pos(xtab, "3")
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:
54 # insert link
55 xtab=xDialog.getChild("tabcontrol")
56 select_pos(xtab, "0")
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:
81 # insert link
82 xtab=xDialog.getChild("tabcontrol")
83 select_pos(xtab, "0")
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")
99 select_pos(xTab, "1")
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':
115 return
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
120 # "Cancel" button:
121 if re.compile(r'XMLHELP\b').search(os.getenv('BUILD_TYPE')):
122 return
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"):
133 pass
135 # vim: set shiftwidth=4 softtabstop=4 expandtab: