2020-08-13 21:08:54 +02:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 David Edmundson <davidedmundson@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
*/
|
2014-09-26 09:55:25 +02:00
|
|
|
|
|
|
|
#include "dialogqmltest.h"
|
|
|
|
|
|
|
|
#include <plasma.h>
|
|
|
|
|
|
|
|
#include <QQmlContext>
|
2021-03-05 19:15:32 +01:00
|
|
|
#include <QQmlEngine>
|
2014-09-26 09:55:25 +02:00
|
|
|
|
2018-11-06 07:23:52 +01:00
|
|
|
#include <QSignalSpy>
|
2014-09-26 09:55:25 +02:00
|
|
|
|
2021-03-05 19:15:32 +01:00
|
|
|
// this test checks that we don't set visible to true until after we set the window flags
|
2014-09-26 09:55:25 +02:00
|
|
|
void DialogQmlTest::loadAndShow()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
|
|
|
|
QByteArray dialogQml =
|
2021-03-05 19:15:32 +01:00
|
|
|
"import QtQuick 2.0\n"
|
|
|
|
"import org.kde.plasma.core 2.0 as PlasmaCore\n"
|
|
|
|
"\n"
|
|
|
|
"PlasmaCore.Dialog {\n"
|
|
|
|
" id: root\n"
|
|
|
|
"\n"
|
|
|
|
" location: true && PlasmaCore.Types.TopEdge\n"
|
|
|
|
" visible: true && true\n"
|
|
|
|
" type: true && PlasmaCore.Dialog.Notification\n"
|
|
|
|
"\n"
|
|
|
|
" mainItem: Rectangle {\n"
|
|
|
|
" width: 200\n"
|
|
|
|
" height: 200\n"
|
|
|
|
" }\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
// we use true && Value to force it to be a complex binding, which won't be evaluated in
|
|
|
|
// component.beginCreate
|
|
|
|
// the bug still appears without this, but we need to delay it in this test
|
|
|
|
// so we can connect to the visibleChanged signal
|
2014-09-26 09:55:25 +02:00
|
|
|
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
|
|
|
|
QSignalSpy spy(&component, SIGNAL(statusChanged(QQmlComponent::Status)));
|
2016-02-29 00:08:05 +01:00
|
|
|
component.setData(dialogQml, QUrl(QStringLiteral("test://dialogTest")));
|
2014-09-26 09:55:25 +02:00
|
|
|
spy.wait();
|
|
|
|
|
2021-03-05 19:15:32 +01:00
|
|
|
PlasmaQuick::Dialog *dialog = qobject_cast<PlasmaQuick::Dialog *>(component.beginCreate(engine.rootContext()));
|
2014-09-26 09:55:25 +02:00
|
|
|
qDebug() << component.errorString();
|
|
|
|
Q_ASSERT(dialog);
|
|
|
|
|
|
|
|
m_dialogShown = false;
|
|
|
|
|
2021-03-05 19:15:32 +01:00
|
|
|
// this will be called during component.completeCreate
|
2014-09-26 09:55:25 +02:00
|
|
|
auto c = connect(dialog, &QWindow::visibleChanged, [=]() {
|
|
|
|
m_dialogShown = true;
|
|
|
|
QCOMPARE(dialog->type(), PlasmaQuick::Dialog::Notification);
|
|
|
|
QCOMPARE(dialog->location(), Plasma::Types::TopEdge);
|
|
|
|
});
|
|
|
|
|
|
|
|
component.completeCreate();
|
|
|
|
QCOMPARE(m_dialogShown, true);
|
|
|
|
|
2021-03-05 19:15:32 +01:00
|
|
|
// disconnect on visible changed before we delete the dialog
|
2014-09-26 09:55:25 +02:00
|
|
|
disconnect(c);
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(DialogQmlTest)
|