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/.
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
:
21 if locale
.Language
!= language
:
25 if locale
.Country
!= country
:
28 # we found the correct combination
31 def launch_dialog(self
):
32 self
.ui_test
.execute_modeless_dialog_through_command(
33 ".uno:SpellingAndGrammarDialog")
35 return self
.xUITest
.getTopFocusWindow()
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"
70 cursor
.goLeft(1, False)
72 # Step 3: Initiate spellchecking, and make sure "Check grammar" is
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
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()))