File indexing completed on 2024-05-19 16:37:09

0001 /*
0002     SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "dialogqmltest.h"
0008 
0009 #include <plasma.h>
0010 
0011 #include <QQmlContext>
0012 #include <QQmlEngine>
0013 
0014 #include <QSignalSpy>
0015 
0016 // this test checks that we don't set visible to true until after we set the window flags
0017 void DialogQmlTest::loadAndShow()
0018 {
0019     QQmlEngine engine;
0020 
0021     QByteArray dialogQml =
0022         "import QtQuick 2.0\n"
0023         "import org.kde.plasma.core 2.0 as PlasmaCore\n"
0024         "\n"
0025         "PlasmaCore.Dialog {\n"
0026         "    id: root\n"
0027         "\n"
0028         "    location: true && PlasmaCore.Types.TopEdge\n"
0029         "    visible: true && true\n"
0030         "    type: true && PlasmaCore.Dialog.Notification\n"
0031         "\n"
0032         "    mainItem: Rectangle {\n"
0033         "        width: 200\n"
0034         "        height: 200\n"
0035         "    }\n"
0036         "}\n";
0037 
0038     // we use true && Value to force it to be a complex binding, which won't be evaluated in
0039     // component.beginCreate
0040     // the bug still appears without this, but we need to delay it in this test
0041     // so we can connect to the visibleChanged signal
0042 
0043     QQmlComponent component(&engine);
0044 
0045     QSignalSpy spy(&component, SIGNAL(statusChanged(QQmlComponent::Status)));
0046     component.setData(dialogQml, QUrl(QStringLiteral("test://dialogTest")));
0047     spy.wait();
0048 
0049     PlasmaQuick::Dialog *dialog = qobject_cast<PlasmaQuick::Dialog *>(component.beginCreate(engine.rootContext()));
0050     qDebug() << component.errorString();
0051     Q_ASSERT(dialog);
0052 
0053     m_dialogShown = false;
0054 
0055     // this will be called during component.completeCreate
0056     auto c = connect(dialog, &QWindow::visibleChanged, [=]() {
0057         m_dialogShown = true;
0058         QCOMPARE(dialog->type(), PlasmaQuick::Dialog::Notification);
0059         QCOMPARE(dialog->location(), Plasma::Types::TopEdge);
0060     });
0061 
0062     component.completeCreate();
0063     QCOMPARE(m_dialogShown, true);
0064 
0065     // disconnect on visible changed before we delete the dialog
0066     disconnect(c);
0067 
0068     delete dialog;
0069 }
0070 
0071 QTEST_MAIN(DialogQmlTest)
0072 
0073 #include "moc_dialogqmltest.cpp"