From 23eefdc3e2f215deb53ab70ce7991183ed7a80e3 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 28 Feb 2024 23:24:25 -0700 Subject: Use showView in most test functions in tst_qquicktextedit Cut down on boilerplate and avoid dynamic allocation. Many of them used requestActivate() before; showView() just calls show() and qWaitForWindowExposed(). It remains to be seen whether activating makes a difference in most of these. Change-Id: I1348b4661a3059635ebde7d9068c348c0bddb44f Reviewed-by: Axel Spoerl Reviewed-by: Qt CI Bot --- .../quick/qquicktextedit/data/focusByDefault.qml | 7 + .../quick/qquicktextedit/tst_qquicktextedit.cpp | 506 ++++++++------------- 2 files changed, 197 insertions(+), 316 deletions(-) create mode 100644 tests/auto/quick/qquicktextedit/data/focusByDefault.qml (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qquicktextedit/data/focusByDefault.qml b/tests/auto/quick/qquicktextedit/data/focusByDefault.qml new file mode 100644 index 0000000000..0f518aa7da --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/focusByDefault.qml @@ -0,0 +1,7 @@ +import QtQuick + +TextEdit { + width: 200 + height: 100 + focus: true +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 60ba1e38d8..dc47520ae3 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -1310,10 +1310,8 @@ void tst_qquicktextedit::textMargin() void tst_qquicktextedit::persistentSelection() { - QQuickView window(testFileUrl("persistentSelection.qml")); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("persistentSelection.qml"))); QQuickTextEdit *edit = qobject_cast(window.rootObject()); QVERIFY(edit); @@ -1592,20 +1590,12 @@ void tst_qquicktextedit::selection() void tst_qquicktextedit::overwriteMode() { - QString componentStr = "import QtQuick 2.0\nTextEdit { focus: true; }"; - QQmlComponent textEditComponent(&engine); - textEditComponent.setData(componentStr.toLatin1(), QUrl()); - QQuickTextEdit *textEdit = qobject_cast(textEditComponent.create()); - QVERIFY(textEdit != nullptr); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("focusByDefault.qml"))); + QQuickTextEdit *textEdit = qobject_cast(window.rootObject()); QSignalSpy spy(textEdit, SIGNAL(overwriteModeChanged(bool))); - QQuickWindow window; - textEdit->setParentItem(window.contentItem()); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); - QVERIFY(textEdit->hasActiveFocus()); textEdit->setOverwriteMode(true); @@ -1717,12 +1707,8 @@ void tst_qquicktextedit::isRightToLeft() void tst_qquicktextedit::keySelection() { - QQuickView window(testFileUrl("navigation.qml")); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); - - QVERIFY(window.rootObject() != nullptr); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("navigation.qml"))); QQuickTextEdit *input = qobject_cast(qvariant_cast(window.rootObject()->property("myInput"))); @@ -2099,7 +2085,7 @@ void tst_qquicktextedit::moveCursorSelectionSequence() void tst_qquicktextedit::mouseSelection_data() { - QTest::addColumn("qmlfile"); + QTest::addColumn("qmlfile"); QTest::addColumn("from"); QTest::addColumn("to"); QTest::addColumn("selectedText"); @@ -2108,64 +2094,64 @@ void tst_qquicktextedit::mouseSelection_data() QTest::addColumn("clicks"); // import installed - QTest::newRow("on") << testFile("mouseselection_true.qml") << 4 << 9 << "45678" << true << true << 1; - QTest::newRow("off") << testFile("mouseselection_false.qml") << 4 << 9 << QString() << true << true << 1; - QTest::newRow("default") << testFile("mouseselectionmode_default.qml") << 4 << 9 << "45678" << true << true << 1; - QTest::newRow("off word selection") << testFile("mouseselection_false_words.qml") << 4 << 9 << QString() << true << true << 1; - QTest::newRow("on word selection (4,9)") << testFile("mouseselection_true_words.qml") << 4 << 9 << "0123456789" << true << true << 1; - - QTest::newRow("on unfocused") << testFile("mouseselection_true.qml") << 4 << 9 << "45678" << false << false << 1; - QTest::newRow("on word selection (4,9) unfocused") << testFile("mouseselection_true_words.qml") << 4 << 9 << "0123456789" << false << false << 1; - - QTest::newRow("on focus on press") << testFile("mouseselection_true.qml") << 4 << 9 << "45678" << false << true << 1; - QTest::newRow("on word selection (4,9) focus on press") << testFile("mouseselection_true_words.qml") << 4 << 9 << "0123456789" << false << true << 1; - - QTest::newRow("on word selection (2,13)") << testFile("mouseselection_true_words.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; - QTest::newRow("on word selection (2,30)") << testFile("mouseselection_true_words.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; - QTest::newRow("on word selection (9,13)") << testFile("mouseselection_true_words.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; - QTest::newRow("on word selection (9,30)") << testFile("mouseselection_true_words.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; - QTest::newRow("on word selection (13,2)") << testFile("mouseselection_true_words.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; - QTest::newRow("on word selection (20,2)") << testFile("mouseselection_true_words.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; - QTest::newRow("on word selection (12,9)") << testFile("mouseselection_true_words.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; - QTest::newRow("on word selection (30,9)") << testFile("mouseselection_true_words.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; - - QTest::newRow("on double click (4,9)") << testFile("mouseselection_true.qml") << 4 << 9 << "0123456789" << true << true << 2; - QTest::newRow("on double click (2,13)") << testFile("mouseselection_true.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; - QTest::newRow("on double click (2,30)") << testFile("mouseselection_true.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; - QTest::newRow("on double click (9,13)") << testFile("mouseselection_true.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; - QTest::newRow("on double click (9,30)") << testFile("mouseselection_true.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; - QTest::newRow("on double click (13,2)") << testFile("mouseselection_true.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; - QTest::newRow("on double click (20,2)") << testFile("mouseselection_true.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; - QTest::newRow("on double click (12,9)") << testFile("mouseselection_true.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; - QTest::newRow("on double click (30,9)") << testFile("mouseselection_true.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; - - QTest::newRow("on triple click (4,9)") << testFile("mouseselection_true.qml") << 4 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - QTest::newRow("on triple click (2,13)") << testFile("mouseselection_true.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - QTest::newRow("on triple click (2,30)") << testFile("mouseselection_true.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - QTest::newRow("on triple click (9,13)") << testFile("mouseselection_true.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - QTest::newRow("on triple click (9,30)") << testFile("mouseselection_true.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - QTest::newRow("on triple click (13,2)") << testFile("mouseselection_true.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - QTest::newRow("on triple click (20,2)") << testFile("mouseselection_true.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - QTest::newRow("on triple click (12,9)") << testFile("mouseselection_true.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - QTest::newRow("on triple click (30,9)") << testFile("mouseselection_true.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; - - QTest::newRow("on triple click (2,40)") << testFile("mouseselection_true.qml") << 2 << 40 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n" << true << true << 3; - QTest::newRow("on triple click (2,50)") << testFile("mouseselection_true.qml") << 2 << 50 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; - QTest::newRow("on triple click (25,40)") << testFile("mouseselection_true.qml") << 25 << 40 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n" << true << true << 3; - QTest::newRow("on triple click (25,50)") << testFile("mouseselection_true.qml") << 25 << 50 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; - QTest::newRow("on triple click (40,25)") << testFile("mouseselection_true.qml") << 40 << 25 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n" << true << true << 3; - QTest::newRow("on triple click (40,50)") << testFile("mouseselection_true.qml") << 40 << 50 << "9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; - QTest::newRow("on triple click (50,25)") << testFile("mouseselection_true.qml") << 50 << 25 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; - QTest::newRow("on triple click (50,40)") << testFile("mouseselection_true.qml") << 50 << 40 << "9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; - - QTest::newRow("on tr align") << testFile("mouseselection_align_tr.qml") << 4 << 9 << "45678" << true << true << 1; - QTest::newRow("on center align") << testFile("mouseselection_align_center.qml") << 4 << 9 << "45678" << true << true << 1; - QTest::newRow("on bl align") << testFile("mouseselection_align_bl.qml") << 4 << 9 << "45678" << true << true << 1; + QTest::newRow("on") << testFileUrl("mouseselection_true.qml") << 4 << 9 << "45678" << true << true << 1; + QTest::newRow("off") << testFileUrl("mouseselection_false.qml") << 4 << 9 << QString() << true << true << 1; + QTest::newRow("default") << testFileUrl("mouseselectionmode_default.qml") << 4 << 9 << "45678" << true << true << 1; + QTest::newRow("off word selection") << testFileUrl("mouseselection_false_words.qml") << 4 << 9 << QString() << true << true << 1; + QTest::newRow("on word selection (4,9)") << testFileUrl("mouseselection_true_words.qml") << 4 << 9 << "0123456789" << true << true << 1; + + QTest::newRow("on unfocused") << testFileUrl("mouseselection_true.qml") << 4 << 9 << "45678" << false << false << 1; + QTest::newRow("on word selection (4,9) unfocused") << testFileUrl("mouseselection_true_words.qml") << 4 << 9 << "0123456789" << false << false << 1; + + QTest::newRow("on focus on press") << testFileUrl("mouseselection_true.qml") << 4 << 9 << "45678" << false << true << 1; + QTest::newRow("on word selection (4,9) focus on press") << testFileUrl("mouseselection_true_words.qml") << 4 << 9 << "0123456789" << false << true << 1; + + QTest::newRow("on word selection (2,13)") << testFileUrl("mouseselection_true_words.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; + QTest::newRow("on word selection (2,30)") << testFileUrl("mouseselection_true_words.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; + QTest::newRow("on word selection (9,13)") << testFileUrl("mouseselection_true_words.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; + QTest::newRow("on word selection (9,30)") << testFileUrl("mouseselection_true_words.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; + QTest::newRow("on word selection (13,2)") << testFileUrl("mouseselection_true_words.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; + QTest::newRow("on word selection (20,2)") << testFileUrl("mouseselection_true_words.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; + QTest::newRow("on word selection (12,9)") << testFileUrl("mouseselection_true_words.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; + QTest::newRow("on word selection (30,9)") << testFileUrl("mouseselection_true_words.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 1; + + QTest::newRow("on double click (4,9)") << testFileUrl("mouseselection_true.qml") << 4 << 9 << "0123456789" << true << true << 2; + QTest::newRow("on double click (2,13)") << testFileUrl("mouseselection_true.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; + QTest::newRow("on double click (2,30)") << testFileUrl("mouseselection_true.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; + QTest::newRow("on double click (9,13)") << testFileUrl("mouseselection_true.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; + QTest::newRow("on double click (9,30)") << testFileUrl("mouseselection_true.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; + QTest::newRow("on double click (13,2)") << testFileUrl("mouseselection_true.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; + QTest::newRow("on double click (20,2)") << testFileUrl("mouseselection_true.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; + QTest::newRow("on double click (12,9)") << testFileUrl("mouseselection_true.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; + QTest::newRow("on double click (30,9)") << testFileUrl("mouseselection_true.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true << true << 2; + + QTest::newRow("on triple click (4,9)") << testFileUrl("mouseselection_true.qml") << 4 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + QTest::newRow("on triple click (2,13)") << testFileUrl("mouseselection_true.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + QTest::newRow("on triple click (2,30)") << testFileUrl("mouseselection_true.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + QTest::newRow("on triple click (9,13)") << testFileUrl("mouseselection_true.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + QTest::newRow("on triple click (9,30)") << testFileUrl("mouseselection_true.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + QTest::newRow("on triple click (13,2)") << testFileUrl("mouseselection_true.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + QTest::newRow("on triple click (20,2)") << testFileUrl("mouseselection_true.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + QTest::newRow("on triple click (12,9)") << testFileUrl("mouseselection_true.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + QTest::newRow("on triple click (30,9)") << testFileUrl("mouseselection_true.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" << true << true << 3; + + QTest::newRow("on triple click (2,40)") << testFileUrl("mouseselection_true.qml") << 2 << 40 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n" << true << true << 3; + QTest::newRow("on triple click (2,50)") << testFileUrl("mouseselection_true.qml") << 2 << 50 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; + QTest::newRow("on triple click (25,40)") << testFileUrl("mouseselection_true.qml") << 25 << 40 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n" << true << true << 3; + QTest::newRow("on triple click (25,50)") << testFileUrl("mouseselection_true.qml") << 25 << 50 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; + QTest::newRow("on triple click (40,25)") << testFileUrl("mouseselection_true.qml") << 40 << 25 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n" << true << true << 3; + QTest::newRow("on triple click (40,50)") << testFileUrl("mouseselection_true.qml") << 40 << 50 << "9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; + QTest::newRow("on triple click (50,25)") << testFileUrl("mouseselection_true.qml") << 50 << 25 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\n9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; + QTest::newRow("on triple click (50,40)") << testFileUrl("mouseselection_true.qml") << 50 << 40 << "9876543210\n\nZXYWVUTSRQPON MLKJIHGFEDCBA" << true << true << 3; + + QTest::newRow("on tr align") << testFileUrl("mouseselection_align_tr.qml") << 4 << 9 << "45678" << true << true << 1; + QTest::newRow("on center align") << testFileUrl("mouseselection_align_center.qml") << 4 << 9 << "45678" << true << true << 1; + QTest::newRow("on bl align") << testFileUrl("mouseselection_align_bl.qml") << 4 << 9 << "45678" << true << true << 1; } void tst_qquicktextedit::mouseSelection() { - QFETCH(QString, qmlfile); + QFETCH(QUrl, qmlfile); QFETCH(int, from); QFETCH(int, to); QFETCH(QString, selectedText); @@ -2173,13 +2159,8 @@ void tst_qquicktextedit::mouseSelection() QFETCH(bool, focusOnPress); QFETCH(int, clicks); - QQuickView window(QUrl::fromLocalFile(qmlfile)); - - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); - - QVERIFY(window.rootObject() != nullptr); + QQuickView window; + QVERIFY(QQuickTest::showView(window, qmlfile)); QQuickTextEdit *textEditObject = qobject_cast(window.rootObject()); QVERIFY(textEditObject != nullptr); @@ -2214,15 +2195,8 @@ void tst_qquicktextedit::mouseSelection() void tst_qquicktextedit::dragMouseSelection() { - QString qmlfile = testFile("mouseselection_true.qml"); - - QQuickView window(QUrl::fromLocalFile(qmlfile)); - - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); - - QVERIFY(window.rootObject() != nullptr); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("mouseselection_true.qml"))); QQuickTextEdit *textEditObject = qobject_cast(window.rootObject()); QVERIFY(textEditObject != nullptr); @@ -2440,27 +2414,19 @@ void tst_qquicktextedit::keyboardSelection() QFETCH(QKeySequence::StandardKey, standardKey); QFETCH(QString, selectedText); - QQmlComponent component(&engine); - component.setData("import QtQuick 2.1\n TextEdit { focus: true }", QUrl()); - QScopedPointer object(component.create()); - QQuickTextEdit *edit = qobject_cast(object.data()); - QVERIFY(edit); - - edit->setText(text); - edit->setSelectByKeyboard(selectByKeyboard); - edit->setReadOnly(readOnly); - edit->setCursorPosition(cursorPosition); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("focusByDefault.qml"))); + QQuickTextEdit *textEdit = qobject_cast(window.rootObject()); + QVERIFY(textEdit->hasActiveFocus()); - QQuickWindow window; - edit->setParentItem(window.contentItem()); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); - QVERIFY(edit->hasActiveFocus()); + textEdit->setText(text); + textEdit->setSelectByKeyboard(selectByKeyboard); + textEdit->setReadOnly(readOnly); + textEdit->setCursorPosition(cursorPosition); simulateKeys(&window, standardKey); - QCOMPARE(edit->selectedText(), selectedText); + QCOMPARE(textEdit->selectedText(), selectedText); } #endif // QT_CONFIG(shortcut) @@ -2491,11 +2457,8 @@ void tst_qquicktextedit::renderType() void tst_qquicktextedit::inputMethodHints() { - QQuickView window(testFileUrl("inputmethodhints.qml")); - window.show(); - window.requestActivate(); - - QVERIFY(window.rootObject() != nullptr); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("inputmethodhints.qml"))); QQuickTextEdit *textEditObject = qobject_cast(window.rootObject()); QVERIFY(textEditObject != nullptr); QVERIFY(textEditObject->inputMethodHints() & Qt::ImhNoPredictiveText); @@ -2530,11 +2493,8 @@ void tst_qquicktextedit::positionAt() QFETCH(QQuickTextEdit::HAlignment, horizontalAlignment); QFETCH(QQuickTextEdit::VAlignment, verticalAlignment); - QQuickView window(testFileUrl("positionAt.qml")); - QVERIFY(window.rootObject() != nullptr); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("positionAt.qml"))); QQuickTextEdit *texteditObject = qobject_cast(window.rootObject()); QVERIFY(texteditObject != nullptr); @@ -2665,13 +2625,8 @@ void tst_qquicktextedit::linkHover() void tst_qquicktextedit::linkInteraction() { - QQuickView window(testFileUrl("linkInteraction.qml")); - QVERIFY(window.rootObject() != nullptr); - QQuickVisualTestUtils::centerOnScreen(&window); - QQuickVisualTestUtils::moveMouseAway(&window); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("linkInteraction.qml"))); QQuickTextEdit *texteditObject = qobject_cast(window.rootObject()); QVERIFY(texteditObject != nullptr); @@ -2728,11 +2683,10 @@ void tst_qquicktextedit::cursorDelegate_data() void tst_qquicktextedit::cursorDelegate() { QFETCH(QUrl, source); - QQuickView view(source); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QQuickTextEdit *textEditObject = view.rootObject()->findChild("textEditObject"); + + QQuickView window; + QVERIFY(QQuickTest::showView(window, source)); + QQuickTextEdit *textEditObject = window.rootObject()->findChild("textEditObject"); QVERIFY(textEditObject != nullptr); // Delegate creation is deferred until focus in or cursor visibility is forced. QVERIFY(!textEditObject->findChild("cursorInstance")); @@ -2755,7 +2709,7 @@ void tst_qquicktextedit::cursorDelegate() textEditObject->setCursorPosition(0); const QPoint point1 = textEditObject->positionToRectangle(5).center().toPoint(); QTest::qWait(400); //ensure this isn't treated as a double-click - QTest::mouseClick(&view, Qt::LeftButton, Qt::NoModifier, point1); + QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, point1); QTest::qWait(50); QTRY_VERIFY(textEditObject->cursorPosition() != 0); QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); @@ -2765,11 +2719,11 @@ void tst_qquicktextedit::cursorDelegate() textEditObject->setCursorPosition(0); const QPoint point2 = textEditObject->positionToRectangle(10).center().toPoint(); QTest::qWait(400); //ensure this isn't treated as a double-click - QTest::mousePress(&view, Qt::LeftButton, Qt::NoModifier, point1); - QMouseEvent mv(QEvent::MouseMove, point2, view.mapToGlobal(point2), + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, point1); + QMouseEvent mv(QEvent::MouseMove, point2, window.mapToGlobal(point2), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); - QGuiApplication::sendEvent(&view, &mv); - QTest::mouseRelease(&view, Qt::LeftButton, Qt::NoModifier, point2); + QGuiApplication::sendEvent(&window, &mv); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, point2); QTest::qWait(50); QTRY_COMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y()); @@ -2777,7 +2731,7 @@ void tst_qquicktextedit::cursorDelegate() textEditObject->setReadOnly(true); textEditObject->setCursorPosition(0); QTest::qWait(400); //ensure this isn't treated as a double-click - QTest::mouseClick(&view, Qt::LeftButton, Qt::NoModifier, textEditObject->positionToRectangle(5).center().toPoint()); + QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, textEditObject->positionToRectangle(5).center().toPoint()); QTest::qWait(50); QTRY_VERIFY(textEditObject->cursorPosition() != 0); QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); @@ -2785,7 +2739,7 @@ void tst_qquicktextedit::cursorDelegate() textEditObject->setCursorPosition(0); QTest::qWait(400); //ensure this isn't treated as a double-click - QTest::mouseClick(&view, Qt::LeftButton, Qt::NoModifier, textEditObject->positionToRectangle(5).center().toPoint()); + QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, textEditObject->positionToRectangle(5).center().toPoint()); QTest::qWait(50); QTRY_VERIFY(textEditObject->cursorPosition() != 0); QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); @@ -2800,7 +2754,7 @@ void tst_qquicktextedit::cursorDelegate() // Delegate moved when text is entered textEditObject->setText(QString()); for (int i = 0; i < 20; ++i) { - QTest::keyClick(&view, Qt::Key_A); + QTest::keyClick(&window, Qt::Key_A); QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y()); } @@ -2870,11 +2824,10 @@ void tst_qquicktextedit::cursorVisible() edit.componentComplete(); QSignalSpy spy(&edit, SIGNAL(cursorVisibleChanged(bool))); - QQuickView view(testFileUrl("cursorVisible.qml")); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(&view, qGuiApp->focusWindow()); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("cursorVisible.qml"))); + + QCOMPARE(qGuiApp->focusWindow(), &window); QCOMPARE(edit.isCursorVisible(), false); @@ -2890,7 +2843,7 @@ void tst_qquicktextedit::cursorVisible() QCOMPARE(edit.isCursorVisible(), false); QCOMPARE(spy.size(), 2); - edit.setParentItem(view.rootObject()); + edit.setParentItem(window.rootObject()); QCOMPARE(edit.isCursorVisible(), true); QCOMPARE(spy.size(), 3); @@ -2910,8 +2863,8 @@ void tst_qquicktextedit::cursorVisible() QCOMPARE(edit.isCursorVisible(), false); QCOMPARE(spy.size(), 6); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); QCOMPARE(edit.isCursorVisible(), true); QCOMPARE(spy.size(), 7); @@ -3015,11 +2968,9 @@ void tst_qquicktextedit::delegateLoading() void tst_qquicktextedit::cursorDelegateHeight() { - QQuickView view(testFileUrl("cursorHeight.qml")); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QQuickTextEdit *textEditObject = view.rootObject()->findChild("textEditObject"); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("cursorHeight.qml"))); + QQuickTextEdit *textEditObject = window.rootObject()->findChild(); QVERIFY(textEditObject); // Delegate creation is deferred until focus in or cursor visibility is forced. QVERIFY(!textEditObject->findChild("cursorInstance")); @@ -3056,12 +3007,8 @@ the extent of the text, then they should ignore the keys. */ void tst_qquicktextedit::navigation() { - QQuickView window(testFileUrl("navigation.qml")); - window.show(); - window.requestActivate(); - - QVERIFY(window.rootObject() != nullptr); - + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("navigation.qml"))); QQuickTextEdit *input = qobject_cast(qvariant_cast(window.rootObject()->property("myInput"))); QVERIFY(input != nullptr); @@ -3207,13 +3154,8 @@ void tst_qquicktextedit::middleClickPaste() if (!PlatformQuirks::isClipboardAvailable()) QSKIP("This machine doesn't support the clipboard"); - QQuickView window(testFileUrl("mouseselection_true.qml")); - - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); - - QVERIFY(window.rootObject() != nullptr); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("mouseselection_true.qml"))); QQuickTextEdit *textEditObject = qobject_cast(window.rootObject()); QVERIFY(textEditObject != nullptr); @@ -3243,9 +3185,8 @@ void tst_qquicktextedit::middleClickPaste() void tst_qquicktextedit::readOnly() { - QQuickView window(testFileUrl("readOnly.qml")); - window.show(); - window.requestActivate(); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("readOnly.qml"))); QVERIFY(window.rootObject() != nullptr); @@ -3285,11 +3226,9 @@ void tst_qquicktextedit::inFlickableMouse() QFETCH(int, expectFlickingAfter); const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); - QQuickView view(testFileUrl("inFlickable.qml")); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QQuickFlickable *flick = qobject_cast(view.rootObject()); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("inFlickable.qml"))); + QQuickFlickable *flick = qobject_cast(window.rootObject()); QVERIFY(flick); QQuickTextEdit *edit = flick->findChild("text"); QVERIFY(edit); @@ -3298,7 +3237,7 @@ void tst_qquicktextedit::inFlickableMouse() // flick with mouse QPoint p(10, 100); - QTest::mousePress(&view, Qt::LeftButton, {}, p); + QTest::mousePress(&window, Qt::LeftButton, {}, p); QObject *pressGrabber = QPointingDevicePrivate::get(QPointingDevice::primaryPointingDevice())->firstPointExclusiveGrabber(); // even if TextEdit is readonly, it still grabs on press. But not if it's disabled. if (enabled) @@ -3309,14 +3248,14 @@ void tst_qquicktextedit::inFlickableMouse() // after a couple of events, Flickable steals the grab and starts moving for (; i < 4 && !flick->isMoving(); ++i) { p -= QPoint(0, dragThreshold); - QTest::mouseMove(&view, p); + QTest::mouseMove(&window, p); } QCOMPARE(flick->isMoving(), bool(expectFlickingAfter)); if (expectFlickingAfter) { qCDebug(lcTests) << "flickable started moving after" << i << "moves, when we got to" << p; QCOMPARE(i, expectFlickingAfter); } - QTest::mouseRelease(&view, Qt::LeftButton, {}, p); + QTest::mouseRelease(&window, Qt::LeftButton, {}, p); } void tst_qquicktextedit::inFlickableTouch_data() @@ -3398,11 +3337,9 @@ bool tst_qquicktextedit::hasWindowActivation() void tst_qquicktextedit::textInput() { - QQuickView view(testFileUrl("inputMethodEvent.qml")); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QQuickTextEdit *edit = qobject_cast(view.rootObject()); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("inputMethodEvent.qml"))); + QQuickTextEdit *edit = qobject_cast(window.rootObject()); QVERIFY(edit); QVERIFY(edit->hasActiveFocus()); @@ -3451,11 +3388,9 @@ void tst_qquicktextedit::inputMethodUpdate() QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); inputMethodPrivate->testContext = &platformInputContext; - QQuickView view(testFileUrl("inputMethodEvent.qml")); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QQuickTextEdit *edit = qobject_cast(view.rootObject()); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("inputMethodEvent.qml"))); + QQuickTextEdit *edit = qobject_cast(window.rootObject()); QVERIFY(edit); QVERIFY(edit->hasActiveFocus()); @@ -3541,12 +3476,10 @@ void tst_qquicktextedit::openInputPanel() QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); inputMethodPrivate->testContext = &platformInputContext; - QQuickView view(testFileUrl("openInputPanel.qml")); - view.showNormal(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("openInputPanel.qml"))); - QQuickTextEdit *edit = qobject_cast(view.rootObject()); + QQuickTextEdit *edit = qobject_cast(window.rootObject()); QVERIFY(edit); // check default values @@ -3557,28 +3490,28 @@ void tst_qquicktextedit::openInputPanel() QCOMPARE(qApp->inputMethod()->isVisible(), false); // input panel should open on focus - QPoint centerPoint(view.width()/2, view.height()/2); + QPoint centerPoint(window.width()/2, window.height()/2); Qt::KeyboardModifiers noModifiers = Qt::NoModifier; - QTest::mousePress(&view, Qt::LeftButton, noModifiers, centerPoint); + QTest::mousePress(&window, Qt::LeftButton, noModifiers, centerPoint); QGuiApplication::processEvents(); QVERIFY(edit->hasActiveFocus()); QCOMPARE(qApp->focusObject(), edit); QCOMPARE(qApp->inputMethod()->isVisible(), true); - QTest::mouseRelease(&view, Qt::LeftButton, noModifiers, centerPoint); + QTest::mouseRelease(&window, Qt::LeftButton, noModifiers, centerPoint); // input panel should be re-opened when pressing already focused TextEdit qApp->inputMethod()->hide(); QCOMPARE(qApp->inputMethod()->isVisible(), false); QVERIFY(edit->hasActiveFocus()); - QTest::mousePress(&view, Qt::LeftButton, noModifiers, centerPoint); + QTest::mousePress(&window, Qt::LeftButton, noModifiers, centerPoint); QGuiApplication::processEvents(); QCOMPARE(qApp->inputMethod()->isVisible(), true); - QTest::mouseRelease(&view, Qt::LeftButton, noModifiers, centerPoint); + QTest::mouseRelease(&window, Qt::LeftButton, noModifiers, centerPoint); // input panel should stay visible if focus is lost to another text editor QSignalSpy inputPanelVisibilitySpy(qApp->inputMethod(), SIGNAL(visibleChanged())); QQuickTextEdit anotherEdit; - anotherEdit.setParentItem(view.rootObject()); + anotherEdit.setParentItem(window.rootObject()); anotherEdit.setFocus(true); QCOMPARE(qApp->inputMethod()->isVisible(), true); QCOMPARE(qApp->focusObject(), qobject_cast(&anotherEdit)); @@ -3586,7 +3519,7 @@ void tst_qquicktextedit::openInputPanel() anotherEdit.setFocus(false); QVERIFY(qApp->focusObject() != &anotherEdit); - QCOMPARE(view.activeFocusItem(), view.contentItem()); + QCOMPARE(window.activeFocusItem(), window.contentItem()); anotherEdit.setFocus(true); qApp->inputMethod()->hide(); @@ -3595,8 +3528,8 @@ void tst_qquicktextedit::openInputPanel() edit->setReadOnly(true); edit->setFocus(true); QCOMPARE(qApp->inputMethod()->isVisible(), false); - QTest::mousePress(&view, Qt::LeftButton, noModifiers, centerPoint); - QTest::mouseRelease(&view, Qt::LeftButton, noModifiers, centerPoint); + QTest::mousePress(&window, Qt::LeftButton, noModifiers, centerPoint); + QTest::mouseRelease(&window, Qt::LeftButton, noModifiers, centerPoint); QGuiApplication::processEvents(); QCOMPARE(qApp->inputMethod()->isVisible(), false); @@ -3605,8 +3538,8 @@ void tst_qquicktextedit::openInputPanel() edit->setFocus(false); edit->setFocus(true); QCOMPARE(qApp->inputMethod()->isVisible(), false); - QTest::mousePress(&view, Qt::LeftButton, noModifiers, centerPoint); - QTest::mouseRelease(&view, Qt::LeftButton, noModifiers, centerPoint); + QTest::mousePress(&window, Qt::LeftButton, noModifiers, centerPoint); + QTest::mouseRelease(&window, Qt::LeftButton, noModifiers, centerPoint); QCOMPARE(qApp->inputMethod()->isVisible(), false); inputMethodPrivate->testContext = nullptr; @@ -3959,20 +3892,14 @@ void tst_qquicktextedit::renderingAroundSelection() void tst_qquicktextedit::signal_editingfinished() { - QQuickView *window = new QQuickView(nullptr); - window->setBaseSize(QSize(800,600)); - - window->setSource(testFileUrl("signal_editingfinished.qml")); - window->show(); - window->requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(window)); - QCOMPARE(QGuiApplication::focusWindow(), window); - - QVERIFY(window->rootObject() != nullptr); + QQuickView window; + window.setBaseSize(QSize(800, 600)); + QVERIFY(QQuickTest::showView(window, testFileUrl("signal_editingfinished.qml"))); + QCOMPARE(QGuiApplication::focusWindow(), &window); - QQuickTextEdit *input1 = qobject_cast(qvariant_cast(window->rootObject()->property("input1"))); + QQuickTextEdit *input1 = qobject_cast(qvariant_cast(window.rootObject()->property("input1"))); QVERIFY(input1); - QQuickTextEdit *input2 = qobject_cast(qvariant_cast(window->rootObject()->property("input2"))); + QQuickTextEdit *input2 = qobject_cast(qvariant_cast(window.rootObject()->property("input2"))); QVERIFY(input2); QSignalSpy editingFinished1Spy(input1, SIGNAL(editingFinished())); @@ -3983,7 +3910,7 @@ void tst_qquicktextedit::signal_editingfinished() { QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); - QGuiApplication::sendEvent(window, &key); + QGuiApplication::sendEvent(&window, &key); QVERIFY(key.isAccepted()); QTRY_COMPARE(editingFinished1Spy.size(), 1); @@ -3999,7 +3926,7 @@ void tst_qquicktextedit::signal_editingfinished() { QKeyEvent key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); - QGuiApplication::sendEvent(window, &key); + QGuiApplication::sendEvent(&window, &key); QVERIFY(key.isAccepted()); QTRY_COMPARE(editingFinished2Spy.size(), 1); @@ -4181,12 +4108,10 @@ void tst_qquicktextedit::preeditCursorRectangle() { QString preeditText = "super"; - QQuickView view(testFileUrl("inputMethodEvent.qml")); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("inputMethodEvent.qml"))); - QQuickTextEdit *edit = qobject_cast(view.rootObject()); + QQuickTextEdit *edit = qobject_cast(window.rootObject()); QVERIFY(edit); QQuickItem *cursor = edit->findChild("cursor"); @@ -4264,12 +4189,10 @@ void tst_qquicktextedit::inputMethodComposing() { QString text = "supercalifragisiticexpialidocious!"; - QQuickView view(testFileUrl("inputContext.qml")); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("inputContext.qml"))); - QQuickTextEdit *edit = qobject_cast(view.rootObject()); + QQuickTextEdit *edit = qobject_cast(window.rootObject()); QVERIFY(edit); QCOMPARE(QGuiApplication::focusObject(), static_cast(edit)); @@ -4380,11 +4303,11 @@ void tst_qquicktextedit::cursorRectangleSize() { QFETCH(bool, useCursorDelegate); - QQuickView *window = new QQuickView(testFileUrl("positionAt.qml")); - QVERIFY(window->rootObject() != nullptr); - QQuickTextEdit *textEdit = qobject_cast(window->rootObject()); + QQuickView window(testFileUrl("positionAt.qml")); + QQuickTextEdit *textEdit = qobject_cast(window.rootObject()); + QVERIFY(textEdit); - QQmlComponent cursorDelegate(window->engine()); + QQmlComponent cursorDelegate(window.engine()); if (useCursorDelegate) { cursorDelegate.setData("import QtQuick 2.0\nRectangle { width:10; height:10; }", QUrl()); textEdit->setCursorDelegate(&cursorDelegate); @@ -4396,9 +4319,9 @@ void tst_qquicktextedit::cursorRectangleSize() textEdit->setCursorPosition(3); QVERIFY(textEdit != nullptr); textEdit->setFocus(true); - window->show(); - window->requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(window)); + window.show(); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); QInputMethodQueryEvent event(Qt::ImCursorRectangle); qApp->sendEvent(textEdit, &event); @@ -4423,8 +4346,6 @@ void tst_qquicktextedit::cursorRectangleSize() // input panel cursorRectangle property and tranformed item cursor rectangle match QRectF sceneCursorRect = QQuickItemPrivate::get(textEdit)->itemToWindowTransform().mapRect(cursorRectFromItem); QCOMPARE(sceneCursorRect, qApp->inputMethod()->cursorRectangle()); - - delete window; } void tst_qquicktextedit::getText_data() @@ -5609,17 +5530,9 @@ void tst_qquicktextedit::undo() QFETCH(IntList, insertMode); QFETCH(QStringList, expectedString); - QString componentStr = "import QtQuick 2.0\nTextEdit { focus: true }"; - QQmlComponent textEditComponent(&engine); - textEditComponent.setData(componentStr.toLatin1(), QUrl()); - QQuickTextEdit *textEdit = qobject_cast(textEditComponent.create()); - QVERIFY(textEdit != nullptr); - - QQuickWindow window; - textEdit->setParentItem(window.contentItem()); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("focusByDefault.qml"))); + QQuickTextEdit *textEdit = qobject_cast(window.rootObject()); QVERIFY(textEdit->hasActiveFocus()); QVERIFY(!textEdit->canUndo()); @@ -5695,17 +5608,10 @@ void tst_qquicktextedit::redo() QFETCH(IntList, insertIndex); QFETCH(QStringList, expectedString); - QString componentStr = "import QtQuick 2.0\nTextEdit { focus: true }"; - QQmlComponent textEditComponent(&engine); - textEditComponent.setData(componentStr.toLatin1(), QUrl()); - QQuickTextEdit *textEdit = qobject_cast(textEditComponent.create()); - QVERIFY(textEdit != nullptr); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("focusByDefault.qml"))); + QQuickTextEdit *textEdit = qobject_cast(window.rootObject()); - QQuickWindow window; - textEdit->setParentItem(window.contentItem()); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); QVERIFY(textEdit->hasActiveFocus()); QVERIFY(!textEdit->canUndo()); @@ -5918,17 +5824,10 @@ void tst_qquicktextedit::undo_keypressevents() QFETCH(KeyList, keys); QFETCH(QStringList, expectedString); - QString componentStr = "import QtQuick 2.0\nTextEdit { focus: true }"; - QQmlComponent textEditComponent(&engine); - textEditComponent.setData(componentStr.toLatin1(), QUrl()); - QQuickTextEdit *textEdit = qobject_cast(textEditComponent.create()); - QVERIFY(textEdit != nullptr); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("focusByDefault.qml"))); + QQuickTextEdit *textEdit = qobject_cast(window.rootObject()); - QQuickWindow window; - textEdit->setParentItem(window.contentItem()); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); QVERIFY(textEdit->hasActiveFocus()); simulateKeys(&window, keys); @@ -5944,17 +5843,9 @@ void tst_qquicktextedit::undo_keypressevents() void tst_qquicktextedit::clear() { - QString componentStr = "import QtQuick 2.0\nTextEdit { focus: true }"; - QQmlComponent textEditComponent(&engine); - textEditComponent.setData(componentStr.toLatin1(), QUrl()); - QQuickTextEdit *textEdit = qobject_cast(textEditComponent.create()); - QVERIFY(textEdit != nullptr); - - QQuickWindow window; - textEdit->setParentItem(window.contentItem()); - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("focusByDefault.qml"))); + QQuickTextEdit *textEdit = qobject_cast(window.rootObject()); QVERIFY(textEdit->hasActiveFocus()); QSignalSpy spy(textEdit, SIGNAL(canUndoChanged())); @@ -6142,12 +6033,8 @@ void tst_qquicktextedit::remoteImagesInDocumentSource() void tst_qquicktextedit::emptytags_QTBUG_22058() { - QQuickView window(testFileUrl("qtbug-22058.qml")); - QVERIFY(window.rootObject() != nullptr); - - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("qtbug-22058.qml"))); QQuickTextEdit *input = qobject_cast(qvariant_cast(window.rootObject()->property("inputField"))); QVERIFY(input->hasActiveFocus()); @@ -6334,31 +6221,25 @@ void tst_qquicktextedit::QTBUG_51115_readOnlyResetsSelection() void tst_qquicktextedit::keys_shortcutoverride() { // Tests that QML TextEdit receives Keys.onShortcutOverride (QTBUG-68711) - QQuickView view; - view.setSource(testFileUrl("keys_shortcutoverride.qml")); - view.show(); - view.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QObject *root = view.rootObject(); - QVERIFY(root); - - QQuickTextEdit *textEdit = root->findChild(); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("keys_shortcutoverride.qml"))); + QQuickTextEdit *textEdit = window.rootObject()->findChild(); QVERIFY(textEdit); - QQuickRectangle *rectangle = root->findChild(QLatin1String("rectangle")); + QQuickRectangle *rectangle = window.rootObject()->findChild(QLatin1String("rectangle")); QVERIFY(rectangle); // Precondition: check if its not already changed - QCOMPARE(root->property("who").value(), QLatin1String("nobody")); + QCOMPARE(window.rootObject()->property("who").value(), QLatin1String("nobody")); // send Key_Escape to the Rectangle QVERIFY(rectangle->hasActiveFocus()); - QTest::keyPress(&view, Qt::Key_Escape); - QCOMPARE(root->property("who").value(), QLatin1String("Rectangle")); + QTest::keyPress(&window, Qt::Key_Escape); + QCOMPARE(window.rootObject()->property("who").value(), QLatin1String("Rectangle")); // send Key_Escape to TextEdit textEdit->setFocus(true); - QTest::keyPress(&view, Qt::Key_Escape); - QCOMPARE(root->property("who").value(), QLatin1String("TextEdit")); + QTest::keyPress(&window, Qt::Key_Escape); + QCOMPARE(window.rootObject()->property("who").value(), QLatin1String("TextEdit")); } void tst_qquicktextedit::transparentSelectionColor() @@ -6366,18 +6247,13 @@ void tst_qquicktextedit::transparentSelectionColor() if (QGuiApplication::platformName() == QLatin1String("minimal")) QSKIP("Skipping due to grabWindow not functional on minimal platforms"); - QQuickView view; - view.setSource(testFileUrl("transparentSelectionColor.qml")); - view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); - QObject *root = view.rootObject(); - QVERIFY(root); - - QQuickTextEdit *textEdit = root->findChild(); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("transparentSelectionColor.qml"))); + QQuickTextEdit *textEdit = window.rootObject()->findChild(); QVERIFY(textEdit); textEdit->selectAll(); - QImage img = view.grabWindow(); + QImage img = window.grabWindow(); QCOMPARE(img.isNull(), false); QColor color = img.pixelColor(int(textEdit->width() / 2), int(textEdit->height()) / 2); @@ -6388,11 +6264,9 @@ void tst_qquicktextedit::transparentSelectionColor() void tst_qquicktextedit::keyEventPropagation() { - QQuickView view; - view.setSource(testFileUrl("keyEventPropagation.qml")); - view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); - QObject *root = view.rootObject(); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("keyEventPropagation.qml"))); + QObject *root = window.rootObject(); QVERIFY(root); QSignalSpy downSpy(root, SIGNAL(keyDown(int))); @@ -6400,7 +6274,7 @@ void tst_qquicktextedit::keyEventPropagation() QQuickTextEdit *textEdit = root->findChild(); QVERIFY(textEdit->hasActiveFocus()); - simulateKey(&view, Qt::Key_Back); + simulateKey(&window, Qt::Key_Back); QCOMPARE(downSpy.size(), 1); QCOMPARE(upSpy.size(), 1); auto downKey = downSpy.takeFirst(); @@ -6408,7 +6282,7 @@ void tst_qquicktextedit::keyEventPropagation() QCOMPARE(downKey.at(0).toInt(), Qt::Key_Back); QCOMPARE(upKey.at(0).toInt(), Qt::Key_Back); - simulateKey(&view, Qt::Key_Shift); + simulateKey(&window, Qt::Key_Shift); QCOMPARE(downSpy.size(), 1); QCOMPARE(upSpy.size(), 1); downKey = downSpy.takeFirst(); @@ -6416,11 +6290,11 @@ void tst_qquicktextedit::keyEventPropagation() QCOMPARE(downKey.at(0).toInt(), Qt::Key_Shift); QCOMPARE(upKey.at(0).toInt(), Qt::Key_Shift); - simulateKey(&view, Qt::Key_A); + simulateKey(&window, Qt::Key_A); QCOMPARE(downSpy.size(), 0); QCOMPARE(upSpy.size(), 0); - simulateKey(&view, Qt::Key_Right); + simulateKey(&window, Qt::Key_Right); QCOMPARE(downSpy.size(), 0); QCOMPARE(upSpy.size(), 1); upKey = upSpy.takeFirst(); -- cgit v1.2.3