summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp')
-rw-r--r--tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp86
1 files changed, 84 insertions, 2 deletions
diff --git a/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp b/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp
index 7d2f59dc83..5ae8eaf30d 100644
--- a/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp
+++ b/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp
@@ -1,10 +1,12 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui/QtGui>
#include <QtWidgets/QColorDialog>
+#include <QtWidgets/QLineEdit>
+#include <QSignalSpy>
QT_FORWARD_DECLARE_CLASS(QtTestEventThread)
@@ -25,6 +27,10 @@ private slots:
void native_activeModalWidget();
void task247349_alpha();
void QTBUG_43548_initialColor();
+ void hexColor_data();
+ void hexColor();
+
+ void hideNativeByDestruction();
};
class TestNativeDialog : public QColorDialog
@@ -77,7 +83,7 @@ void tst_QColorDialog::native_activeModalWidget()
void tst_QColorDialog::postKeyReturn() {
QWidgetList list = QApplication::topLevelWidgets();
- for (int i=0; i<list.count(); ++i) {
+ for (int i=0; i<list.size(); ++i) {
QColorDialog *dialog = qobject_cast<QColorDialog *>(list[i]);
if (dialog) {
QTest::keyClick( list[i], Qt::Key_Return, Qt::NoModifier );
@@ -126,5 +132,81 @@ void tst_QColorDialog::QTBUG_43548_initialColor()
QCOMPARE(a, dialog.currentColor());
}
+void tst_QColorDialog::hexColor_data()
+{
+ QTest::addColumn<const QString>("colorString");
+ QTest::addColumn<const QString>("expectedHexColor");
+ QTest::addColumn<const int>("expectedSignalCount");
+
+ QTest::newRow("White-#") << "#FFFFFE" << "#FFFFFE" << 1;
+ QTest::newRow("White") << "FFFFFD" << "#FFFFFD" << 1;
+ QTest::newRow("Blue-#") << "#77fffb" << "#77fffb" << 2;
+ QTest::newRow("Blue") << "77fffa" << "#77fffa" << 2;
+}
+
+void tst_QColorDialog::hexColor()
+{
+ QColorDialog dialog;
+ dialog.setOption(QColorDialog::DontUseNativeDialog);
+ dialog.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&dialog));
+
+ QLineEdit *lineEdit = dialog.findChild<QLineEdit *>("qt_colorname_lineedit",
+ Qt::FindChildrenRecursively);
+ QVERIFY2(lineEdit, "QLineEdit for color not found. Adapt this test.");
+ QVERIFY(lineEdit); // eliminate compiler warning
+
+ QFETCH(const QString, colorString);
+ QFETCH(const QString, expectedHexColor);
+ QFETCH(const int, expectedSignalCount);
+
+ QSignalSpy spy(&dialog, &QColorDialog::currentColorChanged);
+
+ // Delete existing color
+ lineEdit->activateWindow();
+ QVERIFY(QTest::qWaitForWindowActive(lineEdit));
+ for (int i = 0; i < 8; ++i)
+ QTest::keyEvent(QTest::KeyAction::Click, lineEdit, Qt::Key_Backspace);
+ QVERIFY(lineEdit->text().isEmpty());
+
+ // Enter new color
+ for (const QChar &key : colorString)
+ QTest::keyEvent(QTest::KeyAction::Click, lineEdit, key.toLatin1());
+ QCOMPARE(lineEdit->text().toLower(), expectedHexColor.toLower());
+
+ // Consume all color change signals
+ QTRY_COMPARE(spy.count(), expectedSignalCount);
+
+ const QColor color = qvariant_cast<QColor>(spy.last().at(0));
+ QCOMPARE(color.name(QColor::HexRgb), expectedHexColor.toLower());
+}
+
+void tst_QColorDialog::hideNativeByDestruction()
+{
+ QWidget window;
+ QWidget *child = new QWidget(&window);
+ QPointer<QColorDialog> dialog = new QColorDialog(child);
+ // Make it application modal so that we don't end up with a sheet on macOS
+ dialog->setWindowModality(Qt::ApplicationModal);
+ window.show();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+ dialog->open();
+
+ // We test that the dialog opens and closes by watching the activation of the
+ // transient parent window. If it doesn't deactivate, then we have to skip.
+ const auto windowActive = [&window]{ return window.isActiveWindow(); };
+ const auto windowInactive = [&window]{ return !window.isActiveWindow(); };
+ if (!QTest::qWaitFor(windowInactive, 2000))
+ QSKIP("Dialog didn't activate");
+
+ // This should destroy the dialog and close the native window
+ child->deleteLater();
+ QTRY_VERIFY(!dialog);
+ // If the native window is still open, then the transient parent can't become
+ // active
+ window.activateWindow();
+ QVERIFY(QTest::qWaitFor(windowActive));
+}
+
QTEST_MAIN(tst_QColorDialog)
#include "tst_qcolordialog.moc"