on xenial help sign in
Simplify lightdm plugin layout and use in-session lightdm support
commit1c3376882076461c2b2e63fa85d01d12dde5aaab authorMichael Terry <michael.terry@canonical.com> dateTue 6 Sep 2016, 14:46 (10 years ago) parent3653285
110 files changed+1152−2968
CMakeLists.txt+1 cmake/modules/QmlTest.cmake+3−3 debian/rules−5 plugins/AccountsService/AccountsService.cpp+27−1 plugins/AccountsService/AccountsService.h+8 plugins/LightDM/CMakeLists.txt+16−9 plugins/LightDM/FullLightDM/CMakeLists.txt−28 plugins/LightDM/FullLightDM/qmldir−3 plugins/LightDM/Greeter.cpp+6 plugins/LightDM/Greeter.h+4 plugins/LightDM/IntegratedLightDM/CMakeLists.txt−33 plugins/LightDM/IntegratedLightDM/QLightDM/Greeter−17 plugins/LightDM/IntegratedLightDM/QLightDM/SessionsModel−17 plugins/LightDM/IntegratedLightDM/QLightDM/UsersModel−17 plugins/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txt−55 plugins/LightDM/IntegratedLightDM/liblightdm/Greeter.cpp−179 plugins/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.cpp−304 plugins/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.h−51 plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp−88 plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h−72 plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp−36 plugins/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h−54 plugins/LightDM/IntegratedLightDM/liblightdm/UsersModel.cpp−110 plugins/LightDM/IntegratedLightDM/liblightdm/UsersModel.h−67 plugins/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.cpp−94 plugins/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.h−72 plugins/LightDM/IntegratedLightDM/qmldir−3 plugins/LightDM/SessionsModel.cpp+6−2 plugins/LightDM/SessionsModel.h+6 plugins/LightDM/UsersModel.cpp+7 plugins/LightDM/UsersModel.h+4 plugins/LightDM/plugin.cpp+2−9 plugins/LightDM/plugin.h+1−1 plugins/LightDM/qmldir+2−3 plugins/Unity/Session/dbusunitysessionservice.cpp+3−45 plugins/Unity/Session/dbusunitysessionservice.h−3 qml/Components/Dialogs.qml+4−4 qml/Greeter/FullLightDMImpl.qml−30 qml/Greeter/Greeter.qml+37−33 qml/Greeter/IntegratedLightDMImpl.qml−29 qml/Greeter/LightDMService.qml−54 qml/Greeter/LoginList.qml+5−6 qml/Greeter/SessionsList.qml+3−4 qml/Greeter/WideView.qml+1−2 qml/Greeter/qmldir−1 qml/Shell.qml+9−2 tests/CMakeLists.txt+1−1 tests/autopilot/unity8/fixture_setup.py+1−1 tests/autopilot/unity8/shell/tests/__init__.py+1−1 tests/mocks/AccountsService/AccountsService.cpp+18−3 tests/mocks/AccountsService/AccountsService.h+10−2 tests/mocks/AccountsService/CMakeLists.txt+6−2 tests/mocks/CMakeLists.txt+1−1 tests/mocks/LightDM/CMakeLists.txt−1 tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txt−51 tests/mocks/LightDM/IntegratedLightDM/MockGreeter.cpp−51 tests/mocks/LightDM/IntegratedLightDM/MockGreeter.h−42 tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.cpp−66 tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.h−44 tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.cpp−44 tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.h−39 tests/mocks/LightDM/IntegratedLightDM/QLightDM/Greeter−17 tests/mocks/LightDM/IntegratedLightDM/QLightDM/SessionsModel−17 tests/mocks/LightDM/IntegratedLightDM/QLightDM/UsersModel−17 tests/mocks/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txt−20 tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.cpp−201 tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.h−115 tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.cpp−123 tests/mocks/LightDM/IntegratedLightDM/plugin.cpp−79 tests/mocks/LightDM/IntegratedLightDM/plugin.h−32 tests/mocks/LightDM/IntegratedLightDM/qmldir−2 tests/mocks/liblightdm/CMakeLists.txt+18 tests/mocks/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.cpp → tests/mocks/liblightdm/GreeterPrivate.cpp tests/mocks/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.h → tests/mocks/liblightdm/GreeterPrivate.h tests/mocks/liblightdm/MockController.cpp+123 tests/mocks/liblightdm/MockController.h+83 tests/mocks/liblightdm/MockGreeter.cpp+256 plugins/LightDM/IntegratedLightDM/liblightdm/Greeter.h → tests/mocks/liblightdm/MockGreeter.h+12−11 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp → tests/mocks/liblightdm/MockSessionsModel.cpp+41−40 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h → tests/mocks/liblightdm/MockSessionsModel.h+11−12 tests/mocks/liblightdm/MockUsersModel.cpp+191 tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.h → tests/mocks/liblightdm/MockUsersModel.h+8−11 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.cpp → tests/mocks/liblightdm/SessionsModelPrivate.cpp tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModelPrivate.h → tests/mocks/liblightdm/SessionsModelPrivate.h tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.cpp → tests/mocks/liblightdm/UsersModelPrivate.cpp tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModelPrivate.h → tests/mocks/liblightdm/UsersModelPrivate.h tests/mocks/libusermetrics/UserMetrics.cpp+3−5 tests/plugins/AccountsService/AccountsServer.cpp+11 tests/plugins/AccountsService/AccountsServer.h+5 tests/plugins/AccountsService/client.cpp+71−21 tests/plugins/AccountsService/interfaces.xml+1 tests/plugins/LightDM/CMakeLists.txt+54−1 tests/plugins/LightDM/IntegratedLightDM/CMakeLists.txt−113 tests/plugins/LightDM/IntegratedLightDM/integrated.cpp−88 tests/plugins/LightDM/IntegratedLightDM/pam.cpp−54 tests/plugins/LightDM/IntegratedLightDM/dbus.cpp → tests/plugins/LightDM/dbus.cpp tests/plugins/LightDM/IntegratedLightDM/greeter.qml → tests/plugins/LightDM/greeter.qml+1−6 tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp → tests/plugins/LightDM/sessionsmodel.cpp+14−15 tests/plugins/LightDM/IntegratedLightDM/usersmodel.cpp → tests/plugins/LightDM/usersmodel.cpp+4−14 tests/plugins/Unity/Session/sessionbackendtest.cpp−1 tests/qmltests/Dash/tst_DashShell.qml+7 tests/qmltests/Greeter/TestView.qml+1 tests/qmltests/Greeter/tst_Greeter.qml+5−8 tests/qmltests/Greeter/tst_Infographics.qml+1−11 tests/qmltests/Greeter/tst_NarrowView.qml+8−2 tests/qmltests/Greeter/tst_WideView.qml+15−23 tests/qmltests/Tutorial/tst_Tutorial.qml+2−3 tests/qmltests/tst_OrientedShell.qml+7−1 tests/qmltests/tst_Shell.qml+4−7 tests/qmltests/tst_ShellWithPin.qml+2−3
CMakeLists.txt+1
@@ -61,6 +61,7 @@ pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=21)
6161pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
6262pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
6363pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
64+pkg_check_modules(LIBLIGHTDM REQUIRED liblightdm-qt5-3)
6465pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
6566pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
6667
cmake/modules/QmlTest.cmake+3−3
@@ -65,11 +65,11 @@ endfunction()
6565# This function wraps add_executable_test, see below for available arguments.
6666
6767function(add_qml_unittest PATH COMPONENT_NAME)
68− import_executables(qmltestrunner)
68+ import_executables(dbus-run-session)
6969
70− add_executable_test(${COMPONENT_NAME} qmltestrunner
70+ add_executable_test(${COMPONENT_NAME} dbus-run-session
7171 ${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}
7373 )
7474endfunction()
7575
debian/rules−5
@@ -36,8 +36,3 @@ override_dh_installdeb:
3636# use private lib directories
3737override_dh_makeshlibs:
3838 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)
8080AccountsService::AccountsService(QObject* parent, const QString &user)
8181 : QObject(parent)
8282 , m_service(new AccountsServiceDBusAdaptor(this))
83+ , m_greeterMode(true)
8384{
8485 m_unityInput = new QDBusInterface(QStringLiteral("com.canonical.Unity.Input"),
8586 QStringLiteral("/com/canonical/Unity/Input"),
@@ -155,6 +156,19 @@ void AccountsService::setUser(const QString &user)
155156 refresh(!wasEmpty);
156157}
157158
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+
158172bool AccountsService::demoEdges() const
159173{
160174 auto value = getProperty(IFACE_UNITY, PROP_DEMO_EDGES);
@@ -341,7 +355,19 @@ void AccountsService::setProperty(const QString &interface, const QString &prope
341355{
342356 if (m_properties[interface][property].value != value) {
343357 m_properties[interface][property].value = value;
344− m_service->setUserPropertyAsync(m_user, interface, property, 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).
369+ m_service->setUserPropertyAsync(m_user, interface, property, value);
370+ }
345371 emitChangedForProperty(interface, property);
346372 }
347373}
plugins/AccountsService/AccountsService.h+8
@@ -34,6 +34,10 @@ class AccountsService: public QObject
3434 READ user
3535 WRITE setUser
3636 NOTIFY userChanged)
37+ Q_PROPERTY (bool greeterMode
38+ READ greeterMode
39+ WRITE setGreeterMode
40+ NOTIFY greeterModeChanged)
3741 Q_PROPERTY (bool demoEdges
3842 READ demoEdges
3943 WRITE setDemoEdges
@@ -92,6 +96,8 @@ public:
9296
9397 QString user() const;
9498 void setUser(const QString &user);
99+ bool greeterMode() const;
100+ void setGreeterMode(bool greeterMode);
95101 bool demoEdges() const;
96102 void setDemoEdges(bool demoEdges);
97103 QStringList demoEdgesCompleted() const;
@@ -119,6 +125,7 @@ public:
119125
120126Q_SIGNALS:
121127 void userChanged();
128+ void greeterModeChanged();
122129 void demoEdgesChanged();
123130 void demoEdgesCompletedChanged();
124131 void enableFingerprintIdentificationChanged();
@@ -167,6 +174,7 @@ private:
167174 AccountsServiceDBusAdaptor *m_service;
168175 QDBusInterface *m_unityInput;
169176 QString m_user;
177+ bool m_greeterMode;
170178};
171179
172180#endif
plugins/LightDM/CMakeLists.txt+16−9
@@ -1,19 +1,20 @@
11pkg_check_modules(LIBUSERMETRICSOUTPUT REQUIRED libusermetricsoutput-1)
22
3−find_package(Qt5Core REQUIRED)
4−find_package(Qt5Quick REQUIRED)
5−
63include_directories(
74 ${CMAKE_CURRENT_SOURCE_DIR}
85 ${CMAKE_CURRENT_BINARY_DIR}
96 ${CMAKE_SOURCE_DIR}/plugins/Utils
10− ${CMAKE_BINARY_DIR}/tests/mocks/LightDM/IntegratedLightDM
117 ${libunity8-private_SOURCE_DIR}
8+ )
9+
10+include_directories(
11+ SYSTEM
12+ ${LIBLIGHTDM_INCLUDE_DIRS}
1213 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
13−)
14+ )
1415
15−set(QMLPLUGIN_SRC
16− ../Utils/unitysortfilterproxymodelqml.cpp
16+add_library(LightDM-qml MODULE
17+ ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
1718 DBusGreeter.cpp
1819 DBusGreeterList.cpp
1920 Greeter.cpp
@@ -22,5 +23,11 @@ set(QMLPLUGIN_SRC
2223 UsersModel.cpp
2324 )
2425
25−add_subdirectory(FullLightDM)
26−add_subdirectory(IntegratedLightDM)
26+target_link_libraries(LightDM-qml
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()
147147 Q_EMIT isAuthenticatedChanged();
148148 Q_EMIT authenticationComplete();
149149}
150+
151+QObject *Greeter::mock()
152+{
153+ Q_D(Greeter);
154+ return d->m_greeter->property("mock").value<QObject*>();
155+}
plugins/LightDM/Greeter.h+4
@@ -40,6 +40,8 @@ class Greeter : public QObject
4040 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
4141 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
4242
43+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
44+
4345public:
4446 explicit Greeter(QObject* parent=0);
4547
@@ -50,6 +52,8 @@ public:
5052 bool promptless() const;
5153 QString selectUser() const;
5254
55+ QObject *mock();
56+
5357public Q_SLOTS:
5458 void authenticate(const QString &username=QString());
5559 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 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * 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
111111 }
112112}
113113
114+QObject *SessionsModel::mock()
115+{
116+ return m_model->property("mock").value<QObject*>();
117+}
118+
114119SessionsModel::SessionsModel(QObject* parent)
115120 : UnitySortFilterProxyModelQML(parent)
116121{
@@ -120,7 +125,6 @@ SessionsModel::SessionsModel(QObject* parent)
120125 m_roleNames[IconRole] = "icon_url";
121126
122127 setModel(m_model);
123− setSourceModel(m_model);
124128 setSortCaseSensitivity(Qt::CaseInsensitive);
125129 setSortLocaleAware(true);
126130 setSortRole(Qt::DisplayRole);
plugins/LightDM/SessionsModel.h+6
@@ -32,6 +32,9 @@ class SessionsModel : public UnitySortFilterProxyModelQML
3232
3333 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
3434 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
35+
36+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
37+
3538Q_SIGNALS:
3639 void iconSearchDirectoriesChanged();
3740
@@ -55,6 +58,9 @@ public:
5558 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
5659
5760 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
61+
62+ QObject *mock();
63+
5864private:
5965 QLightDM::SessionsModel* m_model;
6066 QHash<int, QByteArray> m_roleNames;
plugins/LightDM/UsersModel.cpp+7
@@ -68,4 +68,11 @@ UsersModel::UsersModel(QObject* parent)
6868 sort(0);
6969}
7070
71+QObject *UsersModel::mock()
72+{
73+ // get through MangleModel down to QLightDM::UsersModel
74+ MangleModel *mangleModel = static_cast<MangleModel*>(sourceModel());
75+ return mangleModel->sourceModel()->property("mock").value<QObject*>();
76+}
77+
7178#include "UsersModel.moc"
plugins/LightDM/UsersModel.h+4
@@ -30,8 +30,12 @@ class UsersModel : public UnitySortFilterProxyModelQML
3030{
3131 Q_OBJECT
3232
33+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
34+
3335public:
3436 explicit UsersModel(QObject* parent=0);
37+
38+ QObject *mock();
3539};
3640
3741#endif
plugins/LightDM/plugin.cpp+2−9
@@ -63,20 +63,13 @@ static QObject *infographic_provider(QQmlEngine *engine, QJSEngine *scriptEngine
6363 return UserMetricsOutput::UserMetrics::getInstance();
6464}
6565
66−void PLUGIN_CLASSNAME::registerTypes(const char *uri)
66+void LightDM::registerTypes(const char *uri)
6767{
6868 qmlRegisterType<QAbstractItemModel>();
6969 qmlRegisterType<UserMetricsOutput::ColorTheme>();
7070
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"));
7672 qmlRegisterSingletonType<QLightDM::Greeter>(uri, 0, 1, "Greeter", greeter_provider);
77−#else
78− #error No library defined in LightDM plugin
79−#endif
8073
8174 qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
8275 qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
plugins/LightDM/plugin.h+1−1
@@ -21,7 +21,7 @@
2121#include <QtQml/QQmlEngine>
2222#include <QtQml/QQmlExtensionPlugin>
2323
24−class PLUGIN_CLASSNAME : public QQmlExtensionPlugin
24+class LightDM : public QQmlExtensionPlugin
2525{
2626 Q_OBJECT
2727 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
plugins/LightDM/qmldir+2−3
@@ -1,3 +1,2 @@
1−module IntegratedLightDM
2−plugin IntegratedLightDM-qml
3−typeinfo IntegratedLightDM.qmltypes
1+module LightDM
2+plugin LightDM-qml
plugins/Unity/Session/dbusunitysessionservice.cpp+3−45
@@ -337,58 +337,16 @@ void DBusUnitySessionService::PromptLock()
337337 // user session.
338338 Q_EMIT LockRequested();
339339 Q_EMIT lockRequested();
340+ Q_EMIT Locked();
340341}
341342
342343void DBusUnitySessionService::Lock()
343344{
344345 // Normal lock (with animation, as compared to PromptLock above). Usually
345346 // used by indicator-session to lock the session in place.
346− //
347− // FIXME: We also -- as a bit of a hack around indicator-session not fully
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.
347+ // Though here we don't really worry about the difference and just call
348+ // PromptLock.
364349 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− });
392350}
393351
394352void DBusUnitySessionService::doUnlock()
plugins/Unity/Session/dbusunitysessionservice.h−3
@@ -262,9 +262,6 @@ public Q_SLOTS:
262262
263263private Q_SLOTS:
264264 void doUnlock();
265−
266−private:
267− void switchToGreeter();
268265};
269266
270267class DBusGnomeSessionManagerWrapper : public UnityDBusObject
qml/Components/Dialogs.qml+4−4
@@ -19,10 +19,10 @@ import QtQuick.Window 2.2
1919import Unity.Application 0.1
2020import Unity.Session 0.1
2121import GlobalShortcut 1.0
22+import LightDM 0.1 as LightDM
2223import Ubuntu.Components 1.3
2324import Unity.Platform 1.0
2425import Utils 0.1
25−import "../Greeter"
2626
2727Item {
2828 id: root
@@ -112,12 +112,12 @@ Item {
112112
113113 GlobalShortcut { // lock screen
114114 shortcut: Qt.Key_ScreenSaver
115− onTriggered: LightDMService.greeter.showGreeter()
115+ onTriggered: LightDM.Greeter.showGreeter()
116116 }
117117
118118 GlobalShortcut { // lock screen
119119 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
120− onTriggered: LightDMService.greeter.showGreeter()
120+ onTriggered: LightDM.Greeter.showGreeter()
121121 }
122122
123123 QtObject {
@@ -151,7 +151,7 @@ Item {
151151 Button {
152152 text: i18n.ctr("Button: Lock the system", "Lock")
153153 onClicked: {
154− LightDMService.greeter.showGreeter()
154+ LightDM.Greeter.showGreeter()
155155 logoutDialog.hide();
156156 }
157157 }
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
1818import AccountsService 0.1
1919import Biometryd 0.0
2020import GSettings 1.0
21+import LightDM 0.1 as LightDM
2122import Powerd 0.1
2223import Ubuntu.Components 1.3
2324import Ubuntu.SystemImage 0.1
2425import Unity.Launcher 0.1
2526import Unity.Session 0.1
2627
27−import "." 0.1
2828import "../Components"
2929
3030Showable {
@@ -51,7 +51,7 @@ Showable {
5151 readonly property bool hasLockedApp: lockedApp !== ""
5252
5353 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
5555
5656 property bool tabletMode
5757 property url viewSource // only used for testing
@@ -137,16 +137,15 @@ Showable {
137137 }
138138
139139 function sessionToStart() {
140− for (var i = 0; i < LightDMService.sessions.count; i++) {
141− var session = LightDMService.sessions.data(i,
142− LightDMService.sessionRoles.KeyRole);
140+ for (var i = 0; i < LightDM.Sessions.count; i++) {
141+ var session = LightDM.Sessions.data(i, LightDM.SessionRoles.KeyRole);
143142 if (loader.item.sessionToStart === session) {
144143 return session;
145144 }
146145 }
147146
148− if (loader.item.sessionToStart === LightDMService.greeter.defaultSession) {
149− return LightDMService.greeter.defaultSession;
147+ if (loader.item.sessionToStart === LightDM.Greeter.defaultSession) {
148+ return LightDM.Greeter.defaultSession;
150149 } else {
151150 return "ubuntu"; // The default / fallback
152151 }
@@ -155,8 +154,8 @@ Showable {
155154 QtObject {
156155 id: d
157156
158− readonly property bool multiUser: LightDMService.users.count > 1
159− readonly property int selectUserIndex: d.getUserIndex(LightDMService.greeter.selectUser)
157+ readonly property bool multiUser: LightDM.Users.count > 1
158+ readonly property int selectUserIndex: d.getUserIndex(LightDM.Greeter.selectUser)
160159 property int currentIndex: Math.max(selectUserIndex, 0)
161160 property bool waiting
162161 property bool isLockscreen // true when we are locking an active session, rather than first user login
@@ -184,8 +183,8 @@ Showable {
184183 return -1;
185184
186185 // Find index for requested user, if it exists
187− for (var i = 0; i < LightDMService.users.count; i++) {
188− if (username === LightDMService.users.data(i, LightDMService.userRoles.NameRole)) {
186+ for (var i = 0; i < LightDM.Users.count; i++) {
187+ if (username === LightDM.Users.data(i, LightDM.UserRoles.NameRole)) {
189188 return i;
190189 }
191190 }
@@ -194,17 +193,17 @@ Showable {
194193 }
195194
196195 function selectUser(index, reset) {
197− if (index < 0 || index >= LightDMService.users.count)
196+ if (index < 0 || index >= LightDM.Users.count)
198197 return;
199198 d.waiting = true;
200199 if (reset) {
201200 loader.item.reset(false /* forceShow */);
202201 }
203202 currentIndex = index;
204− var user = LightDMService.users.data(index, LightDMService.userRoles.NameRole);
203+ var user = LightDM.Users.data(index, LightDM.UserRoles.NameRole);
205204 AccountsService.user = user;
206205 LauncherModel.setUser(user);
207− LightDMService.greeter.authenticate(user); // always resets auth state
206+ LightDM.Greeter.authenticate(user); // always resets auth state
208207 }
209208
210209 function hideView() {
@@ -212,18 +211,22 @@ Showable {
212211 loader.item.enabled = false; // drop OSK and prevent interaction
213212 loader.item.notifyAuthenticationSucceeded(false /* showFakePassword */);
214213 loader.item.hide();
214+ sessionStarted();
215215 }
216216 }
217217
218218 function login() {
219219 d.waiting = true;
220− if (LightDMService.greeter.startSessionSync(root.sessionToStart())) {
221− sessionStarted();
222− hideView();
223− } else if (loader.item) {
220+ var success = LightDM.Greeter.startSessionSync(root.sessionToStart());
221+ d.waiting = false;
222+
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) {
224227 loader.item.notifyAuthenticationFailed();
228+ d.selectUser(d.currentIndex, false);
225229 }
226− d.waiting = false;
227230 }
228231
229232 function startUnlock(toTheRight) {
@@ -236,6 +239,7 @@ Showable {
236239
237240 function checkForcedUnlock(hideNow) {
238241 if (forcedUnlock && shown) {
242+ d.waiting = false;
239243 hideView();
240244 if (hideNow) {
241245 root.hideNow(); // skip hide animation
@@ -382,7 +386,7 @@ Showable {
382386 root.lockedApp = "";
383387 item.forceActiveFocus();
384388 d.selectUser(d.currentIndex, true);
385− LightDMService.infographic.readyForDataChange();
389+ LightDM.Infographic.readyForDataChange();
386390 }
387391
388392 Connections {
@@ -392,7 +396,7 @@ Showable {
392396 }
393397 onResponded: {
394398 if (root.locked) {
395− LightDMService.greeter.respond(response);
399+ LightDM.Greeter.respond(response);
396400 } else {
397401 d.login();
398402 }
@@ -469,18 +473,18 @@ Showable {
469473 Binding {
470474 target: loader.item
471475 property: "userModel"
472− value: LightDMService.users
476+ value: LightDM.Users
473477 }
474478
475479 Binding {
476480 target: loader.item
477481 property: "infographicModel"
478− value: LightDMService.infographic
482+ value: LightDM.Infographic
479483 }
480484 }
481485
482486 Connections {
483− target: LightDMService.greeter
487+ target: LightDM.Greeter
484488
485489 onShowGreeter: root.forceShow()
486490 onHideGreeter: root.forcedUnlock = true
@@ -498,12 +502,12 @@ Showable {
498502 onAuthenticationComplete: {
499503 d.waiting = false;
500504
501− if (LightDMService.greeter.authenticated) {
502− if (!LightDMService.greeter.promptless) {
505+ if (LightDM.Greeter.authenticated) {
506+ if (!LightDM.Greeter.promptless) {
503507 d.login();
504508 }
505509 } else {
506− if (!LightDMService.greeter.promptless) {
510+ if (!LightDM.Greeter.promptless) {
507511 AccountsService.failedLogins++;
508512 }
509513
@@ -524,7 +528,7 @@ Showable {
524528 }
525529
526530 loader.item.notifyAuthenticationFailed();
527− if (!LightDMService.greeter.promptless) {
531+ if (!LightDM.Greeter.promptless) {
528532 d.selectUser(d.currentIndex, false);
529533 }
530534 }
@@ -543,20 +547,20 @@ Showable {
543547 }
544548
545549 Binding {
546− target: LightDMService.greeter
550+ target: LightDM.Greeter
547551 property: "active"
548552 value: root.active
549553 }
550554
551555 Binding {
552− target: LightDMService.infographic
556+ target: LightDM.Infographic
553557 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) : ""
555559 }
556560
557561 Connections {
558562 target: i18n
559− onLanguageChanged: LightDMService.infographic.readyForDataChange()
563+ onLanguageChanged: LightDM.Infographic.readyForDataChange()
560564 }
561565
562566 Observer {
@@ -606,7 +610,7 @@ Showable {
606610 failOperation("fingerprint reader is locked");
607611 return;
608612 }
609− if (result !== LightDMService.users.data(d.currentIndex, LightDMService.userRoles.UidRole)) {
613+ if (result !== LightDM.Users.data(d.currentIndex, LightDM.UserRoles.UidRole)) {
610614 AccountsService.failedFingerprintLogins++;
611615 failOperation("not the selected user");
612616 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
1818import QtGraphicalEffects 1.0
1919import Ubuntu.Components 1.3
2020import "../Components"
21−import "." 0.1
2221
2322StyledItem {
2423 id: root
@@ -257,8 +256,8 @@ StyledItem {
257256
258257 readonly property alias icon: badge.source
259258
260− visible: LightDMService.sessions.count > 1 &&
261− !LightDMService.users.data(userList.currentIndex, LightDMService.userRoles.LoggedInRole)
259+ visible: LightDM.Sessions.count > 1 &&
260+ !LightDM.Users.data(userList.currentIndex, LightDM.UserRoles.LoggedInRole)
262261
263262 height: units.gu(3.5)
264263 width: units.gu(3.5)
@@ -288,7 +287,7 @@ StyledItem {
288287 anchors.margins: units.dp(3)
289288 keyColor: "#ffffff" // icon providers give us white icons
290289 color: theme.palette.normal.raisedSecondaryText
291− source: LightDMService.sessions.iconUrl(root.currentSession)
290+ source: LightDM.Sessions.iconUrl(root.currentSession)
292291 }
293292
294293 KeyNavigation.tab: passwordInput
@@ -304,9 +303,9 @@ StyledItem {
304303 // Refresh the icon path if looking at different places at runtime
305304 // this is mainly for testing
306305 Connections {
307− target: LightDMService.sessions
306+ target: LightDM.Sessions
308307 onIconSearchDirectoriesChanged: {
309− badge.source = LightDMService.sessions.iconUrl(root.currentSession)
308+ badge.source = LightDM.Sessions.iconUrl(root.currentSession)
310309 }
311310 }
312311 }
qml/Greeter/SessionsList.qml+3−4
@@ -17,7 +17,6 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.Components.ListItems 1.3
20−import "." 0.1
2120import "../Components"
2221
2322Item {
@@ -43,8 +42,8 @@ Item {
4342 }
4443
4544 function currentKey() {
46− var session = LightDMService.sessions.data(
47− sessionsList.currentIndex, LightDMService.sessionRoles.KeyRole)
45+ var session = LightDM.Sessions.data(
46+ sessionsList.currentIndex, LightDM.SessionRoles.KeyRole)
4847 return session;
4948 }
5049
@@ -106,7 +105,7 @@ Item {
106105
107106 boundsBehavior: Flickable.StopAtBounds
108107
109− model: LightDMService.sessions
108+ model: LightDM.Sessions
110109 header: ListItemLayout {
111110 id: header
112111
qml/Greeter/WideView.qml+1−2
@@ -16,7 +16,6 @@
1616
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
19−import "." 0.1
2019
2120FocusScope {
2221 id: root
@@ -141,7 +140,7 @@ FocusScope {
141140 Behavior on boxVerticalOffset { UbuntuNumberAnimation {} }
142141
143142 model: root.userModel
144− currentSession: LightDMService.greeter.defaultSession
143+ currentSession: LightDM.Greeter.defaultSession
145144 onResponded: root.responded(response)
146145 onSelected: root.selected(index)
147146 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
2727import GlobalShortcut 1.0 // has to be before Utils, because of WindowInputFilter
2828import GSettings 1.0
2929import ImageCache 0.1
30+import LightDM 0.1 as LightDM
3031import Utils 0.1
3132import Powerd 0.1
3233import SessionBroadcast 0.1
@@ -209,6 +210,12 @@ StyledItem {
209210 value: ApplicationManager
210211 }
211212
213+ Binding {
214+ target: AccountsService
215+ property: "greeterMode"
216+ value: shell.mode === "greeter"
217+ }
218+
212219 Component.onCompleted: {
213220 finishStartUpTimer.start();
214221 }
@@ -542,7 +549,7 @@ StyledItem {
542549 if (shell.mode === "greeter") {
543550 SessionBroadcast.requestHomeShown(AccountsService.user);
544551 } else {
545− var animate = !LightDMService.greeter.active && !stages.shown;
552+ var animate = !LightDM.Greeter.active && !stages.shown;
546553 dash.setCurrentScope(0, animate, false);
547554 ApplicationManager.requestFocusApplication("unity8-dash");
548555 }
@@ -600,7 +607,7 @@ StyledItem {
600607 readonly property bool focusedSurfaceIsFullscreen: MirFocusController.focusedSurface
601608 ? MirFocusController.focusedSurface.state === Mir.FullscreenState
602609 : false
603− fullscreenMode: (focusedSurfaceIsFullscreen && !LightDMService.greeter.active && launcher.progress == 0)
610+ fullscreenMode: (focusedSurfaceIsFullscreen && !LightDM.Greeter.active && launcher.progress == 0)
604611 || greeter.hasLockedApp
605612 locked: greeter && greeter.active
606613 }
tests/CMakeLists.txt+1−1
@@ -45,8 +45,8 @@ macro(unity8_parse_arguments)
4545
4646 set(ld_paths)
4747 list(APPEND ld_paths
48+ ${UNITY_MOCKPATH}/liblightdm
4849 ${UNITY_MOCKPATH}/libusermetrics
49− ${UNITY_MOCKPATH}/LightDM/IntegratedLightDM/liblightdm
5050 )
5151
5252 string(REPLACE ";" ":" ld_library_path "${ld_paths}")
tests/autopilot/unity8/fixture_setup.py+1−1
@@ -74,7 +74,7 @@ class LaunchUnityWithFakeSensors(fixtures.Fixture):
7474 def _get_lightdm_mock_path(self):
7575 lib_path = get_mocks_library_path()
7676 lightdm_mock_path = os.path.abspath(
77− os.path.join(lib_path, "LightDM" ,"IntegratedLightDM", "liblightdm")
77+ os.path.join(lib_path, "liblightdm")
7878 )
7979
8080 if not os.path.exists(lightdm_mock_path):
tests/autopilot/unity8/shell/tests/__init__.py+1−1
@@ -261,7 +261,7 @@ class UnityTestCase(AutopilotTestCase):
261261 def _get_lightdm_mock_path(self):
262262 lib_path = get_mocks_library_path()
263263 lightdm_mock_path = os.path.abspath(
264− os.path.join(lib_path, "LightDM" ,"IntegratedLightDM", "liblightdm")
264+ os.path.join(lib_path, "liblightdm")
265265 )
266266
267267 if not os.path.exists(lightdm_mock_path):
tests/mocks/AccountsService/AccountsService.cpp+18−3
@@ -15,7 +15,8 @@
1515 */
1616
1717#include "AccountsService.h"
18−#include "MockUsersModel.h"
18+#include "MockController.h"
19+#include "UsersModel.h"
1920
2021#include <QLightDM/UsersModel>
2122#include <paths.h>
@@ -26,6 +27,7 @@ AccountsService::AccountsService(QObject* parent)
2627 m_enableLauncherWhileLocked(true),
2728 m_enableIndicatorsWhileLocked(true),
2829 m_backgroundFile(),
30+ m_greeterMode(true),
2931 m_statsWelcomeScreen(true),
3032 m_failedLogins(0),
3133 m_failedFingerprintLogins(0),
@@ -33,9 +35,9 @@ AccountsService::AccountsService(QObject* parent)
3335 m_demoEdgesCompleted(),
3436 m_hereEnabled(false),
3537 m_hereLicensePath(""),
36− m_usersModel(new MockUsersModel(this))
38+ m_usersModel(new UsersModel(this))
3739{
38− m_usersModel->setMockMode("full");
40+ QLightDM::MockController::instance()->setUserMode("full");
3941}
4042
4143QString AccountsService::user() const
@@ -51,6 +53,19 @@ void AccountsService::setUser(const QString &user)
5153 Q_EMIT backgroundFileChanged();
5254}
5355
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+
5469bool AccountsService::demoEdges() const
5570{
5671 return m_demoEdges;
tests/mocks/AccountsService/AccountsService.h+10−2
@@ -22,7 +22,7 @@
2222#include <QStringList>
2323#include <QVariant>
2424
25−class MockUsersModel;
25+class UsersModel;
2626
2727class AccountsService: public QObject
2828{
@@ -32,6 +32,10 @@ class AccountsService: public QObject
3232 READ user
3333 WRITE setUser
3434 NOTIFY userChanged)
35+ Q_PROPERTY (bool greeterMode
36+ READ greeterMode
37+ WRITE setGreeterMode
38+ NOTIFY greeterModeChanged)
3539 Q_PROPERTY (bool demoEdges
3640 READ demoEdges
3741 WRITE setDemoEdges
@@ -99,6 +103,8 @@ public:
99103
100104 QString user() const;
101105 void setUser(const QString &user);
106+ bool greeterMode() const;
107+ void setGreeterMode(bool greeterMode);
102108 bool demoEdges() const;
103109 void setDemoEdges(bool demoEdges);
104110 QStringList demoEdgesCompleted() const;
@@ -133,6 +139,7 @@ public:
133139
134140Q_SIGNALS:
135141 void userChanged();
142+ void greeterModeChanged();
136143 void demoEdgesChanged();
137144 void demoEdgesCompletedChanged();
138145 void enableFingerprintIdentificationChanged();
@@ -155,6 +162,7 @@ private:
155162 bool m_enableIndicatorsWhileLocked;
156163 QString m_backgroundFile;
157164 QString m_user;
165+ bool m_greeterMode;
158166 bool m_statsWelcomeScreen;
159167 uint m_failedLogins;
160168 uint m_failedFingerprintLogins;
@@ -165,7 +173,7 @@ private:
165173 QString m_realName;
166174 QStringList m_kbdMap;
167175 QString m_email;
168− MockUsersModel *m_usersModel;
176+ UsersModel *m_usersModel;
169177};
170178
171179#endif
tests/mocks/AccountsService/CMakeLists.txt+6−2
@@ -2,13 +2,17 @@ include_directories(
22 ${CMAKE_CURRENT_BINARY_DIR}
33 ${CMAKE_SOURCE_DIR}/plugins/LightDM
44 ${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}
611 )
712
813add_library(MockAccountsService-qml MODULE
914 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
1015 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
11− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.cpp
1216 AccountsService.cpp
1317 plugin.cpp
1418 )
tests/mocks/CMakeLists.txt+1−1
@@ -33,8 +33,8 @@ add_subdirectory(Biometryd)
3333add_subdirectory(Cursor)
3434add_subdirectory(GSettings.1.0)
3535add_subdirectory(indicator-service)
36+add_subdirectory(liblightdm)
3637add_subdirectory(libusermetrics)
37−add_subdirectory(LightDM)
3838add_subdirectory(Lights)
3939add_subdirectory(MeeGo)
4040add_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 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
33 * Copyright (C) 2010-2011 David Edmundson.
44 * Copyright (C) 2010-2011 Robert Ancell
55 *
@@ -21,17 +21,12 @@
2121#ifndef UNITY_MOCK_GREETER_H
2222#define UNITY_MOCK_GREETER_H
2323
24−#include <QtCore/QObject>
25−#include <QtCore/QVariant>
26−
27−/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28− * CHANGES MADE HERE MUST BE REFLECTED ON THE MOCK LIB
29− * COUNTERPART IN tests/mocks/Lightdm/liblightdm
30− * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
24+#include <QObject>
25+#include <QVariant>
3126
3227namespace QLightDM
3328{
34− class GreeterPrivate;
29+class GreeterPrivate;
3530
3631class Q_DECL_EXPORT Greeter : public QObject
3732{
@@ -48,6 +43,8 @@ class Q_DECL_EXPORT Greeter : public QObject
4843
4944 Q_ENUMS(PromptType MessageType)
5045
46+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
47+
5148public:
5249 enum PromptType {
5350 PromptTypeQuestion,
@@ -79,6 +76,8 @@ public:
7976 QString authenticationUser() const;
8077 QString hostname() const;
8178
79+ QObject *mock();
80+
8281public Q_SLOTS:
8382 bool connectSync();
8483 void authenticate(const QString &username=QString());
@@ -96,10 +95,12 @@ Q_SIGNALS:
9695 void authenticationComplete();
9796 void autologinTimerExpired();
9897
99−protected:
100− void sendAuthenticationComplete();
98+private Q_SLOTS:
99+ void handleAuthenticate();
101100
102101private:
102+ void sendAuthenticationComplete();
103+
103104 GreeterPrivate *d_ptr;
104105 Q_DECLARE_PRIVATE(Greeter)
105106};
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp → tests/mocks/liblightdm/MockSessionsModel.cpprenamed+41−40
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -21,22 +21,34 @@
2121// set our compatibility to Qt4 here too.
2222#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
2323
24−#include "SessionsModel.h"
25−#include "SessionsModelPrivate.h"
26−#include <QtCore/QDir>
27−#include <QtCore/QString>
24+#include "MockController.h"
25+#include "MockSessionsModel.h"
2826
2927namespace QLightDM
3028{
3129
32−SessionsModel::SessionsModel(QObject* parent) :
33− QAbstractListModel(parent),
34− d_ptr(new SessionsModelPrivate(this))
30+class SessionsModelPrivate
31+{
32+public:
33+ QHash<int, QByteArray> roleNames;
34+ QList<MockController::SessionItem> sessionItems;
35+};
36+
37+SessionsModel::SessionsModel(QObject* parent)
38+ : QAbstractListModel(parent)
39+ , d_ptr(new SessionsModelPrivate)
3540{
3641 Q_D(SessionsModel);
37− m_roleNames = QAbstractListModel::roleNames();
38− m_roleNames[KeyRole] = "key";
39− m_roleNames[TypeRole] = "type";
42+
43+ d->roleNames = QAbstractListModel::roleNames();
44+ d->roleNames[KeyRole] = "key";
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();
4052}
4153
4254SessionsModel::~SessionsModel()
@@ -66,7 +78,9 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
6678
6779QHash<int, QByteArray> SessionsModel::roleNames() const
6880{
69− return m_roleNames;
81+ Q_D(const SessionsModel);
82+
83+ return d->roleNames;
7084}
7185
7286int SessionsModel::rowCount(const QModelIndex& parent) const
@@ -80,42 +94,29 @@ int SessionsModel::rowCount(const QModelIndex& parent) const
8094 }
8195}
8296
83−int SessionsModel::numSessions() const
97+void SessionsModel::resetEntries()
8498{
85− Q_D(const SessionsModel);
86− return d->numSessions;
87−}
88−
89−int SessionsModel::numAvailableSessions() const
90−{
91− Q_D(const SessionsModel);
92− return d->numAvailableSessions();
93−}
99+ Q_D(SessionsModel);
94100
95−QString SessionsModel::testScenario() const
96−{
97− Q_D(const SessionsModel);
98− return d->testScenario;
99−}
101+ beginResetModel();
100102
101−void SessionsModel::setNumSessions(int numSessions)
102−{
103− Q_D(SessionsModel);
103+ QString sessionMode = MockController::instance()->sessionMode();
104104
105− if (d->numSessions != numSessions) {
106− d->numSessions = numSessions;
107− d->resetEntries();
105+ if (sessionMode == "full") {
106+ d->sessionItems = MockController::instance()->fullSessionItems();
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 = {};
108112 }
113+
114+ endResetModel();
109115}
110116
111−void SessionsModel::setTestScenario(QString testScenario)
117+QObject *SessionsModel::mock()
112118{
113− Q_D(SessionsModel);
114−
115− if (d->testScenario != testScenario) {
116− d->testScenario = testScenario;
117− d->resetEntries();
118− }
119+ return MockController::instance();
119120}
120121
121122} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h → tests/mocks/liblightdm/MockSessionsModel.hrenamed+11−12
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -18,8 +18,10 @@
1818#ifndef UNITY_MOCK_SESSIONSMODEL_H
1919#define UNITY_MOCK_SESSIONSMODEL_H
2020
21−#include <QtCore/QAbstractListModel>
22−#include <QtCore/QString>
21+#include <QAbstractListModel>
22+#include <QByteArray>
23+#include <QHash>
24+#include <QString>
2325
2426namespace QLightDM
2527{
@@ -29,10 +31,11 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
2931 {
3032 Q_OBJECT
3133
34+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
35+
3236 Q_ENUMS(SessionModelRoles SessionType)
3337
3438 public:
35−
3639 enum SessionModelRoles {
3740 //name is exposed as Qt::DisplayRole
3841 //comment is exposed as Qt::TooltipRole
@@ -54,17 +57,13 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
5457 int rowCount(const QModelIndex& parent) const override;
5558 QVariant data(const QModelIndex& index, int role) const override;
5659
57− int numSessions() const;
58− int numAvailableSessions() const;
59− QString testScenario() const;
60− void setNumSessions(int numSessions);
61− void setTestScenario(QString testScenario);
60+ QObject *mock();
6261
63− protected:
64− SessionsModelPrivate* const d_ptr;
62+ private Q_SLOTS:
63+ void resetEntries();
6564
6665 private:
67− QHash<int, QByteArray> m_roleNames;
66+ SessionsModelPrivate *d_ptr;
6867 Q_DECLARE_PRIVATE(SessionsModel)
6968 };
7069}
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 @@
11/*
2− * Copyright (C) 2013-2014 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
33 * Copyright (C) 2010-2011 David Edmundson.
44 *
55 * This program is free software; you can redistribute it and/or modify
@@ -18,10 +18,9 @@
1818#ifndef UNITY_MOCK_USERSMODEL_H
1919#define UNITY_MOCK_USERSMODEL_H
2020
21−#include <QtCore/QString>
22−#include <QtCore/QSharedDataPointer>
2321#include <QAbstractListModel>
24−
22+#include <QList>
23+#include <QString>
2524
2625namespace QLightDM
2726{
@@ -33,11 +32,7 @@ class Q_DECL_EXPORT UsersModel : public QAbstractListModel
3332
3433 Q_ENUMS(UserModelRoles)
3534
36− //Mock-only API for testing purposes
37− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
38−
39−Q_SIGNALS:
40− void mockModeChanged(QString mode);
35+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
4136
4237public:
4338 explicit UsersModel(QObject *parent = 0);
@@ -57,8 +52,10 @@ public:
5752 int rowCount(const QModelIndex &parent) const override;
5853 QVariant data(const QModelIndex &index, int role) const override;
5954
60− QString mockMode() const;
61− void setMockMode(QString mockMode);
55+ QObject *mock();
56+
57+private Q_SLOTS:
58+ void resetEntries();
6259
6360private:
6461 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()
288288 QSharedPointer<UserMetricsData> data(
289289 new UserMetricsData("<b>52km</b> travelled", first, firstMonth,
290290 ninth, secondMonth, this));
291− m_fakeData.insert("single", data);
291+ m_fakeData.insert("has-password", data);
292292 m_fakeData.insert("has-pin", data);
293293 }
294294
@@ -304,7 +304,7 @@ void UserMetricsPrivate::generateFakeData()
304304 QSharedPointer<UserMetricsData> data(
305305 new UserMetricsData("<b>33</b> messages today", second,
306306 firstMonth, eighth, secondMonth, this));
307− m_fakeData.insert("single", data);
307+ m_fakeData.insert("has-password", data);
308308 m_fakeData.insert("has-pin", data);
309309 }
310310
@@ -321,10 +321,8 @@ void UserMetricsPrivate::generateFakeData()
321321 QSharedPointer<UserMetricsData> data(
322322 new UserMetricsData("<b>19</b> minutes talk time", eighth,
323323 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
327324 m_fakeData.insert("has-password", data);
325+ m_fakeData.insert("has-pin", data);
328326 m_fakeData.insert("no-password", data);
329327 m_fakeData.insert("empty-name", data);
330328 }
tests/plugins/AccountsService/AccountsServer.cpp+11
@@ -40,6 +40,8 @@ bool AccountsServer::AddUser(const QString &user)
4040 if (QDBusConnection::sessionBus().objectRegisteredAt(path) != nullptr)
4141 return true;
4242
43+ m_users.insert(path);
44+
4345 auto props = new PropertiesServer(this);
4446 new PropertiesAdaptor(props);
4547 new AccountsUserAdaptor(props);
@@ -52,6 +54,15 @@ bool AccountsServer::RemoveUser(const QString &user)
5254 if (QDBusConnection::sessionBus().objectRegisteredAt(path) == nullptr)
5355 return false;
5456
57+ m_users.remove(path);
5558 QDBusConnection::sessionBus().unregisterObject(path);
5659 return true;
5760}
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 @@
2323#include <QDBusContext>
2424#include <QDBusObjectPath>
2525#include <QObject>
26+#include <QSet>
2627#include <QString>
2728
2829class AccountsServer: public QObject, protected QDBusContext
@@ -39,6 +40,10 @@ public Q_SLOTS:
3940 // mock only.
4041 bool AddUser(const QString &user);
4142 bool RemoveUser(const QString &user);
43+ void RemoveAllUsers();
44+
45+private:
46+ QSet<QString> m_users;
4247};
4348
4449#endif
tests/plugins/AccountsService/client.cpp+71−21
@@ -26,6 +26,8 @@
2626#include <QDBusReply>
2727#include <QDBusMetaType>
2828
29+#include <glib.h>
30+
2931template <class T>
3032QVariant dbusVariant(const T& value) { return QVariant::fromValue(QDBusVariant(value)); }
3133
@@ -62,11 +64,7 @@ public:
6264private Q_SLOTS:
6365
6466 void init() {
65− QDBusReply<bool> addReply = QDBusInterface("org.freedesktop.Accounts",
66− "/org/freedesktop/Accounts",
67− "org.freedesktop.Accounts").call("AddUser", QTest::currentTestFunction());
68− QVERIFY(addReply.isValid());
69− QCOMPARE(addReply.value(), true);
67+ addUser(QTest::currentTestFunction());
7068
7169 m_userInterface = new QDBusInterface("org.freedesktop.Accounts",
7270 QString("/%1").arg(QTest::currentTestFunction()),
@@ -77,17 +75,46 @@ private Q_SLOTS:
7775 }
7876
7977 void cleanup() {
80− QDBusReply<bool> reply = QDBusInterface("org.freedesktop.Accounts",
78+ QDBusReply<void> reply = QDBusInterface("org.freedesktop.Accounts",
8179 "/org/freedesktop/Accounts",
82− "org.freedesktop.Accounts").call("RemoveUser", QTest::currentTestFunction());
80+ "org.freedesktop.Accounts").call("RemoveAllUsers");
8381 QVERIFY(reply.isValid());
84− QCOMPARE(reply.value(), true);
8582
8683 delete m_userInterface;
8784 m_spy.clear();
8885 m_mousePrimaryButtonSpy.clear();
8986 }
9087
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+
91118 void testInvalids()
92119 {
93120 // Test various invalid calls
@@ -323,25 +350,16 @@ private Q_SLOTS:
323350 QCOMPARE(message.type(), QDBusMessage::ErrorMessage);
324351 QCOMPARE(message.errorName(), QStringLiteral("org.freedesktop.DBus.Error.InvalidArgs"));
325352
326− message = m_userInterface->call("Get",
327− "org.freedesktop.Accounts.User",
328− "RealName");
329− QCOMPARE(message.type(), QDBusMessage::ReplyMessage);
330− auto response = message.arguments().first().value<QDBusVariant>().variant().toString();
331− QCOMPARE(response, QStringLiteral(""));
353+ auto response = getASProperty("org.freedesktop.Accounts.User", "RealName");
354+ QCOMPARE(response.toString(), QStringLiteral(""));
332355
333356 // Now try it via our AS wrapper and confirm it did get through, unlike above
334357 session.setRealName("Stallman");
335358
336359 QCOMPARE(session.realName(), QStringLiteral("Stallman"));
337360
338− message = m_userInterface->call("Get",
339− "org.freedesktop.Accounts.User",
340− "RealName");
341− QCOMPARE(message.type(), QDBusMessage::ReplyMessage);
342− response = message.arguments().first().value<QDBusVariant>().variant().toString();
343− QCOMPARE(response, QStringLiteral("Stallman"));
344−
361+ response = getASProperty("org.freedesktop.Accounts.User", "RealName");
362+ QCOMPARE(response.toString(), QStringLiteral("Stallman"));
345363 }
346364
347365 void testAsynchronousChangeForKeymaps()
@@ -367,6 +385,38 @@ private Q_SLOTS:
367385 QTRY_COMPARE(session.keymaps(), result);
368386 }
369387
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+
370420Q_SIGNALS:
371421 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
372422 void setMousePrimaryButtonCalled(int button);
tests/plugins/AccountsService/interfaces.xml+1
@@ -36,6 +36,7 @@
3636 <arg name="user" type="s" direction="in" />
3737 <arg name="success" type="b" direction="out" />
3838 </method>
39+ <method name="RemoveAllUsers"/>
3940 </interface>
4041 <interface name="com.ubuntu.AccountsService.Input" />
4142 <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 @@
1515 */
1616
1717import QtQuick 2.4
18−import LightDM.IntegratedLightDM 0.1 as LightDM
18+import LightDM 0.1 as LightDM
1919
2020Item {
2121 property var greeter: LightDM.Greeter
22− Binding {
23− target: LightDM.Greeter
24− property: "mockMode"
25− value: "full"
26− }
2722}
tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp → tests/plugins/LightDM/sessionsmodel.cpprenamed+14−15
@@ -16,10 +16,9 @@
1616
1717#include "SessionsModel.h"
1818
19−#include <QLightDM/SessionsModel>
20−#include <QtCore/QModelIndex>
21−#include <QtTest>
19+#include <QModelIndex>
2220#include <QString>
21+#include <QtTest>
2322
2423class GreeterSessionsModelTest : public QObject
2524{
@@ -31,14 +30,14 @@ private Q_SLOTS:
3130 {
3231 model = new SessionsModel();
3332 QVERIFY(model);
34− sourceModel = new QLightDM::SessionsModel();
35− QVERIFY(sourceModel);
33+ mock = model->mock();
34+ QVERIFY(mock);
3635 }
3736
3837 void cleanup()
3938 {
4039 delete model;
41− delete sourceModel;
40+ // mock will be a singleton, doesn't need to be cleaned
4241 }
4342
4443 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
@@ -93,34 +92,34 @@ private Q_SLOTS:
9392
9493 void testMultipleSessionsCountIsCorrect()
9594 {
96− sourceModel->setTestScenario("multipleSessions");
97− QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
95+ mock->setProperty("sessionMode", "full");
96+ QVERIFY(model->rowCount(QModelIndex()) > 1);
9897 }
9998
10099 void testNoSessionsCountIsCorrect()
101100 {
102− sourceModel->setTestScenario("noSessions");
103− QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
101+ mock->setProperty("sessionMode", "none");
102+ QVERIFY(model->rowCount(QModelIndex()) == 0);
104103 }
105104
106105 void testSingleSessionCountIsCorrect()
107106 {
108− sourceModel->setTestScenario("singleSession");
109− QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
107+ mock->setProperty("sessionMode", "single");
108+ QVERIFY(model->rowCount(QModelIndex()) == 1);
110109 }
111110
112111 void testSessionNameIsCorrect()
113112 {
114113 // This is testing the lookup, not the correctness of the strings,
115114 // so one test should be sufficient
116− sourceModel->setTestScenario("multipleSessions");
117− QVERIFY(model->data(findByKey(sourceModel, "ubuntu"),
115+ mock->setProperty("sessionMode", "full");
116+ QVERIFY(model->data(findByKey(model, "ubuntu"),
118117 Qt::DisplayRole).toString() == "Ubuntu");
119118 }
120119
121120private:
122121 SessionsModel *model;
123− QLightDM::SessionsModel *sourceModel;
122+ QObject *mock;
124123};
125124
126125QTEST_MAIN(GreeterSessionsModelTest)
tests/plugins/LightDM/IntegratedLightDM/usersmodel.cpp → tests/plugins/LightDM/usersmodel.cpprenamed+4−14
@@ -46,37 +46,27 @@ private Q_SLOTS:
4646 {
4747 model = new UsersModel();
4848 QVERIFY(model);
49− sourceModel = new QLightDM::UsersModel();
50− QVERIFY(sourceModel);
5149 }
5250
5351 void cleanup()
5452 {
5553 delete model;
56− delete sourceModel;
5754 }
5855
5956 void testMangleColor()
6057 {
61− QString background = getStringValue(sourceModel, "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>");
58+ auto background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
59+ QCOMPARE(background, QString("data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#E95420'/></svg>"));
6660 }
6761
6862 void testMangleEmptyName()
6963 {
70− QString name = getStringValue(sourceModel, "empty-name", QLightDM::UsersModel::RealNameRole);
71− QVERIFY(name == "");
72−
73− name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
74− QVERIFY(name == "empty-name");
64+ auto name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
65+ QCOMPARE(name, QString("empty-name"));
7566 }
7667
7768private:
7869 UsersModel *model;
79− QLightDM::UsersModel *sourceModel;
8070};
8171
8272QTEST_MAIN(GreeterUsersModelTest)
tests/plugins/Unity/Session/sessionbackendtest.cpp−1
@@ -62,7 +62,6 @@ private Q_SLOTS:
6262 QTest::newRow("Shutdown") << "RequestShutdown" << "ShutdownRequested(bool)";
6363 QTest::newRow("PromptLock") << "PromptLock" << "LockRequested()";
6464 QTest::newRow("Lock") << "Lock" << "LockRequested()";
65− QTest::newRow("LockLightDM") << "Lock" << "Locked()"; // happens when we lock LightDM, only for Lock()
6665 }
6766
6867 void testUnitySessionLogoutRequested() {
tests/qmltests/Dash/tst_DashShell.qml+7
@@ -20,12 +20,19 @@ import "../../../qml/Dash"
2020import "../../../qml/"
2121import Ubuntu.Components 1.3
2222import Unity.Test 0.1 as UT
23+import LightDM 0.1 as LightDM
2324
2425Item {
2526 id: root
2627 width: units.gu(80)
2728 height: units.gu(80)
2829
30+ Binding {
31+ target: LightDM.Users.mock
32+ property: "userMode"
33+ value: "single"
34+ }
35+
2936 Shell {
3037 id: shell
3138 width: parent.width / 2
tests/qmltests/Greeter/TestView.qml+1
@@ -32,6 +32,7 @@ Item {
3232 property bool alphanumeric
3333 property var userModel
3434 property var infographicModel
35+ property bool waiting
3536 readonly property bool fullyShown: _fullyShown
3637 readonly property bool required: _required
3738 readonly property bool animating: _animating
tests/qmltests/Greeter/tst_Greeter.qml+5−8
@@ -22,7 +22,7 @@ import Ubuntu.Components 1.3
2222import AccountsService 0.1
2323import Biometryd 0.0
2424import GSettings 1.0
25−import LightDM.IntegratedLightDM 0.1 as LightDM // This is the mock
25+import LightDM 0.1 as LightDM
2626import Unity.Test 0.1 as UT
2727
2828Item {
@@ -32,9 +32,6 @@ Item {
3232 property url defaultBackground: "/usr/share/backgrounds/warty-final-ubuntu.png"
3333
3434 Component.onCompleted: {
35− // set the mock mode before loading
36− LightDM.Greeter.mockMode = "full";
37− LightDM.Users.mockMode = "full";
3835 loader.active = true;
3936 }
4037
@@ -146,7 +143,7 @@ Item {
146143
147144 function init() {
148145 greeterSettings.lockedOutTime = 0;
149− LightDM.Greeter.selectUser = "";
146+ LightDM.Greeter.mock.selectUserHint = "";
150147 greeter.failedLoginsDelayAttempts = 7;
151148 greeter.failedLoginsDelayMinutes = 5;
152149 teaseSpy.clear();
@@ -570,20 +567,20 @@ Item {
570567 }
571568
572569 function test_selectUserHint() {
573− LightDM.Greeter.selectUser = "info-prompt";
570+ LightDM.Greeter.mock.selectUserHint = "info-prompt";
574571 resetLoader();
575572 var i = verifySelected("info-prompt");
576573 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
577574 }
578575
579576 function test_selectUserHintUnset() {
580− LightDM.Greeter.selectUser = "";
577+ LightDM.Greeter.mock.selectUserHint = "";
581578 resetLoader();
582579 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
583580 }
584581
585582 function test_selectUserHintInvalid() {
586− LightDM.Greeter.selectUser = "not-a-real-user";
583+ LightDM.Greeter.mock.selectUserHint = "not-a-real-user";
587584 resetLoader();
588585 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
589586 }
tests/qmltests/Greeter/tst_Infographics.qml+1−11
@@ -20,19 +20,9 @@ import ".."
2020import "../../../qml/Greeter"
2121import Ubuntu.Components 1.3
2222import Unity.Test 0.1 as UT
23−import LightDM.IntegratedLightDM 0.1 as LightDM
23+import LightDM 0.1 as LightDM
2424
2525Item {
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− }
3626 property variant infographicModel: LightDM.Infographic
3727
3828 width: units.gu(120)
tests/qmltests/Greeter/tst_NarrowView.qml+8−2
@@ -18,7 +18,7 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import ".."
2020import "../../../qml/Greeter"
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM 0.1 as LightDM
2222import Ubuntu.Components 1.3
2323import Ubuntu.Telephony 0.1 as Telephony
2424import Unity.Test 0.1 as UT
@@ -30,6 +30,12 @@ Item {
3030
3131 Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark" // use the same theme as the real shell
3232
33+ Binding {
34+ target: LightDM.Users.mock
35+ property: "userMode"
36+ value: "single"
37+ }
38+
3339 Row {
3440 anchors.fill: parent
3541 Loader {
@@ -252,7 +258,7 @@ Item {
252258 Binding {
253259 target: LightDM.Infographic
254260 property: "username"
255− value: "single"
261+ value: "has-password"
256262 }
257263
258264 SignalSpy {
tests/qmltests/Greeter/tst_WideView.qml+15−23
@@ -18,7 +18,7 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import ".."
2020import "../../../qml/Greeter"
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM 0.1 as LightDM
2222import Ubuntu.Components 1.3
2323import Unity.Test 0.1 as UT
2424
@@ -31,12 +31,6 @@ StyledItem {
3131
3232 theme.name: "Ubuntu.Components.Themes.SuruDark"
3333
34− Binding {
35− target: LightDM.Users
36− property: "mockMode"
37− value: "full"
38− }
39−
4034 Row {
4135 anchors.fill: parent
4236 Loader {
@@ -271,15 +265,15 @@ StyledItem {
271265 id: multipleSessionsCheckbox
272266 onClicked: {
273267 if (checked) {
274− LightDM.Sessions.testScenario = "multipleSessions"
268+ LightDM.Sessions.mock.sessionMode = "full";
275269 } else {
276− LightDM.Sessions.testScenario = "singleSession"
270+ LightDM.Sessions.mock.sessionMode = "single";
277271 }
278272 }
279273 Connections {
280− target: LightDM.Sessions
281− onTestScenarioChanged: {
282− if (LightDM.Sessions.testScenario === "multipleSessions") {
274+ target: LightDM.Sessions.mock
275+ onSessionModeChanged: {
276+ if (LightDM.Sessions.mock.sessionMode === "full") {
283277 multipleSessionsCheckbox.checked = true;
284278 } else {
285279 multipleSessionsCheckbox.checked = false;
@@ -297,11 +291,11 @@ StyledItem {
297291
298292 width: units.gu(10)
299293 minimumValue: 0
300− maximumValue: LightDM.Sessions.numAvailableSessions
301− value: LightDM.Sessions.numSessions
302− visible: LightDM.Sessions.testScenario === "multipleSessions"
294+ maximumValue: LightDM.Sessions.mock.numAvailableSessions
295+ value: LightDM.Sessions.mock.numSessions
296+ visible: LightDM.Sessions.mock.sessionMode === "full"
303297 Binding {
304− target: LightDM.Sessions
298+ target: LightDM.Sessions.mock
305299 property: "numSessions"
306300 value: numSessionsSlider.value
307301 }
@@ -368,7 +362,7 @@ StyledItem {
368362 respondedSpy.clear();
369363 teaseSpy.clear();
370364 emergencySpy.clear();
371− LightDM.Sessions.testScenario = "multipleSessions"
365+ LightDM.Sessions.mock.sessionMode = "full";
372366 }
373367
374368 function cleanup() {
@@ -426,7 +420,6 @@ StyledItem {
426420 }
427421
428422 function test_sessionIconsAreValid() {
429− LightDM.Sessions.testScenario = "multipleSessions"
430423 var originalDirectories = LightDM.Sessions.iconSearchDirectories
431424 LightDM.Sessions.iconSearchDirectories = [testIconDirectory]
432425
@@ -454,7 +447,6 @@ StyledItem {
454447
455448 selectUser("has-password");
456449
457− LightDM.Sessions.testScenario = "multipleSessions";
458450 var sessionChooserButton = findChild(view, "sessionChooserButton");
459451 var icon = String(sessionChooserButton.icon);
460452 compare(icon.indexOf("ubuntu") > -1, true);
@@ -478,12 +470,12 @@ StyledItem {
478470 }
479471
480472 function test_noSessionsDoesntBreakView() {
481− LightDM.Sessions.testScenario = "noSessions"
473+ LightDM.Sessions.mock.sessionMode = "none";
482474 compare(LightDM.Sessions.count, 0)
483475 }
484476
485477 function test_sessionIconNotShownWithOneSession() {
486− LightDM.Sessions.testScenario = "singleSession"
478+ LightDM.Sessions.mock.sessionMode = "single";
487479 compare(LightDM.Sessions.count, 1);
488480
489481 var sessionChooserButton = findChild(view, "sessionChooserButton");
@@ -491,7 +483,7 @@ StyledItem {
491483 }
492484
493485 function test_sessionIconNotShownWithActiveUser() {
494− LightDM.Sessions.testScenario = "multipleSessions";
486+ LightDM.Sessions.mock.sessionMode = "full";
495487 compare(LightDM.Sessions.count > 1, true);
496488
497489 selectUser("active");
@@ -501,7 +493,7 @@ StyledItem {
501493 }
502494
503495 function test_sessionIconShownWithMultipleSessions() {
504− LightDM.Sessions.testScenario = "multipleSessions"
496+ LightDM.Sessions.mock.sessionMode = "full";
505497 compare(LightDM.Sessions.count > 1, true);
506498
507499 selectUser("has-password");
tests/qmltests/Tutorial/tst_Tutorial.qml+2−3
@@ -17,7 +17,7 @@
1717import QtQuick 2.4
1818import QtTest 1.0
1919import AccountsService 0.1
20−import LightDM.IntegratedLightDM 0.1 as LightDM
20+import LightDM 0.1 as LightDM
2121import Ubuntu.Components 1.3
2222import Ubuntu.Components.ListItems 1.3
2323import Ubuntu.Telephony 0.1 as Telephony
@@ -85,8 +85,7 @@ Rectangle {
8585
8686 Component.onCompleted: {
8787 // 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";
9089 shellLoader.active = true;
9190 }
9291
tests/qmltests/tst_OrientedShell.qml+7−1
@@ -22,7 +22,7 @@ import Ubuntu.Components 1.3
2222import Ubuntu.Components.ListItems 1.3 as ListItem
2323import Unity.Application 0.1
2424import Unity.Test 0.1
25−import LightDM.IntegratedLightDM 0.1 as LightDM
25+import LightDM 0.1 as LightDM
2626import Powerd 0.1
2727import Unity.InputInfo 0.1
2828import Utils 0.1
@@ -36,6 +36,12 @@ Rectangle {
3636 width: units.gu(160) + controls.width
3737 height: units.gu(100)
3838
39+ Binding {
40+ target: LightDM.Users.mock
41+ property: "userMode"
42+ value: "single"
43+ }
44+
3945 QtObject {
4046 id: applicationArguments
4147 property string deviceName: "mako"
tests/qmltests/tst_Shell.qml+4−7
@@ -18,7 +18,7 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import AccountsService 0.1
2020import GSettings 1.0
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM 0.1 as LightDM
2222import SessionBroadcast 0.1
2323import Ubuntu.Components 1.3
2424import Ubuntu.Components.ListItems 1.3 as ListItem
@@ -46,8 +46,7 @@ Rectangle {
4646
4747 Component.onCompleted: {
4848 // must set the mock mode before loading the Shell
49− LightDM.Greeter.mockMode = "single";
50− LightDM.Users.mockMode = "single";
49+ LightDM.Users.mock.userMode = "single";
5150 shellLoader.active = true;
5251 }
5352
@@ -203,8 +202,7 @@ Rectangle {
203202 model: ["single", "single-passphrase", "single-pin", "full"]
204203 onSelectedIndexChanged: {
205204 shellLoader.active = false;
206− LightDM.Greeter.mockMode = model[selectedIndex];
207− LightDM.Users.mockMode = model[selectedIndex];
205+ LightDM.Users.mock.userMode = model[selectedIndex];
208206 shellLoader.active = true;
209207 }
210208 }
@@ -875,8 +873,7 @@ Rectangle {
875873 }
876874
877875 function setLightDMMockMode(mode) {
878− LightDM.Greeter.mockMode = mode;
879− LightDM.Users.mockMode = mode;
876+ LightDM.Users.mock.userMode = mode;
880877 }
881878
882879 /*
tests/qmltests/tst_ShellWithPin.qml+2−3
@@ -19,7 +19,7 @@ import Ubuntu.Components 1.3
1919import QtTest 1.0
2020import AccountsService 0.1
2121import GSettings 1.0
22−import LightDM.IntegratedLightDM 0.1 as LightDM
22+import LightDM 0.1 as LightDM
2323import Ubuntu.SystemImage 0.1
2424import Ubuntu.Telephony 0.1 as Telephony
2525import Unity.Application 0.1
@@ -35,8 +35,7 @@ Item {
3535
3636 Component.onCompleted: {
3737 // 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";
4039 shellLoader.active = true;
4140 }
4241