aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qtquick2/qquicktextedit
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-01-20 16:10:23 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-02 02:36:00 +0100
commit054a1e942f20e5b64626729f72023ac78dd0ce38 (patch)
treeec4ff0deb03f11989a1c40e1f07ad3c098346505 /tests/auto/qtquick2/qquicktextedit
parentc30a170bb0777e5d5ddc2d45a3ca98d3af0c62c4 (diff)
Add a persistentSelection property to TextInput.
Improves feature parity with TextEdit. Task-number: QTBUG-16355 Change-Id: I3919c71454a4f4574a1ee35ad38969459beb8363 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/qtquick2/qquicktextedit')
-rw-r--r--tests/auto/qtquick2/qquicktextedit/data/persistentSelection.qml8
-rw-r--r--tests/auto/qtquick2/qquicktextedit/tst_qquicktextedit.cpp56
2 files changed, 48 insertions, 16 deletions
diff --git a/tests/auto/qtquick2/qquicktextedit/data/persistentSelection.qml b/tests/auto/qtquick2/qquicktextedit/data/persistentSelection.qml
new file mode 100644
index 0000000000..fb2fe0cd6c
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktextedit/data/persistentSelection.qml
@@ -0,0 +1,8 @@
+import QtQuick 2.0
+
+TextEdit {
+ property string selected: selectedText
+
+ text: "Hello World!"
+ focus: true
+}
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()