diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-08-03 16:50:24 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-06 09:06:24 +0200 |
commit | 35c8ad7957aed842e1aba60df96e50c5e2dcf133 (patch) | |
tree | 78594d3984716574eb289c773ad286260d6031c4 /tests | |
parent | 082dff2c8f5383e8372c1a4d7c61bc2eebe5c9df (diff) |
Fix pasting with the middle button in TextInput and TextEdit.
Neither item accepted the middle button which prevented the mouse events
ever reaching them.
Change-Id: Ia8f693099df4d6c248976453d554fef96d1d3b33
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp | 53 | ||||
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 53 |
2 files changed, 106 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 9f381053a9..4953874809 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -153,6 +153,7 @@ private slots: void copyAndPaste(); void canPaste(); void canPasteEmpty(); + void middleClickPaste(); void textInput(); void inputMethodUpdate(); void openInputPanel(); @@ -2706,6 +2707,58 @@ void tst_qquicktextedit::canPasteEmpty() { } +void tst_qquicktextedit::middleClickPaste() +{ +#ifndef QT_NO_CLIPBOARD + +#ifdef Q_OS_MAC + { + PasteboardRef pasteboard; + OSStatus status = PasteboardCreate(0, &pasteboard); + if (status == noErr) + CFRelease(pasteboard); + else + QSKIP("This machine doesn't support the clipboard"); + } +#endif + + QQuickView window(testFileUrl("mouseselection_true.qml")); + + window.show(); + window.requestActivateWindow(); + QTest::qWaitForWindowActive(&window); + + QVERIFY(window.rootObject() != 0); + QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit *>(window.rootObject()); + QVERIFY(textEditObject != 0); + + textEditObject->setFocus(true); + + QString originalText = textEditObject->text(); + QString selectedText = "234567"; + + // press-and-drag-and-release from x1 to x2 + const QPoint p1 = textEditObject->positionToRectangle(2).center().toPoint(); + const QPoint p2 = textEditObject->positionToRectangle(8).center().toPoint(); + const QPoint p3 = textEditObject->positionToRectangle(1).center().toPoint(); + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p1); + QTest::mouseMove(&window, p2); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p2); + QTRY_COMPARE(textEditObject->selectedText(), selectedText); + + // Middle click pastes the selected text, assuming the platform supports it. + QTest::mouseClick(&window, Qt::MiddleButton, Qt::NoModifier, p3); + + // ### This is to prevent double click detection from carrying over to the next test. + QTest::qWait(QGuiApplication::styleHints()->mouseDoubleClickInterval() + 10); + + if (QGuiApplication::clipboard()->supportsSelection()) + QCOMPARE(textEditObject->text().mid(1, selectedText.length()), selectedText); + else + QCOMPARE(textEditObject->text(), originalText); +#endif +} + void tst_qquicktextedit::readOnly() { QQuickView window(testFileUrl("readOnly.qml")); diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 8beb871212..7b9809908d 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -159,6 +159,7 @@ private slots: void copyAndPasteKeySequence(); void canPasteEmpty(); void canPaste(); + void middleClickPaste(); void readOnly(); void focusOnPress(); @@ -2639,6 +2640,58 @@ void tst_qquicktextinput::canPaste() { #endif } +void tst_qquicktextinput::middleClickPaste() +{ +#ifndef QT_NO_CLIPBOARD + +#ifdef Q_OS_MAC + { + PasteboardRef pasteboard; + OSStatus status = PasteboardCreate(0, &pasteboard); + if (status == noErr) + CFRelease(pasteboard); + else + QSKIP("This machine doesn't support the clipboard"); + } +#endif + + QQuickView window(testFileUrl("mouseselection_true.qml")); + + window.show(); + window.requestActivateWindow(); + QTest::qWaitForWindowActive(&window); + + QVERIFY(window.rootObject() != 0); + QQuickTextInput *textInputObject = qobject_cast<QQuickTextInput *>(window.rootObject()); + QVERIFY(textInputObject != 0); + + textInputObject->setFocus(true); + + QString originalText = textInputObject->text(); + QString selectedText = "234567"; + + // press-and-drag-and-release from x1 to x2 + const QPoint p1 = textInputObject->positionToRectangle(2).center().toPoint(); + const QPoint p2 = textInputObject->positionToRectangle(8).center().toPoint(); + const QPoint p3 = textInputObject->positionToRectangle(1).center().toPoint(); + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p1); + QTest::mouseMove(&window, p2); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p2); + QTRY_COMPARE(textInputObject->selectedText(), selectedText); + + // Middle click pastes the selected text, assuming the platform supports it. + QTest::mouseClick(&window, Qt::MiddleButton, Qt::NoModifier, p3); + + // ### This is to prevent double click detection from carrying over to the next test. + QTest::qWait(QGuiApplication::styleHints()->mouseDoubleClickInterval() + 10); + + if (QGuiApplication::clipboard()->supportsSelection()) + QCOMPARE(textInputObject->text().mid(1, selectedText.length()), selectedText); + else + QCOMPARE(textInputObject->text(), originalText); +#endif +} + void tst_qquicktextinput::passwordCharacter() { QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\"; font.family: \"Helvetica\"; echoMode: TextInput.Password }"; |