aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp')
-rw-r--r--tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp56
1 files changed, 40 insertions, 16 deletions
diff --git a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
index bcf4f60bf0..07b8f105fa 100644
--- a/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp
@@ -946,23 +946,47 @@ void tst_qquicktextedit::textMargin()
void tst_qquicktextedit::persistentSelection()
{
- {
- QString componentStr = "import QtQuick 2.0\nTextEdit { persistentSelection: true; text: \"Hello World\" }";
- QDeclarativeComponent texteditComponent(&engine);
- texteditComponent.setData(componentStr.toLatin1(), QUrl());
- QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit*>(texteditComponent.create());
- QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->persistentSelection(), true);
- }
+ QQuickView canvas(testFileUrl("persistentSelection.qml"));
+ canvas.show();
+ canvas.requestActivateWindow();
+ QTest::qWaitForWindowShown(&canvas);
+ QTRY_COMPARE(&canvas, qGuiApp->focusWindow());
+ canvas.requestActivateWindow();
+
+ QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(canvas.rootObject());
+ QVERIFY(edit);
+ QVERIFY(edit->hasActiveFocus());
+
+ QSignalSpy spy(edit, SIGNAL(persistentSelectionChanged(bool)));
+
+ QCOMPARE(edit->persistentSelection(), false);
+
+ edit->setPersistentSelection(false);
+ QCOMPARE(edit->persistentSelection(), false);
+ QCOMPARE(spy.count(), 0);
+
+ edit->select(1, 4);
+ QCOMPARE(edit->property("selected").toString(), QLatin1String("ell"));
+
+ edit->setFocus(false);
+ QCOMPARE(edit->property("selected").toString(), QString());
+
+ edit->setFocus(true);
+ QCOMPARE(edit->property("selected").toString(), QString());
+
+ edit->setPersistentSelection(true);
+ QCOMPARE(edit->persistentSelection(), true);
+ QCOMPARE(spy.count(), 1);
+
+ edit->select(1, 4);
+ QCOMPARE(edit->property("selected").toString(), QLatin1String("ell"));
+
+ edit->setFocus(false);
+ QCOMPARE(edit->property("selected").toString(), QLatin1String("ell"));
+
+ edit->setFocus(true);
+ QCOMPARE(edit->property("selected").toString(), QLatin1String("ell"));
- {
- QString componentStr = "import QtQuick 2.0\nTextEdit { persistentSelection: false; text: \"Hello World\" }";
- QDeclarativeComponent texteditComponent(&engine);
- texteditComponent.setData(componentStr.toLatin1(), QUrl());
- QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit*>(texteditComponent.create());
- QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->persistentSelection(), false);
- }
}
void tst_qquicktextedit::focusOnPress()