on xenial help sign in
Use LightDMController plugin from Albert
commitc5ae041a2711ce9986a53d187f14ce6fcd4907d6 authorMichael Terry <mike@mterry.name> dateTue 20 Dec 2016, 10:27 (10 years ago) parent9282f8d
25 files changed+110−79
plugins/LightDM/CMakeLists.txt−1 plugins/LightDM/Greeter.cpp−6 plugins/LightDM/Greeter.h−4 plugins/LightDM/SessionsModel.cpp−5 plugins/LightDM/SessionsModel.h−4 plugins/LightDM/UsersModel.cpp−7 plugins/LightDM/UsersModel.h−4 tests/mocks/CMakeLists.txt+1 tests/mocks/LightDMController/CMakeLists.txt+15 tests/mocks/LightDMController/plugin.cpp+34 tests/mocks/LightDMController/plugin.h+29 tests/mocks/LightDMController/qmldir+2 tests/mocks/liblightdm/MockGreeter.cpp−5 tests/mocks/liblightdm/MockGreeter.h−4 tests/mocks/liblightdm/MockSessionsModel.cpp−5 tests/mocks/liblightdm/MockSessionsModel.h−4 tests/mocks/liblightdm/MockUsersModel.cpp−5 tests/mocks/liblightdm/MockUsersModel.h−4 tests/plugins/LightDM/IntegratedLightDM/CMakeLists.txt+1 tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+3−1 tests/qmltests/Greeter/tst_Greeter.qml+5−4 tests/qmltests/Greeter/tst_WideView.qml+12−11 tests/qmltests/Tutorial/tst_Tutorial.qml+2−1 tests/qmltests/tst_Shell.qml+4−3 tests/qmltests/tst_ShellWithPin.qml+2−1
plugins/LightDM/CMakeLists.txt−1
@@ -7,7 +7,6 @@ include_directories(
77 ${CMAKE_CURRENT_SOURCE_DIR}
88 ${CMAKE_CURRENT_BINARY_DIR}
99 ${CMAKE_SOURCE_DIR}/plugins/Utils
10− ${CMAKE_BINARY_DIR}/tests/mocks/LightDM/IntegratedLightDM
1110 ${libunity8-private_SOURCE_DIR}
1211 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
1312)
plugins/LightDM/Greeter.cpp−6
@@ -147,9 +147,3 @@ void Greeter::authenticationCompleteFilter()
147147 Q_EMIT isAuthenticatedChanged();
148148 Q_EMIT authenticationComplete();
149149}
150−
151−QObject *Greeter::mock()
152−{
153− Q_D(Greeter);
154− return d->m_greeter->property("mock").value<QObject*>();
155−}
plugins/LightDM/Greeter.h−4
@@ -39,8 +39,6 @@ class Greeter : public QObject
3939 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
4040 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
4141
42− Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
43−
4442public:
4543 explicit Greeter(QObject* parent=0);
4644
@@ -51,8 +49,6 @@ public:
5149 bool promptless() const;
5250 QString selectUser() const;
5351
54− QObject *mock();
55−
5652public Q_SLOTS:
5753 void authenticate(const QString &username=QString());
5854 void respond(const QString &response);
plugins/LightDM/SessionsModel.cpp−5
@@ -111,11 +111,6 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
111111 }
112112}
113113
114−QObject *SessionsModel::mock()
115−{
116− return m_model->property("mock").value<QObject*>();
117−}
118−
119114SessionsModel::SessionsModel(QObject* parent)
120115 : UnitySortFilterProxyModelQML(parent)
121116{
plugins/LightDM/SessionsModel.h−4
@@ -32,8 +32,6 @@ class SessionsModel : public UnitySortFilterProxyModelQML
3232 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
3333 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
3434
35− Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
36−
3735Q_SIGNALS:
3836 void iconSearchDirectoriesChanged();
3937
@@ -58,8 +56,6 @@ public:
5856
5957 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
6058
61− QObject *mock();
62−
6359private:
6460 QLightDM::SessionsModel* m_model;
6561 QHash<int, QByteArray> m_roleNames;
plugins/LightDM/UsersModel.cpp−7
@@ -68,11 +68,4 @@ UsersModel::UsersModel(QObject* parent)
6868 sort(0);
6969}
7070
71−QObject *UsersModel::mock()
72−{
73− // get through MangleModel down to QLightDM::UsersModel
74− MangleModel *mangleModel = static_cast<MangleModel*>(sourceModel());
75− return mangleModel->sourceModel()->property("mock").value<QObject*>();
76−}
77−
7871#include "UsersModel.moc"
plugins/LightDM/UsersModel.h−4
@@ -27,10 +27,6 @@ class UsersModel : public UnitySortFilterProxyModelQML
2727{
2828 Q_OBJECT
2929
30− Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
31−
3230public:
3331 explicit UsersModel(QObject* parent=0);
34−
35− QObject *mock();
3632};
tests/mocks/CMakeLists.txt+1
@@ -35,6 +35,7 @@ add_subdirectory(GSettings.1.0)
3535add_subdirectory(indicator-service)
3636add_subdirectory(liblightdm)
3737add_subdirectory(libusermetrics)
38+add_subdirectory(LightDMController)
3839add_subdirectory(Lights)
3940add_subdirectory(MeeGo)
4041add_subdirectory(Powerd)
tests/mocks/LightDMController/CMakeLists.txtnew file+15
@@ -0,0 +1,15 @@
1+add_library(LightDMController MODULE
2+ plugin.cpp
3+ )
4+
5+target_include_directories(LightDMController PUBLIC
6+ ${CMAKE_SOURCE_DIR}/tests/mocks/liblightdm/
7+ )
8+
9+target_link_libraries(LightDMController
10+ MockLightDM
11+ )
12+
13+qt5_use_modules(LightDMController Qml)
14+
15+add_unity8_mock(LightDMController 0.1 LightDMController TARGETS LightDMController)
tests/mocks/LightDMController/plugin.cppnew file+34
@@ -0,0 +1,34 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "plugin.h"
18+
19+#include "MockController.h"
20+
21+#include <QtQml/qqml.h>
22+
23+static QObject *mock_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
24+{
25+ Q_UNUSED(engine)
26+ Q_UNUSED(scriptEngine)
27+ return QLightDM::MockController::instance();
28+}
29+
30+void LightDMControllerPlugin::registerTypes(const char *uri)
31+{
32+ Q_ASSERT(uri == QLatin1String("LightDMController"));
33+ qmlRegisterSingletonType<QLightDM::MockController>(uri, 0, 1, "LightDMController", mock_provider);
34+}
tests/mocks/LightDMController/plugin.hnew file+29
@@ -0,0 +1,29 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#pragma once
18+
19+#include <QQmlEngine>
20+#include <QQmlExtensionPlugin>
21+
22+class LightDMControllerPlugin : public QQmlExtensionPlugin
23+{
24+ Q_OBJECT
25+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26+
27+public:
28+ void registerTypes(const char *uri) override;
29+};
tests/mocks/LightDMController/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module LightDMController
2+plugin LightDMController
tests/mocks/liblightdm/MockGreeter.cpp−5
@@ -248,9 +248,4 @@ void Greeter::sendAuthenticationComplete()
248248 }
249249}
250250
251−QObject *Greeter::mock()
252−{
253− return MockController::instance();
254−}
255−
256251}
tests/mocks/liblightdm/MockGreeter.h−4
@@ -42,8 +42,6 @@ class Q_DECL_EXPORT Greeter : public QObject
4242
4343 Q_ENUMS(PromptType MessageType)
4444
45− Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
46−
4745public:
4846 enum PromptType {
4947 PromptTypeQuestion,
@@ -75,8 +73,6 @@ public:
7573 QString authenticationUser() const;
7674 QString hostname() const;
7775
78− QObject *mock();
79−
8076public Q_SLOTS:
8177 bool connectSync();
8278 void authenticate(const QString &username=QString());
tests/mocks/liblightdm/MockSessionsModel.cpp−5
@@ -114,9 +114,4 @@ void SessionsModel::resetEntries()
114114 endResetModel();
115115}
116116
117−QObject *SessionsModel::mock()
118−{
119− return MockController::instance();
120−}
121−
122117} // namespace QLightDM
tests/mocks/liblightdm/MockSessionsModel.h−4
@@ -30,8 +30,6 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
3030 {
3131 Q_OBJECT
3232
33− Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
34−
3533 Q_ENUMS(SessionModelRoles SessionType)
3634
3735 public:
@@ -56,8 +54,6 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
5654 int rowCount(const QModelIndex& parent) const override;
5755 QVariant data(const QModelIndex& index, int role) const override;
5856
59− QObject *mock();
60−
6157 private Q_SLOTS:
6258 void resetEntries();
6359
tests/mocks/liblightdm/MockUsersModel.cpp−5
@@ -183,9 +183,4 @@ void UsersModel::resetEntries()
183183 endResetModel();
184184}
185185
186−QObject *UsersModel::mock()
187−{
188− return MockController::instance();
189−}
190−
191186}
tests/mocks/liblightdm/MockUsersModel.h−4
@@ -31,8 +31,6 @@ class Q_DECL_EXPORT UsersModel : public QAbstractListModel
3131
3232 Q_ENUMS(UserModelRoles)
3333
34− Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
35−
3634public:
3735 explicit UsersModel(QObject *parent = 0);
3836 virtual ~UsersModel();
@@ -51,8 +49,6 @@ public:
5149 int rowCount(const QModelIndex &parent) const override;
5250 QVariant data(const QModelIndex &index, int role) const override;
5351
54− QObject *mock();
55−
5652private Q_SLOTS:
5753 void resetEntries();
5854
tests/plugins/LightDM/IntegratedLightDM/CMakeLists.txt+1
@@ -58,6 +58,7 @@ target_include_directories(GreeterSessionsModelTestExec PUBLIC
5858 ${CMAKE_SOURCE_DIR}/plugins/LightDM
5959 ${CMAKE_SOURCE_DIR}/plugins/Utils
6060 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
61+ ${CMAKE_SOURCE_DIR}/tests/mocks/liblightdm/
6162 )
6263add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
6364 DEPENDS MockLightDM
tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+3−1
@@ -16,6 +16,8 @@
1616
1717#include "SessionsModel.h"
1818
19+#include "MockController.h"
20+
1921#include <QLightDM/SessionsModel>
2022#include <QtCore/QModelIndex>
2123#include <QtTest>
@@ -31,7 +33,7 @@ private Q_SLOTS:
3133 {
3234 model = new SessionsModel();
3335 QVERIFY(model);
34− mock = model->mock();
36+ mock = QLightDM::MockController::instance();
3537 QVERIFY(mock);
3638 }
3739
tests/qmltests/Greeter/tst_Greeter.qml+5−4
@@ -22,6 +22,7 @@ import Ubuntu.Components 1.3
2222import AccountsService 0.1
2323import Biometryd 0.0
2424import GSettings 1.0
25+import LightDMController 0.1
2526import LightDM.FullLightDM 0.1 as LightDM
2627import Unity.Test 0.1 as UT
2728
@@ -143,7 +144,7 @@ Item {
143144
144145 function init() {
145146 greeterSettings.lockedOutTime = 0;
146− LightDM.Greeter.mock.selectUserHint = "";
147+ LightDMController.selectUserHint = "";
147148 greeter.failedLoginsDelayAttempts = 7;
148149 greeter.failedLoginsDelayMinutes = 5;
149150 teaseSpy.clear();
@@ -567,20 +568,20 @@ Item {
567568 }
568569
569570 function test_selectUserHint() {
570− LightDM.Greeter.mock.selectUserHint = "info-prompt";
571+ LightDMController.selectUserHint = "info-prompt";
571572 resetLoader();
572573 var i = verifySelected("info-prompt");
573574 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
574575 }
575576
576577 function test_selectUserHintUnset() {
577− LightDM.Greeter.mock.selectUserHint = "";
578+ LightDMController.selectUserHint = "";
578579 resetLoader();
579580 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
580581 }
581582
582583 function test_selectUserHintInvalid() {
583− LightDM.Greeter.mock.selectUserHint = "not-a-real-user";
584+ LightDMController.selectUserHint = "not-a-real-user";
584585 resetLoader();
585586 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
586587 }
tests/qmltests/Greeter/tst_WideView.qml+12−11
@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import ".."
2020import "../../../qml/Greeter"
21+import LightDMController 0.1
2122import LightDM.FullLightDM 0.1 as LightDM
2223import Ubuntu.Components 1.3
2324import Unity.Test 0.1 as UT
@@ -265,15 +266,15 @@ StyledItem {
265266 id: multipleSessionsCheckbox
266267 onClicked: {
267268 if (checked) {
268− LightDM.Sessions.mock.sessionMode = "full";
269+ LightDMController.sessionMode = "full";
269270 } else {
270− LightDM.Sessions.mock.sessionMode = "single";
271+ LightDMController.sessionMode = "single";
271272 }
272273 }
273274 Connections {
274275 target: LightDM.Sessions.mock
275276 onSessionModeChanged: {
276− if (LightDM.Sessions.mock.sessionMode === "full") {
277+ if (LightDMController.sessionMode === "full") {
277278 multipleSessionsCheckbox.checked = true;
278279 } else {
279280 multipleSessionsCheckbox.checked = false;
@@ -291,9 +292,9 @@ StyledItem {
291292
292293 width: units.gu(10)
293294 minimumValue: 0
294− maximumValue: LightDM.Sessions.mock.numAvailableSessions
295− value: LightDM.Sessions.mock.numSessions
296− visible: LightDM.Sessions.mock.sessionMode === "full"
295+ maximumValue: LightDMController.numAvailableSessions
296+ value: LightDMController.numSessions
297+ visible: LightDMController.sessionMode === "full"
297298 Binding {
298299 target: LightDM.Sessions.mock
299300 property: "numSessions"
@@ -362,7 +363,7 @@ StyledItem {
362363 respondedSpy.clear();
363364 teaseSpy.clear();
364365 emergencySpy.clear();
365− LightDM.Sessions.mock.sessionMode = "full";
366+ LightDMController.sessionMode = "full";
366367 LightDM.Sessions.iconSearchDirectories = [testIconDirectory];
367368 }
368369
@@ -467,12 +468,12 @@ StyledItem {
467468 }
468469
469470 function test_noSessionsDoesntBreakView() {
470− LightDM.Sessions.mock.sessionMode = "none";
471+ LightDMController.sessionMode = "none";
471472 compare(LightDM.Sessions.count, 0)
472473 }
473474
474475 function test_sessionIconNotShownWithOneSession() {
475− LightDM.Sessions.mock.sessionMode = "single";
476+ LightDMController.sessionMode = "single";
476477 compare(LightDM.Sessions.count, 1);
477478
478479 var sessionChooserButton = findChild(view, "sessionChooserButton");
@@ -480,7 +481,7 @@ StyledItem {
480481 }
481482
482483 function test_sessionIconNotShownWithActiveUser() {
483− LightDM.Sessions.mock.sessionMode = "full";
484+ LightDMController.sessionMode = "full";
484485 compare(LightDM.Sessions.count > 1, true);
485486
486487 selectUser("active");
@@ -490,7 +491,7 @@ StyledItem {
490491 }
491492
492493 function test_sessionIconShownWithMultipleSessions() {
493− LightDM.Sessions.mock.sessionMode = "full";
494+ LightDMController.sessionMode = "full";
494495 compare(LightDM.Sessions.count > 1, true);
495496
496497 selectUser("has-password");
tests/qmltests/Tutorial/tst_Tutorial.qml+2−1
@@ -17,6 +17,7 @@
1717import QtQuick 2.4
1818import QtTest 1.0
1919import AccountsService 0.1
20+import LightDMController 0.1
2021import LightDM.FullLightDM 0.1 as LightDM
2122import Ubuntu.Components 1.3
2223import Ubuntu.Components.ListItems 1.3
@@ -85,7 +86,7 @@ Rectangle {
8586
8687 Component.onCompleted: {
8788 // must set the mock mode before loading the Shell
88− LightDM.Users.mock.userMode = "single-pin";
89+ LightDMController.userMode = "single-pin";
8990 shellLoader.active = true;
9091 }
9192
tests/qmltests/tst_Shell.qml+4−3
@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import AccountsService 0.1
2020import GSettings 1.0
21+import LightDMController 0.1
2122import LightDM.FullLightDM 0.1 as LightDM
2223import SessionBroadcast 0.1
2324import Ubuntu.Components 1.3
@@ -46,7 +47,7 @@ Rectangle {
4647
4748 Component.onCompleted: {
4849 // must set the mock mode before loading the Shell
49− LightDM.Users.mock.userMode = "single";
50+ LightDMController.userMode = "single";
5051 shellLoader.active = true;
5152 }
5253
@@ -227,7 +228,7 @@ Rectangle {
227228 model: ["single", "single-passphrase", "single-pin", "full"]
228229 onSelectedIndexChanged: {
229230 shellLoader.active = false;
230− LightDM.Users.mock.userMode = model[selectedIndex];
231+ LightDMController.userMode = model[selectedIndex];
231232 shellLoader.active = true;
232233 }
233234 }
@@ -801,7 +802,7 @@ Rectangle {
801802 }
802803
803804 function setLightDMMockMode(mode) {
804− LightDM.Users.mock.userMode = mode;
805+ LightDMController.userMode = mode;
805806 }
806807
807808 function test_showInputMethod() {
tests/qmltests/tst_ShellWithPin.qml+2−1
@@ -19,6 +19,7 @@ import Ubuntu.Components 1.3
1919import QtTest 1.0
2020import AccountsService 0.1
2121import GSettings 1.0
22+import LightDMController 0.1
2223import LightDM.FullLightDM 0.1 as LightDM
2324import Ubuntu.SystemImage 0.1
2425import Ubuntu.Telephony 0.1 as Telephony
@@ -35,7 +36,7 @@ Item {
3536
3637 Component.onCompleted: {
3738 // must set the mock mode before loading the Shell
38− LightDM.Users.mock.userMode = "single-pin";
39+ LightDMController.userMode = "single-pin";
3940 shellLoader.active = true;
4041 }
4142