on xenial help sign in
Refactor our lightdm mock
ddb5511Michael Terry
plugins/LightDM/Greeter.cpp+7−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013, 2015 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -147,3 +147,9 @@ void Greeter::authenticationCompleteFilter()
147 Q_EMIT isAuthenticatedChanged();
147 Q_EMIT isAuthenticatedChanged();
148 Q_EMIT authenticationComplete();
148 Q_EMIT authenticationComplete();
149}
149}
150+
151+QObject *Greeter::mock()
152+{
153+ Q_D(Greeter);
154+ return d->m_greeter->property("mock").value<QObject*>();
155+}
plugins/LightDM/Greeter.h+6−5
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2012,2013,2015 Canonical, Ltd.
2+ * Copyright (C) 2012-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -21,8 +21,7 @@
21 such edits in the future, and by inserting ourselves here, we have more
21 such edits in the future, and by inserting ourselves here, we have more
22 control. */
22 control. */
23
23
24−#ifndef UNITY_GREETER_H
24+#pragma once
25−#define UNITY_GREETER_H
26
25
27#include <QLightDM/Greeter>
26#include <QLightDM/Greeter>
28#include <QtCore/QObject>
27#include <QtCore/QObject>
@@ -40,6 +39,8 @@ class Greeter : public QObject
40 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
39 Q_PROPERTY(bool promptless READ promptless NOTIFY promptlessChanged)
41 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
40 Q_PROPERTY(QString selectUser READ selectUser CONSTANT)
42
41
42+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
43+
43public:
44public:
44 explicit Greeter(QObject* parent=0);
45 explicit Greeter(QObject* parent=0);
45
46
@@ -50,6 +51,8 @@ public:
50 bool promptless() const;
51 bool promptless() const;
51 QString selectUser() const;
52 QString selectUser() const;
52
53
54+ QObject *mock();
55+
53public Q_SLOTS:
56public Q_SLOTS:
54 void authenticate(const QString &username=QString());
57 void authenticate(const QString &username=QString());
55 void respond(const QString &response);
58 void respond(const QString &response);
@@ -81,5 +84,3 @@ private Q_SLOTS:
81 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
84 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
82 void authenticationCompleteFilter();
85 void authenticationCompleteFilter();
83};
86};
84−
85−#endif
plugins/LightDM/SessionsModel.cpp+6−2
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -111,6 +111,11 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
111 }
111 }
112}
112}
113
113
114+QObject *SessionsModel::mock()
115+{
116+ return m_model->property("mock").value<QObject*>();
117+}
118+
114SessionsModel::SessionsModel(QObject* parent)
119SessionsModel::SessionsModel(QObject* parent)
115 : UnitySortFilterProxyModelQML(parent)
120 : UnitySortFilterProxyModelQML(parent)
116{
121{
@@ -128,7 +133,6 @@ SessionsModel::SessionsModel(QObject* parent)
128 }
133 }
129
134
130 setModel(m_model);
135 setModel(m_model);
131− setSourceModel(m_model);
132 setSortCaseSensitivity(Qt::CaseInsensitive);
136 setSortCaseSensitivity(Qt::CaseInsensitive);
133 setSortLocaleAware(true);
137 setSortLocaleAware(true);
134 setSortRole(Qt::DisplayRole);
138 setSortRole(Qt::DisplayRole);
plugins/LightDM/SessionsModel.h+8−5
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -15,8 +15,7 @@
15 *
15 *
16 */
16 */
17
17
18−#ifndef UNITY_SESSIONSMODEL_H
18+#pragma once
19−#define UNITY_SESSIONSMODEL_H
20
19
21#include <unitysortfilterproxymodelqml.h>
20#include <unitysortfilterproxymodelqml.h>
22#include <QLightDM/SessionsModel>
21#include <QLightDM/SessionsModel>
@@ -32,6 +31,9 @@ class SessionsModel : public UnitySortFilterProxyModelQML
32
31
33 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
32 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
34 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
33 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
34+
35+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
36+
35Q_SIGNALS:
37Q_SIGNALS:
36 void iconSearchDirectoriesChanged();
38 void iconSearchDirectoriesChanged();
37
39
@@ -55,6 +57,9 @@ public:
55 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
57 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
56
58
57 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
59 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
60+
61+ QObject *mock();
62+
58private:
63private:
59 QLightDM::SessionsModel* m_model;
64 QLightDM::SessionsModel* m_model;
60 QHash<int, QByteArray> m_roleNames;
65 QHash<int, QByteArray> m_roleNames;
@@ -64,5 +69,3 @@ private:
64 QUrl("/usr/share/unity-greeter/")};
69 QUrl("/usr/share/unity-greeter/")};
65
70
66};
71};
67−
68−#endif // UNITY_SESSIONSMODEL_H
plugins/LightDM/UsersModel.cpp+8−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013,2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -68,4 +68,11 @@ UsersModel::UsersModel(QObject* parent)
68 sort(0);
68 sort(0);
69}
69}
70
70
71+QObject *UsersModel::mock()
72+{
73+ // get through MangleModel down to QLightDM::UsersModel
74+ MangleModel *mangleModel = static_cast<MangleModel*>(sourceModel());
75+ return mangleModel->sourceModel()->property("mock").value<QObject*>();
76+}
77+
71#include "UsersModel.moc"
78#include "UsersModel.moc"
plugins/LightDM/UsersModel.h+6−7
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2012,2013 Canonical, Ltd.
2+ * Copyright (C) 2012-2013,2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -12,16 +12,13 @@
12 *
12 *
13 * You should have received a copy of the GNU General Public License
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/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Authors: Michael Terry <michael.terry@canonical.com>
17 */
15 */
18
16
19/* This class is a really tiny filter around QLightDM::UsersModel. There are
17/* This class is a really tiny filter around QLightDM::UsersModel. There are
20 some operations that we want to edit a bit for the benefit of Qml.
18 some operations that we want to edit a bit for the benefit of Qml.
21 Specifically, we want to sort users according to realName. */
19 Specifically, we want to sort users according to realName. */
22
20
23−#ifndef UNITY_USERSMODEL_H
21+#pragma once
24−#define UNITY_USERSMODEL_H
25
22
26#include <unitysortfilterproxymodelqml.h>
23#include <unitysortfilterproxymodelqml.h>
27#include <QtCore/QObject>
24#include <QtCore/QObject>
@@ -30,8 +27,10 @@ class UsersModel : public UnitySortFilterProxyModelQML
30{
27{
31 Q_OBJECT
28 Q_OBJECT
32
29
30+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // for testing
31+
33public:
32public:
34 explicit UsersModel(QObject* parent=0);
33 explicit UsersModel(QObject* parent=0);
35−};
36
34
37−#endif
35+ QObject *mock();
36+};
qml/Greeter/LightDMService.qml+3−4
@@ -35,10 +35,9 @@ Loader {
35 // This trickery handles cases where applicationArguments aren't provided
35 // This trickery handles cases where applicationArguments aren't provided
36 // such as during testing
36 // such as during testing
37 property var fullLightDM: {
37 property var fullLightDM: {
38− if (typeof applicationArguments !== "undefined") {
38+ if (typeof applicationArguments === "undefined" ||
39− if (applicationArguments.mode === "greeter") {
39+ applicationArguments.mode === "greeter") {
40− return true;
40+ return true;
41− }
42 }
41 }
43 return false;
42 return false;
44 }
43 }
tests/CMakeLists.txt+1−1
@@ -45,8 +45,8 @@ macro(unity8_parse_arguments)
45
45
46 set(ld_paths)
46 set(ld_paths)
47 list(APPEND ld_paths
47 list(APPEND ld_paths
48+ ${UNITY_MOCKPATH}/liblightdm
48 ${UNITY_MOCKPATH}/libusermetrics
49 ${UNITY_MOCKPATH}/libusermetrics
49− ${UNITY_MOCKPATH}/LightDM/IntegratedLightDM/liblightdm
50 )
50 )
51
51
52 string(REPLACE ";" ":" ld_library_path "${ld_paths}")
52 string(REPLACE ";" ":" ld_library_path "${ld_paths}")
tests/autopilot/unity8/fixture_setup.py+1−1
@@ -74,7 +74,7 @@ class LaunchUnityWithFakeSensors(fixtures.Fixture):
74 def _get_lightdm_mock_path(self):
74 def _get_lightdm_mock_path(self):
75 lib_path = get_mocks_library_path()
75 lib_path = get_mocks_library_path()
76 lightdm_mock_path = os.path.abspath(
76 lightdm_mock_path = os.path.abspath(
77− os.path.join(lib_path, "LightDM" ,"IntegratedLightDM", "liblightdm")
77+ os.path.join(lib_path, "liblightdm")
78 )
78 )
79
79
80 if not os.path.exists(lightdm_mock_path):
80 if not os.path.exists(lightdm_mock_path):
tests/autopilot/unity8/shell/tests/__init__.py+1−1
@@ -264,7 +264,7 @@ class UnityTestCase(AutopilotTestCase):
264 def _get_lightdm_mock_path(self):
264 def _get_lightdm_mock_path(self):
265 lib_path = get_mocks_library_path()
265 lib_path = get_mocks_library_path()
266 lightdm_mock_path = os.path.abspath(
266 lightdm_mock_path = os.path.abspath(
267− os.path.join(lib_path, "LightDM" ,"IntegratedLightDM", "liblightdm")
267+ os.path.join(lib_path, "liblightdm")
268 )
268 )
269
269
270 if not os.path.exists(lightdm_mock_path):
270 if not os.path.exists(lightdm_mock_path):
tests/mocks/AccountsService/AccountsService.cpp+2−3
@@ -15,7 +15,7 @@
15 */
15 */
16
16
17#include "AccountsService.h"
17#include "AccountsService.h"
18−#include "MockUsersModel.h"
18+#include "UsersModel.h"
19
19
20#include <QLightDM/UsersModel>
20#include <QLightDM/UsersModel>
21#include <paths.h>
21#include <paths.h>
@@ -33,9 +33,8 @@ AccountsService::AccountsService(QObject* parent)
33 m_demoEdgesCompleted(),
33 m_demoEdgesCompleted(),
34 m_hereEnabled(false),
34 m_hereEnabled(false),
35 m_hereLicensePath(""),
35 m_hereLicensePath(""),
36− m_usersModel(new MockUsersModel(this))
36+ m_usersModel(new UsersModel(this))
37{
37{
38− m_usersModel->setMockMode("full");
39}
38}
40
39
41QString AccountsService::user() const
40QString AccountsService::user() const
tests/mocks/AccountsService/AccountsService.h+3−6
@@ -14,15 +14,14 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−#ifndef UNITY_MOCK_ACCOUNTSSERVICE_H
17+#pragma once
18−#define UNITY_MOCK_ACCOUNTSSERVICE_H
19
18
20#include <QObject>
19#include <QObject>
21#include <QString>
20#include <QString>
22#include <QStringList>
21#include <QStringList>
23#include <QVariant>
22#include <QVariant>
24
23
25−class MockUsersModel;
24+class UsersModel;
26
25
27class AccountsService: public QObject
26class AccountsService: public QObject
28{
27{
@@ -165,7 +164,5 @@ private:
165 QString m_realName;
164 QString m_realName;
166 QStringList m_kbdMap;
165 QStringList m_kbdMap;
167 QString m_email;
166 QString m_email;
168− MockUsersModel *m_usersModel;
167+ UsersModel *m_usersModel;
169};
168};
170−
171−#endif
tests/mocks/AccountsService/CMakeLists.txt+1−2
@@ -1,14 +1,13 @@
1include_directories(
1include_directories(
2 ${CMAKE_CURRENT_BINARY_DIR}
2 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_SOURCE_DIR}/plugins/LightDM
3 ${CMAKE_SOURCE_DIR}/plugins/LightDM
4+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM
4 ${CMAKE_SOURCE_DIR}/plugins/Utils
5 ${CMAKE_SOURCE_DIR}/plugins/Utils
5− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
6 )
6 )
7
7
8add_library(MockAccountsService-qml MODULE
8add_library(MockAccountsService-qml MODULE
9 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
9 ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
10 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
10 ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
11− ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.cpp
12 AccountsService.cpp
11 AccountsService.cpp
13 plugin.cpp
12 plugin.cpp
14 )
13 )
tests/mocks/CMakeLists.txt+1−1
@@ -33,8 +33,8 @@ add_subdirectory(Biometryd)
33add_subdirectory(Cursor)
33add_subdirectory(Cursor)
34add_subdirectory(GSettings.1.0)
34add_subdirectory(GSettings.1.0)
35add_subdirectory(indicator-service)
35add_subdirectory(indicator-service)
36+add_subdirectory(liblightdm)
36add_subdirectory(libusermetrics)
37add_subdirectory(libusermetrics)
37−add_subdirectory(LightDM)
38add_subdirectory(Lights)
38add_subdirectory(Lights)
39add_subdirectory(MeeGo)
39add_subdirectory(MeeGo)
40add_subdirectory(Powerd)
40add_subdirectory(Powerd)
tests/mocks/LightDM/CMakeLists.txtdeleted−1
@@ -1 +0,0 @@
1−add_subdirectory(IntegratedLightDM)
tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txtdeleted−51
@@ -1,51 +0,0 @@
1−# This is a copy of the normal LightDM plugin, but instead of statically
2−# linking in the lightdm bits, this one uses shared libraries so we can swap
3−# out different sets of users for different tests. When we finally switch to
4−# actually using the system liblightdm in the normal plugin, this version can
5−# be deleted.
6−
7−add_subdirectory(liblightdm)
8−
9−include_directories(
10− ${CMAKE_CURRENT_SOURCE_DIR}
11− ${CMAKE_CURRENT_BINARY_DIR}
12− ${CMAKE_SOURCE_DIR}/plugins/Utils
13− ${CMAKE_SOURCE_DIR}/plugins/LightDM
14− ${CMAKE_SOURCE_DIR}/tests/mocks/libusermetrics
15− ${libunity8-private_SOURCE_DIR}
16−)
17−
18−set(QMLPLUGIN_SRC
19− ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeter.cpp
20− ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeterList.cpp
21− ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
22− ${CMAKE_SOURCE_DIR}/plugins/LightDM/SessionsModel.cpp
23− ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
24− ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
25− MockGreeter.cpp
26− MockSessionsModel.cpp
27− MockUsersModel.cpp
28− plugin.cpp
29− )
30−
31−add_library(MockLightDM-qml MODULE
32− ${QMLPLUGIN_SRC}
33− )
34−
35−# We want to link to liblightdm-qt5-3, but we don't want to depend on it being
36−# installed on the system. So we make sure we link to our full fake version
37−# At run time, we can point to whichever version we happen to be using via
38−# LD_LIBRARY_PATH.
39−target_link_libraries(MockLightDM-qml
40− MockLightDM
41− MockUserMetrics
42− unity8-private
43− )
44−
45−qt5_use_modules(MockLightDM-qml DBus Gui Qml)
46−
47−add_unity8_mock(LightDM.IntegratedLightDM 0.1 LightDM/IntegratedLightDM
48− PREFIX mocks
49− TARGETS MockLightDM-qml
50− ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/liblightdm"
51−)
tests/mocks/LightDM/IntegratedLightDM/MockGreeter.cppdeleted−51
@@ -1,51 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#include "MockGreeter.h"
19−#include <GreeterPrivate.h>
20−
21−QString MockGreeter::mockMode() const
22−{
23− Q_D(const Greeter);
24− return d->m_greeter->mockMode();
25−}
26−
27−void MockGreeter::setMockMode(QString mockMode)
28−{
29− Q_D(Greeter);
30−
31− if (d->m_greeter->mockMode() != mockMode) {
32− d->m_greeter->setMockMode(mockMode);
33− Q_EMIT mockModeChanged(mockMode);
34− }
35−}
36−
37−QString MockGreeter::selectUserHint() const
38−{
39− Q_D(const Greeter);
40− return d->m_greeter->selectUserHint();
41−}
42−
43−void MockGreeter::setSelectUserHint(const QString &selectUserHint)
44−{
45− Q_D(Greeter);
46−
47− if (d->m_greeter->selectUserHint() != selectUserHint) {
48− d->m_greeter->setSelectUserHint(selectUserHint);
49− Q_EMIT selectUserHintChanged();
50− }
51−}
tests/mocks/LightDM/IntegratedLightDM/MockGreeter.hdeleted−42
@@ -1,42 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−// The real, production, Greeter
19−#include <Greeter.h>
20−
21−#ifndef MOCK_UNITY_GREETER_H
22−#define MOCK_UNITY_GREETER_H
23−
24−class MockGreeter : public Greeter {
25− Q_OBJECT
26−
27− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
28− Q_PROPERTY(QString selectUser READ selectUserHint WRITE setSelectUserHint NOTIFY selectUserHintChanged)
29−
30−public:
31− QString mockMode() const;
32− void setMockMode(QString mockMode);
33−
34− QString selectUserHint() const;
35− void setSelectUserHint(const QString &selectUserHint);
36−
37−Q_SIGNALS:
38− void mockModeChanged(QString mode);
39− void selectUserHintChanged();
40−};
41−
42−#endif // MOCK_UNITY_GREETER_H
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.cppdeleted−66
@@ -1,66 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#include "MockSessionsModel.h"
19−#include <QLightDM/SessionsModel>
20−
21−
22−int MockSessionsModel::numSessions() const
23−{
24− QLightDM::SessionsModel* qSessionsModel =
25− static_cast<QLightDM::SessionsModel*>(sourceModel());
26−
27− return qSessionsModel->numSessions();
28−}
29−
30−int MockSessionsModel::numAvailableSessions() const
31−{
32− QLightDM::SessionsModel* qSessionsModel =
33− static_cast<QLightDM::SessionsModel*>(sourceModel());
34−
35− return qSessionsModel->numAvailableSessions();
36−}
37−
38−QString MockSessionsModel::testScenario() const
39−{
40− QLightDM::SessionsModel* qSessionsModel =
41− static_cast<QLightDM::SessionsModel*>(sourceModel());
42−
43− return qSessionsModel->testScenario();
44−}
45−
46−void MockSessionsModel::setNumSessions(const int numSessions)
47−{
48− QLightDM::SessionsModel* qSessionsModel =
49− static_cast<QLightDM::SessionsModel*>(sourceModel());
50−
51− if (qSessionsModel->numSessions() != numSessions) {
52− qSessionsModel->setNumSessions(numSessions);
53− Q_EMIT numSessionsChanged();
54− }
55−}
56−
57−void MockSessionsModel::setTestScenario(const QString testScenario)
58−{
59− QLightDM::SessionsModel* qSessionsModel =
60− static_cast<QLightDM::SessionsModel*>(sourceModel());
61−
62− if (qSessionsModel->testScenario() != testScenario) {
63− qSessionsModel->setTestScenario(testScenario);
64− Q_EMIT testScenarioChanged();
65− }
66−}
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.hdeleted−44
@@ -1,44 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#ifndef MOCK_UNITY_SESSIONSMODEL_H
19−#define MOCK_UNITY_SESSIONSMODEL_H
20−
21−#include <SessionsModel.h>
22−
23−class MockSessionsModel : public SessionsModel
24−{
25− Q_OBJECT
26−
27− Q_PROPERTY(int numAvailableSessions READ numAvailableSessions CONSTANT)
28− Q_PROPERTY(int numSessions READ numSessions WRITE setNumSessions NOTIFY numSessionsChanged)
29− Q_PROPERTY(QString testScenario READ testScenario WRITE setTestScenario NOTIFY testScenarioChanged)
30−
31−public:
32− int numAvailableSessions() const;
33− int numSessions() const;
34− QString testScenario() const;
35− void setNumSessions(const int numSessions);
36− void setTestScenario(const QString testScenario);
37−
38−Q_SIGNALS:
39− void numSessionsChanged();
40− void testScenarioChanged();
41−
42−};
43−
44−#endif // MOCK_UNITY_SESSIONSMODEL_H
tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.cppdeleted−44
@@ -1,44 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#include "MockUsersModel.h"
19−#include <QLightDM/UsersModel>
20−#include <QSortFilterProxyModel>
21−
22−MockUsersModel::MockUsersModel(QObject* parent)
23− : UsersModel(parent)
24−{
25−}
26−
27−QString MockUsersModel::mockMode() const
28−{
29− QLightDM::UsersModel* qUsersModel =
30− static_cast<QLightDM::UsersModel*>(static_cast<QSortFilterProxyModel*>(sourceModel())->sourceModel());
31−
32− return qUsersModel->mockMode();
33−}
34−
35−void MockUsersModel::setMockMode(QString mockMode)
36−{
37− QLightDM::UsersModel* qUsersModel =
38− static_cast<QLightDM::UsersModel*>(static_cast<QSortFilterProxyModel*>(sourceModel())->sourceModel());
39−
40− if (qUsersModel->mockMode() != mockMode) {
41− qUsersModel->setMockMode(mockMode);
42− Q_EMIT mockModeChanged(mockMode);
43− }
44−}
tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.hdeleted−39
@@ -1,39 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#ifndef MOCK_UNITY_USERSMODEL_H
19−#define MOCK_UNITY_USERSMODEL_H
20−
21−#include <UsersModel.h>
22−
23−class MockUsersModel : public UsersModel
24−{
25− Q_OBJECT
26−
27− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
28−
29−public:
30− explicit MockUsersModel(QObject* parent=0);
31−
32− QString mockMode() const;
33− void setMockMode(QString mockMode);
34−
35−Q_SIGNALS:
36− void mockModeChanged(QString mode);
37−};
38−
39−#endif // MOCK_UNITY_USERSMODEL_H
tests/mocks/LightDM/IntegratedLightDM/QLightDM/Greeterdeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "../liblightdm/Greeter.h"
tests/mocks/LightDM/IntegratedLightDM/QLightDM/SessionsModeldeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "../liblightdm/SessionsModel.h"
tests/mocks/LightDM/IntegratedLightDM/QLightDM/UsersModeldeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "../liblightdm/UsersModel.h"
tests/mocks/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txtdeleted−20
@@ -1,20 +0,0 @@
1−set(LibLightDM_SOURCES
2− Greeter.cpp
3− SessionsModel.cpp
4− UsersModel.cpp
5− GreeterPrivate.cpp
6− SessionsModelPrivate.cpp
7− UsersModelPrivate.cpp
8− ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
9− )
10−
11−add_library(MockLightDM SHARED ${LibLightDM_SOURCES})
12−
13−qt5_use_modules(MockLightDM Gui)
14−
15−set_target_properties(MockLightDM PROPERTIES
16− OUTPUT_NAME lightdm-qt5-3)
17−
18−install(TARGETS MockLightDM
19− DESTINATION ${SHELL_INSTALL_QML}/mocks/LightDM/IntegratedLightDM/liblightdm
20− )
tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.cppdeleted−201
@@ -1,201 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "Greeter.h"
18−#include "GreeterPrivate.h"
19−#include <QtCore/QCoreApplication>
20−#include <QTimer>
21−
22−namespace QLightDM
23−{
24−
25−Greeter::Greeter(QObject *parent)
26− : QObject(parent),
27− d_ptr(new GreeterPrivate(this))
28−{
29−}
30−
31−Greeter::~Greeter()
32−{
33−}
34−
35−QString Greeter::authenticationUser() const
36−{
37− Q_D(const Greeter);
38− return d->authenticationUser;
39−}
40−
41−bool Greeter::hasGuestAccountHint() const
42−{
43− return true;
44−}
45−
46−QString Greeter::getHint(const QString &name) const
47−{
48− Q_UNUSED(name)
49− return "";
50−}
51−
52−QString Greeter::defaultSessionHint() const
53−{
54− return QStringLiteral("ubuntu");
55−}
56−
57−bool Greeter::hideUsersHint() const
58−{
59− return false;
60−}
61−
62−bool Greeter::showManualLoginHint() const
63−{
64− return true;
65−}
66−
67−bool Greeter::showRemoteLoginHint() const
68−{
69− return true;
70−}
71−
72−QString Greeter::selectUserHint() const
73−{
74− Q_D(const Greeter);
75− return d->selectUserHint;
76−}
77−
78−void Greeter::setSelectUserHint(const QString &selectUserHint)
79−{
80− Q_D(Greeter);
81− d->selectUserHint = selectUserHint;
82−}
83−
84−bool Greeter::selectGuestHint() const
85−{
86− return false;
87−}
88−
89−QString Greeter::autologinUserHint() const
90−{
91− return "";
92−}
93−
94−bool Greeter::autologinGuestHint() const
95−{
96− return false;
97−}
98−
99−int Greeter::autologinTimeoutHint() const
100−{
101− return 0;
102−}
103−
104−bool Greeter::inAuthentication() const
105−{
106− return false;
107−}
108−
109−QString Greeter::hostname() const
110−{
111− return "hostname1";
112−}
113−
114−bool Greeter::isAuthenticated() const
115−{
116− Q_D(const Greeter);
117− return d->authenticated;
118−}
119−
120−bool Greeter::connectSync()
121−{
122− return true;
123−}
124−
125−void Greeter::authenticate(const QString &username)
126−{
127− Q_D(Greeter);
128−
129− d->authenticated = false;
130− d->authenticationUser = username;
131− d->twoFactorDone = false;
132− QTimer::singleShot(0, this, &Greeter::delayedAuthentication);
133−}
134−
135−void Greeter::delayedAuthentication()
136−{
137− Q_D(Greeter);
138− d->handleAuthenticate();
139−}
140−
141−void Greeter::authenticateAsGuest()
142−{}
143−
144−void Greeter::authenticateAutologin()
145−{}
146−
147−void Greeter::authenticateRemote(const QString &session, const QString &username)
148−{
149− Q_UNUSED(session)
150− Q_UNUSED(username)
151−}
152−
153−void Greeter::cancelAuthentication()
154−{}
155−
156−void Greeter::setLanguage (const QString &language)
157−{
158− Q_UNUSED(language)
159−}
160−
161−bool Greeter::startSessionSync(const QString &session)
162−{
163− Q_UNUSED(session)
164− return true;
165−}
166−
167−void Greeter::respond(const QString &response)
168−{
169− Q_D(Greeter);
170−
171− d->handleRespond(response);
172−}
173−
174−void Greeter::sendAuthenticationComplete()
175−{
176− if (qgetenv("UNITY_TESTING").isEmpty()) {
177− // simulate PAM's delay
178− QTimer::singleShot(1000, this, &Greeter::authenticationComplete);
179− } else {
180− Q_EMIT authenticationComplete();
181− }
182−}
183−
184−QString Greeter::mockMode() const
185−{
186− Q_D(const Greeter);
187− return d->mockMode;
188−}
189−
190−
191−void Greeter::setMockMode(QString mockMode)
192−{
193− Q_D(Greeter);
194−
195− if (d->mockMode != mockMode) {
196− d->mockMode = mockMode;
197− Q_EMIT mockModeChanged(mockMode);
198− }
199−}
200−
201−}
tests/mocks/LightDM/IntegratedLightDM/liblightdm/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 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
3 * Copyright (C) 2010-2011 David Edmundson.
3 * Copyright (C) 2010-2011 David Edmundson.
4 * Copyright (C) 2010-2011 Robert Ancell
4 * Copyright (C) 2010-2011 Robert Ancell
5 *
5 *
@@ -18,16 +18,14 @@
18 * Author: David Edmundson <kde@davidedmundson.co.uk>
18 * Author: David Edmundson <kde@davidedmundson.co.uk>
19 */
19 */
20
20
21−#ifndef UNITY_MOCK_GREETER_H
21+#pragma once
22−#define UNITY_MOCK_GREETER_H
23−
24−#include <QtCore/QObject>
25−#include <QtCore/QVariant>
26
22
23+#include <QObject>
24+#include <QVariant>
27
25
28namespace QLightDM
26namespace QLightDM
29{
27{
30− class GreeterPrivate;
28+class GreeterPrivate;
31
29
32class Q_DECL_EXPORT Greeter : public QObject
30class Q_DECL_EXPORT Greeter : public QObject
33{
31{
@@ -44,8 +42,7 @@ class Q_DECL_EXPORT Greeter : public QObject
44
42
45 Q_ENUMS(PromptType MessageType)
43 Q_ENUMS(PromptType MessageType)
46
44
47− //Mock-only API for testing purposes
45+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
48− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
49
46
50public:
47public:
51 enum PromptType {
48 enum PromptType {
@@ -68,7 +65,6 @@ public:
68 bool showRemoteLoginHint() const;
65 bool showRemoteLoginHint() const;
69 bool hasGuestAccountHint() const;
66 bool hasGuestAccountHint() const;
70 QString selectUserHint() const;
67 QString selectUserHint() const;
71− void setSelectUserHint(const QString &selectUserHint); // only in mock
72 bool selectGuestHint() const;
68 bool selectGuestHint() const;
73 QString autologinUserHint() const;
69 QString autologinUserHint() const;
74 bool autologinGuestHint() const;
70 bool autologinGuestHint() const;
@@ -79,8 +75,7 @@ public:
79 QString authenticationUser() const;
75 QString authenticationUser() const;
80 QString hostname() const;
76 QString hostname() const;
81
77
82− QString mockMode() const;
78+ QObject *mock();
83− void setMockMode(QString mockMode);
84
79
85public Q_SLOTS:
80public Q_SLOTS:
86 bool connectSync();
81 bool connectSync();
@@ -98,18 +93,14 @@ Q_SIGNALS:
98 void showPrompt(QString text, QLightDM::Greeter::PromptType type);
93 void showPrompt(QString text, QLightDM::Greeter::PromptType type);
99 void authenticationComplete();
94 void authenticationComplete();
100 void autologinTimerExpired();
95 void autologinTimerExpired();
101− void mockModeChanged(QString mode);
102−
103−protected:
104− void sendAuthenticationComplete();
105
96
106private Q_SLOTS:
97private Q_SLOTS:
107− void delayedAuthentication();
98+ void handleAuthenticate();
108
99
109private:
100private:
101+ void sendAuthenticationComplete();
102+
110 GreeterPrivate *d_ptr;
103 GreeterPrivate *d_ptr;
111 Q_DECLARE_PRIVATE(Greeter)
104 Q_DECLARE_PRIVATE(Greeter)
112};
105};
113}
106}
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 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -21,22 +21,34 @@
21// set our compatibility to Qt4 here too.
21// set our compatibility to Qt4 here too.
22#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
22#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
23
23
24−#include "SessionsModel.h"
24+#include "MockController.h"
25−#include "SessionsModelPrivate.h"
25+#include "MockSessionsModel.h"
26−#include <QtCore/QDir>
27−#include <QtCore/QString>
28
26
29namespace QLightDM
27namespace QLightDM
30{
28{
31
29
30+class SessionsModelPrivate
31+{
32+public:
33+ QHash<int, QByteArray> roleNames;
34+ QList<MockController::SessionItem> sessionItems;
35+};
36+
32−SessionsModel::SessionsModel(QObject* parent) :
37+SessionsModel::SessionsModel(QObject* parent)
33− QAbstractListModel(parent),
38+ : QAbstractListModel(parent)
34− d_ptr(new SessionsModelPrivate(this))
39+ , d_ptr(new SessionsModelPrivate)
35{
40{
36 Q_D(SessionsModel);
41 Q_D(SessionsModel);
42+
37− m_roleNames = QAbstractListModel::roleNames();
43+ d->roleNames = QAbstractListModel::roleNames();
38− m_roleNames[KeyRole] = "key";
44+ d->roleNames[KeyRole] = "key";
39− m_roleNames[TypeRole] = "type";
45+ d->roleNames[TypeRole] = "type";
46+
47+ connect(MockController::instance(), &MockController::sessionModeChanged,
48+ this, &SessionsModel::resetEntries);
49+ connect(MockController::instance(), &MockController::numSessionsChanged,
50+ this, &SessionsModel::resetEntries);
51+ resetEntries();
40}
52}
41
53
42SessionsModel::~SessionsModel()
54SessionsModel::~SessionsModel()
@@ -66,7 +78,9 @@ QVariant SessionsModel::data(const QModelIndex& index, int role) const
66
78
67QHash<int, QByteArray> SessionsModel::roleNames() const
79QHash<int, QByteArray> SessionsModel::roleNames() const
68{
80{
69− return m_roleNames;
81+ Q_D(const SessionsModel);
82+
83+ return d->roleNames;
70}
84}
71
85
72int SessionsModel::rowCount(const QModelIndex& parent) const
86int SessionsModel::rowCount(const QModelIndex& parent) const
@@ -80,42 +94,29 @@ int SessionsModel::rowCount(const QModelIndex& parent) const
80 }
94 }
81}
95}
82
96
83−int SessionsModel::numSessions() const
97+void SessionsModel::resetEntries()
84{
98{
85− Q_D(const SessionsModel);
86− return d->numSessions;
87−}
88−
89−int SessionsModel::numAvailableSessions() const
90−{
91− Q_D(const SessionsModel);
99+ Q_D(SessionsModel);
92− return d->numAvailableSessions();
93−}
94
100
95−QString SessionsModel::testScenario() const
101+ beginResetModel();
96−{
97− Q_D(const SessionsModel);
98− return d->testScenario;
99−}
100
102
101−void SessionsModel::setNumSessions(int numSessions)
103+ QString sessionMode = MockController::instance()->sessionMode();
102−{
103− Q_D(SessionsModel);
104
104
105− if (d->numSessions != numSessions) {
105+ if (sessionMode == "full") {
106− d->numSessions = numSessions;
106+ d->sessionItems = MockController::instance()->fullSessionItems();
107− d->resetEntries();
107+ d->sessionItems = d->sessionItems.mid(0, MockController::instance()->numSessions());
108+ } else if (sessionMode == "single") {
109+ d->sessionItems = {MockController::instance()->fullSessionItems()[0]};
110+ } else {
111+ d->sessionItems = {};
108 }
112 }
113+
114+ endResetModel();
109}
115}
110
116
111−void SessionsModel::setTestScenario(QString testScenario)
117+QObject *SessionsModel::mock()
112{
118{
113− Q_D(SessionsModel);
119+ return MockController::instance();
114−
115− if (d->testScenario != testScenario) {
116− d->testScenario = testScenario;
117− d->resetEntries();
118− }
119}
120}
120
121
121} // namespace QLightDM
122} // namespace QLightDM
tests/mocks/LightDM/IntegratedLightDM/liblightdm/SessionsModel.h → tests/mocks/liblightdm/MockSessionsModel.hrenamed+12−16
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -15,11 +15,12 @@
15 *
15 *
16 */
16 */
17
17
18−#ifndef UNITY_MOCK_SESSIONSMODEL_H
18+#pragma once
19−#define UNITY_MOCK_SESSIONSMODEL_H
20
19
21−#include <QtCore/QAbstractListModel>
20+#include <QAbstractListModel>
21+#include <QByteArray>
22+#include <QHash>
22−#include <QtCore/QString>
23+#include <QString>
23
24
24namespace QLightDM
25namespace QLightDM
25{
26{
@@ -29,10 +30,11 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
29 {
30 {
30 Q_OBJECT
31 Q_OBJECT
31
32
33+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
34+
32 Q_ENUMS(SessionModelRoles SessionType)
35 Q_ENUMS(SessionModelRoles SessionType)
33
36
34 public:
37 public:
35−
36 enum SessionModelRoles {
38 enum SessionModelRoles {
37 //name is exposed as Qt::DisplayRole
39 //name is exposed as Qt::DisplayRole
38 //comment is exposed as Qt::TooltipRole
40 //comment is exposed as Qt::TooltipRole
@@ -54,19 +56,13 @@ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
54 int rowCount(const QModelIndex& parent) const override;
56 int rowCount(const QModelIndex& parent) const override;
55 QVariant data(const QModelIndex& index, int role) const override;
57 QVariant data(const QModelIndex& index, int role) const override;
56
58
57− int numSessions() const;
59+ QObject *mock();
58− int numAvailableSessions() const;
59− QString testScenario() const;
60− void setNumSessions(int numSessions);
61− void setTestScenario(QString testScenario);
62
60
63− protected:
61+ private Q_SLOTS:
64− SessionsModelPrivate* const d_ptr;
62+ void resetEntries();
65
63
66 private:
64 private:
67− QHash<int, QByteArray> m_roleNames;
65+ SessionsModelPrivate *d_ptr;
68 Q_DECLARE_PRIVATE(SessionsModel)
66 Q_DECLARE_PRIVATE(SessionsModel)
69 };
67 };
70}
68}
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 @@
1/*
1/*
2− * Copyright (C) 2013-2014 Canonical, Ltd.
2+ * Copyright (C) 2013-2016 Canonical, Ltd.
3 * Copyright (C) 2010-2011 David Edmundson.
3 * Copyright (C) 2010-2011 David Edmundson.
4 *
4 *
5 * This program is free software; you can redistribute it and/or modify
5 * This program is free software; you can redistribute it and/or modify
@@ -15,13 +15,11 @@
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
16 */
17
17
18−#ifndef UNITY_MOCK_USERSMODEL_H
18+#pragma once
19−#define UNITY_MOCK_USERSMODEL_H
20
19
21−#include <QtCore/QString>
22−#include <QtCore/QSharedDataPointer>
23#include <QAbstractListModel>
20#include <QAbstractListModel>
24−
21+#include <QList>
22+#include <QString>
25
23
26namespace QLightDM
24namespace QLightDM
27{
25{
@@ -33,11 +31,7 @@ class Q_DECL_EXPORT UsersModel : public QAbstractListModel
33
31
34 Q_ENUMS(UserModelRoles)
32 Q_ENUMS(UserModelRoles)
35
33
36− //Mock-only API for testing purposes
34+ Q_PROPERTY(QObject *mock READ mock CONSTANT) // only in mock
37− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
38−
39−Q_SIGNALS:
40− void mockModeChanged(QString mode);
41
35
42public:
36public:
43 explicit UsersModel(QObject *parent = 0);
37 explicit UsersModel(QObject *parent = 0);
@@ -57,8 +51,10 @@ public:
57 int rowCount(const QModelIndex &parent) const override;
51 int rowCount(const QModelIndex &parent) const override;
58 QVariant data(const QModelIndex &index, int role) const override;
52 QVariant data(const QModelIndex &index, int role) const override;
59
53
60− QString mockMode() const;
54+ QObject *mock();
61− void setMockMode(QString mockMode);
55+
56+private Q_SLOTS:
57+ void resetEntries();
62
58
63private:
59private:
64 UsersModelPrivate * const d_ptr;
60 UsersModelPrivate * const d_ptr;
@@ -66,5 +62,3 @@ private:
66};
62};
67
63
68}
64}
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(
4include_directories(
4include_directories(
5 ${GLIB_INCLUDE_DIRS}
5 ${GLIB_INCLUDE_DIRS}
6 ${CMAKE_CURRENT_BINARY_DIR}
6 ${CMAKE_CURRENT_BINARY_DIR}
7+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM
7 )
8 )
8
9
9add_executable(GreeterDBusTestExec
10add_executable(GreeterDBusTestExec
@@ -25,7 +26,6 @@ add_unity8_uitest(GreeterDBus dbus-test-runner
25 ARG_PREFIX "--parameter"
26 ARG_PREFIX "--parameter"
26 ARGS --task $<TARGET_FILE:GreeterDBusTestExec>
27 ARGS --task $<TARGET_FILE:GreeterDBusTestExec>
27 DEPENDS MockLightDM
28 DEPENDS MockLightDM
28− IMPORT_PATHS ${UNITY_MOCKPATH}
29 )
29 )
30
30
31add_executable(GreeterPamTestExec
31add_executable(GreeterPamTestExec
@@ -60,7 +60,6 @@ target_include_directories(GreeterSessionsModelTestExec PUBLIC
60 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
60 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
61 )
61 )
62add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
62add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
63− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
64 DEPENDS MockLightDM
63 DEPENDS MockLightDM
65 )
64 )
66
65
@@ -83,7 +82,6 @@ target_include_directories(GreeterUsersModelTestExec PUBLIC
83 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
82 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
84 )
83 )
85add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
84add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
86− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
87 DEPENDS MockLightDM
85 DEPENDS MockLightDM
88 )
86 )
89
87
tests/plugins/LightDM/IntegratedLightDM/greeter.qml+2−7
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright 2013 Canonical Ltd.
2+ * Copyright 2013,2015-2016 Canonical Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -15,13 +15,8 @@
15 */
15 */
16
16
17import QtQuick 2.4
17import QtQuick 2.4
18−import LightDM.IntegratedLightDM 0.1 as LightDM
18+import LightDM.FullLightDM 0.1 as LightDM
19
19
20Item {
20Item {
21 property var greeter: LightDM.Greeter
21 property var greeter: LightDM.Greeter
22− Binding {
23− target: LightDM.Greeter
24− property: "mockMode"
25− value: "full"
26− }
27}
22}
tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+13−13
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -31,14 +31,14 @@ private Q_SLOTS:
31 {
31 {
32 model = new SessionsModel();
32 model = new SessionsModel();
33 QVERIFY(model);
33 QVERIFY(model);
34− sourceModel = new QLightDM::SessionsModel();
34+ mock = model->mock();
35− QVERIFY(sourceModel);
35+ QVERIFY(mock);
36 }
36 }
37
37
38 void cleanup()
38 void cleanup()
39 {
39 {
40 delete model;
40 delete model;
41− delete sourceModel;
41+ // mock will be a singleton, doesn't need to be cleaned
42 }
42 }
43
43
44 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
44 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
@@ -93,34 +93,34 @@ private Q_SLOTS:
93
93
94 void testMultipleSessionsCountIsCorrect()
94 void testMultipleSessionsCountIsCorrect()
95 {
95 {
96− sourceModel->setTestScenario("multipleSessions");
96+ mock->setProperty("sessionMode", "full");
97− QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
97+ QVERIFY(model->rowCount(QModelIndex()) > 1);
98 }
98 }
99
99
100 void testNoSessionsCountIsCorrect()
100 void testNoSessionsCountIsCorrect()
101 {
101 {
102− sourceModel->setTestScenario("noSessions");
102+ mock->setProperty("sessionMode", "none");
103− QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
103+ QVERIFY(model->rowCount(QModelIndex()) == 0);
104 }
104 }
105
105
106 void testSingleSessionCountIsCorrect()
106 void testSingleSessionCountIsCorrect()
107 {
107 {
108− sourceModel->setTestScenario("singleSession");
108+ mock->setProperty("sessionMode", "single");
109− QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
109+ QVERIFY(model->rowCount(QModelIndex()) == 1);
110 }
110 }
111
111
112 void testSessionNameIsCorrect()
112 void testSessionNameIsCorrect()
113 {
113 {
114 // This is testing the lookup, not the correctness of the strings,
114 // This is testing the lookup, not the correctness of the strings,
115 // so one test should be sufficient
115 // so one test should be sufficient
116− sourceModel->setTestScenario("multipleSessions");
116+ mock->setProperty("sessionMode", "full");
117− QVERIFY(model->data(findByKey(sourceModel, "ubuntu"),
117+ QVERIFY(model->data(findByKey(model, "ubuntu"),
118 Qt::DisplayRole).toString() == "Ubuntu");
118 Qt::DisplayRole).toString() == "Ubuntu");
119 }
119 }
120
120
121private:
121private:
122 SessionsModel *model;
122 SessionsModel *model;
123− QLightDM::SessionsModel *sourceModel;
123+ QObject *mock;
124};
124};
125
125
126QTEST_MAIN(GreeterSessionsModelTest)
126QTEST_MAIN(GreeterSessionsModelTest)
tests/plugins/LightDM/IntegratedLightDM/usersmodel.cpp+2−12
@@ -46,37 +46,27 @@ private Q_SLOTS:
46 {
46 {
47 model = new UsersModel();
47 model = new UsersModel();
48 QVERIFY(model);
48 QVERIFY(model);
49− sourceModel = new QLightDM::UsersModel();
50− QVERIFY(sourceModel);
51 }
49 }
52
50
53 void cleanup()
51 void cleanup()
54 {
52 {
55 delete model;
53 delete model;
56− delete sourceModel;
57 }
54 }
58
55
59 void testMangleColor()
56 void testMangleColor()
60 {
57 {
61− QString background = getStringValue(sourceModel, "color-background", QLightDM::UsersModel::BackgroundPathRole);
62− QVERIFY(background == "#E95420");
63−
64− background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
58+ auto background = getStringValue(model, "color-background", QLightDM::UsersModel::BackgroundPathRole);
65 QVERIFY(background == "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#E95420'/></svg>");
59 QVERIFY(background == "data:image/svg+xml,<svg><rect width='100%' height='100%' fill='#E95420'/></svg>");
66 }
60 }
67
61
68 void testMangleEmptyName()
62 void testMangleEmptyName()
69 {
63 {
70− QString name = getStringValue(sourceModel, "empty-name", QLightDM::UsersModel::RealNameRole);
71− QVERIFY(name == "");
72−
73− name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
64+ auto name = getStringValue(model, "empty-name", QLightDM::UsersModel::RealNameRole);
74 QVERIFY(name == "empty-name");
65 QVERIFY(name == "empty-name");
75 }
66 }
76
67
77private:
68private:
78 UsersModel *model;
69 UsersModel *model;
79− QLightDM::UsersModel *sourceModel;
80};
70};
81
71
82QTEST_MAIN(GreeterUsersModelTest)
72QTEST_MAIN(GreeterUsersModelTest)
tests/qmltests/Dash/tst_DashShell.qml+7
@@ -20,12 +20,19 @@ import "../../../qml/Dash"
20import "../../../qml/"
20import "../../../qml/"
21import Ubuntu.Components 1.3
21import Ubuntu.Components 1.3
22import Unity.Test 0.1 as UT
22import Unity.Test 0.1 as UT
23+import LightDM.FullLightDM 0.1 as LightDM
23
24
24Item {
25Item {
25 id: root
26 id: root
26 width: units.gu(80)
27 width: units.gu(80)
27 height: units.gu(80)
28 height: units.gu(80)
28
29
30+ Binding {
31+ target: LightDM.Users.mock
32+ property: "userMode"
33+ value: "single"
34+ }
35+
29 Shell {
36 Shell {
30 id: shell
37 id: shell
31 width: parent.width / 2
38 width: parent.width / 2
tests/qmltests/Greeter/TestView.qml+1
@@ -32,6 +32,7 @@ Item {
32 property bool alphanumeric
32 property bool alphanumeric
33 property var userModel
33 property var userModel
34 property var infographicModel
34 property var infographicModel
35+ property bool waiting
35 readonly property bool fullyShown: _fullyShown
36 readonly property bool fullyShown: _fullyShown
36 readonly property bool required: _required
37 readonly property bool required: _required
37 readonly property bool animating: _animating
38 readonly property bool animating: _animating
tests/qmltests/Greeter/tst_Greeter.qml+5−8
@@ -22,7 +22,7 @@ import Ubuntu.Components 1.3
22import AccountsService 0.1
22import AccountsService 0.1
23import Biometryd 0.0
23import Biometryd 0.0
24import GSettings 1.0
24import GSettings 1.0
25−import LightDM.IntegratedLightDM 0.1 as LightDM // This is the mock
25+import LightDM.FullLightDM 0.1 as LightDM
26import Unity.Test 0.1 as UT
26import Unity.Test 0.1 as UT
27
27
28Item {
28Item {
@@ -32,9 +32,6 @@ Item {
32 property url defaultBackground: "/usr/share/backgrounds/warty-final-ubuntu.png"
32 property url defaultBackground: "/usr/share/backgrounds/warty-final-ubuntu.png"
33
33
34 Component.onCompleted: {
34 Component.onCompleted: {
35− // set the mock mode before loading
36− LightDM.Greeter.mockMode = "full";
37− LightDM.Users.mockMode = "full";
38 loader.active = true;
35 loader.active = true;
39 }
36 }
40
37
@@ -146,7 +143,7 @@ Item {
146
143
147 function init() {
144 function init() {
148 greeterSettings.lockedOutTime = 0;
145 greeterSettings.lockedOutTime = 0;
149− LightDM.Greeter.selectUser = "";
146+ LightDM.Greeter.mock.selectUserHint = "";
150 greeter.failedLoginsDelayAttempts = 7;
147 greeter.failedLoginsDelayAttempts = 7;
151 greeter.failedLoginsDelayMinutes = 5;
148 greeter.failedLoginsDelayMinutes = 5;
152 teaseSpy.clear();
149 teaseSpy.clear();
@@ -570,20 +567,20 @@ Item {
570 }
567 }
571
568
572 function test_selectUserHint() {
569 function test_selectUserHint() {
573− LightDM.Greeter.selectUser = "info-prompt";
570+ LightDM.Greeter.mock.selectUserHint = "info-prompt";
574 resetLoader();
571 resetLoader();
575 var i = verifySelected("info-prompt");
572 var i = verifySelected("info-prompt");
576 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
573 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
577 }
574 }
578
575
579 function test_selectUserHintUnset() {
576 function test_selectUserHintUnset() {
580− LightDM.Greeter.selectUser = "";
577+ LightDM.Greeter.mock.selectUserHint = "";
581 resetLoader();
578 resetLoader();
582 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
579 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
583 }
580 }
584
581
585 function test_selectUserHintInvalid() {
582 function test_selectUserHintInvalid() {
586− LightDM.Greeter.selectUser = "not-a-real-user";
583+ LightDM.Greeter.mock.selectUserHint = "not-a-real-user";
587 resetLoader();
584 resetLoader();
588 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
585 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
589 }
586 }
tests/qmltests/Greeter/tst_Infographics.qml+1−11
@@ -20,19 +20,9 @@ import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21import Ubuntu.Components 1.3
21import Ubuntu.Components 1.3
22import Unity.Test 0.1 as UT
22import Unity.Test 0.1 as UT
23−import LightDM.IntegratedLightDM 0.1 as LightDM
23+import LightDM.FullLightDM 0.1 as LightDM
24
24
25Item {
25Item {
26− Binding {
27− target: LightDM.Greeter
28− property: "mockMode"
29− value: "full"
30− }
31− Binding {
32− target: LightDM.Users
33− property: "mockMode"
34− value: "full"
35− }
36 property variant infographicModel: LightDM.Infographic
26 property variant infographicModel: LightDM.Infographic
37
27
38 width: units.gu(120)
28 width: units.gu(120)
tests/qmltests/Greeter/tst_NarrowView.qml+8−2
@@ -18,7 +18,7 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import ".."
19import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM.FullLightDM 0.1 as LightDM
22import Ubuntu.Components 1.3
22import Ubuntu.Components 1.3
23import Ubuntu.Telephony 0.1 as Telephony
23import Ubuntu.Telephony 0.1 as Telephony
24import Unity.Test 0.1 as UT
24import Unity.Test 0.1 as UT
@@ -30,6 +30,12 @@ Item {
30
30
31 Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark" // use the same theme as the real shell
31 Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark" // use the same theme as the real shell
32
32
33+ Binding {
34+ target: LightDM.Users.mock
35+ property: "userMode"
36+ value: "single"
37+ }
38+
33 Row {
39 Row {
34 anchors.fill: parent
40 anchors.fill: parent
35 Loader {
41 Loader {
@@ -252,7 +258,7 @@ Item {
252 Binding {
258 Binding {
253 target: LightDM.Infographic
259 target: LightDM.Infographic
254 property: "username"
260 property: "username"
255− value: "single"
261+ value: "has-password"
256 }
262 }
257
263
258 SignalSpy {
264 SignalSpy {
tests/qmltests/Greeter/tst_WideView.qml+15−23
@@ -18,7 +18,7 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import ".."
19import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM.FullLightDM 0.1 as LightDM
22import Ubuntu.Components 1.3
22import Ubuntu.Components 1.3
23import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
24
24
@@ -31,12 +31,6 @@ StyledItem {
31
31
32 theme.name: "Ubuntu.Components.Themes.SuruDark"
32 theme.name: "Ubuntu.Components.Themes.SuruDark"
33
33
34− Binding {
35− target: LightDM.Users
36− property: "mockMode"
37− value: "full"
38− }
39−
40 Row {
34 Row {
41 anchors.fill: parent
35 anchors.fill: parent
42 Loader {
36 Loader {
@@ -271,15 +265,15 @@ StyledItem {
271 id: multipleSessionsCheckbox
265 id: multipleSessionsCheckbox
272 onClicked: {
266 onClicked: {
273 if (checked) {
267 if (checked) {
274− LightDM.Sessions.testScenario = "multipleSessions"
268+ LightDM.Sessions.mock.sessionMode = "full";
275 } else {
269 } else {
276− LightDM.Sessions.testScenario = "singleSession"
270+ LightDM.Sessions.mock.sessionMode = "single";
277 }
271 }
278 }
272 }
279 Connections {
273 Connections {
280− target: LightDM.Sessions
274+ target: LightDM.Sessions.mock
281− onTestScenarioChanged: {
275+ onSessionModeChanged: {
282− if (LightDM.Sessions.testScenario === "multipleSessions") {
276+ if (LightDM.Sessions.mock.sessionMode === "full") {
283 multipleSessionsCheckbox.checked = true;
277 multipleSessionsCheckbox.checked = true;
284 } else {
278 } else {
285 multipleSessionsCheckbox.checked = false;
279 multipleSessionsCheckbox.checked = false;
@@ -297,11 +291,11 @@ StyledItem {
297
291
298 width: units.gu(10)
292 width: units.gu(10)
299 minimumValue: 0
293 minimumValue: 0
300− maximumValue: LightDM.Sessions.numAvailableSessions
294+ maximumValue: LightDM.Sessions.mock.numAvailableSessions
301− value: LightDM.Sessions.numSessions
295+ value: LightDM.Sessions.mock.numSessions
302− visible: LightDM.Sessions.testScenario === "multipleSessions"
296+ visible: LightDM.Sessions.mock.sessionMode === "full"
303 Binding {
297 Binding {
304− target: LightDM.Sessions
298+ target: LightDM.Sessions.mock
305 property: "numSessions"
299 property: "numSessions"
306 value: numSessionsSlider.value
300 value: numSessionsSlider.value
307 }
301 }
@@ -368,7 +362,7 @@ StyledItem {
368 respondedSpy.clear();
362 respondedSpy.clear();
369 teaseSpy.clear();
363 teaseSpy.clear();
370 emergencySpy.clear();
364 emergencySpy.clear();
371− LightDM.Sessions.testScenario = "multipleSessions"
365+ LightDM.Sessions.mock.sessionMode = "full";
372 }
366 }
373
367
374 function cleanup() {
368 function cleanup() {
@@ -426,7 +420,6 @@ StyledItem {
426 }
420 }
427
421
428 function test_sessionIconsAreValid() {
422 function test_sessionIconsAreValid() {
429− LightDM.Sessions.testScenario = "multipleSessions"
430 var originalDirectories = LightDM.Sessions.iconSearchDirectories
423 var originalDirectories = LightDM.Sessions.iconSearchDirectories
431 LightDM.Sessions.iconSearchDirectories = [testIconDirectory]
424 LightDM.Sessions.iconSearchDirectories = [testIconDirectory]
432
425
@@ -454,7 +447,6 @@ StyledItem {
454
447
455 selectUser("has-password");
448 selectUser("has-password");
456
449
457− LightDM.Sessions.testScenario = "multipleSessions";
458 var sessionChooserButton = findChild(view, "sessionChooserButton");
450 var sessionChooserButton = findChild(view, "sessionChooserButton");
459 var icon = String(sessionChooserButton.icon);
451 var icon = String(sessionChooserButton.icon);
460 compare(icon.indexOf("ubuntu") > -1, true);
452 compare(icon.indexOf("ubuntu") > -1, true);
@@ -478,12 +470,12 @@ StyledItem {
478 }
470 }
479
471
480 function test_noSessionsDoesntBreakView() {
472 function test_noSessionsDoesntBreakView() {
481− LightDM.Sessions.testScenario = "noSessions"
473+ LightDM.Sessions.mock.sessionMode = "none";
482 compare(LightDM.Sessions.count, 0)
474 compare(LightDM.Sessions.count, 0)
483 }
475 }
484
476
485 function test_sessionIconNotShownWithOneSession() {
477 function test_sessionIconNotShownWithOneSession() {
486− LightDM.Sessions.testScenario = "singleSession"
478+ LightDM.Sessions.mock.sessionMode = "single";
487 compare(LightDM.Sessions.count, 1);
479 compare(LightDM.Sessions.count, 1);
488
480
489 var sessionChooserButton = findChild(view, "sessionChooserButton");
481 var sessionChooserButton = findChild(view, "sessionChooserButton");
@@ -491,7 +483,7 @@ StyledItem {
491 }
483 }
492
484
493 function test_sessionIconNotShownWithActiveUser() {
485 function test_sessionIconNotShownWithActiveUser() {
494− LightDM.Sessions.testScenario = "multipleSessions";
486+ LightDM.Sessions.mock.sessionMode = "full";
495 compare(LightDM.Sessions.count > 1, true);
487 compare(LightDM.Sessions.count > 1, true);
496
488
497 selectUser("active");
489 selectUser("active");
@@ -501,7 +493,7 @@ StyledItem {
501 }
493 }
502
494
503 function test_sessionIconShownWithMultipleSessions() {
495 function test_sessionIconShownWithMultipleSessions() {
504− LightDM.Sessions.testScenario = "multipleSessions"
496+ LightDM.Sessions.mock.sessionMode = "full";
505 compare(LightDM.Sessions.count > 1, true);
497 compare(LightDM.Sessions.count > 1, true);
506
498
507 selectUser("has-password");
499 selectUser("has-password");
tests/qmltests/Tutorial/tst_Tutorial.qml+2−3
@@ -17,7 +17,7 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import AccountsService 0.1
19import AccountsService 0.1
20−import LightDM.IntegratedLightDM 0.1 as LightDM
20+import LightDM.FullLightDM 0.1 as LightDM
21import Ubuntu.Components 1.3
21import Ubuntu.Components 1.3
22import Ubuntu.Components.ListItems 1.3
22import Ubuntu.Components.ListItems 1.3
23import Ubuntu.Telephony 0.1 as Telephony
23import Ubuntu.Telephony 0.1 as Telephony
@@ -85,8 +85,7 @@ Rectangle {
85
85
86 Component.onCompleted: {
86 Component.onCompleted: {
87 // must set the mock mode before loading the Shell
87 // must set the mock mode before loading the Shell
88− LightDM.Greeter.mockMode = "single-pin";
89− LightDM.Users.mockMode = "single-pin";
88+ LightDM.Users.mock.userMode = "single-pin";
90 shellLoader.active = true;
89 shellLoader.active = true;
91 }
90 }
92
91
tests/qmltests/tst_OrientedShell.qml+7−1
@@ -22,7 +22,7 @@ import Ubuntu.Components 1.3
22import Ubuntu.Components.ListItems 1.3 as ListItem
22import Ubuntu.Components.ListItems 1.3 as ListItem
23import Unity.Application 0.1
23import Unity.Application 0.1
24import Unity.Test 0.1
24import Unity.Test 0.1
25−import LightDM.IntegratedLightDM 0.1 as LightDM
25+import LightDM.FullLightDM 0.1 as LightDM
26import Powerd 0.1
26import Powerd 0.1
27import Unity.InputInfo 0.1
27import Unity.InputInfo 0.1
28import Utils 0.1
28import Utils 0.1
@@ -38,6 +38,12 @@ Rectangle {
38 width: units.gu(160) + controls.width
38 width: units.gu(160) + controls.width
39 height: units.gu(100)
39 height: units.gu(100)
40
40
41+ Binding {
42+ target: LightDM.Users.mock
43+ property: "userMode"
44+ value: "single"
45+ }
46+
41 QtObject {
47 QtObject {
42 id: applicationArguments
48 id: applicationArguments
43 property string deviceName: "mako"
49 property string deviceName: "mako"
tests/qmltests/tst_Shell.qml+4−7
@@ -18,7 +18,7 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import AccountsService 0.1
19import AccountsService 0.1
20import GSettings 1.0
20import GSettings 1.0
21−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM.FullLightDM 0.1 as LightDM
22import SessionBroadcast 0.1
22import SessionBroadcast 0.1
23import Ubuntu.Components 1.3
23import Ubuntu.Components 1.3
24import Ubuntu.Components.ListItems 1.3 as ListItem
24import Ubuntu.Components.ListItems 1.3 as ListItem
@@ -46,8 +46,7 @@ Rectangle {
46
46
47 Component.onCompleted: {
47 Component.onCompleted: {
48 // must set the mock mode before loading the Shell
48 // must set the mock mode before loading the Shell
49− LightDM.Greeter.mockMode = "single";
49+ LightDM.Users.mock.userMode = "single";
50− LightDM.Users.mockMode = "single";
51 shellLoader.active = true;
50 shellLoader.active = true;
52 }
51 }
53
52
@@ -228,8 +227,7 @@ Rectangle {
228 model: ["single", "single-passphrase", "single-pin", "full"]
227 model: ["single", "single-passphrase", "single-pin", "full"]
229 onSelectedIndexChanged: {
228 onSelectedIndexChanged: {
230 shellLoader.active = false;
229 shellLoader.active = false;
231− LightDM.Greeter.mockMode = model[selectedIndex];
232− LightDM.Users.mockMode = model[selectedIndex];
230+ LightDM.Users.mock.userMode = model[selectedIndex];
233 shellLoader.active = true;
231 shellLoader.active = true;
234 }
232 }
235 }
233 }
@@ -803,8 +801,7 @@ Rectangle {
803 }
801 }
804
802
805 function setLightDMMockMode(mode) {
803 function setLightDMMockMode(mode) {
806− LightDM.Greeter.mockMode = mode;
804+ LightDM.Users.mock.userMode = mode;
807− LightDM.Users.mockMode = mode;
808 }
805 }
809
806
810 function test_showInputMethod() {
807 function test_showInputMethod() {
tests/qmltests/tst_ShellWithPin.qml+2−3
@@ -19,7 +19,7 @@ import Ubuntu.Components 1.3
19import QtTest 1.0
19import QtTest 1.0
20import AccountsService 0.1
20import AccountsService 0.1
21import GSettings 1.0
21import GSettings 1.0
22−import LightDM.IntegratedLightDM 0.1 as LightDM
22+import LightDM.FullLightDM 0.1 as LightDM
23import Ubuntu.SystemImage 0.1
23import Ubuntu.SystemImage 0.1
24import Ubuntu.Telephony 0.1 as Telephony
24import Ubuntu.Telephony 0.1 as Telephony
25import Unity.Application 0.1
25import Unity.Application 0.1
@@ -35,8 +35,7 @@ Item {
35
35
36 Component.onCompleted: {
36 Component.onCompleted: {
37 // must set the mock mode before loading the Shell
37 // must set the mock mode before loading the Shell
38− LightDM.Greeter.mockMode = "single-pin";
39− LightDM.Users.mockMode = "single-pin";
38+ LightDM.Users.mock.userMode = "single-pin";
40 shellLoader.active = true;
39 shellLoader.active = true;
41 }
40 }
42
41