diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 5c7f1db9f..ca25e5712 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -37,6 +37,7 @@ MACRO(PLASMA_UNIT_TESTS) ENDMACRO(PLASMA_UNIT_TESTS) PLASMA_UNIT_TESTS( + dialogqmltest fallbackpackagetest packagestructuretest packageurlinterceptortest @@ -48,7 +49,7 @@ PLASMA_UNIT_TESTS( add_executable(storagetest storagetest.cpp ../src/plasma/private/storage.cpp ../src/plasma/private/storagethread.cpp) target_link_libraries(storagetest Qt5::Gui Qt5::Test Qt5::Sql KF5::KIOCore KF5::Plasma KF5::CoreAddons) -set(dialogtest_srcs dialogtest.cpp) +set(dialogtest_srcs dialognativetest.cpp) ecm_add_test(${dialogtest_srcs} TEST_NAME dialogtest LINK_LIBRARIES Qt5::Gui Qt5::Test Qt5::Qml Qt5::Quick KF5::WindowSystem KF5::Plasma KF5::PlasmaQuick) set(coronatest_srcs coronatest.cpp) diff --git a/autotests/dialogtest.cpp b/autotests/dialognativetest.cpp similarity index 93% rename from autotests/dialogtest.cpp rename to autotests/dialognativetest.cpp index 7c03d0794..d808df41d 100644 --- a/autotests/dialogtest.cpp +++ b/autotests/dialognativetest.cpp @@ -17,11 +17,11 @@ * Boston, MA 02110-1301, USA. * *********************************************************************************/ -#include "dialogtest.h" +#include "dialognativetest.h" #include -void DialogTest::initTestCase() +void DialogNativeTest::initTestCase() { m_dialog = new PlasmaQuick::Dialog; @@ -45,14 +45,14 @@ void DialogTest::initTestCase() m_dialog->show(); } -void DialogTest::cleanupTestCase() +void DialogNativeTest::cleanupTestCase() { delete m_dialog; delete m_panel; delete m_panel2; } -void DialogTest::position() +void DialogNativeTest::position() { QTest::qWaitForWindowExposed(m_dialog); @@ -64,4 +64,4 @@ void DialogTest::position() QCOMPARE(m_dialog->y(), 49); } -QTEST_MAIN(DialogTest) +QTEST_MAIN(DialogNativeTest) diff --git a/autotests/dialogtest.h b/autotests/dialognativetest.h similarity index 97% rename from autotests/dialogtest.h rename to autotests/dialognativetest.h index dafa8f4f3..f0f48e810 100644 --- a/autotests/dialogtest.h +++ b/autotests/dialognativetest.h @@ -27,7 +27,7 @@ -class DialogTest : public QObject +class DialogNativeTest : public QObject { Q_OBJECT diff --git a/autotests/dialogqmltest.cpp b/autotests/dialogqmltest.cpp new file mode 100644 index 000000000..618e64dde --- /dev/null +++ b/autotests/dialogqmltest.cpp @@ -0,0 +1,90 @@ +/******************************************************************************** +* Copyright 2014 David Edmundson * +* * +* This library is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Library General Public * +* License as published by the Free Software Foundation; either * +* version 2 of the License, or (at your option) any later version. * +* * +* This library is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * +* Library General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public License * +* along with this library; see the file COPYING.LIB. If not, write to * +* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * +* Boston, MA 02110-1301, USA. * +*********************************************************************************/ + +#include "dialogqmltest.h" + +#include "plasmaquick/dialog.h" +#include + +#include +#include + +#include +#include + + +//this test checks that we don't set visible to true until after we set the window flags +void DialogQmlTest::loadAndShow() +{ + QQmlEngine engine; + + QByteArray dialogQml = +"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 + + + QQmlComponent component(&engine); + + QSignalSpy spy(&component, SIGNAL(statusChanged(QQmlComponent::Status))); + component.setData(dialogQml, QUrl("test://dialogTest")); + spy.wait(); + + PlasmaQuick::Dialog *dialog = qobject_cast< PlasmaQuick::Dialog* >(component.beginCreate(engine.rootContext())); + qDebug() << component.errorString(); + Q_ASSERT(dialog); + + m_dialogShown = false; + + //this will be called during component.completeCreate + 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); + + //disconnect on visible changed before we delete the dialog + disconnect(c); + + delete dialog; +} + + + +QTEST_MAIN(DialogQmlTest) diff --git a/autotests/dialogqmltest.h b/autotests/dialogqmltest.h new file mode 100644 index 000000000..4e750f920 --- /dev/null +++ b/autotests/dialogqmltest.h @@ -0,0 +1,40 @@ +/****************************************************************************** +* Copyright 2014 Marco Martin * +* * +* This library is free software; you can redistribute it and/or * +* modify it under the terms of the GNU Library General Public * +* License as published by the Free Software Foundation; either * +* version 2 of the License, or (at your option) any later version. * +* * +* This library is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * +* Library General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public License * +* along with this library; see the file COPYING.LIB. If not, write to * +* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * +* Boston, MA 02110-1301, USA. * +*******************************************************************************/ +#ifndef DIALOLOADGTEST_H +#define DIALOLOADGTEST_H + +#include + +#include "plasmaquick/dialog.h" + + + +class DialogQmlTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void loadAndShow(); +private: + bool m_dialogShown; + +}; + +#endif +