on xenial help sign in
Simplify lightdm plugin layout and use in-session lightdm support
1c33768Michael Terry
CMakeLists.txt+1
@@ -61,6 +61,7 @@ pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=21)
61pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
61pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
62pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
62pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
63pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
63pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
64+pkg_check_modules(LIBLIGHTDM REQUIRED liblightdm-qt5-3)
64pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
65pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
65pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
66pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
66
67
cmake/modules/QmlTest.cmake+3−3
@@ -65,11 +65,11 @@ endfunction()
65# This function wraps add_executable_test, see below for available arguments.
65# This function wraps add_executable_test, see below for available arguments.
66
66
67function(add_qml_unittest PATH COMPONENT_NAME)
67function(add_qml_unittest PATH COMPONENT_NAME)
68− import_executables(qmltestrunner)
68+ import_executables(dbus-run-session)
69
69
70− add_executable_test(${COMPONENT_NAME} qmltestrunner
70+ add_executable_test(${COMPONENT_NAME} dbus-run-session
71 ${ARGN}
71 ${ARGN}
72− ARGS -input ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
72+ ARGS -- qmltestrunner -input ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
73 )
73 )
74endfunction()
74endfunction()
75
75
debian/rules−5
@@ -36,8 +36,3 @@ override_dh_installdeb:
36# use private lib directories
36# use private lib directories
37override_dh_makeshlibs:
37override_dh_makeshlibs:
38 dh_makeshlibs -Nunity8-private -Nunity8-fake-env
38 dh_makeshlibs -Nunity8-private -Nunity8-fake-env
39−
40−override_dh_shlibdeps:
41− # Some mock libraries link against liblightdm-qt5-3.so which we want to
42− # avoid, since we only really link against our mock one, not the system one.
43− dh_shlibdeps -XlibMockLightDM-qml.so -XlibMockAccountsService-qml.so
plugins/AccountsService/AccountsService.cpp+27−1
@@ -80,6 +80,7 @@ QVariant primaryButtonConverter(const QVariant &value)
80AccountsService::AccountsService(QObject* parent, const QString &user)
80AccountsService::AccountsService(QObject* parent, const QString &user)
81 : QObject(parent)
81 : QObject(parent)
82 , m_service(new AccountsServiceDBusAdaptor(this))
82 , m_service(new AccountsServiceDBusAdaptor(this))
83+ , m_greeterMode(true)
83{
84{
84 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
85 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
85 QStringLiteral("/com/canonical/Unity/Input"),
86 QStringLiteral("/com/canonical/Unity/Input"),
@@ -155,6 +156,19 @@ void AccountsService::setUser(const QString &user)
155 refresh(!wasEmpty);
156 refresh(!wasEmpty);
156}
157}
157
158
159+bool AccountsService::greeterMode() const
160+{
161+ return m_greeterMode;
162+}
163+
164+void AccountsService::setGreeterMode(bool greeterMode)
165+{
166+ if (m_greeterMode != greeterMode) {
167+ m_greeterMode = greeterMode;
168+ Q_EMIT greeterModeChanged();
169+ }
170+}
171+
158bool AccountsService::demoEdges() const
172bool AccountsService::demoEdges() const
159{
173{
160 auto value = getProperty(IFACE_UNITY, PROP_DEMO_EDGES);
174 auto value = getProperty(IFACE_UNITY, PROP_DEMO_EDGES);
@@ -341,7 +355,19 @@ void AccountsService::setProperty(const QString &interface, const QString &prope
341{
355{
342 if (m_properties[interface][property].value != value) {
356 if (m_properties[interface][property].value != value) {
343 m_properties[interface][property].value = value;
357 m_properties[interface][property].value = value;
358+ if (m_greeterMode || m_user == g_get_user_name()) {
359+ // Only write any changes back to AccountsService if we are running
360+ // as a proper LightDM greeter (or are writing values for our own
361+ // user).
362+ // (A) Only the lightdm user has permission to set everyone's
363+ // properties.
364+ // (B) We don't want to have policykit throw up a password dialog
365+ // when we are running in the user session.
366+ // (C) We only write things to AS that are safe to ignore for other
367+ // users anyway (like failedLogins count, which does not NEED
368+ // to be persistent).
344− m_service->setUserPropertyAsync(m_user, interface, property, value);
369+ m_service->setUserPropertyAsync(m_user, interface, property, value);
370+ }
345 emitChangedForProperty(interface, property);
371 emitChangedForProperty(interface, property);
346 }
372 }
347}
373}
plugins/AccountsService/AccountsService.h+8
@@ -34,6 +34,10 @@ class AccountsService: public QObject
34 READ user
34 READ user
35 WRITE setUser
35 WRITE setUser
36 NOTIFY userChanged)
36 NOTIFY userChanged)
37+ Q_PROPERTY (bool greeterMode
38+ READ greeterMode
39+ WRITE setGreeterMode
40+ NOTIFY greeterModeChanged)
37 Q_PROPERTY (bool demoEdges
41 Q_PROPERTY (bool demoEdges
38 READ demoEdges
42 READ demoEdges
39 WRITE setDemoEdges
43 WRITE setDemoEdges
@@ -92,6 +96,8 @@ public:
92
96
93 QString user() const;
97 QString user() const;
94 void setUser(const QString &user);
98 void setUser(const QString &user);
99+ bool greeterMode() const;
100+ void setGreeterMode(bool greeterMode);
95 bool demoEdges() const;
101 bool demoEdges() const;
96 void setDemoEdges(bool demoEdges);
102 void setDemoEdges(bool demoEdges);
97 QStringList demoEdgesCompleted() const;
103 QStringList demoEdgesCompleted() const;
@@ -119,6 +125,7 @@ public:
119
125
120Q_SIGNALS:
126Q_SIGNALS:
121 void userChanged();
127 void userChanged();
128+ void greeterModeChanged();
122 void demoEdgesChanged();
129 void demoEdgesChanged();
123 void demoEdgesCompletedChanged();
130 void demoEdgesCompletedChanged();
124 void enableFingerprintIdentificationChanged();
131 void enableFingerprintIdentificationChanged();
@@ -167,6 +174,7 @@ private:
167 AccountsServiceDBusAdaptor *m_service;
174 AccountsServiceDBusAdaptor *m_service;
168 QDBusInterface *m_unityInput;
175 QDBusInterface *m_unityInput;
169 QString m_user;
176 QString m_user;
177+ bool m_greeterMode;
170};
178};
171
179
172#endif
180#endif
plugins/LightDM/CMakeLists.txt+16−9
@@ -1,19 +1,20 @@
1pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
1pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
2
2
3−find_package(Qt5Core REQUIRED)
4−find_package(Qt5Quick REQUIRED)
5−
6include_directories(
3include_directories(
7 ${CMAKE_CURRENT_SOURCE_DIR}
4 ${CMAKE_CURRENT_SOURCE_DIR}
8 ${CMAKE_CURRENT_BINARY_DIR}
5 ${CMAKE_CURRENT_BINARY_DIR}
9 ${CMAKE_SOURCE_DIR}/plugins/Utils
6 ${CMAKE_SOURCE_DIR}/plugins/Utils
10− ${CMAKE_BINARY_DIR}/tests/mocks/LightDM/IntegratedLightDM
11 ${libunity8-private_SOURCE_DIR}
7 ${libunity8-private_SOURCE_DIR}
8+ )
9+
10+include_directories(
11+ SYSTEM
12+ ${LIBLIGHTDM_INCLUDE_DIRS}
12 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
13 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
13−)
14+ )
14
15
15−set(QMLPLUGIN_SRC
16+add_library(LightDM-qml MODULE
16− ../Utils/unitysortfilterproxymodelqml.cpp
17+ ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
17 DBusGreeter.cpp
18 DBusGreeter.cpp
18 DBusGreeterList.cpp
19 DBusGreeterList.cpp
19 Greeter.cpp
20 Greeter.cpp
@@ -22,5 +23,11 @@ set(QMLPLUGIN_SRC
22 UsersModel.cpp
23 UsersModel.cpp
23 )
24 )
24
25
25−add_subdirectory(FullLightDM)
26+target_link_libraries(LightDM-qml
26−add_subdirectory(IntegratedLightDM)
27+ unity8-private
28+ ${LIBLIGHTDM_LDFLAGS}
29+ ${LIBUSERMETRICSOUTPUT_LDFLAGS}
30+ )
31+
32+qt5_use_modules(LightDM-qml DBus Gui Qml)
33+add_unity8_plugin(LightDM 0.1 LightDM TARGETS LightDM-qml)
plugins/LightDM/FullLightDM/CMakeLists.txtdeleted−28
@@ -1,28 +0,0 @@
1−pkg_check_modules(LIBLIGHTDM REQUIRED liblightdm-qt5-3)
2−
3−set(PLUGIN_CLASSNAME "FullLightDM")
4−
5−add_definitions(-DFULL_LIGHTDM)
6−
7−include_directories(
8− ../
9− ${LIBLIGHTDM_INCLUDE_DIRS}
10− ${CMAKE_CURRENT_BINARY_DIR}
11− )
12−
13−foreach(source_file ${QMLPLUGIN_SRC})
14− list(APPEND RELATIVE_QMLPLUGIN_SRC ../${source_file})
15−endforeach()
16−
17−add_library(FullLightDM-qml MODULE
18− ${RELATIVE_QMLPLUGIN_SRC}
19− )
20−
21−target_link_libraries(FullLightDM-qml
22− unity8-private
23− ${LIBLIGHTDM_LDFLAGS}
24− ${LIBUSERMETRICSOUTPUT_LDFLAGS}
25− )
26−
27−qt5_use_modules(FullLightDM-qml DBus Gui Qml)
28−add_unity8_plugin(FullLightDM 0.1 LightDM/FullLightDM TARGETS FullLightDM-qml)
plugins/LightDM/FullLightDM/qmldirdeleted−3
@@ -1,3 +0,0 @@
1−module LightDM.FullLightDM
2−plugin FullLightDM-qml
3−typeinfo FullLightDM.qmltypes
plugins/LightDM/Greeter.cpp+6
@@ -147,3 +147,9 @@ void Greeter::authenticationCompleteFilter()
147 Q_EMIT isAuthenticatedChanged();
147 Q_EMIT isAuthenticatedChanged();
148 Q_EMIT authenticationComplete();
148 Q_EMIT authenticationComplete();
149}
149}
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
@@ -40,6 +40,8 @@ class Greeter : public QObject
40 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
40 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
41 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
41 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
42
42
43+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
44+
43public:
45public:
44 explicit Greeter(QObject* parent=0);
46 explicit Greeter(QObject* parent=0);
45
47
@@ -50,6 +52,8 @@ public:
50 bool promptless() const;
52 bool promptless() const;
51 QString selectUser() const;
53 QString selectUser() const;
52
54
55+ QObject *mock();
56+
53public Q_SLOTS:
57public Q_SLOTS:
54 void authenticate(const QString &username=QString());
58 void authenticate(const QString &username=QString());
55 void respond(const QString &response);
59 void respond(const QString &response);
plugins/LightDM/IntegratedLightDM/CMakeLists.txtdeleted−33
@@ -1,33 +0,0 @@
1−set(PLUGIN_CLASSNAME "IntegratedLightDM")
2−
3−add_definitions(-DINTEGRATED_LIGHTDM)
4−
5−foreach(include_directory ${QMLPLUGIN_INCLUDES})
6− list(APPEND RELATIVE_QMLPLUGIN_INCLUDES ../${include_directory})
7−endforeach()
8−
9−include_directories(
10− . #QLightDM
11− ${QMLPLUGIN_INCLUDES}
12− ${libunity8-private_SOURCE_DIR}
13− ${CMAKE_CURRENT_BINARY_DIR}
14−)
15−
16−foreach(source_file ${QMLPLUGIN_SRC})
17− list(APPEND RELATIVE_QMLPLUGIN_SRC ../${source_file})
18−endforeach()
19−
20−add_library(IntegratedLightDM-qml MODULE
21− ${RELATIVE_QMLPLUGIN_SRC}
22− )
23−
24−target_link_libraries(IntegratedLightDM-qml
25− integratedLightDM
26− unity8-private
27− ${LIBUSERMETRICSOUTPUT_LDFLAGS}
28− )
29−
30−qt5_use_modules(IntegratedLightDM-qml DBus Gui Qml)
31−add_unity8_plugin(IntegratedLightDM 0.1 LightDM/IntegratedLightDM TARGETS IntegratedLightDM-qml)
32−
33−add_subdirectory(liblightdm)
plugins/LightDM/IntegratedLightDM/QLightDM/Greeterdeleted−17
@@ -1,17 +0,0 @@
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 "../liblightdm/Greeter.h"
plugins/LightDM/IntegratedLightDM/QLightDM/SessionsModeldeleted−17
@@ -1,17 +0,0 @@
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 "../liblightdm/SessionsModel.h"
plugins/LightDM/IntegratedLightDM/QLightDM/UsersModeldeleted−17
@@ -1,17 +0,0 @@
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 "../liblightdm/UsersModel.h"
plugins/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txtdeleted−55
@@ -1,55 +0,0 @@
1−pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
2−
3−set(LibLightDM_SOURCES
4− Greeter.cpp
5− SessionsModel.cpp
6− UsersModel.cpp
7− GreeterPrivate.cpp
8− SessionsModelPrivate.cpp
9− UsersModelPrivate.cpp
10− ${CMAKE_SOURCE_DIR}/plugins/AccountsService/AccountsServiceDBusAdaptor.cpp
11− ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
12− )
13−
14−add_library(integratedLightDM STATIC ${LibLightDM_SOURCES})
15−add_library(integratedLightDMSession STATIC ${LibLightDM_SOURCES})
16−add_library(MockLightDM-demo-shared SHARED ${LibLightDM_SOURCES})
17−
18−include_directories(
19− ${CMAKE_SOURCE_DIR}/plugins/AccountsService
20− ${CMAKE_CURRENT_BINARY_DIR}
21− ${GLIB_INCLUDE_DIRS}
22− ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
23−)
24−
25−target_link_libraries(integratedLightDM
26− ${GLIB_LIBRARIES}
27− ${LIBUSERMETRICSOUTPUT_LDFLAGS}
28− -lpam
29−)
30−target_link_libraries(integratedLightDMSession
31− ${GLIB_LIBRARIES}
32− ${LIBUSERMETRICSOUTPUT_LDFLAGS}
33− -lpam
34−)
35−target_link_libraries(MockLightDM-demo-shared
36− ${GLIB_LIBRARIES}
37− ${LIBUSERMETRICSOUTPUT_LDFLAGS}
38− -lpam
39−)
40−
41−qt5_use_modules(integratedLightDM Concurrent DBus Gui)
42−qt5_use_modules(integratedLightDMSession Concurrent DBus Gui)
43−qt5_use_modules(MockLightDM-demo-shared Concurrent DBus Gui)
44−
45−set_target_properties(integratedLightDM PROPERTIES
46− COMPILE_FLAGS "-DSM_BUSNAME=systemBus -fPIC")
47−set_target_properties(integratedLightDMSession PROPERTIES
48− COMPILE_FLAGS "-DSM_BUSNAME=sessionBus -fPIC")
49−set_target_properties(MockLightDM-demo-shared PROPERTIES
50− COMPILE_FLAGS "-DSM_BUSNAME=systemBus"
51− OUTPUT_NAME lightdm-qt5-3)
52−
53−install(TARGETS MockLightDM-demo-shared
54− DESTINATION ${SHELL_INSTALL_QML}/mocks/LightDM/IntegratedLightDM/demo
55− )
plugins/LightDM/IntegratedLightDM/liblightdm/Greeter.cppdeleted−179
@@ -1,179 +0,0 @@
1−/*
2− * Copyright (C) 2013 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− * Author: Michael Terry <michael.terry@canonical.com>
17− */
18−
19−
20−/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21− * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
22− * COUNTERPART IN tests/mocks/Lightdm/liblightdm
23− * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
24−
25−
26−#include "Greeter.h"
27−#include "GreeterPrivate.h"
28−#include <QtCore/QCoreApplication>
29−#include <QTimer>
30−
31−namespace QLightDM
32−{
33−
34−Greeter::Greeter(QObject *parent)
35− : QObject(parent),
36− d_ptr(new GreeterPrivate(this))
37−{
38−}
39−
40−Greeter::~Greeter()
41−{
42−}
43−
44−QString Greeter::authenticationUser() const
45−{
46− Q_D(const Greeter);
47− return d->authenticationUser;
48−}
49−
50−bool Greeter::hasGuestAccountHint() const
51−{
52− return true;
53−}
54−
55−QString Greeter::getHint(const QString &name) const
56−{
57− Q_UNUSED(name)
58− return QLatin1String("");
59−}
60−
61−QString Greeter::defaultSessionHint() const
62−{
63− return QStringLiteral("ubuntu");
64−}
65−
66−bool Greeter::hideUsersHint() const
67−{
68− return false;
69−}
70−
71−bool Greeter::showManualLoginHint() const
72−{
73− return true;
74−}
75−
76−bool Greeter::showRemoteLoginHint() const
77−{
78− return true;
79−}
80−
81−QString Greeter::selectUserHint() const
82−{
83− return QLatin1String("");
84−}
85−
86−bool Greeter::selectGuestHint() const
87−{
88− return false;
89−}
90−
91−QString Greeter::autologinUserHint() const
92−{
93− return QLatin1String("");
94−}
95−
96−bool Greeter::autologinGuestHint() const
97−{
98− return false;
99−}
100−
101−int Greeter::autologinTimeoutHint() const
102−{
103− return 0;
104−}
105−
106−bool Greeter::inAuthentication() const
107−{
108− return false;
109−}
110−
111−QString Greeter::hostname() const
112−{
113− return QStringLiteral("hostname1");
114−}
115−
116−bool Greeter::isAuthenticated() const
117−{
118− Q_D(const Greeter);
119− return d->authenticated;
120−}
121−
122−bool Greeter::connectSync()
123−{
124− return true;
125−}
126−
127−void Greeter::authenticate(const QString &username)
128−{
129− Q_D(Greeter);
130−
131− d->authenticated = false;
132− d->authenticationUser = username;
133− d->handleAuthenticate();
134−}
135−
136−void Greeter::authenticateAsGuest()
137−{}
138−
139−void Greeter::authenticateAutologin()
140−{}
141−
142−void Greeter::authenticateRemote(const QString &session, const QString &username)
143−{
144− Q_UNUSED(session)
145− Q_UNUSED(username)
146−}
147−
148−void Greeter::cancelAuthentication()
149−{}
150−
151−void Greeter::setLanguage (const QString &language)
152−{
153− Q_UNUSED(language)
154−}
155−
156−bool Greeter::startSessionSync(const QString &session)
157−{
158− Q_UNUSED(session)
159− return true;
160−}
161−
162−void Greeter::respond(const QString &response)
163−{
164− Q_D(Greeter);
165−
166− d->handleRespond(response);
167−}
168−
169−void Greeter::sendAuthenticationComplete()
170−{
171− if (qEnvironmentVariableIsEmpty("UNITY_TESTING")) {
172− // simulate PAM's delay
173− QTimer::singleShot(1000, this, &Greeter::authenticationComplete);
174− } else {
175− Q_EMIT authenticationComplete();
176− }
177−}
178−
179−}
plugins/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.cppdeleted−304
@@ -1,304 +0,0 @@
1−/*
2− * Copyright (C) 2013 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− * Author: Michael Terry <michael.terry@canonical.com>
17− */
18−
19−#include "Greeter.h"
20−#include "GreeterPrivate.h"
21−#include <QFuture>
22−#include <QFutureInterface>
23−#include <QFutureWatcher>
24−#include <QQueue>
25−#include <QtConcurrent>
26−#include <QVector>
27−#include <security/pam_appl.h>
28−
29−namespace QLightDM
30−{
31−
32−class GreeterImpl : public QObject
33−{
34− Q_OBJECT
35−
36− struct AppData
37− {
38− GreeterImpl *impl;
39− pam_handle *handle;
40− };
41−
42− typedef QFutureInterface<QString> ResponseFuture;
43−
44−public:
45− explicit GreeterImpl(Greeter *parent, GreeterPrivate *greeterPrivate)
46− : QObject(parent),
47− greeter(parent),
48− greeterPrivate(greeterPrivate),
49− pamHandle(nullptr)
50− {
51− qRegisterMetaType<QLightDM::GreeterImpl::ResponseFuture>("QLightDM::GreeterImpl::ResponseFuture");
52−
53− connect(&futureWatcher, &QFutureWatcher<int>::finished, this, &GreeterImpl::finishPam);
54− connect(this, SIGNAL(showMessage(pam_handle *, QString, QLightDM::Greeter::MessageType)),
55− this, SLOT(handleMessage(pam_handle *, QString, QLightDM::Greeter::MessageType)));
56− // This next connect is how we pass ResponseFutures between threads
57− connect(this, SIGNAL(showPrompt(pam_handle *, QString, QLightDM::Greeter::PromptType, QLightDM::GreeterImpl::ResponseFuture)),
58− this, SLOT(handlePrompt(pam_handle *, QString, QLightDM::Greeter::PromptType, QLightDM::GreeterImpl::ResponseFuture)),
59− Qt::BlockingQueuedConnection);
60− }
61−
62− ~GreeterImpl()
63− {
64− cancelPam();
65− }
66−
67− void start(QString username)
68− {
69− // Clear out any existing PAM interactions first
70− cancelPam();
71− if (pamHandle != nullptr) {
72− // While we were cancelling pam above, we processed Qt events.
73− // Which may have allowed someone to call start() on us again.
74− // In which case, we'll bail on our current start() call.
75− // This isn't racy because it's all in the same thread.
76− return;
77− }
78−
79− AppData *appData = new AppData();
80− appData->impl = this;
81−
82− // Now actually start a new conversation with PAM
83− pam_conv conversation;
84− conversation.conv = converseWithPam;
85− conversation.appdata_ptr = static_cast<void*>(appData);
86−
87− if (pam_start("lightdm", username.toUtf8(), &conversation, &pamHandle) == PAM_SUCCESS) {
88− appData->handle = pamHandle;
89− futureWatcher.setFuture(QtConcurrent::mapped(QList<pam_handle*>() << pamHandle, authenticateWithPam));
90− } else {
91− delete appData;
92− greeterPrivate->authenticated = false;
93− Q_EMIT greeter->showMessage(QStringLiteral("Internal error: could not start PAM authentication"), QLightDM::Greeter::MessageTypeError);
94− Q_EMIT greeter->authenticationComplete();
95− }
96− }
97−
98− static int authenticateWithPam(pam_handle* const& pamHandle)
99− {
100− int pamStatus = pam_authenticate(pamHandle, 0);
101− if (pamStatus == PAM_SUCCESS) {
102− pamStatus = pam_acct_mgmt(pamHandle, 0);
103− }
104− if (pamStatus == PAM_NEW_AUTHTOK_REQD) {
105− pamStatus = pam_chauthtok(pamHandle, PAM_CHANGE_EXPIRED_AUTHTOK);
106− }
107− if (pamStatus == PAM_SUCCESS) {
108− pam_setcred(pamHandle, PAM_REINITIALIZE_CRED);
109− }
110− return pamStatus;
111− }
112−
113− static int converseWithPam(int num_msg, const pam_message** msg,
114− pam_response** resp, void* appdata_ptr)
115− {
116− if (num_msg <= 0)
117− return PAM_CONV_ERR;
118−
119− auto* tmp_response = static_cast<pam_response*>(calloc(num_msg, sizeof(pam_response)));
120− if (!tmp_response)
121− return PAM_CONV_ERR;
122−
123− AppData *appData = static_cast<AppData*>(appdata_ptr);
124− GreeterImpl *impl = appData->impl;
125− pam_handle *handle = appData->handle;
126−
127− int count;
128− QVector<ResponseFuture> responses;
129−
130− for (count = 0; count < num_msg; ++count)
131− {
132− switch (msg[count]->msg_style)
133− {
134− case PAM_PROMPT_ECHO_ON:
135− {
136− QString message(msg[count]->msg);
137− responses.append(ResponseFuture());
138− responses.last().reportStarted();
139− Q_EMIT impl->showPrompt(handle, message, Greeter::PromptTypeQuestion, responses.last());
140− break;
141− }
142− case PAM_PROMPT_ECHO_OFF:
143− {
144− QString message(msg[count]->msg);
145− responses.append(ResponseFuture());
146− responses.last().reportStarted();
147− Q_EMIT impl->showPrompt(handle, message, Greeter::PromptTypeSecret, responses.last());
148− break;
149− }
150− case PAM_TEXT_INFO:
151− {
152− QString message(msg[count]->msg);
153− Q_EMIT impl->showMessage(handle, message, Greeter::MessageTypeInfo);
154− break;
155− }
156− default:
157− {
158− QString message(msg[count]->msg);
159− Q_EMIT impl->showMessage(handle, message, Greeter::MessageTypeError);
160− break;
161− }
162− }
163− }
164−
165− int i = 0;
166− bool raise_error = false;
167−
168− for (auto &response : responses)
169− {
170− pam_response* resp_item = &tmp_response[i++];
171− resp_item->resp_retcode = 0;
172− resp_item->resp = strdup(response.future().result().toUtf8());
173−
174− if (!resp_item->resp)
175− {
176− raise_error = true;
177− break;
178− }
179− }
180−
181− delete appData;
182−
183− if (raise_error)
184− {
185− for (int i = 0; i < count; ++i)
186− free(tmp_response[i].resp);
187−
188− free(tmp_response);
189− return PAM_CONV_ERR;
190− }
191− else
192− {
193− *resp = tmp_response;
194− return PAM_SUCCESS;
195− }
196− }
197−
198−public Q_SLOTS:
199− bool respond(QString response)
200− {
201− if (!futures.isEmpty()) {
202− futures.dequeue().reportFinished(&response);
203− return true;
204− } else {
205− return false;
206− }
207− }
208−
209−Q_SIGNALS:
210− void showMessage(pam_handle *handle, QString text, QLightDM::Greeter::MessageType type);
211− void showPrompt(pam_handle *handle, QString text, QLightDM::Greeter::PromptType type, QLightDM::GreeterImpl::ResponseFuture response);
212−
213−private Q_SLOTS:
214− void finishPam()
215− {
216− if (pamHandle == nullptr) {
217− return;
218− }
219−
220− int pamStatus = futureWatcher.result();
221−
222− pam_end(pamHandle, pamStatus);
223− pamHandle = nullptr;
224−
225− greeterPrivate->authenticated = (pamStatus == PAM_SUCCESS);
226− Q_EMIT greeter->authenticationComplete();
227− }
228−
229− void handleMessage(pam_handle *handle, QString text, QLightDM::Greeter::MessageType type)
230− {
231− if (handle != pamHandle)
232− return;
233−
234− Q_EMIT greeter->showMessage(text, type);
235− }
236−
237− void handlePrompt(pam_handle *handle, QString text, QLightDM::Greeter::PromptType type, QLightDM::GreeterImpl::ResponseFuture future)
238− {
239− if (handle != pamHandle) {
240− future.reportResult(QString());
241− future.reportFinished();
242− return;
243− }
244−
245− futures.enqueue(future);
246− Q_EMIT greeter->showPrompt(text, type);
247− }
248−
249−private:
250− void cancelPam()
251− {
252− if (pamHandle != nullptr) {
253− QFuture<int> pamFuture = futureWatcher.future();
254− pam_handle *handle = pamHandle;
255− pamHandle = nullptr; // to disable normal finishPam() handling
256− pamFuture.cancel();
257−
258− // Note the empty loop, we just want to clear the futures queue.
259− // Any further prompts from the pam thread will be immediately
260− // responded to/dismissed in handlePrompt().
261− while (respond(QString()));
262−
263− // Now let signal/slot handling happen so the thread can finish
264− while (!pamFuture.isFinished()) {
265− QCoreApplication::processEvents();
266− }
267−
268− pam_end(handle, PAM_CONV_ERR);
269− }
270− }
271−
272− Greeter *greeter;
273− GreeterPrivate *greeterPrivate;
274− pam_handle* pamHandle;
275− QFutureWatcher<int> futureWatcher;
276− QQueue<ResponseFuture> futures;
277−};
278−
279−GreeterPrivate::GreeterPrivate(Greeter* parent)
280− : authenticated(false),
281− authenticationUser(),
282− m_impl(new GreeterImpl(parent, this)),
283− q_ptr(parent)
284−{
285−}
286−
287−GreeterPrivate::~GreeterPrivate()
288−{
289− delete m_impl;
290−}
291−
292−void GreeterPrivate::handleAuthenticate()
293−{
294− m_impl->start(authenticationUser);
295−}
296−
297−void GreeterPrivate::handleRespond(const QString &response)
298−{
299− m_impl->respond(response);
300−}
301−
302−}
303−
304−#include "GreeterPrivate.moc"
plugins/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.hdeleted−51
@@ -1,51 +0,0 @@
1−/*
2− * Copyright (C) 2013 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− * Author: Michael Terry <michael.terry@canonical.com>
17− */
18−
19−#ifndef UNITY_MOCK_GREETER_PRIVATE_H
20−#define UNITY_MOCK_GREETER_PRIVATE_H
21−
22−#include <QtCore/QObject>
23−
24−namespace QLightDM
25−{
26−class Greeter;
27−class GreeterImpl;
28−
29−class GreeterPrivate
30−{
31−public:
32− explicit GreeterPrivate(Greeter* parent=0);
33− virtual ~GreeterPrivate();
34−
35− // These variables may not be used by all subclasses, that's no problem
36− bool authenticated;
37− QString authenticationUser;
38−
39− void handleAuthenticate();
40− void handleRespond(const QString &response);
41−
42−protected:
43− GreeterImpl *m_impl; // if the backend needs more private data
44− Greeter * const q_ptr;
45−
46−private:
47− Q_DECLARE_PUBLIC(Greeter)
48−};
49−}
50−
51−#endif // UNITY_MOCK_GREETER_PRIVATE_H
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cppdeleted−88
@@ -1,88 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−
18−
19−/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20− * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
21− * COUNTERPART IN tests/mocks/LightDM/IntegratedLightDM/liblightdm
22− * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
23−
24−// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
25−// To use the same method of setting role name that it does, we
26−// set our compatibility to Qt4 here too.
27−#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
28−
29−#include "SessionsModel.h"
30−#include "SessionsModelPrivate.h"
31−#include <QtCore/QDir>
32−#include <QtCore/QString>
33−
34−namespace QLightDM
35−{
36−
37−SessionsModel::SessionsModel(QObject* parent) :
38− QAbstractListModel(parent),
39− d_ptr(new SessionsModelPrivate(this))
40−{
41− Q_D(SessionsModel);
42− m_roleNames = QAbstractListModel::roleNames();
43− m_roleNames[KeyRole] = "key";
44− m_roleNames[TypeRole] = "type";
45−}
46−
47−SessionsModel::~SessionsModel()
48−{
49− delete d_ptr;
50−}
51−
52−QVariant SessionsModel::data(const QModelIndex& index, int role) const
53−{
54− Q_D(const SessionsModel);
55−
56− if(!index.isValid()) {
57− return QVariant();
58− }
59−
60− int row = index.row();
61−
62− switch (role) {
63− case QLightDM::SessionsModel::KeyRole:
64− return d->sessionItems[row].key;
65− case Qt::DisplayRole:
66− return d->sessionItems[row].name;
67− default:
68− return QVariant();
69− }
70−}
71−
72−QHash<int, QByteArray> SessionsModel::roleNames() const
73−{
74− return m_roleNames;
75−}
76−
77−int SessionsModel::rowCount(const QModelIndex& parent) const
78−{
79− Q_D(const SessionsModel);
80−
81− if (parent.isValid()) {
82− return 0;
83− } else { // parent is root
84− return d->sessionItems.size();
85− }
86−}
87−
88−} // namespace QLightDM
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.hdeleted−72
@@ -1,72 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−
18−#ifndef UNITY_INTEGRATED_SESSIONSMODEL_H
19−#define UNITY_INTEGRATED_SESSIONSMODEL_H
20−
21−#include <QtCore/QAbstractListModel>
22−#include <QtCore/QString>
23−
24−/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25− * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
26− * COUNTERPART IN tests/mocks/LightDM/IntegratedLightDM/liblightdm
27− * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
28−
29−// This is taken from liblightdm and modified to confirm to our syle conventions
30−namespace QLightDM
31−{
32−class SessionsModelPrivate;
33−
34−class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
35− {
36− Q_OBJECT
37−
38− Q_ENUMS(SessionModelRoles SessionType)
39−
40− public:
41−
42− enum SessionModelRoles {
43− //name is exposed as Qt::DisplayRole
44− //comment is exposed as Qt::TooltipRole
45− KeyRole = Qt::UserRole,
46− IdRole = KeyRole, /** Deprecated */
47− TypeRole
48− };
49−
50− enum SessionType {
51− LocalSessions,
52− RemoteSessions
53− };
54−
55− explicit SessionsModel(QObject* parent=0); /** Deprecated. Loads local sessions*/
56− explicit SessionsModel(SessionsModel::SessionType, QObject* parent=0);
57− virtual ~SessionsModel();
58−
59− QHash<int, QByteArray> roleNames() const override;
60− int rowCount(const QModelIndex& parent) const override;
61− QVariant data(const QModelIndex& index, int role) const override;
62−
63− protected:
64− SessionsModelPrivate* const d_ptr;
65−
66− private:
67− QHash<int, QByteArray> m_roleNames;
68− Q_DECLARE_PRIVATE(SessionsModel)
69− };
70−}
71−
72−#endif // UNITY_INTEGRATED_SESSIONSMODEL_H
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cppdeleted−36
@@ -1,36 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−
18−#include "SessionsModelPrivate.h"
19−
20−#include <QDir>
21−#include <QSettings>
22−#include <QStringList>
23−
24−namespace QLightDM
25−{
26−
27−SessionsModelPrivate::SessionsModelPrivate(SessionsModel* parent)
28− : q_ptr(parent)
29−{
30− // Since this model is never visible, as there is only 1 session,
31− // just use the session name as the key
32− QString sessionName = qgetenv("XDG_SESSION_DESKTOP");
33− sessionItems.append({sessionName, "", sessionName, ""});
34−}
35−
36−} // namespace QLightDM
plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.hdeleted−54
@@ -1,54 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−
18−#ifndef UNITY_INTEGRATED_SESSIONSMODEL_PRIVATE_H
19−#define UNITY_INTEGRATED_SESSIONSMODEL_PRIVATE_H
20−
21−#include <QtCore/QList>
22−#include <QtCore/QString>
23−
24−namespace QLightDM
25−{
26−class SessionsModel;
27−
28−class SessionItem
29−{
30−public:
31− QString key;
32− QString type; // unused
33− QString name;
34− QString comment; // unused
35−};
36−
37−class SessionsModelPrivate
38−{
39−public:
40− explicit SessionsModelPrivate(SessionsModel* parent=0);
41− virtual ~SessionsModelPrivate() = default;
42−
43− QList<SessionItem> sessionItems;
44−
45−protected:
46− SessionsModel* const q_ptr;
47−
48−private:
49− Q_DECLARE_PUBLIC(SessionsModel)
50−};
51−
52−} // namespace QLightDM
53−
54−#endif // UNITY_INTEGRATED_SESSIONSMODEL_PRIVATE_H
plugins/LightDM/IntegratedLightDM/liblightdm/UsersModel.cppdeleted−110
@@ -1,110 +0,0 @@
1−/*
2− * Copyright (C) 2013-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− * Author: Michael Terry <michael.terry@canonical.com>
17− */
18−
19−
20−/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21− * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
22− * COUNTERPART IN tests/mocks/Lightdm/liblightdm
23− * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
24−
25−// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
26−// To use the same method of setting role name that it does, we
27−// set our compatibility to Qt4 here too.
28−#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
29−
30−#include "UsersModel.h"
31−#include "UsersModelPrivate.h"
32−#include <QtCore/QDir>
33−#include <QtCore/QString>
34−#include <QtGui/QIcon>
35−
36−namespace QLightDM
37−{
38−
39−UsersModel::UsersModel(QObject *parent) :
40− QAbstractListModel(parent),
41− d_ptr(new UsersModelPrivate(this))
42−{
43− // Extend roleNames (we want to keep the "display" role)
44− QHash<int, QByteArray> roles = roleNames();
45− roles[NameRole] = "name";
46− roles[RealNameRole] = "realName";
47− roles[LoggedInRole] = "loggedIn";
48− roles[BackgroundRole] = "background";
49− roles[BackgroundPathRole] = "backgroundPath";
50− roles[SessionRole] = "session";
51− roles[HasMessagesRole] = "hasMessages";
52− roles[ImagePathRole] = "imagePath";
53− roles[UidRole] = "uid";
54− setRoleNames(roles);
55−
56− connect(d_ptr, &UsersModelPrivate::dataChanged, this, [this](int i) {
57− QModelIndex index = createIndex(i, 0);
58− Q_EMIT dataChanged(index, index);
59− });
60−}
61−
62−int UsersModel::rowCount(const QModelIndex &parent) const
63−{
64− Q_D(const UsersModel);
65−
66− if (parent.isValid()) {
67− return 0;
68− } else { // parent is root
69− return d->entries.size();
70− }
71−}
72−
73−QVariant UsersModel::data(const QModelIndex &index, int role) const
74−{
75− Q_D(const UsersModel);
76−
77− if (!index.isValid()) {
78− return QVariant();
79− }
80−
81− int row = index.row();
82− switch (role) {
83− case Qt::DisplayRole:
84− return d->entries[row].real_name;
85− case Qt::DecorationRole:
86− return QIcon();
87− case UsersModel::NameRole:
88− return d->entries[row].username;
89− case UsersModel::RealNameRole:
90− return d->entries[row].real_name;
91− case UsersModel::SessionRole:
92− return d->entries[row].session;
93− case UsersModel::LoggedInRole:
94− return d->entries[row].is_active;
95− case UsersModel::BackgroundRole:
96− return QPixmap(d->entries[row].background);
97− case UsersModel::BackgroundPathRole:
98− return d->entries[row].background;
99− case UsersModel::HasMessagesRole:
100− return d->entries[row].has_messages;
101− case UsersModel::ImagePathRole:
102− return "";
103− case UsersModel::UidRole:
104− return d->entries[row].uid;
105− default:
106− return QVariant();
107− }
108−}
109−
110−}
plugins/LightDM/IntegratedLightDM/liblightdm/UsersModel.hdeleted−67
@@ -1,67 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− * Copyright (C) 2010-2011 David Edmundson.
4− *
5− * This program is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published by
7− * the Free Software Foundation; version 3.
8− *
9− * This program is distributed in the hope that it will be useful,
10− * but WITHOUT ANY WARRANTY; without even the implied warranty of
11− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12− * GNU General Public License for more details.
13− *
14− * You should have received a copy of the GNU General Public License
15− * along with this program. If not, see <http://www.gnu.org/licenses/>.
16− *
17− * Author: David Edmundson <kde@davidedmundson.co.uk>
18− */
19−
20−#ifndef UNITY_MOCK_USERSMODEL_H
21−#define UNITY_MOCK_USERSMODEL_H
22−
23−#include <QtCore/QString>
24−#include <QtCore/QSharedDataPointer>
25−#include <QAbstractListModel>
26−
27−/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28− * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
29− * COUNTERPART IN tests/mocks/Lightdm/liblightdm
30− * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
31−
32−namespace QLightDM
33−{
34−class UsersModelPrivate;
35−
36−class Q_DECL_EXPORT UsersModel : public QAbstractListModel
37−{
38− Q_OBJECT
39−
40− Q_ENUMS(UserModelRoles)
41−
42−public:
43− explicit UsersModel(QObject *parent = 0);
44− virtual ~UsersModel() = default;
45−
46− enum UserModelRoles {NameRole = Qt::UserRole,
47− RealNameRole,
48− LoggedInRole,
49− BackgroundRole,
50− SessionRole,
51− HasMessagesRole,
52− ImagePathRole,
53− BackgroundPathRole,
54− UidRole
55− };
56−
57− int rowCount(const QModelIndex &parent) const override;
58− QVariant data(const QModelIndex &index, int role) const override;
59−
60−private:
61− UsersModelPrivate * const d_ptr;
62− Q_DECLARE_PRIVATE(UsersModel)
63−};
64−
65−}
66−
67−#endif // UNITY_MOCK_USERSMODEL_H
plugins/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.cppdeleted−94
@@ -1,94 +0,0 @@
1−/*
2− * Copyright (C) 2013-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− * Author: Michael Terry <michael.terry@canonical.com>
17− */
18−
19−#include "UsersModelPrivate.h"
20−
21−#include "AccountsServiceDBusAdaptor.h"
22−#include "UsersModel.h"
23−
24−#include <glib.h>
25−#include <QDebug>
26−#include <QDir>
27−#include <QSettings>
28−#include <QStringList>
29−#include <unistd.h>
30−
31−namespace QLightDM
32−{
33−
34−UsersModelPrivate::UsersModelPrivate(UsersModel* parent)
35− : QObject(parent),
36− q_ptr(parent),
37− m_service(new AccountsServiceDBusAdaptor(this))
38−{
39− QFileInfo demoFile(QDir::homePath() + "/.unity8-greeter-demo");
40− QString currentUser = g_get_user_name();
41− uid_t currentUid = getuid();
42−
43− if (demoFile.exists()) {
44− QSettings settings(demoFile.filePath(), QSettings::NativeFormat);
45− QStringList users = settings.value(QStringLiteral("users"), QStringList() << currentUser).toStringList();
46−
47− entries.reserve(users.count());
48− Q_FOREACH(const QString &user, users)
49− {
50− QString name = settings.value(user + "/name", user).toString();
51− entries.append({user, name, 0, 0, false, false, 0, 0, currentUid++});
52− }
53− } else {
54− entries.append({currentUser, 0, 0, 0, false, false, 0, 0, currentUid});
55−
56− connect(m_service, &AccountsServiceDBusAdaptor::maybeChanged,
57− this, [this](const QString &user) {
58− if (user == entries[0].username) {
59− updateName(true);
60− }
61− });
62− updateName(false);
63− }
64−}
65−
66−void UsersModelPrivate::updateName(bool async)
67−{
68− auto pendingReply = m_service->getUserPropertyAsync(entries[0].username,
69− QStringLiteral("org.freedesktop.Accounts.User"),
70− QStringLiteral("RealName"));
71− auto *watcher = new QDBusPendingCallWatcher(pendingReply, this);
72−
73− connect(watcher, &QDBusPendingCallWatcher::finished,
74− this, [this](QDBusPendingCallWatcher* watcher) {
75−
76− QDBusPendingReply<QVariant> reply = *watcher;
77− watcher->deleteLater();
78− if (reply.isError()) {
79− qWarning() << "Failed to get 'RealName' property - " << reply.error().message();
80− return;
81− }
82−
83− const QString realName = reply.value().toString();
84− if (entries[0].real_name != realName) {
85− entries[0].real_name = realName;
86− Q_EMIT dataChanged(0);
87− }
88− });
89− if (!async) {
90− watcher->waitForFinished();
91− }
92−}
93−
94−}
plugins/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.hdeleted−72
@@ -1,72 +0,0 @@
1−/*
2− * Copyright (C) 2013-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− * Author: Michael Terry <michael.terry@canonical.com>
17− */
18−
19−#ifndef UNITY_MOCK_USERSMODEL_PRIVATE_H
20−#define UNITY_MOCK_USERSMODEL_PRIVATE_H
21−
22−#include <QList>
23−#include <QObject>
24−#include <QString>
25−
26−class AccountsServiceDBusAdaptor;
27−
28−namespace QLightDM
29−{
30−class UsersModel;
31−
32−class Entry
33−{
34−public:
35− QString username;
36− QString real_name;
37− QString background;
38− QString layouts;
39− bool is_active;
40− bool has_messages;
41− QString session;
42− QString infographic;
43− uid_t uid;
44−};
45−
46−class UsersModelPrivate : public QObject
47−{
48− Q_OBJECT
49−
50−public:
51− explicit UsersModelPrivate(UsersModel *parent = 0);
52− virtual ~UsersModelPrivate() = default;
53−
54− QList<Entry> entries;
55−
56−Q_SIGNALS:
57− void dataChanged(int);
58−
59−protected:
60− UsersModel * const q_ptr;
61−
62−private:
63− Q_DECLARE_PUBLIC(UsersModel)
64−
65− void updateName(bool async);
66−
67− AccountsServiceDBusAdaptor *m_service;
68−};
69−
70−}
71−
72−#endif // UNITY_MOCK_USERSMODEL_PRIVATE_H
plugins/LightDM/IntegratedLightDM/qmldirdeleted−3
@@ -1,3 +0,0 @@
1−module LightDM.IntegratedLightDM
2−plugin IntegratedLightDM-qml
3−typeinfo IntegratedLightDM.qmltypes
plugins/LightDM/SessionsModel.cpp+6−2
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -111,6 +111,11 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
111 }
111 }
112}
112}
113
113
114+QObject *SessionsModel::mock()
115+{
116+ return m_model->property("mock").value<QObject*>();
117+}
118+
114SessionsModel::SessionsModel(QObject* parent)
119SessionsModel::SessionsModel(QObject* parent)
115 : UnitySortFilterProxyModelQML(parent)
120 : UnitySortFilterProxyModelQML(parent)
116{
121{
@@ -120,7 +125,6 @@ SessionsModel::SessionsModel(QObject* parent)
120 m_roleNames[IconRole] = "icon_url";
125 m_roleNames[IconRole] = "icon_url";
121
126
122 setModel(m_model);
127 setModel(m_model);
123− setSourceModel(m_model);
124 setSortCaseSensitivity(Qt::CaseInsensitive);
128 setSortCaseSensitivity(Qt::CaseInsensitive);
125 setSortLocaleAware(true);
129 setSortLocaleAware(true);
126 setSortRole(Qt::DisplayRole);
130 setSortRole(Qt::DisplayRole);
plugins/LightDM/SessionsModel.h+6
@@ -32,6 +32,9 @@ class SessionsModel : public UnitySortFilterProxyModelQML
32
32
33 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
33 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
34 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
34 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
35+
36+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
37+
35Q_SIGNALS:
38Q_SIGNALS:
36 void iconSearchDirectoriesChanged();
39 void iconSearchDirectoriesChanged();
37
40
@@ -55,6 +58,9 @@ public:
55 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
58 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
56
59
57 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
60 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
61+
62+ QObject *mock();
63+
58private:
64private:
59 QLightDM::SessionsModel* m_model;
65 QLightDM::SessionsModel* m_model;
60 QHash<int, QByteArray> m_roleNames;
66 QHash<int, QByteArray> m_roleNames;
plugins/LightDM/UsersModel.cpp+7
@@ -68,4 +68,11 @@ UsersModel::UsersModel(QObject* parent)
68 sort(0);
68 sort(0);
69}
69}
70
70
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+
71#include "UsersModel.moc"
78#include "UsersModel.moc"
plugins/LightDM/UsersModel.h+4
@@ -30,8 +30,12 @@ class UsersModel : public UnitySortFilterProxyModelQML
30{
30{
31 Q_OBJECT
31 Q_OBJECT
32
32
33+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
34+
33public:
35public:
34 explicit UsersModel(QObject* parent=0);
36 explicit UsersModel(QObject* parent=0);
37+
38+ QObject *mock();
35};
39};
36
40
37#endif
41#endif
plugins/LightDM/plugin.cpp+2−9
@@ -63,20 +63,13 @@ static QObject *infographic_provider(QQmlEngine *engine, QJSEngine *scriptEngine
63 return UserMetricsOutput::UserMetrics::getInstance();
63 return UserMetricsOutput::UserMetrics::getInstance();
64}
64}
65
65
66−void PLUGIN_CLASSNAME::registerTypes(const char *uri)
66+void LightDM::registerTypes(const char *uri)
67{
67{
68 qmlRegisterType<QAbstractItemModel>();
68 qmlRegisterType<QAbstractItemModel>();
69 qmlRegisterType<UserMetricsOutput::ColorTheme>();
69 qmlRegisterType<UserMetricsOutput::ColorTheme>();
70
70
71−#if defined INTEGRATED_LIGHTDM
72− Q_ASSERT(uri == QLatin1String("LightDM.IntegratedLightDM"));
73− qmlRegisterSingletonType<Greeter>(uri, 0, 1, "Greeter", greeter_provider);
74−#elif defined FULL_LIGHTDM
75− Q_ASSERT(uri == QLatin1String("LightDM.FullLightDM"));
71+ Q_ASSERT(uri == QLatin1String("LightDM"));
76 qmlRegisterSingletonType<QLightDM::Greeter>(uri, 0, 1, "Greeter", greeter_provider);
72 qmlRegisterSingletonType<QLightDM::Greeter>(uri, 0, 1, "Greeter", greeter_provider);
77−#else
78− #error No library defined in LightDM plugin
79−#endif
80
73
81 qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
74 qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
82 qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
75 qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
plugins/LightDM/plugin.h+1−1
@@ -21,7 +21,7 @@
21#include <QtQml/QQmlEngine>
21#include <QtQml/QQmlEngine>
22#include <QtQml/QQmlExtensionPlugin>
22#include <QtQml/QQmlExtensionPlugin>
23
23
24−class PLUGIN_CLASSNAME : public QQmlExtensionPlugin
24+class LightDM : public QQmlExtensionPlugin
25{
25{
26 Q_OBJECT
26 Q_OBJECT
27 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
27 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
plugins/LightDM/qmldir+2−3
@@ -1,3 +1,2 @@
1−module IntegratedLightDM
1+module LightDM
2−plugin IntegratedLightDM-qml
2+plugin LightDM-qml
3−typeinfo IntegratedLightDM.qmltypes
plugins/Unity/Session/dbusunitysessionservice.cpp+3−45
@@ -337,58 +337,16 @@ void DBusUnitySessionService::PromptLock()
337 // user session.
337 // user session.
338 Q_EMIT LockRequested();
338 Q_EMIT LockRequested();
339 Q_EMIT lockRequested();
339 Q_EMIT lockRequested();
340+ Q_EMIT Locked();
340}
341}
341
342
342void DBusUnitySessionService::Lock()
343void DBusUnitySessionService::Lock()
343{
344{
344 // Normal lock (with animation, as compared to PromptLock above). Usually
345 // Normal lock (with animation, as compared to PromptLock above). Usually
345 // used by indicator-session to lock the session in place.
346 // used by indicator-session to lock the session in place.
346− //
347+ // Though here we don't really worry about the difference and just call
347− // FIXME: We also -- as a bit of a hack around indicator-session not fully
348+ // PromptLock.
348− // supporting a phone profile -- switch to greeter here. The unity7 flow is
349− // that the user chooses "Lock/Switch" from the indicator, and then can go
350− // to greeter by selecting "Switch" again from the indicator, which is now
351− // exposed by the desktop_lockscreen profile. But since in unity8, we try
352− // to expose most things all the time, we don't use the separate lockscreen
353− // profile. Instead, we just go directly to the greeter the first time
354− // a user presses "Lock/Switch". This isn't what this DBus call is
355− // supposed to do, but we can live with it for now.
356− //
357− // Here's a bug about indicator-session growing a converged Touch profile:
358− // https://launchpad.net/bugs/1557716
359− //
360− // We only do this here in the animated-lock call because that's the only
361− // time the indicator locks without also asking the display manager to
362− // switch sessions on us. And since we are switching screens, we also
363− // don't bother respecting the animate request, simply doing a PromptLock.
364 PromptLock();
349 PromptLock();
365− switchToGreeter();
366−}
367−
368−void DBusUnitySessionService::switchToGreeter()
369−{
370− // lock the session using the org.freedesktop.DisplayManager system DBUS service
371− const QString sessionPath = QString::fromLocal8Bit(qgetenv("XDG_SESSION_PATH"));
372− QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DisplayManager"),
373− sessionPath,
374− QStringLiteral("org.freedesktop.DisplayManager.Session"),
375− QStringLiteral("Lock"));
376−
377− QDBusPendingCall pendingCall = QDBusConnection::SM_BUSNAME().asyncCall(msg);
378− QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall, this);
379− connect(watcher, &QDBusPendingCallWatcher::finished,
380− this, [this](QDBusPendingCallWatcher* watcher) {
381−
382− QDBusPendingReply<void> reply = *watcher;
383− watcher->deleteLater();
384− if (reply.isError()) {
385− qWarning() << "Lock call failed" << reply.error().message();
386− return;
387− }
388−
389− // emit Locked when the call succeeds
390− Q_EMIT Locked();
391− });
392}
350}
393
351
394void DBusUnitySessionService::doUnlock()
352void DBusUnitySessionService::doUnlock()
plugins/Unity/Session/dbusunitysessionservice.h−3
@@ -262,9 +262,6 @@ public Q_SLOTS:
262
262
263private Q_SLOTS:
263private Q_SLOTS:
264 void doUnlock();
264 void doUnlock();
265−
266−private:
267− void switchToGreeter();
268};
265};
269
266
270class DBusGnomeSessionManagerWrapper : public UnityDBusObject
267class DBusGnomeSessionManagerWrapper : public UnityDBusObject
qml/Components/Dialogs.qml+4−4
@@ -19,10 +19,10 @@ import QtQuick.Window 2.2
19import Unity.Application 0.1
19import Unity.Application 0.1
20import Unity.Session 0.1
20import Unity.Session 0.1
21import GlobalShortcut 1.0
21import GlobalShortcut 1.0
22+import LightDM 0.1 as LightDM
22import Ubuntu.Components 1.3
23import Ubuntu.Components 1.3
23import Unity.Platform 1.0
24import Unity.Platform 1.0
24import Utils 0.1
25import Utils 0.1
25−import "../Greeter"
26
26
27Item {
27Item {
28 id: root
28 id: root
@@ -112,12 +112,12 @@ Item {
112
112
113 GlobalShortcut { // lock screen
113 GlobalShortcut { // lock screen
114 shortcut: Qt.Key_ScreenSaver
114 shortcut: Qt.Key_ScreenSaver
115− onTriggered: LightDMService.greeter.showGreeter()
115+ onTriggered: LightDM.Greeter.showGreeter()
116 }
116 }
117
117
118 GlobalShortcut { // lock screen
118 GlobalShortcut { // lock screen
119 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
119 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
120− onTriggered: LightDMService.greeter.showGreeter()
120+ onTriggered: LightDM.Greeter.showGreeter()
121 }
121 }
122
122
123 QtObject {
123 QtObject {
@@ -151,7 +151,7 @@ Item {
151 Button {
151 Button {
152 text: i18n.ctr("Button: Lock the system", "Lock")
152 text: i18n.ctr("Button: Lock the system", "Lock")
153 onClicked: {
153 onClicked: {
154− LightDMService.greeter.showGreeter()
154+ LightDM.Greeter.showGreeter()
155 logoutDialog.hide();
155 logoutDialog.hide();
156 }
156 }
157 }
157 }
qml/Greeter/FullLightDMImpl.qmldeleted−30
@@ -1,30 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−import QtQuick 2.4
18−import LightDM.FullLightDM 0.1 as LightDM
19−
20−Item{
21− id: implementation
22−
23− property var greeter: LightDM.Greeter
24− property var infographic: LightDM.Infographic
25− property var sessions: LightDM.Sessions
26− property var sessionRoles: LightDM.SessionRoles
27− property var users: LightDM.Users
28− property var userRoles: LightDM.UserRoles
29−
30−}
qml/Greeter/Greeter.qml+37−33
@@ -18,13 +18,13 @@ import QtQuick 2.4
18import AccountsService 0.1
18import AccountsService 0.1
19import Biometryd 0.0
19import Biometryd 0.0
20import GSettings 1.0
20import GSettings 1.0
21+import LightDM 0.1 as LightDM
21import Powerd 0.1
22import Powerd 0.1
22import Ubuntu.Components 1.3
23import Ubuntu.Components 1.3
23import Ubuntu.SystemImage 0.1
24import Ubuntu.SystemImage 0.1
24import Unity.Launcher 0.1
25import Unity.Launcher 0.1
25import Unity.Session 0.1
26import Unity.Session 0.1
26
27
27−import "." 0.1
28import "../Components"
28import "../Components"
29
29
30Showable {
30Showable {
@@ -51,7 +51,7 @@ Showable {
51 readonly property bool hasLockedApp: lockedApp !== ""
51 readonly property bool hasLockedApp: lockedApp !== ""
52
52
53 property bool forcedUnlock
53 property bool forcedUnlock
54− readonly property bool locked: LightDMService.greeter.active && !LightDMService.greeter.authenticated && !forcedUnlock
54+ readonly property bool locked: LightDM.Greeter.active && !LightDM.Greeter.authenticated && !forcedUnlock
55
55
56 property bool tabletMode
56 property bool tabletMode
57 property url viewSource // only used for testing
57 property url viewSource // only used for testing
@@ -137,16 +137,15 @@ Showable {
137 }
137 }
138
138
139 function sessionToStart() {
139 function sessionToStart() {
140− for (var i = 0; i < LightDMService.sessions.count; i++) {
140+ for (var i = 0; i < LightDM.Sessions.count; i++) {
141− var session = LightDMService.sessions.data(i,
141+ var session = LightDM.Sessions.data(i, LightDM.SessionRoles.KeyRole);
142− LightDMService.sessionRoles.KeyRole);
143 if (loader.item.sessionToStart === session) {
142 if (loader.item.sessionToStart === session) {
144 return session;
143 return session;
145 }
144 }
146 }
145 }
147
146
148− if (loader.item.sessionToStart === LightDMService.greeter.defaultSession) {
147+ if (loader.item.sessionToStart === LightDM.Greeter.defaultSession) {
149− return LightDMService.greeter.defaultSession;
148+ return LightDM.Greeter.defaultSession;
150 } else {
149 } else {
151 return "ubuntu"; // The default / fallback
150 return "ubuntu"; // The default / fallback
152 }
151 }
@@ -155,8 +154,8 @@ Showable {
155 QtObject {
154 QtObject {
156 id: d
155 id: d
157
156
158− readonly property bool multiUser: LightDMService.users.count > 1
157+ readonly property bool multiUser: LightDM.Users.count > 1
159− readonly property int selectUserIndex: d.getUserIndex(LightDMService.greeter.selectUser)
158+ readonly property int selectUserIndex: d.getUserIndex(LightDM.Greeter.selectUser)
160 property int currentIndex: Math.max(selectUserIndex, 0)
159 property int currentIndex: Math.max(selectUserIndex, 0)
161 property bool waiting
160 property bool waiting
162 property bool isLockscreen // true when we are locking an active session, rather than first user login
161 property bool isLockscreen // true when we are locking an active session, rather than first user login
@@ -184,8 +183,8 @@ Showable {
184 return -1;
183 return -1;
185
184
186 // Find index for requested user, if it exists
185 // Find index for requested user, if it exists
187− for (var i = 0; i < LightDMService.users.count; i++) {
186+ for (var i = 0; i < LightDM.Users.count; i++) {
188− if (username === LightDMService.users.data(i, LightDMService.userRoles.NameRole)) {
187+ if (username === LightDM.Users.data(i, LightDM.UserRoles.NameRole)) {
189 return i;
188 return i;
190 }
189 }
191 }
190 }
@@ -194,17 +193,17 @@ Showable {
194 }
193 }
195
194
196 function selectUser(index, reset) {
195 function selectUser(index, reset) {
197− if (index < 0 || index >= LightDMService.users.count)
196+ if (index < 0 || index >= LightDM.Users.count)
198 return;
197 return;
199 d.waiting = true;
198 d.waiting = true;
200 if (reset) {
199 if (reset) {
201 loader.item.reset(false /* forceShow */);
200 loader.item.reset(false /* forceShow */);
202 }
201 }
203 currentIndex = index;
202 currentIndex = index;
204− var user = LightDMService.users.data(index, LightDMService.userRoles.NameRole);
203+ var user = LightDM.Users.data(index, LightDM.UserRoles.NameRole);
205 AccountsService.user = user;
204 AccountsService.user = user;
206 LauncherModel.setUser(user);
205 LauncherModel.setUser(user);
207− LightDMService.greeter.authenticate(user); // always resets auth state
206+ LightDM.Greeter.authenticate(user); // always resets auth state
208 }
207 }
209
208
210 function hideView() {
209 function hideView() {
@@ -212,18 +211,22 @@ Showable {
212 loader.item.enabled = false; // drop OSK and prevent interaction
211 loader.item.enabled = false; // drop OSK and prevent interaction
213 loader.item.notifyAuthenticationSucceeded(false /* showFakePassword */);
212 loader.item.notifyAuthenticationSucceeded(false /* showFakePassword */);
214 loader.item.hide();
213 loader.item.hide();
214+ sessionStarted();
215 }
215 }
216 }
216 }
217
217
218 function login() {
218 function login() {
219 d.waiting = true;
219 d.waiting = true;
220− if (LightDMService.greeter.startSessionSync(root.sessionToStart())) {
220+ var success = LightDM.Greeter.startSessionSync(root.sessionToStart());
221− sessionStarted();
221+ d.waiting = false;
222− hideView();
222+
223− } else if (loader.item) {
223+ // If successful as a lockscreen, we don't need to hide ourselves.
224+ // logind will tell us to unlock if our current user logged in.
225+
226+ if (!success) {
224 loader.item.notifyAuthenticationFailed();
227 loader.item.notifyAuthenticationFailed();
228+ d.selectUser(d.currentIndex, false);
225 }
229 }
226− d.waiting = false;
227 }
230 }
228
231
229 function startUnlock(toTheRight) {
232 function startUnlock(toTheRight) {
@@ -236,6 +239,7 @@ Showable {
236
239
237 function checkForcedUnlock(hideNow) {
240 function checkForcedUnlock(hideNow) {
238 if (forcedUnlock && shown) {
241 if (forcedUnlock && shown) {
242+ d.waiting = false;
239 hideView();
243 hideView();
240 if (hideNow) {
244 if (hideNow) {
241 root.hideNow(); // skip hide animation
245 root.hideNow(); // skip hide animation
@@ -382,7 +386,7 @@ Showable {
382 root.lockedApp = "";
386 root.lockedApp = "";
383 item.forceActiveFocus();
387 item.forceActiveFocus();
384 d.selectUser(d.currentIndex, true);
388 d.selectUser(d.currentIndex, true);
385− LightDMService.infographic.readyForDataChange();
389+ LightDM.Infographic.readyForDataChange();
386 }
390 }
387
391
388 Connections {
392 Connections {
@@ -392,7 +396,7 @@ Showable {
392 }
396 }
393 onResponded: {
397 onResponded: {
394 if (root.locked) {
398 if (root.locked) {
395− LightDMService.greeter.respond(response);
399+ LightDM.Greeter.respond(response);
396 } else {
400 } else {
397 d.login();
401 d.login();
398 }
402 }
@@ -469,18 +473,18 @@ Showable {
469 Binding {
473 Binding {
470 target: loader.item
474 target: loader.item
471 property: "userModel"
475 property: "userModel"
472− value: LightDMService.users
476+ value: LightDM.Users
473 }
477 }
474
478
475 Binding {
479 Binding {
476 target: loader.item
480 target: loader.item
477 property: "infographicModel"
481 property: "infographicModel"
478− value: LightDMService.infographic
482+ value: LightDM.Infographic
479 }
483 }
480 }
484 }
481
485
482 Connections {
486 Connections {
483− target: LightDMService.greeter
487+ target: LightDM.Greeter
484
488
485 onShowGreeter: root.forceShow()
489 onShowGreeter: root.forceShow()
486 onHideGreeter: root.forcedUnlock = true
490 onHideGreeter: root.forcedUnlock = true
@@ -498,12 +502,12 @@ Showable {
498 onAuthenticationComplete: {
502 onAuthenticationComplete: {
499 d.waiting = false;
503 d.waiting = false;
500
504
501− if (LightDMService.greeter.authenticated) {
505+ if (LightDM.Greeter.authenticated) {
502− if (!LightDMService.greeter.promptless) {
506+ if (!LightDM.Greeter.promptless) {
503 d.login();
507 d.login();
504 }
508 }
505 } else {
509 } else {
506− if (!LightDMService.greeter.promptless) {
510+ if (!LightDM.Greeter.promptless) {
507 AccountsService.failedLogins++;
511 AccountsService.failedLogins++;
508 }
512 }
509
513
@@ -524,7 +528,7 @@ Showable {
524 }
528 }
525
529
526 loader.item.notifyAuthenticationFailed();
530 loader.item.notifyAuthenticationFailed();
527− if (!LightDMService.greeter.promptless) {
531+ if (!LightDM.Greeter.promptless) {
528 d.selectUser(d.currentIndex, false);
532 d.selectUser(d.currentIndex, false);
529 }
533 }
530 }
534 }
@@ -543,20 +547,20 @@ Showable {
543 }
547 }
544
548
545 Binding {
549 Binding {
546− target: LightDMService.greeter
550+ target: LightDM.Greeter
547 property: "active"
551 property: "active"
548 value: root.active
552 value: root.active
549 }
553 }
550
554
551 Binding {
555 Binding {
552− target: LightDMService.infographic
556+ target: LightDM.Infographic
553 property: "username"
557 property: "username"
554− value: AccountsService.statsWelcomeScreen ? LightDMService.users.data(d.currentIndex, LightDMService.userRoles.NameRole) : ""
558+ value: AccountsService.statsWelcomeScreen ? LightDM.Users.data(d.currentIndex, LightDM.UserRoles.NameRole) : ""
555 }
559 }
556
560
557 Connections {
561 Connections {
558 target: i18n
562 target: i18n
559− onLanguageChanged: LightDMService.infographic.readyForDataChange()
563+ onLanguageChanged: LightDM.Infographic.readyForDataChange()
560 }
564 }
561
565
562 Observer {
566 Observer {
@@ -606,7 +610,7 @@ Showable {
606 failOperation("fingerprint reader is locked");
610 failOperation("fingerprint reader is locked");
607 return;
611 return;
608 }
612 }
609− if (result !== LightDMService.users.data(d.currentIndex, LightDMService.userRoles.UidRole)) {
613+ if (result !== LightDM.Users.data(d.currentIndex, LightDM.UserRoles.UidRole)) {
610 AccountsService.failedFingerprintLogins++;
614 AccountsService.failedFingerprintLogins++;
611 failOperation("not the selected user");
615 failOperation("not the selected user");
612 return;
616 return;
qml/Greeter/IntegratedLightDMImpl.qmldeleted−29
@@ -1,29 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−import QtQuick 2.4
18−import LightDM.IntegratedLightDM 0.1 as LightDM
19−
20−Item{
21− id: implementation
22−
23− property var greeter: LightDM.Greeter
24− property var infographic: LightDM.Infographic
25− property var sessions: LightDM.Sessions
26− property var sessionRoles: LightDM.SessionRoles
27− property var users: LightDM.Users
28− property var userRoles: LightDM.UserRoles
29−}
qml/Greeter/LightDMService.qmldeleted−54
@@ -1,54 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−/**
18− * Lightweight wrapper that allows for loading integrated/real LightDM
19− * plugin
20− */
21−
22−pragma Singleton
23−import QtQuick 2.4
24−
25−Loader {
26− id: loader
27−
28− property var greeter: d.valid ? loader.item.greeter : null
29− property var infographic: d.valid ? loader.item.infographic : null
30− property var sessions: d.valid ? loader.item.sessions : null
31− property var sessionRoles: d.valid ? loader.item.sessionRoles : null
32− property var users: d.valid ? loader.item.users : null
33− property var userRoles: d.valid ? loader.item.userRoles : null
34−
35− // This trickery handles cases where applicationArguments aren't provided
36− // such as during testing
37− property var fullLightDM: {
38− if (typeof applicationArguments !== "undefined") {
39− if (applicationArguments.mode === "greeter") {
40− return true;
41− }
42− }
43− return false;
44− }
45−
46− source: fullLightDM ?
47− "FullLightDMImpl.qml" : "IntegratedLightDMImpl.qml"
48−
49− QtObject {
50− id: d
51−
52− property bool valid: loader.item !== null
53− }
54−}
qml/Greeter/LoginList.qml+5−6
@@ -18,7 +18,6 @@ import QtQuick 2.4
18import QtGraphicalEffects 1.0
18import QtGraphicalEffects 1.0
19import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
20import "../Components"
20import "../Components"
21−import "." 0.1
22
21
23StyledItem {
22StyledItem {
24 id: root
23 id: root
@@ -257,8 +256,8 @@ StyledItem {
257
256
258 readonly property alias icon: badge.source
257 readonly property alias icon: badge.source
259
258
260− visible: LightDMService.sessions.count > 1 &&
259+ visible: LightDM.Sessions.count > 1 &&
261− !LightDMService.users.data(userList.currentIndex, LightDMService.userRoles.LoggedInRole)
260+ !LightDM.Users.data(userList.currentIndex, LightDM.UserRoles.LoggedInRole)
262
261
263 height: units.gu(3.5)
262 height: units.gu(3.5)
264 width: units.gu(3.5)
263 width: units.gu(3.5)
@@ -288,7 +287,7 @@ StyledItem {
288 anchors.margins: units.dp(3)
287 anchors.margins: units.dp(3)
289 keyColor: "#ffffff" // icon providers give us white icons
288 keyColor: "#ffffff" // icon providers give us white icons
290 color: theme.palette.normal.raisedSecondaryText
289 color: theme.palette.normal.raisedSecondaryText
291− source: LightDMService.sessions.iconUrl(root.currentSession)
290+ source: LightDM.Sessions.iconUrl(root.currentSession)
292 }
291 }
293
292
294 KeyNavigation.tab: passwordInput
293 KeyNavigation.tab: passwordInput
@@ -304,9 +303,9 @@ StyledItem {
304 // Refresh the icon path if looking at different places at runtime
303 // Refresh the icon path if looking at different places at runtime
305 // this is mainly for testing
304 // this is mainly for testing
306 Connections {
305 Connections {
307− target: LightDMService.sessions
306+ target: LightDM.Sessions
308 onIconSearchDirectoriesChanged: {
307 onIconSearchDirectoriesChanged: {
309− badge.source = LightDMService.sessions.iconUrl(root.currentSession)
308+ badge.source = LightDM.Sessions.iconUrl(root.currentSession)
310 }
309 }
311 }
310 }
312 }
311 }
qml/Greeter/SessionsList.qml+3−4
@@ -17,7 +17,6 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import Ubuntu.Components 1.3
18import Ubuntu.Components 1.3
19import Ubuntu.Components.ListItems 1.3
19import Ubuntu.Components.ListItems 1.3
20−import "." 0.1
21import "../Components"
20import "../Components"
22
21
23Item {
22Item {
@@ -43,8 +42,8 @@ Item {
43 }
42 }
44
43
45 function currentKey() {
44 function currentKey() {
46− var session = LightDMService.sessions.data(
45+ var session = LightDM.Sessions.data(
47− sessionsList.currentIndex, LightDMService.sessionRoles.KeyRole)
46+ sessionsList.currentIndex, LightDM.SessionRoles.KeyRole)
48 return session;
47 return session;
49 }
48 }
50
49
@@ -106,7 +105,7 @@ Item {
106
105
107 boundsBehavior: Flickable.StopAtBounds
106 boundsBehavior: Flickable.StopAtBounds
108
107
109− model: LightDMService.sessions
108+ model: LightDM.Sessions
110 header: ListItemLayout {
109 header: ListItemLayout {
111 id: header
110 id: header
112
111
qml/Greeter/WideView.qml+1−2
@@ -16,7 +16,6 @@
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18import Ubuntu.Components 1.3
18import Ubuntu.Components 1.3
19−import "." 0.1
20
19
21FocusScope {
20FocusScope {
22 id: root
21 id: root
@@ -141,7 +140,7 @@ FocusScope {
141 Behavior on boxVerticalOffset { UbuntuNumberAnimation {} }
140 Behavior on boxVerticalOffset { UbuntuNumberAnimation {} }
142
141
143 model: root.userModel
142 model: root.userModel
144− currentSession: LightDMService.greeter.defaultSession
143+ currentSession: LightDM.Greeter.defaultSession
145 onResponded: root.responded(response)
144 onResponded: root.responded(response)
146 onSelected: root.selected(index)
145 onSelected: root.selected(index)
147 onSessionChooserButtonClicked: parent.state = "SessionsList"
146 onSessionChooserButtonClicked: parent.state = "SessionsList"
qml/Greeter/qmldirdeleted−1
@@ -1 +0,0 @@
1−singleton LightDMService 0.1 LightDMService.qml
qml/Shell.qml+9−2
@@ -27,6 +27,7 @@ import Unity.Launcher 0.1
27import GlobalShortcut 1.0 // has to be before Utils, because of WindowInputFilter
27import GlobalShortcut 1.0 // has to be before Utils, because of WindowInputFilter
28import GSettings 1.0
28import GSettings 1.0
29import ImageCache 0.1
29import ImageCache 0.1
30+import LightDM 0.1 as LightDM
30import Utils 0.1
31import Utils 0.1
31import Powerd 0.1
32import Powerd 0.1
32import SessionBroadcast 0.1
33import SessionBroadcast 0.1
@@ -209,6 +210,12 @@ StyledItem {
209 value: ApplicationManager
210 value: ApplicationManager
210 }
211 }
211
212
213+ Binding {
214+ target: AccountsService
215+ property: "greeterMode"
216+ value: shell.mode === "greeter"
217+ }
218+
212 Component.onCompleted: {
219 Component.onCompleted: {
213 finishStartUpTimer.start();
220 finishStartUpTimer.start();
214 }
221 }
@@ -542,7 +549,7 @@ StyledItem {
542 if (shell.mode === "greeter") {
549 if (shell.mode === "greeter") {
543 SessionBroadcast.requestHomeShown(AccountsService.user);
550 SessionBroadcast.requestHomeShown(AccountsService.user);
544 } else {
551 } else {
545− var animate = !LightDMService.greeter.active && !stages.shown;
552+ var animate = !LightDM.Greeter.active && !stages.shown;
546 dash.setCurrentScope(0, animate, false);
553 dash.setCurrentScope(0, animate, false);
547 ApplicationManager.requestFocusApplication("unity8-dash");
554 ApplicationManager.requestFocusApplication("unity8-dash");
548 }
555 }
@@ -600,7 +607,7 @@ StyledItem {
600 readonly property bool focusedSurfaceIsFullscreen: MirFocusController.focusedSurface
607 readonly property bool focusedSurfaceIsFullscreen: MirFocusController.focusedSurface
601 ? MirFocusController.focusedSurface.state === Mir.FullscreenState
608 ? MirFocusController.focusedSurface.state === Mir.FullscreenState
602 : false
609 : false
603− fullscreenMode: (focusedSurfaceIsFullscreen && !LightDMService.greeter.active && launcher.progress == 0)
610+ fullscreenMode: (focusedSurfaceIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
604 || greeter.hasLockedApp
611 || greeter.hasLockedApp
605 locked: greeter && greeter.active
612 locked: greeter && greeter.active
606 }
613 }
tests/CMakeLists.txt+1−1
@@ -45,8 +45,8 @@ macro(unity8_parse_arguments)
45
45
46 set(ld_paths)
46 set(ld_paths)
47 list(APPEND ld_paths
47 list(APPEND ld_paths
48+ ${UNITY_MOCKPATH}/liblightdm
48 ${UNITY_MOCKPATH}/libusermetrics
49 ${UNITY_MOCKPATH}/libusermetrics
49− ${UNITY_MOCKPATH}/LightDM/IntegratedLightDM/liblightdm
50 )
50 )
51
51
52 string(REPLACE ";" ":" ld_library_path "${ld_paths}")
52 string(REPLACE ";" ":" ld_library_path "${ld_paths}")
tests/autopilot/unity8/fixture_setup.py+1−1
@@ -74,7 +74,7 @@ class LaunchUnityWithFakeSensors(fixtures.Fixture):
74 def _get_lightdm_mock_path(self):
74 def _get_lightdm_mock_path(self):
75 lib_path = get_mocks_library_path()
75 lib_path = get_mocks_library_path()
76 lightdm_mock_path = os.path.abspath(
76 lightdm_mock_path = os.path.abspath(
77− os.path.join(lib_path, "LightDM" ,"IntegratedLightDM", "liblightdm")
77+ os.path.join(lib_path, "liblightdm")
78 )
78 )
79
79
80 if not os.path.exists(lightdm_mock_path):
80 if not os.path.exists(lightdm_mock_path):
tests/autopilot/unity8/shell/tests/__init__.py+1−1
@@ -261,7 +261,7 @@ class UnityTestCase(AutopilotTestCase):
261 def _get_lightdm_mock_path(self):
261 def _get_lightdm_mock_path(self):
262 lib_path = get_mocks_library_path()
262 lib_path = get_mocks_library_path()
263 lightdm_mock_path = os.path.abspath(
263 lightdm_mock_path = os.path.abspath(
264− os.path.join(lib_path, "LightDM" ,"IntegratedLightDM", "liblightdm")
264+ os.path.join(lib_path, "liblightdm")
265 )
265 )
266
266
267 if not os.path.exists(lightdm_mock_path):
267 if not os.path.exists(lightdm_mock_path):
tests/mocks/AccountsService/AccountsService.cpp+18−3
@@ -15,7 +15,8 @@
15 */
15 */
16
16
17#include "AccountsService.h"
17#include "AccountsService.h"
18−#include "MockUsersModel.h"
18+#include "MockController.h"
19+#include "UsersModel.h"
19
20
20#include <QLightDM/UsersModel>
21#include <QLightDM/UsersModel>
21#include <paths.h>
22#include <paths.h>
@@ -26,6 +27,7 @@ AccountsService::AccountsService(QObject* parent)
26 m_enableLauncherWhileLocked(true),
27 m_enableLauncherWhileLocked(true),
27 m_enableIndicatorsWhileLocked(true),
28 m_enableIndicatorsWhileLocked(true),
28 m_backgroundFile(),
29 m_backgroundFile(),
30+ m_greeterMode(true),
29 m_statsWelcomeScreen(true),
31 m_statsWelcomeScreen(true),
30 m_failedLogins(0),
32 m_failedLogins(0),
31 m_failedFingerprintLogins(0),
33 m_failedFingerprintLogins(0),
@@ -33,9 +35,9 @@ AccountsService::AccountsService(QObject* parent)
33 m_demoEdgesCompleted(),
35 m_demoEdgesCompleted(),
34 m_hereEnabled(false),
36 m_hereEnabled(false),
35 m_hereLicensePath(""),
37 m_hereLicensePath(""),
36− m_usersModel(new MockUsersModel(this))
38+ m_usersModel(new UsersModel(this))
37{
39{
38− m_usersModel->setMockMode("full");
40+ QLightDM::MockController::instance()->setUserMode("full");
39}
41}
40
42
41QString AccountsService::user() const
43QString AccountsService::user() const
@@ -51,6 +53,19 @@ void AccountsService::setUser(const QString &user)
51 Q_EMIT backgroundFileChanged();
53 Q_EMIT backgroundFileChanged();
52}
54}
53
55
56+bool AccountsService::greeterMode() const
57+{
58+ return m_greeterMode;
59+}
60+
61+void AccountsService::setGreeterMode(bool greeterMode)
62+{
63+ if (m_greeterMode != greeterMode) {
64+ m_greeterMode = greeterMode;
65+ Q_EMIT greeterModeChanged();
66+ }
67+}
68+
54bool AccountsService::demoEdges() const
69bool AccountsService::demoEdges() const
55{
70{
56 return m_demoEdges;
71 return m_demoEdges;
tests/mocks/AccountsService/AccountsService.h+10−2
@@ -22,7 +22,7 @@
22#include <QStringList>
22#include <QStringList>
23#include <QVariant>
23#include <QVariant>
24
24
25−class MockUsersModel;
25+class UsersModel;
26
26
27class AccountsService: public QObject
27class AccountsService: public QObject
28{
28{
@@ -32,6 +32,10 @@ class AccountsService: public QObject
32 READ user
32 READ user
33 WRITE setUser
33 WRITE setUser
34 NOTIFY userChanged)
34 NOTIFY userChanged)
35+ Q_PROPERTY (bool greeterMode
36+ READ greeterMode
37+ WRITE setGreeterMode
38+ NOTIFY greeterModeChanged)
35 Q_PROPERTY (bool demoEdges
39 Q_PROPERTY (bool demoEdges
36 READ demoEdges
40 READ demoEdges
37 WRITE setDemoEdges
41 WRITE setDemoEdges
@@ -99,6 +103,8 @@ public:
99
103
100 QString user() const;
104 QString user() const;
101 void setUser(const QString &user);
105 void setUser(const QString &user);
106+ bool greeterMode() const;
107+ void setGreeterMode(bool greeterMode);
102 bool demoEdges() const;
108 bool demoEdges() const;
103 void setDemoEdges(bool demoEdges);
109 void setDemoEdges(bool demoEdges);
104 QStringList demoEdgesCompleted() const;
110 QStringList demoEdgesCompleted() const;
@@ -133,6 +139,7 @@ public:
133
139
134Q_SIGNALS:
140Q_SIGNALS:
135 void userChanged();
141 void userChanged();
142+ void greeterModeChanged();
136 void demoEdgesChanged();
143 void demoEdgesChanged();
137 void demoEdgesCompletedChanged();
144 void demoEdgesCompletedChanged();
138 void enableFingerprintIdentificationChanged();
145 void enableFingerprintIdentificationChanged();
@@ -155,6 +162,7 @@ private:
155 bool m_enableIndicatorsWhileLocked;
162 bool m_enableIndicatorsWhileLocked;
156 QString m_backgroundFile;
163 QString m_backgroundFile;
157 QString m_user;
164 QString m_user;
165+ bool m_greeterMode;
158 bool m_statsWelcomeScreen;
166 bool m_statsWelcomeScreen;
159 uint m_failedLogins;
167 uint m_failedLogins;
160 uint m_failedFingerprintLogins;
168 uint m_failedFingerprintLogins;
@@ -165,7 +173,7 @@ private:
165 QString m_realName;
173 QString m_realName;
166 QStringList m_kbdMap;
174 QStringList m_kbdMap;
167 QString m_email;
175 QString m_email;
168− MockUsersModel *m_usersModel;
176+ UsersModel *m_usersModel;
169};
177};
170
178
171#endif
179#endif
tests/mocks/AccountsService/CMakeLists.txt+6−2
@@ -2,13 +2,17 @@ include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}
2 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_SOURCE_DIR}/plugins/LightDM
3 ${CMAKE_SOURCE_DIR}/plugins/LightDM
4 ${CMAKE_SOURCE_DIR}/plugins/Utils
4 ${CMAKE_SOURCE_DIR}/plugins/Utils
5− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
5+ ${CMAKE_SOURCE_DIR}/tests/mocks/liblightdm
6+ )
7+
8+include_directories(
9+ SYSTEM
10+ ${LIBLIGHTDM_INCLUDE_DIRS}
6 )
11 )
7
12
8add_library(MockAccountsService-qml MODULE
13add_library(MockAccountsService-qml MODULE
9 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
14 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
10 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
15 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
11− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.cpp
12 AccountsService.cpp
16 AccountsService.cpp
13 plugin.cpp
17 plugin.cpp
14 )
18 )
tests/mocks/CMakeLists.txt+1−1
@@ -33,8 +33,8 @@ add_subdirectory(Biometryd)
33add_subdirectory(Cursor)
33add_subdirectory(Cursor)
34add_subdirectory(GSettings.1.0)
34add_subdirectory(GSettings.1.0)
35add_subdirectory(indicator-service)
35add_subdirectory(indicator-service)
36+add_subdirectory(liblightdm)
36add_subdirectory(libusermetrics)
37add_subdirectory(libusermetrics)
37−add_subdirectory(LightDM)
38add_subdirectory(Lights)
38add_subdirectory(Lights)
39add_subdirectory(MeeGo)
39add_subdirectory(MeeGo)
40add_subdirectory(Powerd)
40add_subdirectory(Powerd)
tests/mocks/LightDM/CMakeLists.txtdeleted−1
@@ -1 +0,0 @@
1−add_subdirectory(IntegratedLightDM)
tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txtdeleted−51
@@ -1,51 +0,0 @@
1−# This is a copy of the normal LightDM plugin, but instead of statically
2−# linking in the lightdm bits, this one uses shared libraries so we can swap
3−# out different sets of users for different tests. When we finally switch to
4−# actually using the system liblightdm in the normal plugin, this version can
5−# be deleted.
6−
7−add_subdirectory(liblightdm)
8−
9−include_directories(
10− ${CMAKE_CURRENT_SOURCE_DIR}
11− ${CMAKE_CURRENT_BINARY_DIR}
12− ${CMAKE_SOURCE_DIR}/plugins/Utils
13− ${CMAKE_SOURCE_DIR}/plugins/LightDM
14− ${CMAKE_SOURCE_DIR}/tests/mocks/libusermetrics
15− ${libunity8-private_SOURCE_DIR}
16−)
17−
18−set(QMLPLUGIN_SRC
19− ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeter.cpp
20− ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeterList.cpp
21− ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
22− ${CMAKE_SOURCE_DIR}/plugins/LightDM/SessionsModel.cpp
23− ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
24− ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
25− MockGreeter.cpp
26− MockSessionsModel.cpp
27− MockUsersModel.cpp
28− plugin.cpp
29− )
30−
31−add_library(MockLightDM-qml MODULE
32− ${QMLPLUGIN_SRC}
33− )
34−
35−# We want to link to liblightdm-qt5-3, but we don't want to depend on it being
36−# installed on the system. So we make sure we link to our full fake version
37−# At run time, we can point to whichever version we happen to be using via
38−# LD_LIBRARY_PATH.
39−target_link_libraries(MockLightDM-qml
40− MockLightDM
41− MockUserMetrics
42− unity8-private
43− )
44−
45−qt5_use_modules(MockLightDM-qml DBus Gui Qml)
46−
47−add_unity8_mock(LightDM.IntegratedLightDM 0.1 LightDM/IntegratedLightDM
48− PREFIX mocks
49− TARGETS MockLightDM-qml
50− ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/liblightdm"
51−)
tests/mocks/LightDM/IntegratedLightDM/MockGreeter.cppdeleted−51
@@ -1,51 +0,0 @@
1−/*
2− * Copyright (C) 2014 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−
18−#include "MockGreeter.h"
19−#include <GreeterPrivate.h>
20−
21−QString MockGreeter::mockMode() const
22−{
23− Q_D(const Greeter);
24− return d->m_greeter->mockMode();
25−}
26−
27−void MockGreeter::setMockMode(QString mockMode)
28−{
29− Q_D(Greeter);
30−
31− if (d->m_greeter->mockMode() != mockMode) {
32− d->m_greeter->setMockMode(mockMode);
33− Q_EMIT mockModeChanged(mockMode);
34− }
35−}
36−
37−QString MockGreeter::selectUserHint() const
38−{
39− Q_D(const Greeter);
40− return d->m_greeter->selectUserHint();
41−}
42−
43−void MockGreeter::setSelectUserHint(const QString &selectUserHint)
44−{
45− Q_D(Greeter);
46−
47− if (d->m_greeter->selectUserHint() != selectUserHint) {
48− d->m_greeter->setSelectUserHint(selectUserHint);
49− Q_EMIT selectUserHintChanged();
50− }
51−}
tests/mocks/LightDM/IntegratedLightDM/MockGreeter.hdeleted−42
@@ -1,42 +0,0 @@
1−/*
2− * Copyright (C) 2014 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−
18−// The real, production, Greeter
19−#include <Greeter.h>
20−
21−#ifndef MOCK_UNITY_GREETER_H
22−#define MOCK_UNITY_GREETER_H
23−
24−class MockGreeter : public Greeter {
25− Q_OBJECT
26−
27− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
28− Q_PROPERTY(QString selectUser READ selectUserHint WRITE setSelectUserHint NOTIFY selectUserHintChanged)
29−
30−public:
31− QString mockMode() const;
32− void setMockMode(QString mockMode);
33−
34− QString selectUserHint() const;
35− void setSelectUserHint(const QString &selectUserHint);
36−
37−Q_SIGNALS:
38− void mockModeChanged(QString mode);
39− void selectUserHintChanged();
40−};
41−
42−#endif // MOCK_UNITY_GREETER_H
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.cppdeleted−66
@@ -1,66 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−
18−#include "MockSessionsModel.h"
19−#include <QLightDM/SessionsModel>
20−
21−
22−int MockSessionsModel::numSessions() const
23−{
24− QLightDM::SessionsModel* qSessionsModel =
25− static_cast<QLightDM::SessionsModel*>(sourceModel());
26−
27− return qSessionsModel->numSessions();
28−}
29−
30−int MockSessionsModel::numAvailableSessions() const
31−{
32− QLightDM::SessionsModel* qSessionsModel =
33− static_cast<QLightDM::SessionsModel*>(sourceModel());
34−
35− return qSessionsModel->numAvailableSessions();
36−}
37−
38−QString MockSessionsModel::testScenario() const
39−{
40− QLightDM::SessionsModel* qSessionsModel =
41− static_cast<QLightDM::SessionsModel*>(sourceModel());
42−
43− return qSessionsModel->testScenario();
44−}
45−
46−void MockSessionsModel::setNumSessions(const int numSessions)
47−{
48− QLightDM::SessionsModel* qSessionsModel =
49− static_cast<QLightDM::SessionsModel*>(sourceModel());
50−
51− if (qSessionsModel->numSessions() != numSessions) {
52− qSessionsModel->setNumSessions(numSessions);
53− Q_EMIT numSessionsChanged();
54− }
55−}
56−
57−void MockSessionsModel::setTestScenario(const QString testScenario)
58−{
59− QLightDM::SessionsModel* qSessionsModel =
60− static_cast<QLightDM::SessionsModel*>(sourceModel());
61−
62− if (qSessionsModel->testScenario() != testScenario) {
63− qSessionsModel->setTestScenario(testScenario);
64− Q_EMIT testScenarioChanged();
65− }
66−}
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.hdeleted−44
@@ -1,44 +0,0 @@
1−/*
2− * Copyright (C) 2015 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−
18−#ifndef MOCK_UNITY_SESSIONSMODEL_H
19−#define MOCK_UNITY_SESSIONSMODEL_H
20−
21−#include <SessionsModel.h>
22−
23−class MockSessionsModel : public SessionsModel
24−{
25− Q_OBJECT
26−
27− Q_PROPERTY(int numAvailableSessions READ numAvailableSessions CONSTANT)
28− Q_PROPERTY(int numSessions READ numSessions WRITE setNumSessions NOTIFY numSessionsChanged)
29− Q_PROPERTY(QString testScenario READ testScenario WRITE setTestScenario NOTIFY testScenarioChanged)
30−
31−public:
32− int numAvailableSessions() const;
33− int numSessions() const;
34− QString testScenario() const;
35− void setNumSessions(const int numSessions);
36− void setTestScenario(const QString testScenario);
37−
38−Q_SIGNALS:
39− void numSessionsChanged();
40− void testScenarioChanged();
41−
42−};
43−
44−#endif // MOCK_UNITY_SESSIONSMODEL_H
tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.cppdeleted−44
@@ -1,44 +0,0 @@
1−/*
2− * Copyright (C) 2014 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−
18−#include "MockUsersModel.h"
19−#include <QLightDM/UsersModel>
20−#include <QSortFilterProxyModel>
21−
22−MockUsersModel::MockUsersModel(QObject* parent)
23− : UsersModel(parent)
24−{
25−}
26−
27−QString MockUsersModel::mockMode() const
28−{
29− QLightDM::UsersModel* qUsersModel =
30− static_cast<QLightDM::UsersModel*>(static_cast<QSortFilterProxyModel*>(sourceModel())->sourceModel());
31−
32− return qUsersModel->mockMode();
33−}
34−
35−void MockUsersModel::setMockMode(QString mockMode)
36−{
37− QLightDM::UsersModel* qUsersModel =
38− static_cast<QLightDM::UsersModel*>(static_cast<QSortFilterProxyModel*>(sourceModel())->sourceModel());
39−
40− if (qUsersModel->mockMode() != mockMode) {
41− qUsersModel->setMockMode(mockMode);
42− Q_EMIT mockModeChanged(mockMode);
43− }
44−}
tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.hdeleted−39
@@ -1,39 +0,0 @@
1−/*
2− * Copyright (C) 2014 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−
18−#ifndef MOCK_UNITY_USERSMODEL_H
19−#define MOCK_UNITY_USERSMODEL_H
20−
21−#include <UsersModel.h>
22−
23−class MockUsersModel : public UsersModel
24−{
25− Q_OBJECT
26−
27− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
28−
29−public:
30− explicit MockUsersModel(QObject* parent=0);
31−
32− QString mockMode() const;
33− void setMockMode(QString mockMode);
34−
35−Q_SIGNALS:
36− void mockModeChanged(QString mode);
37−};
38−
39−#endif // MOCK_UNITY_USERSMODEL_H
tests/mocks/LightDM/IntegratedLightDM/QLightDM/Greeterdeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2014 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 "../liblightdm/Greeter.h"
tests/mocks/LightDM/IntegratedLightDM/QLightDM/SessionsModeldeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2015 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 "../liblightdm/SessionsModel.h"
tests/mocks/LightDM/IntegratedLightDM/QLightDM/UsersModeldeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2014 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 "../liblightdm/UsersModel.h"
tests/mocks/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txtdeleted−20
@@ -1,20 +0,0 @@
1−set(LibLightDM_SOURCES
2− Greeter.cpp
3− SessionsModel.cpp
4− UsersModel.cpp
5− GreeterPrivate.cpp
6− SessionsModelPrivate.cpp
7− UsersModelPrivate.cpp
8− ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
9− )
10−
11−add_library(MockLightDM SHARED ${LibLightDM_SOURCES})
12−
13−qt5_use_modules(MockLightDM Gui)
14−
15−set_target_properties(MockLightDM PROPERTIES
16− OUTPUT_NAME lightdm-qt5-3)
17−
18−install(TARGETS MockLightDM
19− DESTINATION ${SHELL_INSTALL_QML}/mocks/LightDM/IntegratedLightDM/liblightdm
20− )
tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.cppdeleted−201
@@ -1,201 +0,0 @@
1−/*
2− * Copyright (C) 2014 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 "Greeter.h"
18−#include "GreeterPrivate.h"
19−#include <QtCore/QCoreApplication>
20−#include <QTimer>
21−
22−namespace QLightDM
23−{
24−
25−Greeter::Greeter(QObject *parent)
26− : QObject(parent),
27− d_ptr(new GreeterPrivate(this))
28−{
29−}
30−
31−Greeter::~Greeter()
32−{
33−}
34−
35−QString Greeter::authenticationUser() const
36−{
37− Q_D(const Greeter);
38− return d->authenticationUser;
39−}
40−
41−bool Greeter::hasGuestAccountHint() const
42−{
43− return true;
44−}
45−
46−QString Greeter::getHint(const QString &name) const
47−{
48− Q_UNUSED(name)
49− return "";
50−}
51−
52−QString Greeter::defaultSessionHint() const
53−{
54− return QStringLiteral("ubuntu");
55−}
56−
57−bool Greeter::hideUsersHint() const
58−{
59− return false;
60−}
61−
62−bool Greeter::showManualLoginHint() const
63−{
64− return true;
65−}
66−
67−bool Greeter::showRemoteLoginHint() const
68−{
69− return true;
70−}
71−
72−QString Greeter::selectUserHint() const
73−{
74− Q_D(const Greeter);
75− return d->selectUserHint;
76−}
77−
78−void Greeter::setSelectUserHint(const QString &selectUserHint)
79−{
80− Q_D(Greeter);
81− d->selectUserHint = selectUserHint;
82−}
83−
84−bool Greeter::selectGuestHint() const
85−{
86− return false;
87−}
88−
89−QString Greeter::autologinUserHint() const
90−{
91− return "";
92−}
93−
94−bool Greeter::autologinGuestHint() const
95−{
96− return false;
97−}
98−
99−int Greeter::autologinTimeoutHint() const
100−{
101− return 0;
102−}
103−
104−bool Greeter::inAuthentication() const
105−{
106− return false;
107−}
108−
109−QString Greeter::hostname() const
110−{
111− return "hostname1";
112−}
113−
114−bool Greeter::isAuthenticated() const
115−{
116− Q_D(const Greeter);
117− return d->authenticated;
118−}
119−
120−bool Greeter::connectSync()
121−{
122− return true;
123−}
124−
125−void Greeter::authenticate(const QString &username)
126−{
127− Q_D(Greeter);
128−
129− d->authenticated = false;
130− d->authenticationUser = username;
131− d->twoFactorDone = false;
132− QTimer::singleShot(0, this, &Greeter::delayedAuthentication);
133−}
134−
135−void Greeter::delayedAuthentication()
136−{
137− Q_D(Greeter);
138− d->handleAuthenticate();
139−}
140−
141−void Greeter::authenticateAsGuest()
142−{}
143−
144−void Greeter::authenticateAutologin()
145−{}
146−
147−void Greeter::authenticateRemote(const QString &session, const QString &username)
148−{
149− Q_UNUSED(session)
150− Q_UNUSED(username)
151−}
152−
153−void Greeter::cancelAuthentication()
154−{}
155−
156−void Greeter::setLanguage (const QString &language)
157−{
158− Q_UNUSED(language)
159−}
160−
161−bool Greeter::startSessionSync(const QString &session)
162−{
163− Q_UNUSED(session)
164− return true;
165−}
166−
167−void Greeter::respond(const QString &response)
168−{
169− Q_D(Greeter);
170−
171− d->handleRespond(response);
172−}
173−
174−void Greeter::sendAuthenticationComplete()
175−{
176− if (qgetenv("UNITY_TESTING").isEmpty()) {
177− // simulate PAM's delay
178− QTimer::singleShot(1000, this, &Greeter::authenticationComplete);
179− } else {
180− Q_EMIT authenticationComplete();
181− }
182−}
183−
184−QString Greeter::mockMode() const
185−{
186− Q_D(const Greeter);
187− return d->mockMode;
188−}
189−
190−
191−void Greeter::setMockMode(QString mockMode)
192−{
193− Q_D(Greeter);
194−
195− if (d->mockMode != mockMode) {
196− d->mockMode = mockMode;
197− Q_EMIT mockModeChanged(mockMode);
198− }
199−}
200−
201−}
tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.hdeleted−115
@@ -1,115 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− * Copyright (C) 2010-2011 David Edmundson.
4− * Copyright (C) 2010-2011 Robert Ancell
5− *
6− * This program is free software; you can redistribute it and/or modify
7− * it under the terms of the GNU General Public License as published by
8− * the Free Software Foundation; version 3.
9− *
10− * This program is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with this program. If not, see <http://www.gnu.org/licenses/>.
17− *
18− * Author: David Edmundson <kde@davidedmundson.co.uk>
19− */
20−
21−#ifndef UNITY_MOCK_GREETER_H
22−#define UNITY_MOCK_GREETER_H
23−
24−#include <QtCore/QObject>
25−#include <QtCore/QVariant>
26−
27−
28−namespace QLightDM
29−{
30− class GreeterPrivate;
31−
32−class Q_DECL_EXPORT Greeter : public QObject
33−{
34− Q_OBJECT
35−
36− Q_PROPERTY(bool authenticated READ isAuthenticated ) //NOTFIY authenticationComplete
37− Q_PROPERTY(QString authenticationUser READ authenticationUser )
38− Q_PROPERTY(QString defaultSession READ defaultSessionHint CONSTANT)
39− Q_PROPERTY(QString selectUser READ selectUserHint CONSTANT)
40− Q_PROPERTY(bool selectGuest READ selectGuestHint CONSTANT)
41−
42− Q_PROPERTY(QString hostname READ hostname CONSTANT)
43− Q_PROPERTY(bool hasGuestAccount READ hasGuestAccountHint CONSTANT)
44−
45− Q_ENUMS(PromptType MessageType)
46−
47− //Mock-only API for testing purposes
48− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
49−
50−public:
51− enum PromptType {
52− PromptTypeQuestion,
53− PromptTypeSecret
54− };
55−
56− enum MessageType {
57− MessageTypeInfo,
58− MessageTypeError
59− };
60−
61− explicit Greeter(QObject* parent=0);
62− virtual ~Greeter();
63−
64− QString getHint(const QString &name) const;
65− QString defaultSessionHint() const;
66− bool hideUsersHint() const;
67− bool showManualLoginHint() const;
68− bool showRemoteLoginHint() const;
69− bool hasGuestAccountHint() const;
70− QString selectUserHint() const;
71− void setSelectUserHint(const QString &selectUserHint); // only in mock
72− bool selectGuestHint() const;
73− QString autologinUserHint() const;
74− bool autologinGuestHint() const;
75− int autologinTimeoutHint() const;
76−
77− bool inAuthentication() const;
78− bool isAuthenticated() const;
79− QString authenticationUser() const;
80− QString hostname() const;
81−
82− QString mockMode() const;
83− void setMockMode(QString mockMode);
84−
85−public Q_SLOTS:
86− bool connectSync();
87− void authenticate(const QString &username=QString());
88− void authenticateAsGuest();
89− void authenticateAutologin();
90− void authenticateRemote(const QString &session=QString(), const QString &username=QString());
91− void respond(const QString &response);
92− void cancelAuthentication();
93− void setLanguage (const QString &language);
94− bool startSessionSync(const QString &session=QString());
95−
96−Q_SIGNALS:
97− void showMessage(QString text, QLightDM::Greeter::MessageType type);
98− void showPrompt(QString text, QLightDM::Greeter::PromptType type);
99− void authenticationComplete();
100− void autologinTimerExpired();
101− void mockModeChanged(QString mode);
102−
103−protected:
104− void sendAuthenticationComplete();
105−
106−private Q_SLOTS:
107− void delayedAuthentication();
108−
109−private:
110− GreeterPrivate *d_ptr;
111− Q_DECLARE_PRIVATE(Greeter)
112−};
113−}
114−
115−#endif // UNITY_MOCK_GREETER_H
tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.cppdeleted−123
@@ -1,123 +0,0 @@
1−/*
2− * Copyright (C) 2013-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− * Author: Michael Terry <michael.terry@canonical.com>
17− */
18−
19−// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
20−// To use the same method of setting role name that it does, we
21−// set our compatibility to Qt4 here too.
22−#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
23−
24−#include "UsersModel.h"
25−#include "UsersModelPrivate.h"
26−#include <QtCore/QDir>
27−#include <QtCore/QString>
28−#include <QtGui/QIcon>
29−
30−namespace QLightDM
31−{
32−
33−UsersModel::UsersModel(QObject *parent) :
34− QAbstractListModel(parent),
35− d_ptr(new UsersModelPrivate(this))
36−{
37− Q_D(UsersModel);
38−
39− // Extend roleNames (we want to keep the "display" role)
40− QHash<int, QByteArray> roles = roleNames();
41− roles[NameRole] = "name";
42− roles[RealNameRole] = "realName";
43− roles[LoggedInRole] = "loggedIn";
44− roles[BackgroundRole] = "background";
45− roles[BackgroundPathRole] = "backgroundPath";
46− roles[SessionRole] = "session";
47− roles[HasMessagesRole] = "hasMessages";
48− roles[ImagePathRole] = "imagePath";
49− roles[UidRole] = "uid";
50− setRoleNames(roles);
51−}
52−
53−UsersModel::~UsersModel()
54−{
55− delete d_ptr;
56−}
57−
58−int UsersModel::rowCount(const QModelIndex &parent) const
59−{
60− Q_D(const UsersModel);
61−
62− if (parent.isValid()) {
63− return 0;
64− } else { // parent is root
65− return d->entries.size();
66− }
67−}
68−
69−QVariant UsersModel::data(const QModelIndex &index, int role) const
70−{
71− Q_D(const UsersModel);
72−
73− if (!index.isValid()) {
74− return QVariant();
75− }
76−
77− int row = index.row();
78− switch (role) {
79− case Qt::DisplayRole:
80− return d->entries[row].real_name;
81− case Qt::DecorationRole:
82− return QIcon();
83− case UsersModel::NameRole:
84− return d->entries[row].username;
85− case UsersModel::RealNameRole:
86− return d->entries[row].real_name;
87− case UsersModel::SessionRole:
88− return d->entries[row].session;
89− case UsersModel::LoggedInRole:
90− return d->entries[row].is_active;
91− case UsersModel::BackgroundRole:
92− return QPixmap(d->entries[row].background);
93− case UsersModel::BackgroundPathRole:
94− return d->entries[row].background;
95− case UsersModel::HasMessagesRole:
96− return d->entries[row].has_messages;
97− case UsersModel::ImagePathRole:
98− return "";
99− case UsersModel::UidRole:
100− return d->entries[row].uid;
101− default:
102− return QVariant();
103− }
104−}
105−
106−QString UsersModel::mockMode() const
107−{
108− Q_D(const UsersModel);
109− return d->mockMode;
110−}
111−
112−void UsersModel::setMockMode(QString mockMode)
113−{
114− Q_D(UsersModel);
115−
116− if (d->mockMode != mockMode) {
117− d->mockMode = mockMode;
118− Q_EMIT mockModeChanged(mockMode);
119− d->resetEntries();
120− }
121−}
122−
123−}
tests/mocks/LightDM/IntegratedLightDM/plugin.cppdeleted−79
@@ -1,79 +0,0 @@
1−/*
2− * Copyright (C) 2014, 2015 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−#include <DBusGreeter.h>
19−#include <DBusGreeterList.h>
20−#include "MockGreeter.h"
21−#include "MockSessionsModel.h"
22−#include "MockUsersModel.h"
23−#include <QLightDM/SessionsModel>
24−#include "ColorTheme.h"
25−#include "UserMetrics.h"
26−#include <QLightDM/UsersModel>
27−
28−#include <QAbstractItemModel>
29−#include <QDBusConnection>
30−#include <QtQml/qqml.h>
31−
32−static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
33−{
34− Q_UNUSED(engine)
35− Q_UNUSED(scriptEngine)
36−
37− MockGreeter *greeter = new MockGreeter;
38− new DBusGreeter(greeter, "/");
39− new DBusGreeterList(greeter, "/list");
40−
41− return greeter;
42−}
43−
44−static QObject *sessions_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
45−{
46− Q_UNUSED(engine)
47− Q_UNUSED(scriptEngine)
48− return new MockSessionsModel;
49−}
50−
51−static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
52−{
53− Q_UNUSED(engine)
54− Q_UNUSED(scriptEngine)
55− return new MockUsersModel;
56−}
57−
58−static QObject *infographic_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
59−{
60− Q_UNUSED(engine)
61− Q_UNUSED(scriptEngine)
62− return UserMetricsOutput::UserMetrics::getInstance();
63−}
64−
65−void LightDMPlugin::registerTypes(const char *uri)
66−{
67− qmlRegisterType<QAbstractItemModel>();
68− qmlRegisterType<UserMetricsOutput::ColorTheme>();
69−
70− Q_ASSERT(uri == QLatin1String("LightDM.IntegratedLightDM"));
71− qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
72− qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
73− qmlRegisterSingletonType<MockGreeter>(uri, 0, 1, "Greeter", greeter_provider);
74− qmlRegisterSingletonType<MockSessionsModel>(uri, 0, 1, "Sessions", sessions_provider);
75− qmlRegisterUncreatableType<QLightDM::SessionsModel>(uri, 0, 1, "SessionRoles", "Type is not instantiable");
76− qmlRegisterSingletonType<MockUsersModel>(uri, 0, 1, "Users", users_provider);
77− qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", "Type is not instantiable");
78− qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
79−}
tests/mocks/LightDM/IntegratedLightDM/plugin.hdeleted−32
@@ -1,32 +0,0 @@
1−/*
2− * Copyright (C) 2014, 2015 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−#ifndef MOCK_LIGHTDM_PLUGIN_H
18−#define MOCK_LIGHTDM_PLUGIN_H
19−
20−#include <QtQml/QQmlEngine>
21−#include <QtQml/QQmlExtensionPlugin>
22−
23−class LightDMPlugin : public QQmlExtensionPlugin
24−{
25− Q_OBJECT
26− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
27−
28−public:
29− void registerTypes(const char *uri) override;
30−};
31−
32−#endif
tests/mocks/LightDM/IntegratedLightDM/qmldirdeleted−2
@@ -1,2 +0,0 @@
1−module LightDM.IntegratedLightDM
2−plugin MockLightDM-qml
tests/mocks/liblightdm/CMakeLists.txtnew file+18
@@ -0,0 +1,18 @@
1+set(MockLightDM_SOURCES
2+ MockController.cpp
3+ MockGreeter.cpp
4+ MockSessionsModel.cpp
5+ MockUsersModel.cpp
6+ )
7+
8+add_library(MockLightDM SHARED ${MockLightDM_SOURCES})
9+
10+qt5_use_modules(MockLightDM DBus Gui)
11+
12+set_target_properties(MockLightDM PROPERTIES
13+ OUTPUT_NAME lightdm-qt5-3
14+ VERSION 0)
15+
16+install(TARGETS MockLightDM
17+ DESTINATION ${SHELL_INSTALL_QML}/mocks/liblightdm
18+ )
tests/mocks/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.cpp → tests/mocks/liblightdm/GreeterPrivate.cpprenamed

The content is the same.

tests/mocks/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.h → tests/mocks/liblightdm/GreeterPrivate.hrenamed

The content is the same.

tests/mocks/liblightdm/MockController.cppnew file+123
@@ -0,0 +1,123 @@
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 "MockController.h"
18+
19+static QLightDM::MockController *m_instance = nullptr;
20+
21+namespace QLightDM
22+{
23+
24+MockController::MockController(QObject *parent)
25+ : QObject(parent)
26+ , m_fullSessions(
27+ {
28+ {"ubuntu", "Ubuntu"},
29+ {"ubuntu-2d", "Ubuntu 2D"},
30+ {"gnome", "GNOME"},
31+ {"gnome-classic", "GNOME Classic"},
32+ {"gnome-flashback-compiz", "GNOME Flashback (Compiz)"},
33+ {"gnome-flashback-metacity", "GNOME Flashback (Metacity)"},
34+ {"gnome-wayland", "GNOME on Wayland"},
35+ {"plasma", "Plasma"},
36+ {"kde", "KDE" },
37+ {"xterm", "Recovery Console"},
38+ {"", "Unknown?"}
39+ })
40+{
41+ m_userMode = qgetenv("LIBLIGHTDM_MOCK_MODE");
42+ if (m_userMode.isEmpty()) {
43+ m_userMode = "full";
44+ }
45+ m_sessionMode = "full";
46+ m_numSessions = numFullSessions();
47+}
48+
49+MockController::~MockController()
50+{
51+}
52+
53+MockController *MockController::instance()
54+{
55+ if (!m_instance) {
56+ m_instance = new MockController;
57+ }
58+ return m_instance;
59+}
60+
61+QString MockController::selectUserHint() const
62+{
63+ return m_selectUserHint;
64+}
65+
66+void MockController::setSelectUserHint(const QString &selectUserHint)
67+{
68+ if (m_selectUserHint != selectUserHint) {
69+ m_selectUserHint = selectUserHint;
70+ Q_EMIT selectUserHintChanged();
71+ }
72+}
73+
74+QString MockController::userMode() const
75+{
76+ return m_userMode;
77+}
78+
79+void MockController::setUserMode(const QString &userMode)
80+{
81+ if (m_userMode != userMode) {
82+ m_userMode = userMode;
83+ Q_EMIT userModeChanged();
84+ }
85+}
86+
87+QString MockController::sessionMode() const
88+{
89+ return m_sessionMode;
90+}
91+
92+void MockController::setSessionMode(const QString &sessionMode)
93+{
94+ if (m_sessionMode != sessionMode) {
95+ m_sessionMode = sessionMode;
96+ Q_EMIT sessionModeChanged();
97+ }
98+}
99+
100+const QList<MockController::SessionItem> &MockController::fullSessionItems() const
101+{
102+ return m_fullSessions;
103+}
104+
105+int MockController::numFullSessions() const
106+{
107+ return m_fullSessions.size();
108+}
109+
110+int MockController::numSessions() const
111+{
112+ return m_numSessions;
113+}
114+
115+void MockController::setNumSessions(int numSessions)
116+{
117+ if (m_numSessions != numSessions) {
118+ m_numSessions = numSessions;
119+ Q_EMIT numSessionsChanged();
120+ }
121+}
122+
123+}
tests/mocks/liblightdm/MockController.hnew file+83
@@ -0,0 +1,83 @@
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+#ifndef UNITY_MOCK_LIBLIGHTDM_CONTROLLER_H
18+#define UNITY_MOCK_LIBLIGHTDM_CONTROLLER_H
19+
20+#include <QObject>
21+#include <QString>
22+
23+
24+namespace QLightDM
25+{
26+class Q_DECL_EXPORT MockController : public QObject
27+{
28+ Q_OBJECT
29+
30+ Q_PROPERTY(QString selectUserHint READ selectUserHint WRITE setSelectUserHint NOTIFY selectUserHintChanged)
31+
32+ // single, single-pin, single-passphrase, full
33+ Q_PROPERTY(QString userMode READ userMode WRITE setUserMode NOTIFY userModeChanged)
34+
35+ // single, none, full
36+ Q_PROPERTY(QString sessionMode READ sessionMode WRITE setSessionMode NOTIFY sessionModeChanged)
37+
38+ Q_PROPERTY(int numAvailableSessions READ numFullSessions CONSTANT)
39+ Q_PROPERTY(int numSessions READ numSessions WRITE setNumSessions NOTIFY numSessionsChanged)
40+
41+public:
42+ static MockController *instance();
43+ virtual ~MockController();
44+
45+ QString selectUserHint() const;
46+ void setSelectUserHint(const QString &selectUserHint);
47+
48+ QString userMode() const;
49+ void setUserMode(const QString &userMode);
50+
51+ QString sessionMode() const;
52+ void setSessionMode(const QString &sessionMode);
53+
54+ class SessionItem
55+ {
56+ public:
57+ QString key;
58+ QString name;
59+ };
60+ int numFullSessions() const;
61+ const QList<SessionItem> &fullSessionItems() const;
62+
63+ int numSessions() const;
64+ void setNumSessions(int numSessions);
65+
66+Q_SIGNALS:
67+ void selectUserHintChanged();
68+ void userModeChanged();
69+ void sessionModeChanged();
70+ void numSessionsChanged();
71+
72+private:
73+ explicit MockController(QObject* parent=0);
74+
75+ QString m_selectUserHint;
76+ QString m_userMode;
77+ QString m_sessionMode;
78+ QList<SessionItem> m_fullSessions;
79+ int m_numSessions;
80+};
81+}
82+
83+#endif
tests/mocks/liblightdm/MockGreeter.cppnew file+256
@@ -0,0 +1,256 @@
1+/*
2+ * Copyright (C) 2014-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 "MockController.h"
18+#include "MockGreeter.h"
19+#include <QDBusInterface>
20+#include <QDBusPendingCall>
21+#include <QTimer>
22+
23+namespace QLightDM
24+{
25+
26+class GreeterPrivate
27+{
28+public:
29+ bool authenticated = false;
30+ QString authenticationUser;
31+ bool twoFactorDone = false;
32+};
33+
34+Greeter::Greeter(QObject *parent)
35+ : QObject(parent)
36+ , d_ptr(new GreeterPrivate)
37+{
38+}
39+
40+Greeter::~Greeter()
41+{
42+ delete d_ptr;
43+}
44+
45+QString Greeter::authenticationUser() const
46+{
47+ Q_D(const Greeter);
48+
49+ return d->authenticationUser;
50+}
51+
52+bool Greeter::hasGuestAccountHint() const
53+{
54+ return true;
55+}
56+
57+QString Greeter::getHint(const QString &name) const
58+{
59+ Q_UNUSED(name)
60+ return "";
61+}
62+
63+QString Greeter::defaultSessionHint() const
64+{
65+ return QStringLiteral("ubuntu");
66+}
67+
68+bool Greeter::hideUsersHint() const
69+{
70+ return false;
71+}
72+
73+bool Greeter::showManualLoginHint() const
74+{
75+ return true;
76+}
77+
78+bool Greeter::showRemoteLoginHint() const
79+{
80+ return true;
81+}
82+
83+QString Greeter::selectUserHint() const
84+{
85+ return MockController::instance()->selectUserHint();
86+}
87+
88+bool Greeter::selectGuestHint() const
89+{
90+ return false;
91+}
92+
93+QString Greeter::autologinUserHint() const
94+{
95+ return "";
96+}
97+
98+bool Greeter::autologinGuestHint() const
99+{
100+ return false;
101+}
102+
103+int Greeter::autologinTimeoutHint() const
104+{
105+ return 0;
106+}
107+
108+bool Greeter::inAuthentication() const
109+{
110+ return false;
111+}
112+
113+QString Greeter::hostname() const
114+{
115+ return "hostname1";
116+}
117+
118+bool Greeter::isAuthenticated() const
119+{
120+ Q_D(const Greeter);
121+
122+ return d->authenticated;
123+}
124+
125+bool Greeter::connectSync()
126+{
127+ return true;
128+}
129+
130+void Greeter::authenticate(const QString &username)
131+{
132+ Q_D(Greeter);
133+
134+ d->authenticated = false;
135+ d->authenticationUser = username;
136+ d->twoFactorDone = false;
137+ QTimer::singleShot(0, this, &Greeter::handleAuthenticate);
138+}
139+
140+void Greeter::handleAuthenticate()
141+{
142+ Q_D(Greeter);
143+
144+ // Send out any messages we need to
145+ if (d->authenticationUser == "info-prompt")
146+ Q_EMIT showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
147+ else if (d->authenticationUser == "wide-info-prompt")
148+ Q_EMIT showMessage("Welcome to Unity Greeter, the greeteriest greeter that ever did appear in these fine lands", Greeter::MessageTypeInfo);
149+ else if (d->authenticationUser == "html-info-prompt")
150+ Q_EMIT showMessage("<b>&</b>", Greeter::MessageTypeInfo);
151+ else if (d->authenticationUser == "long-info-prompt")
152+ Q_EMIT showMessage("Welcome to Unity Greeter\n\nWe like to annoy you with super ridiculously long messages.\nLike this one\n\nThis is the last line of a multiple line message.", Greeter::MessageTypeInfo);
153+ else if (d->authenticationUser == "multi-info-prompt") {
154+ Q_EMIT showMessage("Welcome to Unity Greeter", Greeter::MessageTypeInfo);
155+ Q_EMIT showMessage("This is an error", Greeter::MessageTypeError);
156+ Q_EMIT showMessage("You should have seen three messages", Greeter::MessageTypeInfo);
157+ }
158+
159+ // OK, now actually do the prompt
160+ if (d->authenticationUser == "no-password") {
161+ d->authenticated = true;
162+ Q_EMIT authenticationComplete();
163+ } else if (d->authenticationUser == "has-pin"){
164+ Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
165+ } else if (d->authenticationUser == "auth-error") {
166+ d->authenticated = false;
167+ Q_EMIT authenticationComplete();
168+ } else if (d->authenticationUser == "different-prompt") {
169+ Q_EMIT showPrompt("Secret word: ", Greeter::PromptTypeSecret);
170+ } else {
171+ Q_EMIT showPrompt("Password: ", Greeter::PromptTypeSecret);
172+ }
173+}
174+
175+void Greeter::authenticateAsGuest()
176+{}
177+
178+void Greeter::authenticateAutologin()
179+{}
180+
181+void Greeter::authenticateRemote(const QString &session, const QString &username)
182+{
183+ Q_UNUSED(session)
184+ Q_UNUSED(username)
185+}
186+
187+void Greeter::cancelAuthentication()
188+{}
189+
190+void Greeter::setLanguage (const QString &language)
191+{
192+ Q_UNUSED(language)
193+}
194+
195+bool Greeter::startSessionSync(const QString &session)
196+{
197+ Q_UNUSED(session)
198+
199+ // Send a request to hide the greeter. This is normally done by logind,
200+ // but when testing, we don't want the bother of mocking that out. Instead,
201+ // just send the request directly ourselves.
202+ QDBusInterface iface("com.canonical.UnityGreeter",
203+ "/",
204+ "com.canonical.UnityGreeter",
205+ QDBusConnection::sessionBus());
206+ iface.asyncCall("HideGreeter");
207+
208+ return true;
209+}
210+
211+void Greeter::respond(const QString &response)
212+{
213+ Q_D(Greeter);
214+
215+ if (d->authenticationUser == "no-response")
216+ return;
217+ else if (d->authenticationUser == "two-factor") {
218+ if (!d->twoFactorDone) {
219+ if (response == "password") {
220+ d->twoFactorDone = true;
221+ Q_EMIT showPrompt("otp", Greeter::PromptTypeQuestion);
222+ } else {
223+ d->authenticated = false;
224+ sendAuthenticationComplete();
225+ }
226+ } else {
227+ d->authenticated = (response == "otp");
228+ sendAuthenticationComplete();
229+ }
230+ return;
231+ }
232+
233+ if (d->authenticationUser == "has-pin") {
234+ d->authenticated = (response == "1234");
235+ } else {
236+ d->authenticated = (response == "password");
237+ }
238+ sendAuthenticationComplete();
239+}
240+
241+void Greeter::sendAuthenticationComplete()
242+{
243+ if (qgetenv("UNITY_TESTING").isEmpty()) {
244+ // simulate PAM's delay
245+ QTimer::singleShot(1000, this, &Greeter::authenticationComplete);
246+ } else {
247+ Q_EMIT authenticationComplete();
248+ }
249+}
250+
251+QObject *Greeter::mock()
252+{
253+ return MockController::instance();
254+}
255+
256+}
plugins/LightDM/IntegratedLightDM/liblightdm/Greeter.h → tests/mocks/liblightdm/MockGreeter.hrenamed+12−11
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
3 * Copyright (C) 2010-2011 David Edmundson.
3 * Copyright (C) 2010-2011 David Edmundson.
4 * Copyright (C) 2010-2011 Robert Ancell
4 * Copyright (C) 2010-2011 Robert Ancell
5 *
5 *
@@ -21,17 +21,12 @@
21#ifndef UNITY_MOCK_GREETER_H
21#ifndef UNITY_MOCK_GREETER_H
22#define UNITY_MOCK_GREETER_H
22#define UNITY_MOCK_GREETER_H
23
23
24−#include <QtCore/QObject>
24+#include <QObject>
25−#include <QtCore/QVariant>
25+#include <QVariant>
26−
27−/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28− * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
29− * COUNTERPART IN tests/mocks/Lightdm/liblightdm
30− * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
31
26
32namespace QLightDM
27namespace QLightDM
33{
28{
34− class GreeterPrivate;
29+class GreeterPrivate;
35
30
36class Q_DECL_EXPORT Greeter : public QObject
31class Q_DECL_EXPORT Greeter : public QObject
37{
32{
@@ -48,6 +43,8 @@ class Q_DECL_EXPORT Greeter : public QObject
48
43
49 Q_ENUMS(PromptType MessageType)
44 Q_ENUMS(PromptType MessageType)
50
45
46+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
47+
51public:
48public:
52 enum PromptType {
49 enum PromptType {
53 PromptTypeQuestion,
50 PromptTypeQuestion,
@@ -79,6 +76,8 @@ public:
79 QString authenticationUser() const;
76 QString authenticationUser() const;
80 QString hostname() const;
77 QString hostname() const;
81
78
79+ QObject *mock();
80+
82public Q_SLOTS:
81public Q_SLOTS:
83 bool connectSync();
82 bool connectSync();
84 void authenticate(const QString &username=QString());
83 void authenticate(const QString &username=QString());
@@ -96,10 +95,12 @@ Q_SIGNALS:
96 void authenticationComplete();
95 void authenticationComplete();
97 void autologinTimerExpired();
96 void autologinTimerExpired();
98
97
99−protected:
98+private Q_SLOTS:
100− void sendAuthenticationComplete();
99+ void handleAuthenticate();
101
100
102private:
101private:
102+ void sendAuthenticationComplete();
103+
103 GreeterPrivate *d_ptr;
104 GreeterPrivate *d_ptr;
104 Q_DECLARE_PRIVATE(Greeter)
105 Q_DECLARE_PRIVATE(Greeter)
105};
106};
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp → tests/mocks/liblightdm/MockSessionsModel.cpprenamed+41−40
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -21,22 +21,34 @@
21// set our compatibility to Qt4 here too.
21// set our compatibility to Qt4 here too.
22#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
22#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
23
23
24−#include "SessionsModel.h"
24+#include "MockController.h"
25−#include "SessionsModelPrivate.h"
25+#include "MockSessionsModel.h"
26−#include <QtCore/QDir>
27−#include <QtCore/QString>
28
26
29namespace QLightDM
27namespace QLightDM
30{
28{
31
29
30+class SessionsModelPrivate
31+{
32+public:
33+ QHash<int, QByteArray> roleNames;
34+ QList<MockController::SessionItem> sessionItems;
35+};
36+
32−SessionsModel::SessionsModel(QObject* parent) :
37+SessionsModel::SessionsModel(QObject* parent)
33− QAbstractListModel(parent),
38+ : QAbstractListModel(parent)
34− d_ptr(new SessionsModelPrivate(this))
39+ , d_ptr(new SessionsModelPrivate)
35{
40{
36 Q_D(SessionsModel);
41 Q_D(SessionsModel);
42+
37− m_roleNames = QAbstractListModel::roleNames();
43+ d->roleNames = QAbstractListModel::roleNames();
38− m_roleNames[KeyRole] = "key";
44+ d->roleNames[KeyRole] = "key";
39− m_roleNames[TypeRole] = "type";
45+ d->roleNames[TypeRole] = "type";
46+
47+ connect(MockController::instance(), SIGNAL(sessionModeChanged()),
48+ this, SLOT(resetEntries()));
49+ connect(MockController::instance(), SIGNAL(numSessionsChanged()),
50+ this, SLOT(resetEntries()));
51+ resetEntries();
40}
52}
41
53
42SessionsModel::~SessionsModel()
54SessionsModel::~SessionsModel()
@@ -66,7 +78,9 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
66
78
67QHash<int, QByteArray> SessionsModel::roleNames() const
79QHash<int, QByteArray> SessionsModel::roleNames() const
68{
80{
69− return m_roleNames;
81+ Q_D(const SessionsModel);
82+
83+ return d->roleNames;
70}
84}
71
85
72int SessionsModel::rowCount(const QModelIndex& parent) const
86int SessionsModel::rowCount(const QModelIndex& parent) const
@@ -80,42 +94,29 @@ int SessionsModel::rowCount(const QModelIndex& parent) const
80 }
94 }
81}
95}
82
96
83−int SessionsModel::numSessions() const
97+void SessionsModel::resetEntries()
84{
98{
85− Q_D(const SessionsModel);
86− return d->numSessions;
87−}
88−
89−int SessionsModel::numAvailableSessions() const
90−{
91− Q_D(const SessionsModel);
99+ Q_D(SessionsModel);
92− return d->numAvailableSessions();
93−}
94
100
95−QString SessionsModel::testScenario() const
101+ beginResetModel();
96−{
97− Q_D(const SessionsModel);
98− return d->testScenario;
99−}
100
102
101−void SessionsModel::setNumSessions(int numSessions)
103+ QString sessionMode = MockController::instance()->sessionMode();
102−{
103− Q_D(SessionsModel);
104
104
105− if (d->numSessions != numSessions) {
105+ if (sessionMode == "full") {
106− d->numSessions = numSessions;
106+ d->sessionItems = MockController::instance()->fullSessionItems();
107− d->resetEntries();
107+ d->sessionItems = d->sessionItems.mid(0, MockController::instance()->numSessions());
108+ } else if (sessionMode == "single") {
109+ d->sessionItems = {MockController::instance()->fullSessionItems()[0]};
110+ } else {
111+ d->sessionItems = {};
108 }
112 }
113+
114+ endResetModel();
109}
115}
110
116
111−void SessionsModel::setTestScenario(QString testScenario)
117+QObject *SessionsModel::mock()
112{
118{
113− Q_D(SessionsModel);
119+ return MockController::instance();
114−
115− if (d->testScenario != testScenario) {
116− d->testScenario = testScenario;
117− d->resetEntries();
118− }
119}
120}
120
121
121} // namespace QLightDM
122} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h → tests/mocks/liblightdm/MockSessionsModel.hrenamed+11−12
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by
@@ -18,8 +18,10 @@
18#ifndef UNITY_MOCK_SESSIONSMODEL_H
18#ifndef UNITY_MOCK_SESSIONSMODEL_H
19#define UNITY_MOCK_SESSIONSMODEL_H
19#define UNITY_MOCK_SESSIONSMODEL_H
20
20
21−#include <QtCore/QAbstractListModel>
21+#include <QAbstractListModel>
22+#include <QByteArray>
23+#include <QHash>
22−#include <QtCore/QString>
24+#include <QString>
23
25
24namespace QLightDM
26namespace QLightDM
25{
27{
@@ -29,10 +31,11 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
29 {
31 {
30 Q_OBJECT
32 Q_OBJECT
31
33
34+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
35+
32 Q_ENUMS(SessionModelRoles SessionType)
36 Q_ENUMS(SessionModelRoles SessionType)
33
37
34 public:
38 public:
35−
36 enum SessionModelRoles {
39 enum SessionModelRoles {
37 //name is exposed as Qt::DisplayRole
40 //name is exposed as Qt::DisplayRole
38 //comment is exposed as Qt::TooltipRole
41 //comment is exposed as Qt::TooltipRole
@@ -54,17 +57,13 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
54 int rowCount(const QModelIndex& parent) const override;
57 int rowCount(const QModelIndex& parent) const override;
55 QVariant data(const QModelIndex& index, int role) const override;
58 QVariant data(const QModelIndex& index, int role) const override;
56
59
57− int numSessions() const;
60+ QObject *mock();
58− int numAvailableSessions() const;
59− QString testScenario() const;
60− void setNumSessions(int numSessions);
61− void setTestScenario(QString testScenario);
62
61
63− protected:
62+ private Q_SLOTS:
64− SessionsModelPrivate* const d_ptr;
63+ void resetEntries();
65
64
66 private:
65 private:
67− QHash<int, QByteArray> m_roleNames;
66+ SessionsModelPrivate *d_ptr;
68 Q_DECLARE_PRIVATE(SessionsModel)
67 Q_DECLARE_PRIVATE(SessionsModel)
69 };
68 };
70}
69}
tests/mocks/liblightdm/MockUsersModel.cppnew file+191
@@ -0,0 +1,191 @@
1+/*
2+ * Copyright (C) 2013-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+ * Author: Michael Terry <michael.terry@canonical.com>
17+ */
18+
19+// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
20+// To use the same method of setting role name that it does, we
21+// set our compatibility to Qt4 here too.
22+#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
23+
24+#include "MockController.h"
25+#include "MockUsersModel.h"
26+#include <QDir>
27+#include <QIcon>
28+
29+namespace QLightDM
30+{
31+
32+class Entry
33+{
34+public:
35+ QString username;
36+ QString real_name;
37+ QString background;
38+ QString layouts;
39+ bool is_active;
40+ bool has_messages;
41+ QString session;
42+ uid_t uid;
43+};
44+
45+class UsersModelPrivate
46+{
47+public:
48+ QList<Entry> entries;
49+};
50+
51+UsersModel::UsersModel(QObject *parent)
52+ : QAbstractListModel(parent)
53+ , d_ptr(new UsersModelPrivate)
54+{
55+ // Extend roleNames (we want to keep the "display" role)
56+ QHash<int, QByteArray> roles = roleNames();
57+ roles[NameRole] = "name";
58+ roles[RealNameRole] = "realName";
59+ roles[LoggedInRole] = "loggedIn";
60+ roles[BackgroundRole] = "background";
61+ roles[BackgroundPathRole] = "backgroundPath";
62+ roles[SessionRole] = "session";
63+ roles[HasMessagesRole] = "hasMessages";
64+ roles[ImagePathRole] = "imagePath";
65+ roles[UidRole] = "uid";
66+ setRoleNames(roles);
67+
68+ connect(MockController::instance(), SIGNAL(userModeChanged()),
69+ this, SLOT(resetEntries()));
70+ resetEntries();
71+}
72+
73+UsersModel::~UsersModel()
74+{
75+ delete d_ptr;
76+}
77+
78+int UsersModel::rowCount(const QModelIndex &parent) const
79+{
80+ Q_D(const UsersModel);
81+
82+ if (parent.isValid()) {
83+ return 0;
84+ } else { // parent is root
85+ return d->entries.size();
86+ }
87+}
88+
89+QVariant UsersModel::data(const QModelIndex &index, int role) const
90+{
91+ Q_D(const UsersModel);
92+
93+ if (!index.isValid()) {
94+ return QVariant();
95+ }
96+
97+ int row = index.row();
98+ switch (role) {
99+ case Qt::DisplayRole:
100+ return d->entries[row].real_name;
101+ case Qt::DecorationRole:
102+ return QIcon();
103+ case UsersModel::NameRole:
104+ return d->entries[row].username;
105+ case UsersModel::RealNameRole:
106+ return d->entries[row].real_name;
107+ case UsersModel::SessionRole:
108+ return d->entries[row].session;
109+ case UsersModel::LoggedInRole:
110+ return d->entries[row].is_active;
111+ case UsersModel::BackgroundRole:
112+ return QPixmap(d->entries[row].background);
113+ case UsersModel::BackgroundPathRole:
114+ return d->entries[row].background;
115+ case UsersModel::HasMessagesRole:
116+ return d->entries[row].has_messages;
117+ case UsersModel::ImagePathRole:
118+ return "";
119+ case UsersModel::UidRole:
120+ return d->entries[row].uid;
121+ default:
122+ return QVariant();
123+ }
124+}
125+
126+void UsersModel::resetEntries()
127+{
128+ Q_D(UsersModel);
129+
130+ beginResetModel();
131+
132+ QString userMode = MockController::instance()->userMode();
133+
134+ if (userMode == "single") {
135+ d->entries = {{"no-password", "No Password", 0, 0, false, false, "ubuntu", 0}};
136+ } else if (userMode == "single-passphrase") {
137+ d->entries = {{"has-password", "Has Password", 0, 0, false, false, "ubuntu", 0}};
138+ } else if (userMode == "single-pin") {
139+ d->entries = {{"has-pin", "Has PIN", 0, 0, false, false, "ubuntu", 0}};
140+ } else if (userMode == "full") {
141+ d->entries = {
142+ { "has-password", "Has Password", 0, 0, false, false, "ubuntu", 0 },
143+ { "has-pin", "Has PIN", 0, 0, false, false, "ubuntu", 0 },
144+ { "different-prompt", "Different Prompt", 0, 0, false, false, "ubuntu", 0 },
145+ { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
146+ { "auth-error", "Auth Error", 0, 0, false, false, "ubuntu", 0 },
147+ { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
148+ { "info-prompt", "Info Prompt", 0, 0, false, false, "ubuntu", 0 },
149+ { "html-info-prompt", "HTML Info Prompt", 0, 0, false, false, "ubuntu", 0 },
150+ { "long-info-prompt", "Long Info Prompt", 0, 0, false, false, "ubuntu", 0 },
151+ { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, "ubuntu", 0 },
152+ { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "ubuntu", 0 },
153+ { "long-name", "Long name (far far too long to fit, seriously this would never fit on the screen, you will never see this part of the name)", 0, 0, false, false, "ubuntu", 0 },
154+ { "color-background", "Color Background", "#E95420", 0, false, false, "ubuntu", 0 },
155+ // white and black are a bit redundant, but useful for manually testing if UI is still readable
156+ { "white-background", "White Background", "#ffffff", 0, false, false, "ubuntu", 0 },
157+ { "black-background", "Black Background", "#000000", 0, false, false, "ubuntu", 0 },
158+ { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
159+ { "unicode", "가나다라마", 0, 0, false, false, "ubuntu", 0 },
160+ { "no-response", "No Response", 0, 0, false, false, "ubuntu", 0 },
161+ { "empty-name", "", 0, 0, false, false, "ubuntu", 0 },
162+ { "active", "Active Account", 0, 0, true, false, "ubuntu", 0 },
163+ };
164+ }
165+
166+ // Assign uids in a loop, just to avoid having to muck with them when
167+ // adding or removing test users.
168+ for (int i = 0; i < d->entries.size(); i++) {
169+ d->entries[i].uid = i + 1;
170+ }
171+
172+ // Assign backgrounds
173+ QDir backgroundDir("/usr/share/backgrounds");
174+ QStringList backgrounds = backgroundDir.entryList(QDir::Files);
175+ if (!backgrounds.empty()) {
176+ for (int i = 0; i < d->entries.size(); i++) {
177+ if (d->entries[i].background.isNull()) {
178+ d->entries[i].background = backgroundDir.filePath(backgrounds[i % backgrounds.size()]);
179+ }
180+ }
181+ }
182+
183+ endResetModel();
184+}
185+
186+QObject *UsersModel::mock()
187+{
188+ return MockController::instance();
189+}
190+
191+}
tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.h → tests/mocks/liblightdm/MockUsersModel.hrenamed+8−11
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013-2014 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
3 * Copyright (C) 2010-2011 David Edmundson.
3 * Copyright (C) 2010-2011 David Edmundson.
4 *
4 *
5 * This program is free software; you can redistribute it and/or modify
5 * This program is free software; you can redistribute it and/or modify
@@ -18,10 +18,9 @@
18#ifndef UNITY_MOCK_USERSMODEL_H
18#ifndef UNITY_MOCK_USERSMODEL_H
19#define UNITY_MOCK_USERSMODEL_H
19#define UNITY_MOCK_USERSMODEL_H
20
20
21−#include <QtCore/QString>
22−#include <QtCore/QSharedDataPointer>
23#include <QAbstractListModel>
21#include <QAbstractListModel>
24−
22+#include <QList>
23+#include <QString>
25
24
26namespace QLightDM
25namespace QLightDM
27{
26{
@@ -33,11 +32,7 @@ class Q_DECL_EXPORT UsersModel : public QAbstractListModel
33
32
34 Q_ENUMS(UserModelRoles)
33 Q_ENUMS(UserModelRoles)
35
34
36− //Mock-only API for testing purposes
35+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
37− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
38−
39−Q_SIGNALS:
40− void mockModeChanged(QString mode);
41
36
42public:
37public:
43 explicit UsersModel(QObject *parent = 0);
38 explicit UsersModel(QObject *parent = 0);
@@ -57,8 +52,10 @@ public:
57 int rowCount(const QModelIndex &parent) const override;
52 int rowCount(const QModelIndex &parent) const override;
58 QVariant data(const QModelIndex &index, int role) const override;
53 QVariant data(const QModelIndex &index, int role) const override;
59
54
60− QString mockMode() const;
55+ QObject *mock();
61− void setMockMode(QString mockMode);
56+
57+private Q_SLOTS:
58+ void resetEntries();
62
59
63private:
60private:
64 UsersModelPrivate * const d_ptr;
61 UsersModelPrivate * const d_ptr;
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp → tests/mocks/liblightdm/SessionsModelPrivate.cpprenamed

The content is the same.

tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h → tests/mocks/liblightdm/SessionsModelPrivate.hrenamed

The content is the same.

tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.cpp → tests/mocks/liblightdm/UsersModelPrivate.cpprenamed

The content is the same.

tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.h → tests/mocks/liblightdm/UsersModelPrivate.hrenamed

The content is the same.

tests/mocks/libusermetrics/UserMetrics.cpp+3−5
@@ -288,7 +288,7 @@ void UserMetricsPrivate::generateFakeData()
288 QSharedPointer<UserMetricsData> data(
288 QSharedPointer<UserMetricsData> data(
289 new UserMetricsData("<b>52km</b> travelled", first, firstMonth,
289 new UserMetricsData("<b>52km</b> travelled", first, firstMonth,
290 ninth, secondMonth, this));
290 ninth, secondMonth, this));
291− m_fakeData.insert("single", data);
291+ m_fakeData.insert("has-password", data);
292 m_fakeData.insert("has-pin", data);
292 m_fakeData.insert("has-pin", data);
293 }
293 }
294
294
@@ -304,7 +304,7 @@ void UserMetricsPrivate::generateFakeData()
304 QSharedPointer<UserMetricsData> data(
304 QSharedPointer<UserMetricsData> data(
305 new UserMetricsData("<b>33</b> messages today", second,
305 new UserMetricsData("<b>33</b> messages today", second,
306 firstMonth, eighth, secondMonth, this));
306 firstMonth, eighth, secondMonth, this));
307− m_fakeData.insert("single", data);
307+ m_fakeData.insert("has-password", data);
308 m_fakeData.insert("has-pin", data);
308 m_fakeData.insert("has-pin", data);
309 }
309 }
310
310
@@ -321,10 +321,8 @@ void UserMetricsPrivate::generateFakeData()
321 QSharedPointer<UserMetricsData> data(
321 QSharedPointer<UserMetricsData> data(
322 new UserMetricsData("<b>19</b> minutes talk time", eighth,
322 new UserMetricsData("<b>19</b> minutes talk time", eighth,
323 firstMonth, second, secondMonth, this));
323 firstMonth, second, secondMonth, this));
324− m_fakeData.insert("single", data);
325− m_fakeData.insert("has-pin", data);
326− // Also use same data for some tablet users
327 m_fakeData.insert("has-password", data);
324 m_fakeData.insert("has-password", data);
325+ m_fakeData.insert("has-pin", data);
328 m_fakeData.insert("no-password", data);
326 m_fakeData.insert("no-password", data);
329 m_fakeData.insert("empty-name", data);
327 m_fakeData.insert("empty-name", data);
330 }
328 }
tests/plugins/AccountsService/AccountsServer.cpp+11
@@ -40,6 +40,8 @@ bool AccountsServer::AddUser(const QString &user)
40 if (QDBusConnection::sessionBus().objectRegisteredAt(path) != nullptr)
40 if (QDBusConnection::sessionBus().objectRegisteredAt(path) != nullptr)
41 return true;
41 return true;
42
42
43+ m_users.insert(path);
44+
43 auto props = new PropertiesServer(this);
45 auto props = new PropertiesServer(this);
44 new PropertiesAdaptor(props);
46 new PropertiesAdaptor(props);
45 new AccountsUserAdaptor(props);
47 new AccountsUserAdaptor(props);
@@ -52,6 +54,15 @@ bool AccountsServer::RemoveUser(const QString &user)
52 if (QDBusConnection::sessionBus().objectRegisteredAt(path) == nullptr)
54 if (QDBusConnection::sessionBus().objectRegisteredAt(path) == nullptr)
53 return false;
55 return false;
54
56
57+ m_users.remove(path);
55 QDBusConnection::sessionBus().unregisterObject(path);
58 QDBusConnection::sessionBus().unregisterObject(path);
56 return true;
59 return true;
57}
60}
61+
62+void AccountsServer::RemoveAllUsers()
63+{
64+ Q_FOREACH(const QString &path, m_users) {
65+ m_users.remove(path);
66+ QDBusConnection::sessionBus().unregisterObject(path);
67+ }
68+}
tests/plugins/AccountsService/AccountsServer.h+5
@@ -23,6 +23,7 @@
23#include <QDBusContext>
23#include <QDBusContext>
24#include <QDBusObjectPath>
24#include <QDBusObjectPath>
25#include <QObject>
25#include <QObject>
26+#include <QSet>
26#include <QString>
27#include <QString>
27
28
28class AccountsServer: public QObject, protected QDBusContext
29class AccountsServer: public QObject, protected QDBusContext
@@ -39,6 +40,10 @@ public Q_SLOTS:
39 // mock only.
40 // mock only.
40 bool AddUser(const QString &user);
41 bool AddUser(const QString &user);
41 bool RemoveUser(const QString &user);
42 bool RemoveUser(const QString &user);
43+ void RemoveAllUsers();
44+
45+private:
46+ QSet<QString> m_users;
42};
47};
43
48
44#endif
49#endif
tests/plugins/AccountsService/client.cpp+71−21
@@ -26,6 +26,8 @@
26#include <QDBusReply>
26#include <QDBusReply>
27#include <QDBusMetaType>
27#include <QDBusMetaType>
28
28
29+#include <glib.h>
30+
29template <class T>
31template <class T>
30QVariant dbusVariant(const T& value) { return QVariant::fromValue(QDBusVariant(value)); }
32QVariant dbusVariant(const T& value) { return QVariant::fromValue(QDBusVariant(value)); }
31
33
@@ -62,11 +64,7 @@ public:
62private Q_SLOTS:
64private Q_SLOTS:
63
65
64 void init() {
66 void init() {
65− QDBusReply<bool> addReply = QDBusInterface("org.freedesktop.Accounts",
66− "/org/freedesktop/Accounts",
67− "org.freedesktop.Accounts").call("AddUser", QTest::currentTestFunction());
67+ addUser(QTest::currentTestFunction());
68− QVERIFY(addReply.isValid());
69− QCOMPARE(addReply.value(), true);
70
68
71 m_userInterface = new QDBusInterface("org.freedesktop.Accounts",
69 m_userInterface = new QDBusInterface("org.freedesktop.Accounts",
72 QString("/%1").arg(QTest::currentTestFunction()),
70 QString("/%1").arg(QTest::currentTestFunction()),
@@ -77,17 +75,46 @@ private Q_SLOTS:
77 }
75 }
78
76
79 void cleanup() {
77 void cleanup() {
80− QDBusReply<bool> reply = QDBusInterface("org.freedesktop.Accounts",
78+ QDBusReply<void> reply = QDBusInterface("org.freedesktop.Accounts",
81 "/org/freedesktop/Accounts",
79 "/org/freedesktop/Accounts",
82− "org.freedesktop.Accounts").call("RemoveUser", QTest::currentTestFunction());
80+ "org.freedesktop.Accounts").call("RemoveAllUsers");
83 QVERIFY(reply.isValid());
81 QVERIFY(reply.isValid());
84− QCOMPARE(reply.value(), true);
85
82
86 delete m_userInterface;
83 delete m_userInterface;
87 m_spy.clear();
84 m_spy.clear();
88 m_mousePrimaryButtonSpy.clear();
85 m_mousePrimaryButtonSpy.clear();
89 }
86 }
90
87
88+ void addUser(const QString &user)
89+ {
90+ QDBusReply<bool> addReply = QDBusInterface("org.freedesktop.Accounts",
91+ "/org/freedesktop/Accounts",
92+ "org.freedesktop.Accounts").call("AddUser", user);
93+ QVERIFY(addReply.isValid());
94+ QCOMPARE(addReply.value(), true);
95+ }
96+
97+ QVariant getASProperty(const QString &interface, const QString &key, const QString &user = QString())
98+ {
99+ QString ifaceUser = user;
100+ if (ifaceUser.isEmpty())
101+ ifaceUser = QTest::currentTestFunction();
102+
103+ QDBusInterface iface("org.freedesktop.Accounts",
104+ QString("/%1").arg(ifaceUser),
105+ "org.freedesktop.DBus.Properties",
106+ QDBusConnection::sessionBus());
107+
108+ auto message = iface.call("Get", interface, key);
109+ if (message.type() == QDBusMessage::ReplyMessage) {
110+ return message.arguments().first().value<QDBusVariant>().variant();
111+ }
112+ else {
113+ qWarning() << "Could not get property" << key << ":" << message.errorMessage();
114+ return QVariant();
115+ }
116+ }
117+
91 void testInvalids()
118 void testInvalids()
92 {
119 {
93 // Test various invalid calls
120 // Test various invalid calls
@@ -323,25 +350,16 @@ private Q_SLOTS:
323 QCOMPARE(message.type(), QDBusMessage::ErrorMessage);
350 QCOMPARE(message.type(), QDBusMessage::ErrorMessage);
324 QCOMPARE(message.errorName(), QStringLiteral("org.freedesktop.DBus.Error.InvalidArgs"));
351 QCOMPARE(message.errorName(), QStringLiteral("org.freedesktop.DBus.Error.InvalidArgs"));
325
352
326− message = m_userInterface->call("Get",
327− "org.freedesktop.Accounts.User",
353+ auto response = getASProperty("org.freedesktop.Accounts.User", "RealName");
328− "RealName");
329− QCOMPARE(message.type(), QDBusMessage::ReplyMessage);
330− auto response = message.arguments().first().value<QDBusVariant>().variant().toString();
331− QCOMPARE(response, QStringLiteral(""));
354+ QCOMPARE(response.toString(), QStringLiteral(""));
332
355
333 // Now try it via our AS wrapper and confirm it did get through, unlike above
356 // Now try it via our AS wrapper and confirm it did get through, unlike above
334 session.setRealName("Stallman");
357 session.setRealName("Stallman");
335
358
336 QCOMPARE(session.realName(), QStringLiteral("Stallman"));
359 QCOMPARE(session.realName(), QStringLiteral("Stallman"));
337
360
338− message = m_userInterface->call("Get",
339− "org.freedesktop.Accounts.User",
361+ response = getASProperty("org.freedesktop.Accounts.User", "RealName");
340− "RealName");
341− QCOMPARE(message.type(), QDBusMessage::ReplyMessage);
342− response = message.arguments().first().value<QDBusVariant>().variant().toString();
343− QCOMPARE(response, QStringLiteral("Stallman"));
362+ QCOMPARE(response.toString(), QStringLiteral("Stallman"));
344−
345 }
363 }
346
364
347 void testAsynchronousChangeForKeymaps()
365 void testAsynchronousChangeForKeymaps()
@@ -367,6 +385,38 @@ private Q_SLOTS:
367 QTRY_COMPARE(session.keymaps(), result);
385 QTRY_COMPARE(session.keymaps(), result);
368 }
386 }
369
387
388+ void testGreeterMode()
389+ {
390+ addUser(g_get_user_name());
391+ addUser("OtherUser"); // presumably will never conflict with running user
392+ AccountsService session(this);
393+ QVERIFY(session.greeterMode());
394+
395+ session.setGreeterMode(false);
396+
397+ // NOTE: we change real user data here, but it's a harmless change
398+ session.setFailedLogins(1);
399+ QCOMPARE(session.failedLogins(), 1u);
400+ QCOMPARE(getASProperty("com.canonical.unity.AccountsService.Private",
401+ "FailedLogins", session.user()), QVariant(1));
402+
403+ // This will fail because we aren't the active user
404+ session.setUser("OtherUser");
405+ session.setFailedLogins(2);
406+ QCOMPARE(session.failedLogins(), 2u);
407+ QCOMPARE(getASProperty("com.canonical.unity.AccountsService.Private",
408+ "FailedLogins", "OtherUser"), QVariant(0));
409+
410+ session.setGreeterMode(true);
411+
412+ // But now a similar call will succeed because we're in greeter mode
413+ session.setFailedLogins(3);
414+ QCOMPARE(session.failedLogins(), 3u);
415+ QCOMPARE(getASProperty("com.canonical.unity.AccountsService.Private",
416+ "FailedLogins", "OtherUser"), QVariant(3));
417+
418+ }
419+
370Q_SIGNALS:
420Q_SIGNALS:
371 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
421 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
372 void setMousePrimaryButtonCalled(int button);
422 void setMousePrimaryButtonCalled(int button);
tests/plugins/AccountsService/interfaces.xml+1
@@ -36,6 +36,7 @@
36 <arg name="user" type="s" direction="in" />
36 <arg name="user" type="s" direction="in" />
37 <arg name="success" type="b" direction="out" />
37 <arg name="success" type="b" direction="out" />
38 </method>
38 </method>
39+ <method name="RemoveAllUsers"/>
39 </interface>
40 </interface>
40 <interface name="com.ubuntu.AccountsService.Input" />
41 <interface name="com.ubuntu.AccountsService.Input" />
41 <interface name="com.ubuntu.touch.AccountsService.SecurityPrivacy" />
42 <interface name="com.ubuntu.touch.AccountsService.SecurityPrivacy" />
tests/plugins/LightDM/CMakeLists.txt+54−1
@@ -1 +1,54 @@
1−add_subdirectory(IntegratedLightDM)
1+add_definitions(
2+ -DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
3+ )
4+
5+include_directories(
6+ ${CMAKE_CURRENT_BINARY_DIR}
7+ ${CMAKE_SOURCE_DIR}/plugins/LightDM
8+ ${CMAKE_SOURCE_DIR}/plugins/Utils
9+ )
10+
11+include_directories(
12+ SYSTEM
13+ ${GLIB_INCLUDE_DIRS}
14+ ${LIBLIGHTDM_INCLUDE_DIRS}
15+ )
16+
17+link_libraries(
18+ LightDM-qml
19+ ${LIBLIGHTDM_LDFLAGS}
20+ )
21+
22+# DBusTest
23+add_executable(GreeterDBusTestExec
24+ dbus.cpp
25+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
26+ )
27+qt5_use_modules(GreeterDBusTestExec Core DBus Quick Test)
28+add_unity8_uitest(GreeterDBus dbus-test-runner
29+ ARG_PREFIX "--parameter"
30+ ARGS --task $<TARGET_FILE:GreeterDBusTestExec>
31+ DEPENDS LightDM-qml;MockLightDM
32+ )
33+
34+# SessionsModelTest
35+add_executable(GreeterSessionsModelTestExec
36+ sessionsmodel.cpp
37+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/SessionsModel.cpp
38+ ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
39+ )
40+qt5_use_modules(GreeterSessionsModelTestExec Core Test)
41+add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
42+ DEPENDS LightDM-qml;MockLightDM
43+ )
44+
45+# UsersModelTest
46+add_executable(GreeterUsersModelTestExec
47+ usersmodel.cpp
48+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
49+ ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
50+ )
51+qt5_use_modules(GreeterUsersModelTestExec Core Test)
52+add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
53+ DEPENDS LightDM-qml;MockLightDM
54+ )
tests/plugins/LightDM/IntegratedLightDM/CMakeLists.txtdeleted−113
@@ -1,113 +0,0 @@
1−add_definitions(
2− -DCURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
3− )
4−include_directories(
5− ${GLIB_INCLUDE_DIRS}
6− ${CMAKE_CURRENT_BINARY_DIR}
7− )
8−
9−add_executable(GreeterDBusTestExec
10− dbus.cpp
11− ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
12− )
13−# This add_dependencies is needed since we're linking with with -L and -l below
14−# make seems to work but ninja breaks without it
15−add_dependencies(GreeterDBusTestExec MockLightDM)
16−qt5_use_modules(GreeterDBusTestExec Core DBus Quick Test)
17−target_link_libraries(GreeterDBusTestExec
18− MockLightDM
19− )
20−target_include_directories(GreeterDBusTestExec PUBLIC
21− ${CMAKE_SOURCE_DIR}/plugins/LightDM
22− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
23− )
24−add_unity8_uitest(GreeterDBus dbus-test-runner
25− ARG_PREFIX "--parameter"
26− ARGS --task $<TARGET_FILE:GreeterDBusTestExec>
27− DEPENDS MockLightDM
28− IMPORT_PATHS ${UNITY_MOCKPATH}
29− )
30−
31−add_executable(GreeterPamTestExec
32− pam.cpp
33− ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.cpp
34− )
35−qt5_use_modules(GreeterPamTestExec Concurrent Core Test)
36−target_link_libraries(GreeterPamTestExec
37− integratedLightDM
38− )
39−
40−target_include_directories(GreeterPamTestExec PUBLIC
41− ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM
42− ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM/liblightdm
43− )
44−add_qmltest_target(testGreeterPam GreeterPamTestExec COMMAND $<TARGET_FILE:GreeterPamTestExec>)
45−
46−# SessionsModelTest
47−add_executable(GreeterSessionsModelTestExec
48− sessionsmodel.cpp
49− ${CMAKE_SOURCE_DIR}/plugins/LightDM/SessionsModel.cpp
50− ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
51− )
52−add_dependencies(GreeterSessionsModelTestExec MockLightDM)
53−qt5_use_modules(GreeterSessionsModelTestExec Core Test)
54−target_link_libraries(GreeterSessionsModelTestExec
55− MockLightDM
56− )
57−target_include_directories(GreeterSessionsModelTestExec PUBLIC
58− ${CMAKE_SOURCE_DIR}/plugins/LightDM
59− ${CMAKE_SOURCE_DIR}/plugins/Utils
60− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
61− )
62−add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
63− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
64− DEPENDS MockLightDM
65− )
66−
67−# UsersModelTest
68−add_executable(GreeterUsersModelTestExec
69− usersmodel.cpp
70− ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
71− ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
72− )
73−# This add_dependencies is needed since we're linking with with -L and -l below
74−# make seems to work but ninja breaks without it
75−add_dependencies(GreeterUsersModelTestExec MockLightDM)
76−qt5_use_modules(GreeterUsersModelTestExec Core Test)
77−target_link_libraries(GreeterUsersModelTestExec
78− MockLightDM
79− )
80−target_include_directories(GreeterUsersModelTestExec PUBLIC
81− ${CMAKE_SOURCE_DIR}/plugins/LightDM
82− ${CMAKE_SOURCE_DIR}/plugins/Utils
83− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
84− )
85−add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
86− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
87− DEPENDS MockLightDM
88− )
89−
90−add_executable(GreeterIntegratedTestExec
91− integrated.cpp
92− )
93−qt5_use_modules(GreeterIntegratedTestExec Core DBus Quick Test)
94−target_link_libraries(GreeterIntegratedTestExec
95− ${GLIB_LIBRARIES}
96− integratedLightDMSession
97− )
98−target_include_directories(GreeterIntegratedTestExec PUBLIC
99− ${GLIB_INCLUDE_DIRS}
100− ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM/liblightdm
101− )
102−add_unity8_unittest(GreeterIntegrated dbus-test-runner
103− ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/IntegratedLightDM/liblightdm/
104− ARG_PREFIX "--parameter"
105− ARGS
106− --task $<TARGET_FILE:mock-server>
107− --task-name server
108− --ignore-return
109− --task $<TARGET_FILE:GreeterIntegratedTestExec>
110− --task-name client
111− --wait-for org.freedesktop.Accounts
112− DEPENDS integratedLightDMSession
113− )
tests/plugins/LightDM/IntegratedLightDM/integrated.cppdeleted−88
@@ -1,88 +0,0 @@
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 "UsersModel.h"
18−
19−#include <glib.h>
20−#include <QDBusInterface>
21−#include <QDBusReply>
22−#include <QtTest>
23−
24−class GreeterIntegratedTest : public QObject
25−{
26− Q_OBJECT
27−
28−private Q_SLOTS:
29−
30− void init()
31− {
32− m_accounts = new QDBusInterface(QStringLiteral("org.freedesktop.Accounts"),
33− QStringLiteral("/org/freedesktop/Accounts"),
34− QStringLiteral("org.freedesktop.Accounts"),
35− QDBusConnection::sessionBus());
36− QDBusReply<bool> addReply = m_accounts->call(QStringLiteral("AddUser"),
37− g_get_user_name());
38− QVERIFY(addReply.isValid());
39− QCOMPARE(addReply.value(), true);
40−
41− m_user = new QDBusInterface(QStringLiteral("org.freedesktop.Accounts"),
42− QStringLiteral("/%1").arg(g_get_user_name()),
43− QStringLiteral("org.freedesktop.DBus.Properties"),
44− QDBusConnection::sessionBus());
45−
46− m_model = new QLightDM::UsersModel();
47− QVERIFY(m_model);
48− }
49−
50− void cleanup()
51− {
52− QDBusReply<bool> addReply = m_accounts->call(QStringLiteral("RemoveUser"),
53− g_get_user_name());
54− QVERIFY(addReply.isValid());
55− QCOMPARE(addReply.value(), true);
56−
57− delete m_model;
58− delete m_accounts;
59− delete m_user;
60− }
61−
62− void testWatchRealName()
63− {
64− auto index = m_model->index(0, 0);
65−
66− QCOMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
67− QStringLiteral(""));
68−
69− QDBusInterface accountsIface(m_user->service(),
70− m_user->path(),
71− "org.freedesktop.Accounts.User");
72− QDBusReply<void> reply = accountsIface.call(QStringLiteral("SetRealName"),
73− QStringLiteral("Test User"));
74− QVERIFY(reply.isValid());
75−
76− QTRY_COMPARE(m_model->data(index, QLightDM::UsersModel::RealNameRole).toString(),
77− QStringLiteral("Test User"));
78− }
79−
80−private:
81− QLightDM::UsersModel *m_model;
82− QDBusInterface *m_accounts;
83− QDBusInterface *m_user;
84−};
85−
86−QTEST_MAIN(GreeterIntegratedTest)
87−
88−#include "integrated.moc"
tests/plugins/LightDM/IntegratedLightDM/pam.cppdeleted−54
@@ -1,54 +0,0 @@
1−/*
2− * Copyright (C) 2015 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 "GreeterPrivate.h"
18−
19−#include <QtTest>
20−
21−#include <glib.h>
22−
23−class GreeterPamTest : public QObject
24−{
25− Q_OBJECT
26−
27−private Q_SLOTS:
28−
29− void init()
30− {
31− m_greeterpriv = new QLightDM::GreeterPrivate();
32− }
33−
34− void cleanup()
35− {
36− delete m_greeterpriv;
37− QTRY_COMPARE(QThreadPool::globalInstance()->activeThreadCount(), 0);
38− }
39−
40− void testRapidFireAuthentication()
41− {
42− m_greeterpriv->authenticationUser = QString::fromUtf8(g_get_user_name());
43− for (int i = 0; i < 100; i++) {
44− m_greeterpriv->handleAuthenticate();
45− }
46− }
47−
48−private:
49− QLightDM::GreeterPrivate *m_greeterpriv;
50−};
51−
52−QTEST_GUILESS_MAIN(GreeterPamTest)
53−
54−#include "pam.moc"
tests/plugins/LightDM/IntegratedLightDM/dbus.cpp → tests/plugins/LightDM/dbus.cpprenamed

The content is the same.

tests/plugins/LightDM/IntegratedLightDM/greeter.qml → tests/plugins/LightDM/greeter.qmlrenamed+1−6
@@ -15,13 +15,8 @@
15 */
15 */
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18−import LightDM.IntegratedLightDM 0.1 as LightDM
18+import LightDM 0.1 as LightDM
19
19
20Item {
20Item {
21 property var greeter: LightDM.Greeter
21 property var greeter: LightDM.Greeter
22− Binding {
23− target: LightDM.Greeter
24− property: "mockMode"
25− value: "full"
26− }
27}
22}
tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp → tests/plugins/LightDM/sessionsmodel.cpprenamed+14−15
@@ -16,10 +16,9 @@
16
16
17#include "SessionsModel.h"
17#include "SessionsModel.h"
18
18
19−#include <QLightDM/SessionsModel>
20−#include <QtCore/QModelIndex>
19+#include <QModelIndex>
21−#include <QtTest>
22#include <QString>
20#include <QString>
21+#include <QtTest>
23
22
24class GreeterSessionsModelTest : public QObject
23class GreeterSessionsModelTest : public QObject
25{
24{
@@ -31,14 +30,14 @@ private Q_SLOTS:
31 {
30 {
32 model = new SessionsModel();
31 model = new SessionsModel();
33 QVERIFY(model);
32 QVERIFY(model);
34− sourceModel = new QLightDM::SessionsModel();
33+ mock = model->mock();
35− QVERIFY(sourceModel);
34+ QVERIFY(mock);
36 }
35 }
37
36
38 void cleanup()
37 void cleanup()
39 {
38 {
40 delete model;
39 delete model;
41− delete sourceModel;
40+ // mock will be a singleton, doesn't need to be cleaned
42 }
41 }
43
42
44 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
43 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
@@ -93,34 +92,34 @@ private Q_SLOTS:
93
92
94 void testMultipleSessionsCountIsCorrect()
93 void testMultipleSessionsCountIsCorrect()
95 {
94 {
96− sourceModel->setTestScenario("multipleSessions");
95+ mock->setProperty("sessionMode", "full");
97− QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
96+ QVERIFY(model->rowCount(QModelIndex()) > 1);
98 }
97 }
99
98
100 void testNoSessionsCountIsCorrect()
99 void testNoSessionsCountIsCorrect()
101 {
100 {
102− sourceModel->setTestScenario("noSessions");
101+ mock->setProperty("sessionMode", "none");
103− QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
102+ QVERIFY(model->rowCount(QModelIndex()) == 0);
104 }
103 }
105
104
106 void testSingleSessionCountIsCorrect()
105 void testSingleSessionCountIsCorrect()
107 {
106 {
108− sourceModel->setTestScenario("singleSession");
107+ mock->setProperty("sessionMode", "single");
109− QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
108+ QVERIFY(model->rowCount(QModelIndex()) == 1);
110 }
109 }
111
110
112 void testSessionNameIsCorrect()
111 void testSessionNameIsCorrect()
113 {
112 {
114 // This is testing the lookup, not the correctness of the strings,
113 // This is testing the lookup, not the correctness of the strings,
115 // so one test should be sufficient
114 // so one test should be sufficient
116− sourceModel->setTestScenario("multipleSessions");
115+ mock->setProperty("sessionMode", "full");
117− QVERIFY(model->data(findByKey(sourceModel, "ubuntu"),
116+ QVERIFY(model->data(findByKey(model, "ubuntu"),
118 Qt::DisplayRole).toString() == "Ubuntu");
117 Qt::DisplayRole).toString() == "Ubuntu");
119 }
118 }
120
119
121private:
120private:
122 SessionsModel *model;
121 SessionsModel *model;
123− QLightDM::SessionsModel *sourceModel;
122+ QObject *mock;
124};
123};
125
124
126QTEST_MAIN(GreeterSessionsModelTest)
125QTEST_MAIN(GreeterSessionsModelTest)
tests/plugins/LightDM/IntegratedLightDM/usersmodel.cpp → tests/plugins/LightDM/usersmodel.cpprenamed+4−14
@@ -46,37 +46,27 @@ private Q_SLOTS:
46 {
46 {
47 model = new UsersModel();
47 model = new UsersModel();
48 QVERIFY(model);
48 QVERIFY(model);
49− sourceModel = new QLightDM::UsersModel();
50− QVERIFY(sourceModel);
51 }
49 }
52
50
53 void cleanup()
51 void cleanup()
54 {
52 {
55 delete model;
53 delete model;
56− delete sourceModel;
57 }
54 }
58
55
59 void testMangleColor()
56 void testMangleColor()
60 {
57 {
61− QString background = getStringValue(sourceModel, "color-background", QLightDM::UsersModel::BackgroundPathRole);
58+ auto background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
62− QVERIFY(background == "#E95420");
63−
64− background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
65− QVERIFY(background == "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#E95420'/></svg>");
59+ QCOMPARE(background, QString("data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#E95420'/></svg>"));
66 }
60 }
67
61
68 void testMangleEmptyName()
62 void testMangleEmptyName()
69 {
63 {
70− QString name = getStringValue(sourceModel, "empty-name", QLightDM::UsersModel::RealNameRole);
71− QVERIFY(name == "");
72−
73− name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
64+ auto name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
74− QVERIFY(name == "empty-name");
65+ QCOMPARE(name, QString("empty-name"));
75 }
66 }
76
67
77private:
68private:
78 UsersModel *model;
69 UsersModel *model;
79− QLightDM::UsersModel *sourceModel;
80};
70};
81
71
82QTEST_MAIN(GreeterUsersModelTest)
72QTEST_MAIN(GreeterUsersModelTest)
tests/plugins/Unity/Session/sessionbackendtest.cpp−1
@@ -62,7 +62,6 @@ private Q_SLOTS:
62 QTest::newRow("Shutdown") << "RequestShutdown" << "ShutdownRequested(bool)";
62 QTest::newRow("Shutdown") << "RequestShutdown" << "ShutdownRequested(bool)";
63 QTest::newRow("PromptLock") << "PromptLock" << "LockRequested()";
63 QTest::newRow("PromptLock") << "PromptLock" << "LockRequested()";
64 QTest::newRow("Lock") << "Lock" << "LockRequested()";
64 QTest::newRow("Lock") << "Lock" << "LockRequested()";
65− QTest::newRow("LockLightDM") << "Lock" << "Locked()"; // happens when we lock LightDM, only for Lock()
66 }
65 }
67
66
68 void testUnitySessionLogoutRequested() {
67 void testUnitySessionLogoutRequested() {
tests/qmltests/Dash/tst_DashShell.qml+7
@@ -20,12 +20,19 @@ import "../../../qml/Dash"
20import "../../../qml/"
20import "../../../qml/"
21import Ubuntu.Components 1.3
21import Ubuntu.Components 1.3
22import Unity.Test 0.1 as UT
22import Unity.Test 0.1 as UT
23+import LightDM 0.1 as LightDM
23
24
24Item {
25Item {
25 id: root
26 id: root
26 width: units.gu(80)
27 width: units.gu(80)
27 height: units.gu(80)
28 height: units.gu(80)
28
29
30+ Binding {
31+ target: LightDM.Users.mock
32+ property: "userMode"
33+ value: "single"
34+ }
35+
29 Shell {
36 Shell {
30 id: shell
37 id: shell
31 width: parent.width / 2
38 width: parent.width / 2
tests/qmltests/Greeter/TestView.qml+1
@@ -32,6 +32,7 @@ Item {
32 property bool alphanumeric
32 property bool alphanumeric
33 property var userModel
33 property var userModel
34 property var infographicModel
34 property var infographicModel
35+ property bool waiting
35 readonly property bool fullyShown: _fullyShown
36 readonly property bool fullyShown: _fullyShown
36 readonly property bool required: _required
37 readonly property bool required: _required
37 readonly property bool animating: _animating
38 readonly property bool animating: _animating
tests/qmltests/Greeter/tst_Greeter.qml+5−8
@@ -22,7 +22,7 @@ import Ubuntu.Components 1.3
22import AccountsService 0.1
22import AccountsService 0.1
23import Biometryd 0.0
23import Biometryd 0.0
24import GSettings 1.0
24import GSettings 1.0
25−import LightDM.IntegratedLightDM 0.1 as LightDM // This is the mock
25+import LightDM 0.1 as LightDM
26import Unity.Test 0.1 as UT
26import Unity.Test 0.1 as UT
27
27
28Item {
28Item {
@@ -32,9 +32,6 @@ Item {
32 property url defaultBackground: "/usr/share/backgrounds/warty-final-ubuntu.png"
32 property url defaultBackground: "/usr/share/backgrounds/warty-final-ubuntu.png"
33
33
34 Component.onCompleted: {
34 Component.onCompleted: {
35− // set the mock mode before loading
36− LightDM.Greeter.mockMode = "full";
37− LightDM.Users.mockMode = "full";
38 loader.active = true;
35 loader.active = true;
39 }
36 }
40
37
@@ -146,7 +143,7 @@ Item {
146
143
147 function init() {
144 function init() {
148 greeterSettings.lockedOutTime = 0;
145 greeterSettings.lockedOutTime = 0;
149− LightDM.Greeter.selectUser = "";
146+ LightDM.Greeter.mock.selectUserHint = "";
150 greeter.failedLoginsDelayAttempts = 7;
147 greeter.failedLoginsDelayAttempts = 7;
151 greeter.failedLoginsDelayMinutes = 5;
148 greeter.failedLoginsDelayMinutes = 5;
152 teaseSpy.clear();
149 teaseSpy.clear();
@@ -570,20 +567,20 @@ Item {
570 }
567 }
571
568
572 function test_selectUserHint() {
569 function test_selectUserHint() {
573− LightDM.Greeter.selectUser = "info-prompt";
570+ LightDM.Greeter.mock.selectUserHint = "info-prompt";
574 resetLoader();
571 resetLoader();
575 var i = verifySelected("info-prompt");
572 var i = verifySelected("info-prompt");
576 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
573 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
577 }
574 }
578
575
579 function test_selectUserHintUnset() {
576 function test_selectUserHintUnset() {
580− LightDM.Greeter.selectUser = "";
577+ LightDM.Greeter.mock.selectUserHint = "";
581 resetLoader();
578 resetLoader();
582 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
579 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
583 }
580 }
584
581
585 function test_selectUserHintInvalid() {
582 function test_selectUserHintInvalid() {
586− LightDM.Greeter.selectUser = "not-a-real-user";
583+ LightDM.Greeter.mock.selectUserHint = "not-a-real-user";
587 resetLoader();
584 resetLoader();
588 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
585 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
589 }
586 }
tests/qmltests/Greeter/tst_Infographics.qml+1−11
@@ -20,19 +20,9 @@ import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21import Ubuntu.Components 1.3
21import Ubuntu.Components 1.3
22import Unity.Test 0.1 as UT
22import Unity.Test 0.1 as UT
23−import LightDM.IntegratedLightDM 0.1 as LightDM
23+import LightDM 0.1 as LightDM
24
24
25Item {
25Item {
26− Binding {
27− target: LightDM.Greeter
28− property: "mockMode"
29− value: "full"
30− }
31− Binding {
32− target: LightDM.Users
33− property: "mockMode"
34− value: "full"
35− }
36 property variant infographicModel: LightDM.Infographic
26 property variant infographicModel: LightDM.Infographic
37
27
38 width: units.gu(120)
28 width: units.gu(120)
tests/qmltests/Greeter/tst_NarrowView.qml+8−2
@@ -18,7 +18,7 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import ".."
19import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM 0.1 as LightDM
22import Ubuntu.Components 1.3
22import Ubuntu.Components 1.3
23import Ubuntu.Telephony 0.1 as Telephony
23import Ubuntu.Telephony 0.1 as Telephony
24import Unity.Test 0.1 as UT
24import Unity.Test 0.1 as UT
@@ -30,6 +30,12 @@ Item {
30
30
31 Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark" // use the same theme as the real shell
31 Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark" // use the same theme as the real shell
32
32
33+ Binding {
34+ target: LightDM.Users.mock
35+ property: "userMode"
36+ value: "single"
37+ }
38+
33 Row {
39 Row {
34 anchors.fill: parent
40 anchors.fill: parent
35 Loader {
41 Loader {
@@ -252,7 +258,7 @@ Item {
252 Binding {
258 Binding {
253 target: LightDM.Infographic
259 target: LightDM.Infographic
254 property: "username"
260 property: "username"
255− value: "single"
261+ value: "has-password"
256 }
262 }
257
263
258 SignalSpy {
264 SignalSpy {
tests/qmltests/Greeter/tst_WideView.qml+15−23
@@ -18,7 +18,7 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import ".."
19import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM 0.1 as LightDM
22import Ubuntu.Components 1.3
22import Ubuntu.Components 1.3
23import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
24
24
@@ -31,12 +31,6 @@ StyledItem {
31
31
32 theme.name: "Ubuntu.Components.Themes.SuruDark"
32 theme.name: "Ubuntu.Components.Themes.SuruDark"
33
33
34− Binding {
35− target: LightDM.Users
36− property: "mockMode"
37− value: "full"
38− }
39−
40 Row {
34 Row {
41 anchors.fill: parent
35 anchors.fill: parent
42 Loader {
36 Loader {
@@ -271,15 +265,15 @@ StyledItem {
271 id: multipleSessionsCheckbox
265 id: multipleSessionsCheckbox
272 onClicked: {
266 onClicked: {
273 if (checked) {
267 if (checked) {
274− LightDM.Sessions.testScenario = "multipleSessions"
268+ LightDM.Sessions.mock.sessionMode = "full";
275 } else {
269 } else {
276− LightDM.Sessions.testScenario = "singleSession"
270+ LightDM.Sessions.mock.sessionMode = "single";
277 }
271 }
278 }
272 }
279 Connections {
273 Connections {
280− target: LightDM.Sessions
274+ target: LightDM.Sessions.mock
281− onTestScenarioChanged: {
275+ onSessionModeChanged: {
282− if (LightDM.Sessions.testScenario === "multipleSessions") {
276+ if (LightDM.Sessions.mock.sessionMode === "full") {
283 multipleSessionsCheckbox.checked = true;
277 multipleSessionsCheckbox.checked = true;
284 } else {
278 } else {
285 multipleSessionsCheckbox.checked = false;
279 multipleSessionsCheckbox.checked = false;
@@ -297,11 +291,11 @@ StyledItem {
297
291
298 width: units.gu(10)
292 width: units.gu(10)
299 minimumValue: 0
293 minimumValue: 0
300− maximumValue: LightDM.Sessions.numAvailableSessions
294+ maximumValue: LightDM.Sessions.mock.numAvailableSessions
301− value: LightDM.Sessions.numSessions
295+ value: LightDM.Sessions.mock.numSessions
302− visible: LightDM.Sessions.testScenario === "multipleSessions"
296+ visible: LightDM.Sessions.mock.sessionMode === "full"
303 Binding {
297 Binding {
304− target: LightDM.Sessions
298+ target: LightDM.Sessions.mock
305 property: "numSessions"
299 property: "numSessions"
306 value: numSessionsSlider.value
300 value: numSessionsSlider.value
307 }
301 }
@@ -368,7 +362,7 @@ StyledItem {
368 respondedSpy.clear();
362 respondedSpy.clear();
369 teaseSpy.clear();
363 teaseSpy.clear();
370 emergencySpy.clear();
364 emergencySpy.clear();
371− LightDM.Sessions.testScenario = "multipleSessions"
365+ LightDM.Sessions.mock.sessionMode = "full";
372 }
366 }
373
367
374 function cleanup() {
368 function cleanup() {
@@ -426,7 +420,6 @@ StyledItem {
426 }
420 }
427
421
428 function test_sessionIconsAreValid() {
422 function test_sessionIconsAreValid() {
429− LightDM.Sessions.testScenario = "multipleSessions"
430 var originalDirectories = LightDM.Sessions.iconSearchDirectories
423 var originalDirectories = LightDM.Sessions.iconSearchDirectories
431 LightDM.Sessions.iconSearchDirectories = [testIconDirectory]
424 LightDM.Sessions.iconSearchDirectories = [testIconDirectory]
432
425
@@ -454,7 +447,6 @@ StyledItem {
454
447
455 selectUser("has-password");
448 selectUser("has-password");
456
449
457− LightDM.Sessions.testScenario = "multipleSessions";
458 var sessionChooserButton = findChild(view, "sessionChooserButton");
450 var sessionChooserButton = findChild(view, "sessionChooserButton");
459 var icon = String(sessionChooserButton.icon);
451 var icon = String(sessionChooserButton.icon);
460 compare(icon.indexOf("ubuntu") > -1, true);
452 compare(icon.indexOf("ubuntu") > -1, true);
@@ -478,12 +470,12 @@ StyledItem {
478 }
470 }
479
471
480 function test_noSessionsDoesntBreakView() {
472 function test_noSessionsDoesntBreakView() {
481− LightDM.Sessions.testScenario = "noSessions"
473+ LightDM.Sessions.mock.sessionMode = "none";
482 compare(LightDM.Sessions.count, 0)
474 compare(LightDM.Sessions.count, 0)
483 }
475 }
484
476
485 function test_sessionIconNotShownWithOneSession() {
477 function test_sessionIconNotShownWithOneSession() {
486− LightDM.Sessions.testScenario = "singleSession"
478+ LightDM.Sessions.mock.sessionMode = "single";
487 compare(LightDM.Sessions.count, 1);
479 compare(LightDM.Sessions.count, 1);
488
480
489 var sessionChooserButton = findChild(view, "sessionChooserButton");
481 var sessionChooserButton = findChild(view, "sessionChooserButton");
@@ -491,7 +483,7 @@ StyledItem {
491 }
483 }
492
484
493 function test_sessionIconNotShownWithActiveUser() {
485 function test_sessionIconNotShownWithActiveUser() {
494− LightDM.Sessions.testScenario = "multipleSessions";
486+ LightDM.Sessions.mock.sessionMode = "full";
495 compare(LightDM.Sessions.count > 1, true);
487 compare(LightDM.Sessions.count > 1, true);
496
488
497 selectUser("active");
489 selectUser("active");
@@ -501,7 +493,7 @@ StyledItem {
501 }
493 }
502
494
503 function test_sessionIconShownWithMultipleSessions() {
495 function test_sessionIconShownWithMultipleSessions() {
504− LightDM.Sessions.testScenario = "multipleSessions"
496+ LightDM.Sessions.mock.sessionMode = "full";
505 compare(LightDM.Sessions.count > 1, true);
497 compare(LightDM.Sessions.count > 1, true);
506
498
507 selectUser("has-password");
499 selectUser("has-password");
tests/qmltests/Tutorial/tst_Tutorial.qml+2−3
@@ -17,7 +17,7 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import AccountsService 0.1
19import AccountsService 0.1
20−import LightDM.IntegratedLightDM 0.1 as LightDM
20+import LightDM 0.1 as LightDM
21import Ubuntu.Components 1.3
21import Ubuntu.Components 1.3
22import Ubuntu.Components.ListItems 1.3
22import Ubuntu.Components.ListItems 1.3
23import Ubuntu.Telephony 0.1 as Telephony
23import Ubuntu.Telephony 0.1 as Telephony
@@ -85,8 +85,7 @@ Rectangle {
85
85
86 Component.onCompleted: {
86 Component.onCompleted: {
87 // must set the mock mode before loading the Shell
87 // must set the mock mode before loading the Shell
88− LightDM.Greeter.mockMode = "single-pin";
89− LightDM.Users.mockMode = "single-pin";
88+ LightDM.Users.mock.userMode = "single-pin";
90 shellLoader.active = true;
89 shellLoader.active = true;
91 }
90 }
92
91
tests/qmltests/tst_OrientedShell.qml+7−1
@@ -22,7 +22,7 @@ import Ubuntu.Components 1.3
22import Ubuntu.Components.ListItems 1.3 as ListItem
22import Ubuntu.Components.ListItems 1.3 as ListItem
23import Unity.Application 0.1
23import Unity.Application 0.1
24import Unity.Test 0.1
24import Unity.Test 0.1
25−import LightDM.IntegratedLightDM 0.1 as LightDM
25+import LightDM 0.1 as LightDM
26import Powerd 0.1
26import Powerd 0.1
27import Unity.InputInfo 0.1
27import Unity.InputInfo 0.1
28import Utils 0.1
28import Utils 0.1
@@ -36,6 +36,12 @@ Rectangle {
36 width: units.gu(160) + controls.width
36 width: units.gu(160) + controls.width
37 height: units.gu(100)
37 height: units.gu(100)
38
38
39+ Binding {
40+ target: LightDM.Users.mock
41+ property: "userMode"
42+ value: "single"
43+ }
44+
39 QtObject {
45 QtObject {
40 id: applicationArguments
46 id: applicationArguments
41 property string deviceName: "mako"
47 property string deviceName: "mako"
tests/qmltests/tst_Shell.qml+4−7
@@ -18,7 +18,7 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import AccountsService 0.1
19import AccountsService 0.1
20import GSettings 1.0
20import GSettings 1.0
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM 0.1 as LightDM
22import SessionBroadcast 0.1
22import SessionBroadcast 0.1
23import Ubuntu.Components 1.3
23import Ubuntu.Components 1.3
24import Ubuntu.Components.ListItems 1.3 as ListItem
24import Ubuntu.Components.ListItems 1.3 as ListItem
@@ -46,8 +46,7 @@ Rectangle {
46
46
47 Component.onCompleted: {
47 Component.onCompleted: {
48 // must set the mock mode before loading the Shell
48 // must set the mock mode before loading the Shell
49− LightDM.Greeter.mockMode = "single";
49+ LightDM.Users.mock.userMode = "single";
50− LightDM.Users.mockMode = "single";
51 shellLoader.active = true;
50 shellLoader.active = true;
52 }
51 }
53
52
@@ -203,8 +202,7 @@ Rectangle {
203 model: ["single", "single-passphrase", "single-pin", "full"]
202 model: ["single", "single-passphrase", "single-pin", "full"]
204 onSelectedIndexChanged: {
203 onSelectedIndexChanged: {
205 shellLoader.active = false;
204 shellLoader.active = false;
206− LightDM.Greeter.mockMode = model[selectedIndex];
207− LightDM.Users.mockMode = model[selectedIndex];
205+ LightDM.Users.mock.userMode = model[selectedIndex];
208 shellLoader.active = true;
206 shellLoader.active = true;
209 }
207 }
210 }
208 }
@@ -875,8 +873,7 @@ Rectangle {
875 }
873 }
876
874
877 function setLightDMMockMode(mode) {
875 function setLightDMMockMode(mode) {
878− LightDM.Greeter.mockMode = mode;
876+ LightDM.Users.mock.userMode = mode;
879− LightDM.Users.mockMode = mode;
880 }
877 }
881
878
882 /*
879 /*
tests/qmltests/tst_ShellWithPin.qml+2−3
@@ -19,7 +19,7 @@ import Ubuntu.Components 1.3
19import QtTest 1.0
19import QtTest 1.0
20import AccountsService 0.1
20import AccountsService 0.1
21import GSettings 1.0
21import GSettings 1.0
22−import LightDM.IntegratedLightDM 0.1 as LightDM
22+import LightDM 0.1 as LightDM
23import Ubuntu.SystemImage 0.1
23import Ubuntu.SystemImage 0.1
24import Ubuntu.Telephony 0.1 as Telephony
24import Ubuntu.Telephony 0.1 as Telephony
25import Unity.Application 0.1
25import Unity.Application 0.1
@@ -35,8 +35,7 @@ Item {
35
35
36 Component.onCompleted: {
36 Component.onCompleted: {
37 // must set the mock mode before loading the Shell
37 // must set the mock mode before loading the Shell
38− LightDM.Greeter.mockMode = "single-pin";
39− LightDM.Users.mockMode = "single-pin";
38+ LightDM.Users.mock.userMode = "single-pin";
40 shellLoader.active = true;
39 shellLoader.active = true;
41 }
40 }
42
41