diff options
author | Pekka Vuorela <pekka.ta.vuorela@nokia.com> | 2012-01-04 14:46:09 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-05 16:31:56 +0100 |
commit | 4e9efd590df116bad85632d32ac4fed0a1c29065 (patch) | |
tree | fd069050940c090ee4f3e1cd1e21d0e2ab967a9c /tests | |
parent | cd1342197e3132a901ab71af6e2d0891a91ad534 (diff) |
QQuickTextInput to better call QInputPanel::update()
Some updates were previously omitted, e.g. if text content
changed but cursor position remained the same, or if input
method changed the selection.
Change-Id: I11abd105632d73f8ebb23d0e8c308c53c236cc15
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp index 44040f3d91..8ed8b9d11c 100644 --- a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp @@ -162,6 +162,7 @@ private slots: void preeditCursorRectangle(); void inputContextMouseHandler(); void inputMethodComposing(); + void inputPanelUpdate(); void cursorRectangleSize(); void getText_data(); @@ -2769,6 +2770,73 @@ void tst_qquicktextinput::inputMethodComposing() QCOMPARE(spy.count(), 2); } +void tst_qquicktextinput::inputPanelUpdate() +{ + PlatformInputContext platformInputContext; + QInputPanelPrivate *inputPanelPrivate = QInputPanelPrivate::get(qApp->inputPanel()); + inputPanelPrivate->testContext = &platformInputContext; + + QQuickView view(testFileUrl("inputContext.qml")); + view.show(); + view.requestActivateWindow(); + QTest::qWaitForWindowShown(&view); + QTRY_COMPARE(&view, qGuiApp->focusWindow()); + QQuickTextInput *input = qobject_cast<QQuickTextInput *>(view.rootObject()); + QVERIFY(input); + + // text change even without cursor position change needs to trigger update + input->setText("test"); + platformInputContext.clear(); + input->setText("xxxx"); + QVERIFY(platformInputContext.m_updateCallCount > 0); + + // input method event replacing text + platformInputContext.clear(); + { + QInputMethodEvent inputMethodEvent; + inputMethodEvent.setCommitString("y", -1, 1); + QGuiApplication::sendEvent(input, &inputMethodEvent); + } + QVERIFY(platformInputContext.m_updateCallCount > 0); + + // input method changing selection + platformInputContext.clear(); + { + QList<QInputMethodEvent::Attribute> attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 2, QVariant()); + QInputMethodEvent inputMethodEvent("", attributes); + QGuiApplication::sendEvent(input, &inputMethodEvent); + } + QVERIFY(input->selectionStart() != input->selectionEnd()); + QVERIFY(platformInputContext.m_updateCallCount > 0); + + // programmatical selections trigger update + platformInputContext.clear(); + input->selectAll(); + QVERIFY(platformInputContext.m_updateCallCount > 0); + + // font changes + platformInputContext.clear(); + QFont font = input->font(); + font.setBold(!font.bold()); + input->setFont(font); + QVERIFY(platformInputContext.m_updateCallCount > 0); + + // normal input + platformInputContext.clear(); + { + QInputMethodEvent inputMethodEvent; + inputMethodEvent.setCommitString("y"); + QGuiApplication::sendEvent(input, &inputMethodEvent); + } + QVERIFY(platformInputContext.m_updateCallCount > 0); + + // changing cursor position + platformInputContext.clear(); + input->setCursorPosition(0); + QVERIFY(platformInputContext.m_updateCallCount > 0); +} + void tst_qquicktextinput::cursorRectangleSize() { QQuickView *canvas = new QQuickView(testFileUrl("positionAt.qml")); |