Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / uitest / writer_tests / spellDialog.py
blob9f69fc2c8fe3e959f9b52c151516cbd2e938ea04
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 import re
9 from uitest.framework import UITestCase
10 from uitest.uihelper.common import get_state_as_dict
12 from libreoffice.linguistic.linguservice import get_spellchecker
14 class SpellingAndGrammarDialog(UITestCase):
16 def is_supported_locale(self, language, country):
17 xSpellChecker = get_spellchecker(self.ui_test._xContext)
18 locales = xSpellChecker.getLocales()
19 for locale in locales:
20 if language != None:
21 if locale.Language != language:
22 continue
24 if country != None:
25 if locale.Country != country:
26 continue
28 # we found the correct combination
29 return True
31 def launch_dialog(self):
32 self.ui_test.execute_modeless_dialog_through_command(
33 ".uno:SpellingAndGrammarDialog")
35 return self.xUITest.getTopFocusWindow()
37 TDF46852_INPUT = """\
38 dogg
39 dogg
40 catt dogg
41 frogg frogg
42 frogg catt dogg
43 dogg catt
44 frog, dogg, catt"""
46 TDF46852_REGEX = """\
47 ([a-z]+)
48 \\1
49 ([a-z]+) \\1
50 ([a-z]+) \\3
51 \\3 \\2 \\1
52 \\1 \\2
53 \\3, \\1, \\2"""
55 def test_tdf46852(self):
56 supported_locale = self.is_supported_locale("en", "US")
57 if not supported_locale:
58 self.skipTest("no dictionary support for en_US available")
59 # This automates the steps described in the bug report tdf#46852
61 # Step 1: Create a document with repetitious misspelled words
62 self.ui_test.create_doc_in_start_center("writer")
63 document = self.ui_test.get_component()
64 cursor = document.getCurrentController().getViewCursor()
65 input_text = self.TDF46852_INPUT.replace('\n', '\r') # \r = para break
66 document.Text.insertString(cursor, input_text, False)
68 # Step 2: Place cursor on 4th line after second "frogg"
69 cursor.goUp(2, False)
70 cursor.goLeft(1, False)
72 # Step 3: Initiate spellchecking, and make sure "Check grammar" is
73 # unchecked
74 spell_dialog = self.launch_dialog()
75 checkgrammar = spell_dialog.getChild('checkgrammar')
76 if get_state_as_dict(checkgrammar)['Selected'] == 'true':
77 checkgrammar.executeAction('CLICK', ())
78 self.assertTrue(get_state_as_dict(checkgrammar)['Selected'] == 'false')
80 # Step 4: Repetitively click on "Correct all" for each misspelling
81 # prompt until end of document is reached.
82 changeall = spell_dialog.getChild('changeall')
83 changeall.executeAction("CLICK", ())
84 changeall.executeAction("CLICK", ())
85 # The third time we click on changeall, the click action is going to
86 # block while two message boxes are shown, so we need to do this third
87 # click specially:
88 self.ui_test.execute_blocking_action(
89 changeall.executeAction, args=('CLICK', ()),
90 # Step 5: Confirm to "Continue check at beginning of document"
91 dialog_handler=lambda dialog :
92 self.ui_test.execute_blocking_action(
93 dialog.getChild('yes').executeAction, 'ok', ('CLICK', ())
97 self.assertTrue(re.match(self.TDF46852_REGEX, document.Text.getString()))