on xenial help sign in
Simplify the lightdm mock to make future greeter improvements easier to test.

I simplified the mock liblightdm to avoid separate files for the Private classes. That can all go into the main files. The separation isn't worth wading through the files to find what you want. And I dropped the mock LightDM plugin entirely. (opting instead for a tiny "mock()" API call on the real plugin that returns an object that can be used to manipulate our mock liblightdm, if we're in testing mode) Approved by: Albert Astals Cid, Unity8 CI Bot

commit75ef7acee29f4fdc7448c1939fe7a761b9f72e16 authorMichael Terry <mike@mterry.name> dateTue 24 Jan 2017, 07:39 (10 years ago) parent7b99df27124cda
64 files changed+872−1039
debian/rules+1−1 plugins/LightDM/CMakeLists.txt−1 plugins/LightDM/Greeter.cpp+1−1 plugins/LightDM/Greeter.h+2−5 plugins/LightDM/SessionsModel.cpp+1−2 plugins/LightDM/SessionsModel.h+4−5 plugins/LightDM/UsersModel.cpp+1−1 plugins/LightDM/UsersModel.h+2−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+2−1 tests/mocks/LightDM/CMakeLists.txt−1 tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txt−50 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/QLightDM/Greeter−17 tests/mocks/LightDM/IntegratedLightDM/QLightDM/SessionsModel−17 tests/mocks/LightDM/IntegratedLightDM/QLightDM/UsersModel−17 tests/mocks/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txt−21 tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.cpp−201 tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.cpp−121 tests/mocks/LightDM/IntegratedLightDM/plugin.cpp−79 tests/mocks/LightDM/IntegratedLightDM/qmldir−2 tests/mocks/LightDMController/CMakeLists.txt+15 tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.h → tests/mocks/LightDMController/plugin.cpp+16−20 tests/mocks/LightDM/IntegratedLightDM/plugin.h → tests/mocks/LightDMController/plugin.h+5−8 tests/mocks/LightDMController/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+251 tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.h → tests/mocks/liblightdm/MockGreeter.h+8−21 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp → tests/mocks/liblightdm/MockSessionsModel.cpp+40−42 tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h → tests/mocks/liblightdm/MockSessionsModel.h+9−17 tests/mocks/liblightdm/MockUsersModel.cpp+186 tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.h → tests/mocks/liblightdm/MockUsersModel.h+6−16 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+3−3 tests/plugins/LightDM/IntegratedLightDM/greeter.qml+2−7 tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+15−13 tests/plugins/LightDM/IntegratedLightDM/usersmodel.cpp+2−12 tests/qmltests/Dash/tst_DashShell.qml+8 tests/qmltests/Greeter/TestView.qml+1 tests/qmltests/Greeter/tst_Greeter.qml+6−8 tests/qmltests/Greeter/tst_Infographics.qml+1−11 tests/qmltests/Greeter/tst_NarrowView.qml+9−2 tests/qmltests/Greeter/tst_WideView.qml+20−30 tests/qmltests/Tutorial/tst_Tutorial.qml+3−3 tests/qmltests/tst_OrientedShell.qml+8−1 tests/qmltests/tst_Shell.qml+5−7 tests/qmltests/tst_ShellWithPin.qml+3−3
debian/rules+1−1
@@ -40,4 +40,4 @@ override_dh_makeshlibs:
4040override_dh_shlibdeps:
4141 # Some mock libraries link against liblightdm-qt5-3.so which we want to
4242 # avoid, since we only really link against our mock one, not the system one.
43− dh_shlibdeps -XlibMockLightDM-qml.so -XlibMockAccountsService-qml.so -Lunity8-private
43+ dh_shlibdeps -XlibMockAccountsService-qml.so -Lunity8-private
plugins/LightDM/CMakeLists.txt−1
@@ -7,7 +7,6 @@ include_directories(
77 ${CMAKE_CURRENT_SOURCE_DIR}
88 ${CMAKE_CURRENT_BINARY_DIR}
99 ${CMAKE_SOURCE_DIR}/plugins/Utils
10− ${CMAKE_BINARY_DIR}/tests/mocks/LightDM/IntegratedLightDM
1110 ${libunity8-private_SOURCE_DIR}
1211 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
1312)
plugins/LightDM/Greeter.cpp+1−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
plugins/LightDM/Greeter.h+2−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>
@@ -81,5 +80,3 @@ private Q_SLOTS:
8180 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
8281 void authenticationCompleteFilter();
8382};
84−
85−#endif
plugins/LightDM/SessionsModel.cpp+1−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
@@ -128,7 +128,6 @@ SessionsModel::SessionsModel(QObject* parent)
128128 }
129129
130130 setModel(m_model);
131− setSourceModel(m_model);
132131 setSortCaseSensitivity(Qt::CaseInsensitive);
133132 setSortLocaleAware(true);
134133 setSortRole(Qt::DisplayRole);
plugins/LightDM/SessionsModel.h+4−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>
@@ -30,6 +29,7 @@ class SessionsModel : public UnitySortFilterProxyModelQML
3029
3130 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
3231 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
32+
3333Q_SIGNALS:
3434 void iconSearchDirectoriesChanged();
3535
@@ -54,6 +54,7 @@ public:
5454 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
5555
5656 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
57+
5758private:
5859 QLightDM::SessionsModel* m_model;
5960 QHash<int, QByteArray> m_roleNames;
@@ -63,5 +64,3 @@ private:
6364 QUrl("/usr/share/unity-greeter/")};
6465
6566};
66−
67−#endif // UNITY_SESSIONSMODEL_H
plugins/LightDM/UsersModel.cpp+1−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
plugins/LightDM/UsersModel.h+2−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>
@@ -33,5 +30,3 @@ class UsersModel : public UnitySortFilterProxyModelQML
3330public:
3431 explicit UsersModel(QObject* parent=0);
3532};
36−
37−#endif
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
@@ -42,8 +42,8 @@ macro(unity8_parse_arguments)
4242
4343 set(ld_paths)
4444 list(APPEND ld_paths
45+ ${UNITY_MOCKPATH}/liblightdm
4546 ${UNITY_MOCKPATH}/libusermetrics
46− ${UNITY_MOCKPATH}/LightDM/IntegratedLightDM/liblightdm
4747 )
4848
4949 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+2−1
@@ -32,8 +32,9 @@ add_subdirectory(Biometryd)
3232add_subdirectory(Cursor)
3333add_subdirectory(GSettings.1.0)
3434add_subdirectory(indicator-service)
35+add_subdirectory(liblightdm)
3536add_subdirectory(libusermetrics)
36−add_subdirectory(LightDM)
37+add_subdirectory(LightDMController)
3738add_subdirectory(Lights)
3839add_subdirectory(MeeGo)
3940add_subdirectory(Powerd)
tests/mocks/LightDM/CMakeLists.txtdeleted−1
@@ -1 +0,0 @@
1−add_subdirectory(IntegratedLightDM)
tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txtdeleted−50
@@ -1,50 +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− TARGETS MockLightDM-qml
49− ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/liblightdm"
50−)
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/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−21
@@ -1,21 +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− SOVERSION 0)
18−
19−install(TARGETS MockLightDM
20− DESTINATION ${SHELL_INSTALL_QML}/mocks/LightDM/IntegratedLightDM/liblightdm
21− )
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 (qEnvironmentVariableIsEmpty("UNITY_TESTING")) {
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−121
@@ -1,121 +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− // Extend roleNames (we want to keep the "display" role)
38− QHash<int, QByteArray> roles = roleNames();
39− roles[NameRole] = "name";
40− roles[RealNameRole] = "realName";
41− roles[LoggedInRole] = "loggedIn";
42− roles[BackgroundRole] = "background";
43− roles[BackgroundPathRole] = "backgroundPath";
44− roles[SessionRole] = "session";
45− roles[HasMessagesRole] = "hasMessages";
46− roles[ImagePathRole] = "imagePath";
47− roles[UidRole] = "uid";
48− setRoleNames(roles);
49−}
50−
51−UsersModel::~UsersModel()
52−{
53− delete d_ptr;
54−}
55−
56−int UsersModel::rowCount(const QModelIndex &parent) const
57−{
58− Q_D(const UsersModel);
59−
60− if (parent.isValid()) {
61− return 0;
62− } else { // parent is root
63− return d->entries.size();
64− }
65−}
66−
67−QVariant UsersModel::data(const QModelIndex &index, int role) const
68−{
69− Q_D(const UsersModel);
70−
71− if (!index.isValid()) {
72− return QVariant();
73− }
74−
75− int row = index.row();
76− switch (role) {
77− case Qt::DisplayRole:
78− return d->entries[row].real_name;
79− case Qt::DecorationRole:
80− return QIcon();
81− case UsersModel::NameRole:
82− return d->entries[row].username;
83− case UsersModel::RealNameRole:
84− return d->entries[row].real_name;
85− case UsersModel::SessionRole:
86− return d->entries[row].session;
87− case UsersModel::LoggedInRole:
88− return d->entries[row].is_active;
89− case UsersModel::BackgroundRole:
90− return QPixmap(d->entries[row].background);
91− case UsersModel::BackgroundPathRole:
92− return d->entries[row].background;
93− case UsersModel::HasMessagesRole:
94− return d->entries[row].has_messages;
95− case UsersModel::ImagePathRole:
96− return "";
97− case UsersModel::UidRole:
98− return d->entries[row].uid;
99− default:
100− return QVariant();
101− }
102−}
103−
104−QString UsersModel::mockMode() const
105−{
106− Q_D(const UsersModel);
107− return d->mockMode;
108−}
109−
110−void UsersModel::setMockMode(QString mockMode)
111−{
112− Q_D(UsersModel);
113−
114− if (d->mockMode != mockMode) {
115− d->mockMode = mockMode;
116− Q_EMIT mockModeChanged(mockMode);
117− d->resetEntries();
118− }
119−}
120−
121−}
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/qmldirdeleted−2
@@ -1,2 +0,0 @@
1−module LightDM.IntegratedLightDM
2−plugin MockLightDM-qml
tests/mocks/LightDMController/CMakeLists.txtnew file+15
@@ -0,0 +1,15 @@
1+add_library(LightDMController MODULE
2+ plugin.cpp
3+ )
4+
5+target_include_directories(LightDMController PUBLIC
6+ ${CMAKE_SOURCE_DIR}/tests/mocks/liblightdm/
7+ )
8+
9+target_link_libraries(LightDMController
10+ MockLightDM
11+ )
12+
13+qt5_use_modules(LightDMController Qml)
14+
15+add_unity8_mock(LightDMController 0.1 LightDMController TARGETS LightDMController)
tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.h → tests/mocks/LightDMController/plugin.cpprenamed+16−20
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright (C) 2017 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,28 +12,24 @@
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− *
1615 */
1716
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
17+#include "plugin.h"
2618
27− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
19+#include "MockController.h"
2820
29−public:
30− explicit MockUsersModel(QObject* parent=0);
21+#include <QtQml/qqml.h>
3122
32− QString mockMode() const;
33− void setMockMode(QString mockMode);
34−
35−Q_SIGNALS:
36− void mockModeChanged(QString mode);
37−};
23+static QObject *mock_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
24+{
25+ Q_UNUSED(scriptEngine)
26+ auto controller = QLightDM::MockController::instance();
27+ engine->setObjectOwnership(controller, QQmlEngine::CppOwnership);
28+ return controller;
29+}
3830
39−#endif // MOCK_UNITY_USERSMODEL_H
31+void LightDMControllerPlugin::registerTypes(const char *uri)
32+{
33+ Q_ASSERT(uri == QLatin1String("LightDMController"));
34+ qmlRegisterSingletonType<QLightDM::MockController>(uri, 0, 1, "LightDMController", mock_provider);
35+}
tests/mocks/LightDM/IntegratedLightDM/plugin.h → tests/mocks/LightDMController/plugin.hrenamed+5−8
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014, 2015 Canonical, Ltd.
2+ * Copyright (C) 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
@@ -14,13 +14,12 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef MOCK_LIGHTDM_PLUGIN_H
18−#define MOCK_LIGHTDM_PLUGIN_H
17+#pragma once
1918
20−#include <QtQml/QQmlEngine>
21−#include <QtQml/QQmlExtensionPlugin>
19+#include <QQmlEngine>
20+#include <QQmlExtensionPlugin>
2221
23−class LightDMPlugin : public QQmlExtensionPlugin
22+class LightDMControllerPlugin : public QQmlExtensionPlugin
2423{
2524 Q_OBJECT
2625 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
@@ -28,5 +27,3 @@ class LightDMPlugin : public QQmlExtensionPlugin
2827public:
2928 void registerTypes(const char *uri) override;
3029};
31−
32−#endif
tests/mocks/LightDMController/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module LightDMController
2+plugin LightDMController
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+ SOVERSION 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+251
@@ -0,0 +1,251 @@
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 (qEnvironmentVariableIsEmpty("UNITY_TESTING")) {
244+ // simulate PAM's delay
245+ QTimer::singleShot(1000, this, &Greeter::authenticationComplete);
246+ } else {
247+ Q_EMIT authenticationComplete();
248+ }
249+}
250+
251+}
tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.h → tests/mocks/liblightdm/MockGreeter.hrenamed+8−21
@@ -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{
@@ -42,9 +40,6 @@ class Q_DECL_EXPORT Greeter : public QObject
4240 Q_PROPERTY(QString hostname READ hostname CONSTANT)
4341 Q_PROPERTY(bool hasGuestAccount READ hasGuestAccountHint CONSTANT)
4442
45− //Mock-only API for testing purposes
46− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
47−
4843public:
4944 enum PromptType {
5045 PromptTypeQuestion,
@@ -68,7 +63,6 @@ public:
6863 bool showRemoteLoginHint() const;
6964 bool hasGuestAccountHint() const;
7065 QString selectUserHint() const;
71− void setSelectUserHint(const QString &selectUserHint); // only in mock
7266 bool selectGuestHint() const;
7367 QString autologinUserHint() const;
7468 bool autologinGuestHint() const;
@@ -79,9 +73,6 @@ public:
7973 QString authenticationUser() const;
8074 QString hostname() const;
8175
82− QString mockMode() const;
83− void setMockMode(QString mockMode);
84−
8576public Q_SLOTS:
8677 bool connectSync();
8778 void authenticate(const QString &username=QString());
@@ -98,18 +89,14 @@ Q_SIGNALS:
9889 void showPrompt(QString text, QLightDM::Greeter::PromptType type);
9990 void authenticationComplete();
10091 void autologinTimerExpired();
101− void mockModeChanged(QString mode);
102−
103−protected:
104− void sendAuthenticationComplete();
10592
10693private Q_SLOTS:
107− void delayedAuthentication();
94+ void handleAuthenticate();
10895
10996private:
97+ void sendAuthenticationComplete();
98+
11099 GreeterPrivate *d_ptr;
111100 Q_DECLARE_PRIVATE(Greeter)
112101};
113102}
114−
115−#endif // UNITY_MOCK_GREETER_H
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.cpp → tests/mocks/liblightdm/MockSessionsModel.cpprenamed+40−42
@@ -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,21 +21,35 @@
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
3531{
36− m_roleNames = QAbstractListModel::roleNames();
37− m_roleNames[KeyRole] = "key";
38− m_roleNames[TypeRole] = "type";
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)
40+{
41+ Q_D(SessionsModel);
42+
43+ d->roleNames = QAbstractListModel::roleNames();
44+ d->roleNames[KeyRole] = "key";
45+ d->roleNames[TypeRole] = "type";
46+ setRoleNames(d->roleNames);
47+
48+ connect(MockController::instance(), &MockController::sessionModeChanged,
49+ this, &SessionsModel::resetEntries);
50+ connect(MockController::instance(), &MockController::numSessionsChanged,
51+ this, &SessionsModel::resetEntries);
52+ resetEntries();
3953}
4054
4155SessionsModel::~SessionsModel()
@@ -65,7 +79,9 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
6579
6680QHash<int, QByteArray> SessionsModel::roleNames() const
6781{
68− return m_roleNames;
82+ Q_D(const SessionsModel);
83+
84+ return d->roleNames;
6985}
7086
7187int SessionsModel::rowCount(const QModelIndex& parent) const
@@ -79,42 +95,24 @@ int SessionsModel::rowCount(const QModelIndex& parent) const
7995 }
8096}
8197
82−int SessionsModel::numSessions() const
83−{
84− Q_D(const SessionsModel);
85− return d->numSessions;
86−}
87−
88−int SessionsModel::numAvailableSessions() const
89−{
90− Q_D(const SessionsModel);
91− return d->numAvailableSessions();
92−}
93−
94−QString SessionsModel::testScenario() const
95−{
96− Q_D(const SessionsModel);
97− return d->testScenario;
98−}
99−
100−void SessionsModel::setNumSessions(int numSessions)
98+void SessionsModel::resetEntries()
10199{
102100 Q_D(SessionsModel);
103101
104− if (d->numSessions != numSessions) {
105− d->numSessions = numSessions;
106− d->resetEntries();
107− }
108−}
102+ beginResetModel();
109103
110−void SessionsModel::setTestScenario(QString testScenario)
111−{
112− Q_D(SessionsModel);
104+ QString sessionMode = MockController::instance()->sessionMode();
113105
114− if (d->testScenario != testScenario) {
115− d->testScenario = testScenario;
116− d->resetEntries();
106+ if (sessionMode == "full") {
107+ d->sessionItems = MockController::instance()->fullSessionItems();
108+ d->sessionItems = d->sessionItems.mid(0, MockController::instance()->numSessions());
109+ } else if (sessionMode == "single") {
110+ d->sessionItems = {MockController::instance()->fullSessionItems()[0]};
111+ } else {
112+ d->sessionItems = {};
117113 }
114+
115+ endResetModel();
118116}
119117
120118} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h → tests/mocks/liblightdm/MockSessionsModel.hrenamed+9−17
@@ -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{
@@ -30,7 +31,6 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
3031 Q_OBJECT
3132
3233 public:
33−
3434 enum SessionModelRoles {
3535 //name is exposed as Qt::DisplayRole
3636 //comment is exposed as Qt::TooltipRole
@@ -54,19 +54,11 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
5454 int rowCount(const QModelIndex& parent) const override;
5555 QVariant data(const QModelIndex& index, int role) const override;
5656
57− int numSessions() const;
58− int numAvailableSessions() const;
59− QString testScenario() const;
60− void setNumSessions(int numSessions);
61− void setTestScenario(QString testScenario);
62−
63− protected:
64− SessionsModelPrivate* const d_ptr;
57+ private Q_SLOTS:
58+ void resetEntries();
6559
6660 private:
67− QHash<int, QByteArray> m_roleNames;
61+ SessionsModelPrivate *d_ptr;
6862 Q_DECLARE_PRIVATE(SessionsModel)
6963 };
7064}
71−
72−#endif // UNITY_MOCK_SESSIONSMODEL_H
tests/mocks/liblightdm/MockUsersModel.cppnew file+186
@@ -0,0 +1,186 @@
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+}
tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.h → tests/mocks/liblightdm/MockUsersModel.hrenamed+6−16
@@ -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{
@@ -31,12 +29,6 @@ class Q_DECL_EXPORT UsersModel : public QAbstractListModel
3129{
3230 Q_OBJECT
3331
34− //Mock-only API for testing purposes
35− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
36−
37−Q_SIGNALS:
38− void mockModeChanged(QString mode);
39−
4032public:
4133 explicit UsersModel(QObject *parent = 0);
4234 virtual ~UsersModel();
@@ -56,8 +48,8 @@ public:
5648 int rowCount(const QModelIndex &parent) const override;
5749 QVariant data(const QModelIndex &index, int role) const override;
5850
59− QString mockMode() const;
60− void setMockMode(QString mockMode);
51+private Q_SLOTS:
52+ void resetEntries();
6153
6254private:
6355 UsersModelPrivate * const d_ptr;
@@ -65,5 +57,3 @@ private:
6557};
6658
6759}
68−
69−#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+3−3
@@ -1,6 +1,7 @@
11include_directories(
22 ${GLIB_INCLUDE_DIRS}
33 ${CMAKE_CURRENT_BINARY_DIR}
4+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM
45 )
56
67add_executable(GreeterDBusTestExec
@@ -28,7 +29,7 @@ install(FILES greeter.qml
2829add_unity8_uitest(GreeterDBus dbus-test-runner
2930 ARG_PREFIX "--parameter"
3031 ARGS --task $<TARGET_FILE:GreeterDBusTestExec>
31− DEPENDS MockLightDM MockLightDM-qml
32+ DEPENDS MockLightDM
3233 )
3334
3435add_executable(GreeterPamTestExec
@@ -64,12 +65,12 @@ target_include_directories(GreeterSessionsModelTestExec PUBLIC
6465 ${CMAKE_SOURCE_DIR}/plugins/LightDM
6566 ${CMAKE_SOURCE_DIR}/plugins/Utils
6667 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
68+ ${CMAKE_SOURCE_DIR}/tests/mocks/liblightdm/
6769 )
6870install(TARGETS GreeterSessionsModelTestExec
6971 DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/plugins/LightDM/IntegratedLightDM"
7072 )
7173add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
72− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
7374 DEPENDS MockLightDM
7475 )
7576
@@ -96,7 +97,6 @@ install(TARGETS GreeterUsersModelTestExec
9697 DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/plugins/LightDM/IntegratedLightDM"
9798 )
9899add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
99− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
100100 DEPENDS MockLightDM
101101 )
102102
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+15−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
@@ -16,6 +16,8 @@
1616
1717#include "SessionsModel.h"
1818
19+#include "MockController.h"
20+
1921#include <QLightDM/SessionsModel>
2022#include <QtCore/QModelIndex>
2123#include <QtTest>
@@ -31,14 +33,14 @@ private Q_SLOTS:
3133 {
3234 model = new SessionsModel();
3335 QVERIFY(model);
34− sourceModel = new QLightDM::SessionsModel();
35− QVERIFY(sourceModel);
36+ mock = QLightDM::MockController::instance();
37+ QVERIFY(mock);
3638 }
3739
3840 void cleanup()
3941 {
4042 delete model;
41− delete sourceModel;
43+ // mock will be a singleton, doesn't need to be cleaned
4244 }
4345
4446 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
@@ -93,34 +95,34 @@ private Q_SLOTS:
9395
9496 void testMultipleSessionsCountIsCorrect()
9597 {
96− sourceModel->setTestScenario("multipleSessions");
97− QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
98+ mock->setProperty("sessionMode", "full");
99+ QVERIFY(model->rowCount(QModelIndex()) > 1);
98100 }
99101
100102 void testNoSessionsCountIsCorrect()
101103 {
102− sourceModel->setTestScenario("noSessions");
103− QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
104+ mock->setProperty("sessionMode", "none");
105+ QVERIFY(model->rowCount(QModelIndex()) == 0);
104106 }
105107
106108 void testSingleSessionCountIsCorrect()
107109 {
108− sourceModel->setTestScenario("singleSession");
109− QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
110+ mock->setProperty("sessionMode", "single");
111+ QVERIFY(model->rowCount(QModelIndex()) == 1);
110112 }
111113
112114 void testSessionNameIsCorrect()
113115 {
114116 // This is testing the lookup, not the correctness of the strings,
115117 // so one test should be sufficient
116− sourceModel->setTestScenario("multipleSessions");
117− QVERIFY(model->data(findByKey(sourceModel, "ubuntu"),
118+ mock->setProperty("sessionMode", "full");
119+ QVERIFY(model->data(findByKey(model, "ubuntu"),
118120 Qt::DisplayRole).toString() == "Ubuntu");
119121 }
120122
121123private:
122124 SessionsModel *model;
123− QLightDM::SessionsModel *sourceModel;
125+ QObject *mock;
124126};
125127
126128QTEST_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+8
@@ -20,12 +20,20 @@ import "../../../qml/Dash"
2020import "../../../qml/"
2121import Ubuntu.Components 1.3
2222import Unity.Test 0.1 as UT
23+import LightDMController 0.1
24+import LightDM.FullLightDM 0.1 as LightDM
2325
2426Item {
2527 id: root
2628 width: units.gu(80)
2729 height: units.gu(80)
2830
31+ Binding {
32+ target: LightDMController
33+ property: "userMode"
34+ value: "single"
35+ }
36+
2937 Shell {
3038 id: shell
3139 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+6−8
@@ -22,7 +22,8 @@ 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 LightDMController 0.1
26+import LightDM.FullLightDM 0.1 as LightDM
2627import Unity.Test 0.1 as UT
2728
2829Item {
@@ -32,9 +33,6 @@ Item {
3233 property url defaultBackground: "/usr/share/backgrounds/warty-final-ubuntu.png"
3334
3435 Component.onCompleted: {
35− // set the mock mode before loading
36− LightDM.Greeter.mockMode = "full";
37− LightDM.Users.mockMode = "full";
3836 loader.active = true;
3937 }
4038
@@ -146,7 +144,7 @@ Item {
146144
147145 function init() {
148146 greeterSettings.lockedOutTime = 0;
149− LightDM.Greeter.selectUser = "";
147+ LightDMController.selectUserHint = "";
150148 greeter.failedLoginsDelayAttempts = 7;
151149 greeter.failedLoginsDelayMinutes = 5;
152150 teaseSpy.clear();
@@ -570,20 +568,20 @@ Item {
570568 }
571569
572570 function test_selectUserHint() {
573− LightDM.Greeter.selectUser = "info-prompt";
571+ LightDMController.selectUserHint = "info-prompt";
574572 resetLoader();
575573 var i = verifySelected("info-prompt");
576574 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
577575 }
578576
579577 function test_selectUserHintUnset() {
580− LightDM.Greeter.selectUser = "";
578+ LightDMController.selectUserHint = "";
581579 resetLoader();
582580 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
583581 }
584582
585583 function test_selectUserHintInvalid() {
586− LightDM.Greeter.selectUser = "not-a-real-user";
584+ LightDMController.selectUserHint = "not-a-real-user";
587585 resetLoader();
588586 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
589587 }
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+9−2
@@ -18,7 +18,8 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import ".."
2020import "../../../qml/Greeter"
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDMController 0.1
22+import LightDM.FullLightDM 0.1 as LightDM
2223import Ubuntu.Components 1.3
2324import Ubuntu.Telephony 0.1 as Telephony
2425import Unity.Test 0.1 as UT
@@ -30,6 +31,12 @@ Item {
3031
3132 Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark" // use the same theme as the real shell
3233
34+ Binding {
35+ target: LightDMController
36+ property: "userMode"
37+ value: "single"
38+ }
39+
3340 Row {
3441 anchors.fill: parent
3542 Loader {
@@ -252,7 +259,7 @@ Item {
252259 Binding {
253260 target: LightDM.Infographic
254261 property: "username"
255− value: "single"
262+ value: "has-password"
256263 }
257264
258265 SignalSpy {
tests/qmltests/Greeter/tst_WideView.qml+20−30
@@ -18,7 +18,8 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import ".."
2020import "../../../qml/Greeter"
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDMController 0.1
22+import LightDM.FullLightDM 0.1 as LightDM
2223import Ubuntu.Components 1.3
2324import Unity.Test 0.1 as UT
2425
@@ -31,12 +32,6 @@ StyledItem {
3132
3233 theme.name: "Ubuntu.Components.Themes.SuruDark"
3334
34− Binding {
35− target: LightDM.Users
36− property: "mockMode"
37− value: "full"
38− }
39−
4035 Row {
4136 anchors.fill: parent
4237 Loader {
@@ -271,15 +266,15 @@ StyledItem {
271266 id: multipleSessionsCheckbox
272267 onClicked: {
273268 if (checked) {
274− LightDM.Sessions.testScenario = "multipleSessions"
269+ LightDMController.sessionMode = "full";
275270 } else {
276− LightDM.Sessions.testScenario = "singleSession"
271+ LightDMController.sessionMode = "single";
277272 }
278273 }
279274 Connections {
280− target: LightDM.Sessions
281− onTestScenarioChanged: {
282− if (LightDM.Sessions.testScenario === "multipleSessions") {
275+ target: LightDMController
276+ onSessionModeChanged: {
277+ if (LightDMController.sessionMode === "full") {
283278 multipleSessionsCheckbox.checked = true;
284279 } else {
285280 multipleSessionsCheckbox.checked = false;
@@ -297,11 +292,11 @@ StyledItem {
297292
298293 width: units.gu(10)
299294 minimumValue: 0
300− maximumValue: LightDM.Sessions.numAvailableSessions
301− value: LightDM.Sessions.numSessions
302− visible: LightDM.Sessions.testScenario === "multipleSessions"
295+ maximumValue: LightDMController.numAvailableSessions
296+ value: LightDMController.numSessions
297+ visible: LightDMController.sessionMode === "full"
303298 Binding {
304− target: LightDM.Sessions
299+ target: LightDMController
305300 property: "numSessions"
306301 value: numSessionsSlider.value
307302 }
@@ -368,7 +363,8 @@ StyledItem {
368363 respondedSpy.clear();
369364 teaseSpy.clear();
370365 emergencySpy.clear();
371− LightDM.Sessions.testScenario = "multipleSessions"
366+ LightDMController.sessionMode = "full";
367+ LightDM.Sessions.iconSearchDirectories = [testIconDirectory];
372368 }
373369
374370 function cleanup() {
@@ -426,10 +422,6 @@ StyledItem {
426422 }
427423
428424 function test_sessionIconsAreValid() {
429− LightDM.Sessions.testScenario = "multipleSessions"
430− var originalDirectories = LightDM.Sessions.iconSearchDirectories
431− LightDM.Sessions.iconSearchDirectories = [testIconDirectory]
432−
433425 selectUser("has-password");
434426
435427 // Test the login list icon is valid
@@ -449,12 +441,10 @@ StyledItem {
449441
450442 function test_choosingNewSessionChangesLoginListIcon() {
451443 // Ensure the default session is selected (Ubuntu)
452− loader.active = false;
453− loader.active = true;
444+ cleanup();
454445
455446 selectUser("has-password");
456447
457− LightDM.Sessions.testScenario = "multipleSessions";
458448 var sessionChooserButton = findChild(view, "sessionChooserButton");
459449 var icon = String(sessionChooserButton.icon);
460450 compare(icon.indexOf("ubuntu") > -1, true);
@@ -465,25 +455,25 @@ StyledItem {
465455 var currentDelegate = findChild(view, delegateName);
466456 var sessionKey = LightDM.Sessions.data(i,LightDM.SessionRoles.KeyRole);
467457 if (sessionKey === "gnome-classic") {
458+ waitForRendering(currentDelegate);
468459 tap(currentDelegate);
469− var sessionChooserButton = findChild(view, "sessionChooserButton");
470460 waitForRendering(sessionChooserButton);
471− var icon = String(sessionChooserButton.icon);
472461 break;
473462 }
474463 }
475464
465+ icon = String(sessionChooserButton.icon);
476466 compare(icon.indexOf("gnome") > -1, true,
477467 "Expected icon to contain gnome but it was " + icon);
478468 }
479469
480470 function test_noSessionsDoesntBreakView() {
481− LightDM.Sessions.testScenario = "noSessions"
471+ LightDMController.sessionMode = "none";
482472 compare(LightDM.Sessions.count, 0)
483473 }
484474
485475 function test_sessionIconNotShownWithOneSession() {
486− LightDM.Sessions.testScenario = "singleSession"
476+ LightDMController.sessionMode = "single";
487477 compare(LightDM.Sessions.count, 1);
488478
489479 var sessionChooserButton = findChild(view, "sessionChooserButton");
@@ -491,7 +481,7 @@ StyledItem {
491481 }
492482
493483 function test_sessionIconNotShownWithActiveUser() {
494− LightDM.Sessions.testScenario = "multipleSessions";
484+ LightDMController.sessionMode = "full";
495485 compare(LightDM.Sessions.count > 1, true);
496486
497487 selectUser("active");
@@ -501,7 +491,7 @@ StyledItem {
501491 }
502492
503493 function test_sessionIconShownWithMultipleSessions() {
504− LightDM.Sessions.testScenario = "multipleSessions"
494+ LightDMController.sessionMode = "full";
505495 compare(LightDM.Sessions.count > 1, true);
506496
507497 selectUser("has-password");
tests/qmltests/Tutorial/tst_Tutorial.qml+3−3
@@ -17,7 +17,8 @@
1717import QtQuick 2.4
1818import QtTest 1.0
1919import AccountsService 0.1
20−import LightDM.IntegratedLightDM 0.1 as LightDM
20+import LightDMController 0.1
21+import LightDM.FullLightDM 0.1 as LightDM
2122import Ubuntu.Components 1.3
2223import Ubuntu.Components.ListItems 1.3
2324import Ubuntu.Telephony 0.1 as Telephony
@@ -85,8 +86,7 @@ Rectangle {
8586
8687 Component.onCompleted: {
8788 // must set the mock mode before loading the Shell
88− LightDM.Greeter.mockMode = "single-pin";
89− LightDM.Users.mockMode = "single-pin";
89+ LightDMController.userMode = "single-pin";
9090 shellLoader.active = true;
9191 }
9292
tests/qmltests/tst_OrientedShell.qml+8−1
@@ -22,7 +22,8 @@ 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 LightDMController 0.1
26+import LightDM.FullLightDM 0.1 as LightDM
2627import Powerd 0.1
2728import Unity.InputInfo 0.1
2829import Utils 0.1
@@ -38,6 +39,12 @@ Rectangle {
3839 width: units.gu(160) + controls.width
3940 height: units.gu(100)
4041
42+ Binding {
43+ target: LightDMController
44+ property: "userMode"
45+ value: "single"
46+ }
47+
4148 QtObject {
4249 id: applicationArguments
4350 property string deviceName: "mako"
tests/qmltests/tst_Shell.qml+5−7
@@ -18,7 +18,8 @@ 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 LightDMController 0.1
22+import LightDM.FullLightDM 0.1 as LightDM
2223import SessionBroadcast 0.1
2324import Ubuntu.Components 1.3
2425import Ubuntu.Components.ListItems 1.3 as ListItem
@@ -48,8 +49,7 @@ Rectangle {
4849
4950 Component.onCompleted: {
5051 // must set the mock mode before loading the Shell
51− LightDM.Greeter.mockMode = "single";
52− LightDM.Users.mockMode = "single";
52+ LightDMController.userMode = "single";
5353 shellLoader.active = true;
5454 }
5555
@@ -248,8 +248,7 @@ Rectangle {
248248 model: ["single", "single-passphrase", "single-pin", "full"]
249249 onSelectedIndexChanged: {
250250 testCase.tearDown();
251− LightDM.Greeter.mockMode = model[selectedIndex];
252− LightDM.Users.mockMode = model[selectedIndex];
251+ LightDMController.userMode = model[selectedIndex];
253252 shellLoader.active = true;
254253 }
255254 }
@@ -880,8 +879,7 @@ Rectangle {
880879 }
881880
882881 function setLightDMMockMode(mode) {
883− LightDM.Greeter.mockMode = mode;
884− LightDM.Users.mockMode = mode;
882+ LightDMController.userMode = mode;
885883 }
886884
887885 function test_showInputMethod() {
tests/qmltests/tst_ShellWithPin.qml+3−3
@@ -19,7 +19,8 @@ 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 LightDMController 0.1
23+import LightDM.FullLightDM 0.1 as LightDM
2324import Ubuntu.SystemImage 0.1
2425import Ubuntu.Telephony 0.1 as Telephony
2526import Unity.Application 0.1
@@ -35,8 +36,7 @@ Item {
3536
3637 Component.onCompleted: {
3738 // must set the mock mode before loading the Shell
38− LightDM.Greeter.mockMode = "single-pin";
39− LightDM.Users.mockMode = "single-pin";
39+ LightDMController.userMode = "single-pin";
4040 shellLoader.active = true;
4141 }
4242