on xenial help sign in
Refactor our lightdm mock
commitddb5511b4f10948bcf37bb23c2df812d6274eeb5 authorMichael Terry <mike@mterry.name> dateFri 16 Dec 2016, 18:24 (10 years ago) parent0d4b032
60 files changed+865−1069
plugins/LightDM/Greeter.cpp+7−1 plugins/LightDM/Greeter.h+6−5 plugins/LightDM/SessionsModel.cpp+6−2 plugins/LightDM/SessionsModel.h+8−5 plugins/LightDM/UsersModel.cpp+8−1 plugins/LightDM/UsersModel.h+6−7 qml/Greeter/LightDMService.qml+3−4 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+2−3 tests/mocks/AccountsService/AccountsService.h+3−6 tests/mocks/AccountsService/CMakeLists.txt+1−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/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+124 tests/mocks/liblightdm/MockController.h+80 tests/mocks/liblightdm/MockGreeter.cpp+256 tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.h → tests/mocks/liblightdm/MockGreeter.h+10−19 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+12−16 tests/mocks/liblightdm/MockUsersModel.cpp+191 tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.h → tests/mocks/liblightdm/MockUsersModel.h+9−15 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/plugins/LightDM/IntegratedLightDM/CMakeLists.txt+1−3 tests/plugins/LightDM/IntegratedLightDM/greeter.qml+2−7 tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+13−13 tests/plugins/LightDM/IntegratedLightDM/usersmodel.cpp+2−12 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
plugins/LightDM/Greeter.cpp+7−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013, 2015 Canonical, Ltd.
2+ * Copyright (C) 2013-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
@@ -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+6−5
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2012,2013,2015 Canonical, Ltd.
2+ * Copyright (C) 2012-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,8 +21,7 @@
2121 such edits in the future, and by inserting ourselves here, we have more
2222 control. */
2323
24−#ifndef UNITY_GREETER_H
25−#define UNITY_GREETER_H
24+#pragma once
2625
2726#include <QLightDM/Greeter>
2827#include <QtCore/QObject>
@@ -40,6 +39,8 @@ class Greeter : public QObject
4039 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
4140 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
4241
42+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
43+
4344public:
4445 explicit Greeter(QObject* parent=0);
4546
@@ -50,6 +51,8 @@ public:
5051 bool promptless() const;
5152 QString selectUser() const;
5253
54+ QObject *mock();
55+
5356public Q_SLOTS:
5457 void authenticate(const QString &username=QString());
5558 void respond(const QString &response);
@@ -81,5 +84,3 @@ private Q_SLOTS:
8184 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
8285 void authenticationCompleteFilter();
8386};
84−
85−#endif
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{
@@ -128,7 +133,6 @@ SessionsModel::SessionsModel(QObject* parent)
128133 }
129134
130135 setModel(m_model);
131− setSourceModel(m_model);
132136 setSortCaseSensitivity(Qt::CaseInsensitive);
133137 setSortLocaleAware(true);
134138 setSortRole(Qt::DisplayRole);
plugins/LightDM/SessionsModel.h+8−5
@@ -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
@@ -15,8 +15,7 @@
1515 *
1616 */
1717
18−#ifndef UNITY_SESSIONSMODEL_H
19−#define UNITY_SESSIONSMODEL_H
18+#pragma once
2019
2120#include <unitysortfilterproxymodelqml.h>
2221#include <QLightDM/SessionsModel>
@@ -32,6 +31,9 @@ class SessionsModel : public UnitySortFilterProxyModelQML
3231
3332 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
3433 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
34+
35+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
36+
3537Q_SIGNALS:
3638 void iconSearchDirectoriesChanged();
3739
@@ -55,6 +57,9 @@ public:
5557 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
5658
5759 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
60+
61+ QObject *mock();
62+
5863private:
5964 QLightDM::SessionsModel* m_model;
6065 QHash<int, QByteArray> m_roleNames;
@@ -64,5 +69,3 @@ private:
6469 QUrl("/usr/share/unity-greeter/")};
6570
6671};
67−
68−#endif // UNITY_SESSIONSMODEL_H
plugins/LightDM/UsersModel.cpp+8−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013,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
@@ -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+6−7
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2012,2013 Canonical, Ltd.
2+ * Copyright (C) 2012-2013,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
@@ -12,16 +12,13 @@
1212 *
1313 * You should have received a copy of the GNU General Public License
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors: Michael Terry <michael.terry@canonical.com>
1715 */
1816
1917/* This class is a really tiny filter around QLightDM::UsersModel. There are
2018 some operations that we want to edit a bit for the benefit of Qml.
2119 Specifically, we want to sort users according to realName. */
2220
23−#ifndef UNITY_USERSMODEL_H
24−#define UNITY_USERSMODEL_H
21+#pragma once
2522
2623#include <unitysortfilterproxymodelqml.h>
2724#include <QtCore/QObject>
@@ -30,8 +27,10 @@ class UsersModel : public UnitySortFilterProxyModelQML
3027{
3128 Q_OBJECT
3229
30+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
31+
3332public:
3433 explicit UsersModel(QObject* parent=0);
35−};
3634
37−#endif
35+ QObject *mock();
36+};
qml/Greeter/LightDMService.qml+3−4
@@ -35,10 +35,9 @@ Loader {
3535 // This trickery handles cases where applicationArguments aren't provided
3636 // such as during testing
3737 property var fullLightDM: {
38− if (typeof applicationArguments !== "undefined") {
39− if (applicationArguments.mode === "greeter") {
40− return true;
41− }
38+ if (typeof applicationArguments === "undefined" ||
39+ applicationArguments.mode === "greeter") {
40+ return true;
4241 }
4342 return false;
4443 }
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
@@ -264,7 +264,7 @@ class UnityTestCase(AutopilotTestCase):
264264 def _get_lightdm_mock_path(self):
265265 lib_path = get_mocks_library_path()
266266 lightdm_mock_path = os.path.abspath(
267− os.path.join(lib_path, "LightDM" ,"IntegratedLightDM", "liblightdm")
267+ os.path.join(lib_path, "liblightdm")
268268 )
269269
270270 if not os.path.exists(lightdm_mock_path):
tests/mocks/AccountsService/AccountsService.cpp+2−3
@@ -15,7 +15,7 @@
1515 */
1616
1717#include "AccountsService.h"
18−#include "MockUsersModel.h"
18+#include "UsersModel.h"
1919
2020#include <QLightDM/UsersModel>
2121#include <paths.h>
@@ -33,9 +33,8 @@ AccountsService::AccountsService(QObject* parent)
3333 m_demoEdgesCompleted(),
3434 m_hereEnabled(false),
3535 m_hereLicensePath(""),
36− m_usersModel(new MockUsersModel(this))
36+ m_usersModel(new UsersModel(this))
3737{
38− m_usersModel->setMockMode("full");
3938}
4039
4140QString AccountsService::user() const
tests/mocks/AccountsService/AccountsService.h+3−6
@@ -14,15 +14,14 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef UNITY_MOCK_ACCOUNTSSERVICE_H
18−#define UNITY_MOCK_ACCOUNTSSERVICE_H
17+#pragma once
1918
2019#include <QObject>
2120#include <QString>
2221#include <QStringList>
2322#include <QVariant>
2423
25−class MockUsersModel;
24+class UsersModel;
2625
2726class AccountsService: public QObject
2827{
@@ -165,7 +164,5 @@ private:
165164 QString m_realName;
166165 QStringList m_kbdMap;
167166 QString m_email;
168− MockUsersModel *m_usersModel;
167+ UsersModel *m_usersModel;
169168};
170−
171−#endif
tests/mocks/AccountsService/CMakeLists.txt+1−2
@@ -1,14 +1,13 @@
11include_directories(
22 ${CMAKE_CURRENT_BINARY_DIR}
33 ${CMAKE_SOURCE_DIR}/plugins/LightDM
4+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM
45 ${CMAKE_SOURCE_DIR}/plugins/Utils
5− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
66 )
77
88add_library(MockAccountsService-qml MODULE
99 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
1010 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
11− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.cpp
1211 AccountsService.cpp
1312 plugin.cpp
1413 )
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/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+124
@@ -0,0 +1,124 @@
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+ m_instance = nullptr;
52+}
53+
54+MockController *MockController::instance()
55+{
56+ if (!m_instance) {
57+ m_instance = new MockController;
58+ }
59+ return m_instance;
60+}
61+
62+QString MockController::selectUserHint() const
63+{
64+ return m_selectUserHint;
65+}
66+
67+void MockController::setSelectUserHint(const QString &selectUserHint)
68+{
69+ if (m_selectUserHint != selectUserHint) {
70+ m_selectUserHint = selectUserHint;
71+ Q_EMIT selectUserHintChanged();
72+ }
73+}
74+
75+QString MockController::userMode() const
76+{
77+ return m_userMode;
78+}
79+
80+void MockController::setUserMode(const QString &userMode)
81+{
82+ if (m_userMode != userMode) {
83+ m_userMode = userMode;
84+ Q_EMIT userModeChanged();
85+ }
86+}
87+
88+QString MockController::sessionMode() const
89+{
90+ return m_sessionMode;
91+}
92+
93+void MockController::setSessionMode(const QString &sessionMode)
94+{
95+ if (m_sessionMode != sessionMode) {
96+ m_sessionMode = sessionMode;
97+ Q_EMIT sessionModeChanged();
98+ }
99+}
100+
101+const QList<MockController::SessionItem> &MockController::fullSessionItems() const
102+{
103+ return m_fullSessions;
104+}
105+
106+int MockController::numFullSessions() const
107+{
108+ return m_fullSessions.size();
109+}
110+
111+int MockController::numSessions() const
112+{
113+ return m_numSessions;
114+}
115+
116+void MockController::setNumSessions(int numSessions)
117+{
118+ if (m_numSessions != numSessions) {
119+ m_numSessions = numSessions;
120+ Q_EMIT numSessionsChanged();
121+ }
122+}
123+
124+}
tests/mocks/liblightdm/MockController.hnew file+80
@@ -0,0 +1,80 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#pragma once
18+
19+#include <QObject>
20+#include <QString>
21+
22+
23+namespace QLightDM
24+{
25+class Q_DECL_EXPORT MockController : public QObject
26+{
27+ Q_OBJECT
28+
29+ Q_PROPERTY(QString selectUserHint READ selectUserHint WRITE setSelectUserHint NOTIFY selectUserHintChanged)
30+
31+ // single, single-pin, single-passphrase, full
32+ Q_PROPERTY(QString userMode READ userMode WRITE setUserMode NOTIFY userModeChanged)
33+
34+ // single, none, full
35+ Q_PROPERTY(QString sessionMode READ sessionMode WRITE setSessionMode NOTIFY sessionModeChanged)
36+
37+ Q_PROPERTY(int numAvailableSessions READ numFullSessions CONSTANT)
38+ Q_PROPERTY(int numSessions READ numSessions WRITE setNumSessions NOTIFY numSessionsChanged)
39+
40+public:
41+ static MockController *instance();
42+ virtual ~MockController();
43+
44+ QString selectUserHint() const;
45+ void setSelectUserHint(const QString &selectUserHint);
46+
47+ QString userMode() const;
48+ void setUserMode(const QString &userMode);
49+
50+ QString sessionMode() const;
51+ void setSessionMode(const QString &sessionMode);
52+
53+ class SessionItem
54+ {
55+ public:
56+ QString key;
57+ QString name;
58+ };
59+ int numFullSessions() const;
60+ const QList<SessionItem> &fullSessionItems() const;
61+
62+ int numSessions() const;
63+ void setNumSessions(int numSessions);
64+
65+Q_SIGNALS:
66+ void selectUserHintChanged();
67+ void userModeChanged();
68+ void sessionModeChanged();
69+ void numSessionsChanged();
70+
71+private:
72+ explicit MockController(QObject* parent=0);
73+
74+ QString m_selectUserHint;
75+ QString m_userMode;
76+ QString m_sessionMode;
77+ QList<SessionItem> m_fullSessions;
78+ int m_numSessions;
79+};
80+}
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+}
tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.h → tests/mocks/liblightdm/MockGreeter.hrenamed+10−19
@@ -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 *
@@ -18,16 +18,14 @@
1818 * Author: David Edmundson <kde@davidedmundson.co.uk>
1919 */
2020
21−#ifndef UNITY_MOCK_GREETER_H
22−#define UNITY_MOCK_GREETER_H
23−
24−#include <QtCore/QObject>
25−#include <QtCore/QVariant>
21+#pragma once
2622
23+#include <QObject>
24+#include <QVariant>
2725
2826namespace QLightDM
2927{
30− class GreeterPrivate;
28+class GreeterPrivate;
3129
3230class Q_DECL_EXPORT Greeter : public QObject
3331{
@@ -44,8 +42,7 @@ class Q_DECL_EXPORT Greeter : public QObject
4442
4543 Q_ENUMS(PromptType MessageType)
4644
47− //Mock-only API for testing purposes
48− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
45+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
4946
5047public:
5148 enum PromptType {
@@ -68,7 +65,6 @@ public:
6865 bool showRemoteLoginHint() const;
6966 bool hasGuestAccountHint() const;
7067 QString selectUserHint() const;
71− void setSelectUserHint(const QString &selectUserHint); // only in mock
7268 bool selectGuestHint() const;
7369 QString autologinUserHint() const;
7470 bool autologinGuestHint() const;
@@ -79,8 +75,7 @@ public:
7975 QString authenticationUser() const;
8076 QString hostname() const;
8177
82− QString mockMode() const;
83− void setMockMode(QString mockMode);
78+ QObject *mock();
8479
8580public Q_SLOTS:
8681 bool connectSync();
@@ -98,18 +93,14 @@ Q_SIGNALS:
9893 void showPrompt(QString text, QLightDM::Greeter::PromptType type);
9994 void authenticationComplete();
10095 void autologinTimerExpired();
101− void mockModeChanged(QString mode);
102−
103−protected:
104− void sendAuthenticationComplete();
10596
10697private Q_SLOTS:
107− void delayedAuthentication();
98+ void handleAuthenticate();
10899
109100private:
101+ void sendAuthenticationComplete();
102+
110103 GreeterPrivate *d_ptr;
111104 Q_DECLARE_PRIVATE(Greeter)
112105};
113106}
114−
115−#endif // UNITY_MOCK_GREETER_H
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(), &MockController::sessionModeChanged,
48+ this, &SessionsModel::resetEntries);
49+ connect(MockController::instance(), &MockController::numSessionsChanged,
50+ this, &SessionsModel::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+12−16
@@ -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
@@ -15,11 +15,12 @@
1515 *
1616 */
1717
18−#ifndef UNITY_MOCK_SESSIONSMODEL_H
19−#define UNITY_MOCK_SESSIONSMODEL_H
18+#pragma once
2019
21−#include <QtCore/QAbstractListModel>
22−#include <QtCore/QString>
20+#include <QAbstractListModel>
21+#include <QByteArray>
22+#include <QHash>
23+#include <QString>
2324
2425namespace QLightDM
2526{
@@ -29,10 +30,11 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
2930 {
3031 Q_OBJECT
3132
33+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
34+
3235 Q_ENUMS(SessionModelRoles SessionType)
3336
3437 public:
35−
3638 enum SessionModelRoles {
3739 //name is exposed as Qt::DisplayRole
3840 //comment is exposed as Qt::TooltipRole
@@ -54,19 +56,13 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
5456 int rowCount(const QModelIndex& parent) const override;
5557 QVariant data(const QModelIndex& index, int role) const override;
5658
57− int numSessions() const;
58− int numAvailableSessions() const;
59− QString testScenario() const;
60− void setNumSessions(int numSessions);
61− void setTestScenario(QString testScenario);
59+ QObject *mock();
6260
63− protected:
64− SessionsModelPrivate* const d_ptr;
61+ private Q_SLOTS:
62+ void resetEntries();
6563
6664 private:
67− QHash<int, QByteArray> m_roleNames;
65+ SessionsModelPrivate *d_ptr;
6866 Q_DECLARE_PRIVATE(SessionsModel)
6967 };
7068}
71−
72−#endif // UNITY_MOCK_SESSIONSMODEL_H
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(), &MockController::userModeChanged,
69+ this, &UsersModel::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, false, false, "ubuntu", 0}};
136+ } else if (userMode == "single-passphrase") {
137+ d->entries = {{"has-password", "Has Password", "", 0, false, false, "ubuntu", 0}};
138+ } else if (userMode == "single-pin") {
139+ d->entries = {{"has-pin", "Has PIN", "", 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+9−15
@@ -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
@@ -15,13 +15,11 @@
1515 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1616 */
1717
18−#ifndef UNITY_MOCK_USERSMODEL_H
19−#define UNITY_MOCK_USERSMODEL_H
18+#pragma once
2019
21−#include <QtCore/QString>
22−#include <QtCore/QSharedDataPointer>
2320#include <QAbstractListModel>
24−
21+#include <QList>
22+#include <QString>
2523
2624namespace QLightDM
2725{
@@ -33,11 +31,7 @@ class Q_DECL_EXPORT UsersModel : public QAbstractListModel
3331
3432 Q_ENUMS(UserModelRoles)
3533
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);
34+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
4135
4236public:
4337 explicit UsersModel(QObject *parent = 0);
@@ -57,8 +51,10 @@ public:
5751 int rowCount(const QModelIndex &parent) const override;
5852 QVariant data(const QModelIndex &index, int role) const override;
5953
60− QString mockMode() const;
61− void setMockMode(QString mockMode);
54+ QObject *mock();
55+
56+private Q_SLOTS:
57+ void resetEntries();
6258
6359private:
6460 UsersModelPrivate * const d_ptr;
@@ -66,5 +62,3 @@ private:
6662};
6763
6864}
69−
70−#endif // UNITY_MOCK_USERSMODEL_H
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/plugins/LightDM/IntegratedLightDM/CMakeLists.txt+1−3
@@ -4,6 +4,7 @@ add_definitions(
44include_directories(
55 ${GLIB_INCLUDE_DIRS}
66 ${CMAKE_CURRENT_BINARY_DIR}
7+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM
78 )
89
910add_executable(GreeterDBusTestExec
@@ -25,7 +26,6 @@ add_unity8_uitest(GreeterDBus dbus-test-runner
2526 ARG_PREFIX "--parameter"
2627 ARGS --task $<TARGET_FILE:GreeterDBusTestExec>
2728 DEPENDS MockLightDM
28− IMPORT_PATHS ${UNITY_MOCKPATH}
2929 )
3030
3131add_executable(GreeterPamTestExec
@@ -60,7 +60,6 @@ target_include_directories(GreeterSessionsModelTestExec PUBLIC
6060 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
6161 )
6262add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
63− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
6463 DEPENDS MockLightDM
6564 )
6665
@@ -83,7 +82,6 @@ target_include_directories(GreeterUsersModelTestExec PUBLIC
8382 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
8483 )
8584add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
86− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
8785 DEPENDS MockLightDM
8886 )
8987
tests/plugins/LightDM/IntegratedLightDM/greeter.qml+2−7
@@ -1,5 +1,5 @@
11/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013,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
@@ -15,13 +15,8 @@
1515 */
1616
1717import QtQuick 2.4
18−import LightDM.IntegratedLightDM 0.1 as LightDM
18+import LightDM.FullLightDM 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+13−13
@@ -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
@@ -31,14 +31,14 @@ private Q_SLOTS:
3131 {
3232 model = new SessionsModel();
3333 QVERIFY(model);
34− sourceModel = new QLightDM::SessionsModel();
35− QVERIFY(sourceModel);
34+ mock = model->mock();
35+ QVERIFY(mock);
3636 }
3737
3838 void cleanup()
3939 {
4040 delete model;
41− delete sourceModel;
41+ // mock will be a singleton, doesn't need to be cleaned
4242 }
4343
4444 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
@@ -93,34 +93,34 @@ private Q_SLOTS:
9393
9494 void testMultipleSessionsCountIsCorrect()
9595 {
96− sourceModel->setTestScenario("multipleSessions");
97− QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
96+ mock->setProperty("sessionMode", "full");
97+ QVERIFY(model->rowCount(QModelIndex()) > 1);
9898 }
9999
100100 void testNoSessionsCountIsCorrect()
101101 {
102− sourceModel->setTestScenario("noSessions");
103− QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
102+ mock->setProperty("sessionMode", "none");
103+ QVERIFY(model->rowCount(QModelIndex()) == 0);
104104 }
105105
106106 void testSingleSessionCountIsCorrect()
107107 {
108− sourceModel->setTestScenario("singleSession");
109− QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
108+ mock->setProperty("sessionMode", "single");
109+ QVERIFY(model->rowCount(QModelIndex()) == 1);
110110 }
111111
112112 void testSessionNameIsCorrect()
113113 {
114114 // This is testing the lookup, not the correctness of the strings,
115115 // so one test should be sufficient
116− sourceModel->setTestScenario("multipleSessions");
117− QVERIFY(model->data(findByKey(sourceModel, "ubuntu"),
116+ mock->setProperty("sessionMode", "full");
117+ QVERIFY(model->data(findByKey(model, "ubuntu"),
118118 Qt::DisplayRole).toString() == "Ubuntu");
119119 }
120120
121121private:
122122 SessionsModel *model;
123− QLightDM::SessionsModel *sourceModel;
123+ QObject *mock;
124124};
125125
126126QTEST_MAIN(GreeterSessionsModelTest)
tests/plugins/LightDM/IntegratedLightDM/usersmodel.cpp+2−12
@@ -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);
58+ auto background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
6559 QVERIFY(background == "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);
64+ auto name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
7465 QVERIFY(name == "empty-name");
7566 }
7667
7768private:
7869 UsersModel *model;
79− QLightDM::UsersModel *sourceModel;
8070};
8171
8272QTEST_MAIN(GreeterUsersModelTest)
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.FullLightDM 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.FullLightDM 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.FullLightDM 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.FullLightDM 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.FullLightDM 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.FullLightDM 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.FullLightDM 0.1 as LightDM
2626import Powerd 0.1
2727import Unity.InputInfo 0.1
2828import Utils 0.1
@@ -38,6 +38,12 @@ Rectangle {
3838 width: units.gu(160) + controls.width
3939 height: units.gu(100)
4040
41+ Binding {
42+ target: LightDM.Users.mock
43+ property: "userMode"
44+ value: "single"
45+ }
46+
4147 QtObject {
4248 id: applicationArguments
4349 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.FullLightDM 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
@@ -228,8 +227,7 @@ Rectangle {
228227 model: ["single", "single-passphrase", "single-pin", "full"]
229228 onSelectedIndexChanged: {
230229 shellLoader.active = false;
231− LightDM.Greeter.mockMode = model[selectedIndex];
232− LightDM.Users.mockMode = model[selectedIndex];
230+ LightDM.Users.mock.userMode = model[selectedIndex];
233231 shellLoader.active = true;
234232 }
235233 }
@@ -803,8 +801,7 @@ Rectangle {
803801 }
804802
805803 function setLightDMMockMode(mode) {
806− LightDM.Greeter.mockMode = mode;
807− LightDM.Users.mockMode = mode;
804+ LightDM.Users.mock.userMode = mode;
808805 }
809806
810807 function test_showInputMethod() {
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.FullLightDM 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