diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-06-01 04:50:59 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-06-02 01:43:45 (GMT) |
commit | e891abddfe42699a8c2c9a583b91269237e17008 (patch) | |
tree | a35d24cba102549a7e5c9ad2ff4a1608e84fc84a /tests | |
parent | 850efd1651acbec1f99fc3b7f35307a88504327b (diff) | |
download | Qt-e891abddfe42699a8c2c9a583b91269237e17008.zip Qt-e891abddfe42699a8c2c9a583b91269237e17008.tar.gz Qt-e891abddfe42699a8c2c9a583b91269237e17008.tar.bz2 |
Take into account platform differences in input panel support
Task-number:
Reviewed-by: Warwick Allison
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 83 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 83 |
2 files changed, 136 insertions, 30 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 47c5b63..fbab30e 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -50,6 +50,7 @@ #include <QtDeclarative/qdeclarativeexpression.h> #include <QtDeclarative/qdeclarativecomponent.h> #include <private/qdeclarativetextedit_p.h> +#include <private/qdeclarativetextedit_p_p.h> #include <QFontMetrics> #include <QDeclarativeView> #include <QStyle> @@ -86,7 +87,8 @@ private slots: void delegateLoading(); void navigation(); void readOnly(); - void sendRequestSoftwareInputPanelEvent(); + void openInputPanelOnClick(); + void openInputPanelOnFocus(); void geometrySignals(); private: void simulateKey(QDeclarativeView *, int key); @@ -817,14 +819,14 @@ public: bool closeInputPanelReceived; }; -void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() +void tst_qdeclarativetextedit::openInputPanelOnClick() { QGraphicsScene scene; QGraphicsView view(&scene); MyInputContext ic; view.setInputContext(&ic); QDeclarativeTextEdit edit; - QSignalSpy inputPanelonFocusSpy(&edit, SIGNAL(showInputPanelOnFocusChanged(bool))); + QSignalSpy focusOnPressSpy(&edit, SIGNAL(focusOnPressChanged(bool))); edit.setText("Hello world"); edit.setPos(0, 0); scene.addItem(&edit); @@ -834,7 +836,58 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QTest::qWaitForWindowShown(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); - QVERIFY(edit.showInputPanelOnFocus()); + QDeclarativeItemPrivate* pri = QDeclarativeItemPrivate::get(&edit); + QDeclarativeTextEditPrivate *editPrivate = static_cast<QDeclarativeTextEditPrivate*>(pri); + + // input panel on click + editPrivate->showInputPanelOnFocus = false; + + QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( + view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QApplication::processEvents(); + if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) { + QCOMPARE(ic.openInputPanelReceived, false); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, true); + } else if (behavior == QStyle::RSIP_OnMouseClick) { + QCOMPARE(ic.openInputPanelReceived, true); + } + ic.openInputPanelReceived = false; + + // focus should not cause input panels to open or close + edit.setFocus(false); + edit.setFocus(true); + edit.setFocus(false); + edit.setFocus(true); + edit.setFocus(false); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); +} + +void tst_qdeclarativetextedit::openInputPanelOnFocus() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + MyInputContext ic; + view.setInputContext(&ic); + QDeclarativeTextEdit edit; + QSignalSpy focusOnPressSpy(&edit, SIGNAL(focusOnPressChanged(bool))); + edit.setText("Hello world"); + edit.setPos(0, 0); + scene.addItem(&edit); + view.show(); + qApp->setAutoSipEnabled(true); + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); + + QDeclarativeItemPrivate* pri = QDeclarativeItemPrivate::get(&edit); + QDeclarativeTextEditPrivate *editPrivate = static_cast<QDeclarativeTextEditPrivate*>(pri); + editPrivate->showInputPanelOnFocus = true; + + QVERIFY(edit.focusOnPress()); QCOMPARE(ic.openInputPanelReceived, false); QCOMPARE(ic.closeInputPanelReceived, false); @@ -867,9 +920,9 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.closeInputPanelReceived, true); ic.closeInputPanelReceived = false; - // no input panel events if showInputPanelOnFocus is false - edit.setShowInputPanelOnFocus(false); - QCOMPARE(inputPanelonFocusSpy.count(),1); + // no automatic input panel events if focusOnPress is false + edit.setFocusOnPress(false); + QCOMPARE(focusOnPressSpy.count(),1); QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(edit.scenePos())); edit.setFocus(false); @@ -877,8 +930,8 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.openInputPanelReceived, false); QCOMPARE(ic.closeInputPanelReceived, false); - edit.setShowInputPanelOnFocus(false); - QCOMPARE(inputPanelonFocusSpy.count(),1); + edit.setFocusOnPress(false); + QCOMPARE(focusOnPressSpy.count(),1); // one show input panel event when openSoftwareInputPanel is called edit.openSoftwareInputPanel(); @@ -892,14 +945,17 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.closeInputPanelReceived, true); ic.openInputPanelReceived = false; - // set showInputPanelOnFocus back to true - edit.setShowInputPanelOnFocus(true); - QCOMPARE(inputPanelonFocusSpy.count(),2); + // set focusOnPress back to true + edit.setFocusOnPress(true); + QCOMPARE(focusOnPressSpy.count(),2); edit.setFocus(false); QCOMPARE(ic.openInputPanelReceived, false); QCOMPARE(ic.closeInputPanelReceived, true); ic.closeInputPanelReceived = false; + edit.setFocusOnPress(true); + QCOMPARE(focusOnPressSpy.count(),2); + // active window focus reason should not cause input panel to open QGraphicsObject * editObject = qobject_cast<QGraphicsObject*>(&edit); editObject->setFocus(Qt::ActiveWindowFocusReason); @@ -910,9 +966,6 @@ void tst_qdeclarativetextedit::sendRequestSoftwareInputPanelEvent() edit.setFocus(true); QCOMPARE(ic.openInputPanelReceived, false); QCOMPARE(ic.closeInputPanelReceived, false); - - edit.setShowInputPanelOnFocus(true); - QCOMPARE(inputPanelonFocusSpy.count(),2); } void tst_qdeclarativetextedit::geometrySignals() diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index c943c89..3cb4da0 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -45,6 +45,7 @@ #include <QFile> #include <QtDeclarative/qdeclarativeview.h> #include <private/qdeclarativetextinput_p.h> +#include <private/qdeclarativetextinput_p_p.h> #include <QDebug> #include <QStyle> #include <QInputContext> @@ -74,7 +75,8 @@ private slots: void navigation(); void readOnly(); - void sendRequestSoftwareInputPanelEvent(); + void openInputPanelOnClick(); + void openInputPanelOnFocus(); void setHAlignClearCache(); void focusOutClearSelection(); @@ -763,14 +765,14 @@ public: bool closeInputPanelReceived; }; -void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() +void tst_qdeclarativetextinput::openInputPanelOnClick() { QGraphicsScene scene; QGraphicsView view(&scene); MyInputContext ic; view.setInputContext(&ic); QDeclarativeTextInput input; - QSignalSpy inputPanelonFocusSpy(&input, SIGNAL(showInputPanelOnFocusChanged(bool))); + QSignalSpy focusOnPressSpy(&input, SIGNAL(focusOnPressChanged(bool))); input.setText("Hello world"); input.setPos(0, 0); scene.addItem(&input); @@ -780,7 +782,58 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QTest::qWaitForWindowShown(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); - QVERIFY(input.showInputPanelOnFocus()); + QDeclarativeItemPrivate* pri = QDeclarativeItemPrivate::get(&input); + QDeclarativeTextInputPrivate *inputPrivate = static_cast<QDeclarativeTextInputPrivate*>(pri); + + // input panel on click + inputPrivate->showInputPanelOnFocus = false; + + QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel( + view.style()->styleHint(QStyle::SH_RequestSoftwareInputPanel)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QApplication::processEvents(); + if (behavior == QStyle::RSIP_OnMouseClickAndAlreadyFocused) { + QCOMPARE(ic.openInputPanelReceived, false); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); + QApplication::processEvents(); + QCOMPARE(ic.openInputPanelReceived, true); + } else if (behavior == QStyle::RSIP_OnMouseClick) { + QCOMPARE(ic.openInputPanelReceived, true); + } + ic.openInputPanelReceived = false; + + // focus should not cause input panels to open or close + input.setFocus(false); + input.setFocus(true); + input.setFocus(false); + input.setFocus(true); + input.setFocus(false); + QCOMPARE(ic.openInputPanelReceived, false); + QCOMPARE(ic.closeInputPanelReceived, false); +} + +void tst_qdeclarativetextinput::openInputPanelOnFocus() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + MyInputContext ic; + view.setInputContext(&ic); + QDeclarativeTextInput input; + QSignalSpy focusOnPressSpy(&input, SIGNAL(focusOnPressChanged(bool))); + input.setText("Hello world"); + input.setPos(0, 0); + scene.addItem(&input); + view.show(); + qApp->setAutoSipEnabled(true); + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); + + QDeclarativeItemPrivate* pri = QDeclarativeItemPrivate::get(&input); + QDeclarativeTextInputPrivate *inputPrivate = static_cast<QDeclarativeTextInputPrivate*>(pri); + inputPrivate->showInputPanelOnFocus = true; + + QVERIFY(input.focusOnPress()); QCOMPARE(ic.openInputPanelReceived, false); QCOMPARE(ic.closeInputPanelReceived, false); @@ -813,9 +866,9 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.closeInputPanelReceived, true); ic.closeInputPanelReceived = false; - // no input panel events if showInputPanelOnFocus is false - input.setShowInputPanelOnFocus(false); - QCOMPARE(inputPanelonFocusSpy.count(),1); + // no automatic input panel events if focusOnPress is false + input.setFocusOnPress(false); + QCOMPARE(focusOnPressSpy.count(),1); QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(input.scenePos())); input.setFocus(false); @@ -823,8 +876,8 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.openInputPanelReceived, false); QCOMPARE(ic.closeInputPanelReceived, false); - input.setShowInputPanelOnFocus(false); - QCOMPARE(inputPanelonFocusSpy.count(),1); + input.setFocusOnPress(false); + QCOMPARE(focusOnPressSpy.count(),1); // one show input panel event when openSoftwareInputPanel is called input.openSoftwareInputPanel(); @@ -838,14 +891,17 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() QCOMPARE(ic.closeInputPanelReceived, true); ic.openInputPanelReceived = false; - // set showInputPanelOnFocus back to true - input.setShowInputPanelOnFocus(true); - QCOMPARE(inputPanelonFocusSpy.count(),2); + // set focusOnPress back to true + input.setFocusOnPress(true); + QCOMPARE(focusOnPressSpy.count(),2); input.setFocus(false); QCOMPARE(ic.openInputPanelReceived, false); QCOMPARE(ic.closeInputPanelReceived, true); ic.closeInputPanelReceived = false; + input.setFocusOnPress(true); + QCOMPARE(focusOnPressSpy.count(),2); + // active window focus reason should not cause input panel to open QGraphicsObject * inputObject = qobject_cast<QGraphicsObject*>(&input); inputObject->setFocus(Qt::ActiveWindowFocusReason); @@ -856,9 +912,6 @@ void tst_qdeclarativetextinput::sendRequestSoftwareInputPanelEvent() input.setFocus(true); QCOMPARE(ic.openInputPanelReceived, false); QCOMPARE(ic.closeInputPanelReceived, false); - - input.setShowInputPanelOnFocus(true); - QCOMPARE(inputPanelonFocusSpy.count(),2); } class MyTextInput : public QDeclarativeTextInput |