From 80ebe0d1e3061aaf5ba792f21813e0a8804112ad Mon Sep 17 00:00:00 2001 From: Jarkko Koivikko Date: Thu, 9 Apr 2015 16:55:58 +0300 Subject: Make spell correction tests non-flaky Replaced the timeout condition in the spell correction tests with more flexible solution where the spell correction results are polled in short intervals. Removed an unnecessary wait condition from the automatic space insertion tests where the actual spell correction results are irrelevant. Change-Id: I74eb8f2f4dfd69d47cfe55a33b743524d21759ca Task-number: QTRD-3573 Reviewed-by: Rainer Keller --- .../auto/inputpanel/data/inputpanel/inputpanel.qml | 42 ++++++++++++++-------- tests/auto/inputpanel/data/tst_inputpanel.qml | 20 +++++------ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml index fa6c9a51..e1bc3d04 100644 --- a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml +++ b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml @@ -385,25 +385,37 @@ InputPanel { VirtualKeyboardSettings.styleName = style } - function selectionListSearchSuggestion(suggestion) { + function selectionListSearchSuggestion(suggestion, timeout) { + if (timeout === undefined || timeout < 0) + timeout = 0 var suggestionFound = false - var origIndex = inputPanel.wordCandidateView.currentIndex - if (origIndex !== -1) { - while (true) { - if (inputPanel.wordCandidateView.model.itemData(inputPanel.wordCandidateView.currentIndex) === suggestion) { - suggestionFound = true - break + var dt = new Date() + var startTime = dt.getTime() + while (true) { + var origIndex = inputPanel.wordCandidateView.currentIndex + if (origIndex !== -1) { + while (true) { + if (inputPanel.wordCandidateView.model.itemData(inputPanel.wordCandidateView.currentIndex) === suggestion) { + suggestionFound = true + break + } + if (inputPanel.wordCandidateView.currentIndex === inputPanel.wordCandidateView.count - 1) + break + inputPanel.wordCandidateView.incrementCurrentIndex() } - if (inputPanel.wordCandidateView.currentIndex === inputPanel.wordCandidateView.count - 1) - break - inputPanel.wordCandidateView.incrementCurrentIndex() - } - if (!suggestionFound) { - while (inputPanel.wordCandidateView.currentIndex !== origIndex) { - inputPanel.wordCandidateView.decrementCurrentIndex() + if (!suggestionFound) { + while (inputPanel.wordCandidateView.currentIndex !== origIndex) { + inputPanel.wordCandidateView.decrementCurrentIndex() + } } + testcase.waitForRendering(inputPanel) } - testcase.waitForRendering(inputPanel) + dt = new Date() + var elapsedTime = dt.getTime() - startTime + if (suggestionFound || elapsedTime >= timeout) + break + var maxWait = Math.min(timeout - elapsedTime, 50) + testcase.wait(maxWait) } return suggestionFound } diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml index 19f499b5..96e820b1 100644 --- a/tests/auto/inputpanel/data/tst_inputpanel.qml +++ b/tests/auto/inputpanel/data/tst_inputpanel.qml @@ -555,20 +555,22 @@ Rectangle { for (var inputIndex in data.inputSequence) { verify(inputPanel.virtualKeyClick(data.inputSequence[inputIndex])) } - wait(300) + waitForRendering(inputPanel) if (data.hasOwnProperty("expectedSuggestion")) { - if (inputPanel.wordCandidateView.count <= 1) + if (inputPanel.wordCandidateView.count > 0) { + verify(inputPanel.selectionListSearchSuggestion(data.expectedSuggestion, 2000), "The expected spell correction suggestion \"%1\" was not found".arg(data.expectedSuggestion)) + verify(inputPanel.selectionListSelectCurrentItem(), "Word candidate not selected") + } else if (textInput.text !== data.outputText) { expectFail("", "Prediction/spell correction not enabled") - verify(inputPanel.wordCandidateView.count > 1, "Prediction/spell correction results are expected") - - verify(inputPanel.selectionListSearchSuggestion(data.expectedSuggestion)) - verify(inputPanel.selectionListSelectCurrentItem()) + } } else { + wait(1000) verify(inputPanel.wordCandidateView.count <= 1, "Prediction/spell correction results are not expected") Qt.inputMethod.commit() waitForRendering(inputPanel) } + compare(textInput.text, data.outputText) } @@ -595,11 +597,7 @@ Rectangle { for (var inputIndex in data.inputSequence) { var key = data.inputSequence[inputIndex] if (key === Qt.Key_Select) { - wait(300) - if (inputPanel.wordCandidateView.count > 1) - inputPanel.selectionListSelectCurrentItem() - else - expectFail("", "Prediction/spell correction not enabled") + inputPanel.selectionListSelectCurrentItem() } else { inputPanel.virtualKeyClick(key) } -- cgit v1.2.3