Skip to content

Commit b7054e3

Browse files
author
Kirill Burtsev
committed
Fix spellcheck test flaky failure with misspelled word missing
Work is done asynchronously by chromium SpellChecker object. Therefore there is no guarantee that on ShowContextMenu event for WebContents there will be a result with misspelled word. Change-Id: I2978ed99e4c14f0a7d9086853c5218f82ea1ab60 Reviewed-by: Michal Klocek <[email protected]>
1 parent a2e47fa commit b7054e3

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

tests/auto/widgets/spellchecking/tst_spellchecking.cpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,41 @@ void tst_Spellchecking::spellcheck()
174174
QString result = evaluateJavaScriptSync(m_view->page(), "text();").toString();
175175
QVERIFY(result == text);
176176

177-
// open menu on misspelled word
178-
m_view->activateMenu(m_view->focusWidget(), rect.center());
179-
QSignalSpy spyMenuReady(m_view, &WebView::menuReady);
180-
QVERIFY(spyMenuReady.wait());
181-
182-
// check if menu is valid
183-
QVERIFY(m_view->data().isValid());
184-
QVERIFY(m_view->data().isContentEditable());
177+
bool gotMisspelledWord = false; // clumsy QTRY_VERIFY still execs expr after first success
178+
QString detail;
179+
180+
// check that spellchecker has done text processing and filled misspelled word
181+
QTRY_VERIFY2([&] () {
182+
detail.clear();
183+
if (gotMisspelledWord)
184+
return true;
185+
186+
// open menu on misspelled word
187+
m_view->activateMenu(m_view->focusWidget(), rect.center());
188+
QSignalSpy spyMenuReady(m_view, &WebView::menuReady);
189+
if (!spyMenuReady.wait()) {
190+
detail = "menu was not shown";
191+
return false;
192+
}
193+
194+
if (!m_view->data().isValid()) {
195+
detail = "invalid data";
196+
return false;
197+
}
198+
199+
if (!m_view->data().isContentEditable()) {
200+
detail = "content is not editable";
201+
return false;
202+
}
203+
204+
if (m_view->data().misspelledWord().isEmpty()) {
205+
detail = "no misspelled word";
206+
return false;
207+
};
208+
209+
gotMisspelledWord = true;
210+
return true;
211+
} (), qPrintable(QString("Context menu: %1").arg(detail)));
185212

186213
// check misspelled word
187214
QCOMPARE(m_view->data().misspelledWord(), QStringLiteral("lowe"));

0 commit comments

Comments
 (0)