diff options
author | Liang Qi <liang.qi@qt.io> | 2016-06-13 09:04:09 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-06-13 19:06:06 +0200 |
commit | 4d2f743baaf6869693f4540df668e1b998154785 (patch) | |
tree | ba712b420e5d299be28faf641d30585ae8dce4e7 /tests/auto/quick/qquicktextinput | |
parent | 0c5a9ff9876cb1af53317720d1de8baae003e21d (diff) | |
parent | 0932a59971f606f07b41da19f3974d51b7008180 (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp
Change-Id: I26d6435a29cac3840bb567ade5149c2562a94bf9
Diffstat (limited to 'tests/auto/quick/qquicktextinput')
-rw-r--r-- | tests/auto/quick/qquicktextinput/data/focusOnlyOneOnPress.qml | 32 | ||||
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 41 |
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextinput/data/focusOnlyOneOnPress.qml b/tests/auto/quick/qquicktextinput/data/focusOnlyOneOnPress.qml new file mode 100644 index 0000000000..037b36c8ff --- /dev/null +++ b/tests/auto/quick/qquicktextinput/data/focusOnlyOneOnPress.qml @@ -0,0 +1,32 @@ +import QtQuick 2.2 + +Rectangle { + width: 400 + height: 400 + + Column { + spacing: 5 + TextInput { + objectName: "first" + onEditingFinished: second.focus = true + width: 100 + Rectangle { anchors.fill: parent; color: parent.activeFocus ? "red" : "blue"; opacity: 0.3 } + } + TextInput { + id: second + objectName: "second" + onEditingFinished: third.focus = true + width: 100 + Rectangle { anchors.fill: parent; color: parent.activeFocus ? "red" : "blue"; opacity: 0.3 } + } + TextInput { + objectName: "third" + id: third + width: 100 + Rectangle { anchors.fill: parent; color: parent.activeFocus ? "red" : "blue"; opacity: 0.3 } + } + Component.onCompleted: { + second.focus = true + } + } +} diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index f505487a14..942eb67563 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -154,6 +154,7 @@ private slots: #endif void readOnly(); void focusOnPress(); + void focusOnPressOnlyOneItem(); void openInputPanel(); void setHAlignClearCache(); @@ -3511,6 +3512,46 @@ void tst_qquicktextinput::focusOnPress() QTest::mouseRelease(&window, Qt::LeftButton, noModifiers); } +void tst_qquicktextinput::focusOnPressOnlyOneItem() +{ + QQuickView window(testFileUrl("focusOnlyOneOnPress.qml")); + window.show(); + window.requestActivate(); + QTest::qWaitForWindowActive(&window); + + QQuickTextInput *first = window.rootObject()->findChild<QQuickTextInput*>("first"); + QQuickTextInput *second = window.rootObject()->findChild<QQuickTextInput*>("second"); + QQuickTextInput *third = window.rootObject()->findChild<QQuickTextInput*>("third"); + + // second is focused onComplete + QVERIFY(second->hasActiveFocus()); + + // and first will try focus when we press it + QVERIFY(first->focusOnPress()); + + // write some text to start editing + QTest::keyClick(&window, Qt::Key_A); + + // click the first input. naturally, we are giving focus on press, but + // second's editingFinished also attempts to assign focus. lastly, focus + // should bounce back to second from first's editingFinished signal. + // + // this is a contrived example to be sure, but at the end of this, the + // important thing is that only one thing should have activeFocus. + Qt::KeyboardModifiers noModifiers = 0; + QTest::mousePress(&window, Qt::LeftButton, noModifiers, QPoint(10, 10)); + + // make sure the press is processed. + QGuiApplication::processEvents(); + + QVERIFY(second->hasActiveFocus()); // make sure it's still there + QVERIFY(!third->hasActiveFocus()); // make sure it didn't end up anywhere else + QVERIFY(!first->hasActiveFocus()); // make sure it didn't end up anywhere else + + // reset state + QTest::mouseRelease(&window, Qt::LeftButton, noModifiers, QPoint(10, 10)); +} + void tst_qquicktextinput::openInputPanel() { PlatformInputContext platformInputContext; |