Fix tst_QLineEdit for offscreen and minimal platforms

Unselecting with offscreen and minimal platforms behave similarly as in
Windows and QNX. If left or right key is used for unselecting, cursor
position is changed.

Change-Id: I022cd2fec80ad1875fec983e1e3536a105e18bb2
Reviewed-by: Teemu Holappa <teemu.holappa@qt.io>
bb10
Sami Nurmenniemi 2017-04-03 15:37:16 +03:00
parent 99017d78ee
commit e5a1c7fff7
1 changed files with 27 additions and 11 deletions

View File

@ -325,6 +325,7 @@ private:
// keyClicks(..) is moved to QtTestCase
void psKeyClick(QWidget *target, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
void psKeyClick(QTestEventList &keys, Qt::Key key, Qt::KeyboardModifiers pressState = 0);
bool unselectingWithLeftOrRightChangesCursorPosition();
QLineEdit *ensureTestWidget();
bool validInput;
@ -1315,9 +1316,10 @@ void tst_QLineEdit::undo_keypressevents_data()
// unselect any current selection
keys.addKeyClick(Qt::Key_Right);
#if defined Q_OS_WIN || defined Q_OS_QNX //Windows and QNX do not jump to the beginning of the selection
keys.addKeyClick(Qt::Key_Left);
#endif
// If previous right changed cursor position, go back left
if (unselectingWithLeftOrRightChangesCursorPosition())
keys.addKeyClick(Qt::Key_Left);
// selecting '12'
keys.addKeyClick(Qt::Key_Right, Qt::ShiftModifier);
@ -3298,14 +3300,11 @@ void tst_QLineEdit::leftKeyOnSelectedText()
QCOMPARE(testWidget->cursorPosition(), 2);
QCOMPARE(testWidget->selectedText(), QString("23"));
QTest::keyClick(testWidget, Qt::Key_Left);
#if defined Q_OS_WIN || defined Q_OS_QNX
QCOMPARE(testWidget->cursorPosition(), 1);
#else
// Selection is cleared ands cursor remains at position 2.
// X11 used to behave like window prior to 4.2. Changes caused by QKeySequence
// resulted in an inadvertant change in behavior
QCOMPARE(testWidget->cursorPosition(), 2);
#endif
if (unselectingWithLeftOrRightChangesCursorPosition())
QCOMPARE(testWidget->cursorPosition(), 1);
else
QCOMPARE(testWidget->cursorPosition(), 2);
}
void tst_QLineEdit::inlineCompletion()
@ -4639,5 +4638,22 @@ void tst_QLineEdit::QTBUG59957_clearButtonLeftmostAction()
#endif // QT_BUILD_INTERNAL
}
bool tst_QLineEdit::unselectingWithLeftOrRightChangesCursorPosition()
{
#if defined Q_OS_WIN || defined Q_OS_QNX //Windows and QNX do not jump to the beginning of the selection
return true;
#endif
// Platforms minimal/offscreen also need left after unselecting with right
if (!QGuiApplication::platformName().compare("minimal", Qt::CaseInsensitive)
|| !QGuiApplication::platformName().compare("offscreen", Qt::CaseInsensitive)) {
return true;
}
// Selection is cleared ands cursor remains at previous position.
// X11 used to behave like window prior to 4.2. Changes caused by QKeySequence
// resulted in an inadvertant change in behavior
return false;
}
QTEST_MAIN(tst_QLineEdit)
#include "tst_qlineedit.moc"