on xenial help sign in
Simplify the lightdm mock to make future greeter improvements easier to test.
75ef7acMichael Terry
debian/rules+1−1
@@ -40,4 +40,4 @@ override_dh_makeshlibs:
40override_dh_shlibdeps:
40override_dh_shlibdeps:
41 # Some mock libraries link against liblightdm-qt5-3.so which we want to
41 # Some mock libraries link against liblightdm-qt5-3.so which we want to
42 # avoid, since we only really link against our mock one, not the system one.
42 # avoid, since we only really link against our mock one, not the system one.
43− dh_shlibdeps -XlibMockLightDM-qml.so -XlibMockAccountsService-qml.so -Lunity8-private
43+ dh_shlibdeps -XlibMockAccountsService-qml.so -Lunity8-private
plugins/LightDM/CMakeLists.txt−1
@@ -7,7 +7,6 @@ include_directories(
7 ${CMAKE_CURRENT_SOURCE_DIR}
7 ${CMAKE_CURRENT_SOURCE_DIR}
8 ${CMAKE_CURRENT_BINARY_DIR}
8 ${CMAKE_CURRENT_BINARY_DIR}
9 ${CMAKE_SOURCE_DIR}/plugins/Utils
9 ${CMAKE_SOURCE_DIR}/plugins/Utils
10− ${CMAKE_BINARY_DIR}/tests/mocks/LightDM/IntegratedLightDM
11 ${libunity8-private_SOURCE_DIR}
10 ${libunity8-private_SOURCE_DIR}
12 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
11 ${LIBUSERMETRICSOUTPUT_INCLUDE_DIRS}
13)
12)
plugins/LightDM/Greeter.cpp+1−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
plugins/LightDM/Greeter.h+2−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>
@@ -81,5 +80,3 @@ private Q_SLOTS:
81 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
80 void showPromptFilter(const QString &text, QLightDM::Greeter::PromptType type);
82 void authenticationCompleteFilter();
81 void authenticationCompleteFilter();
83};
82};
84−
85−#endif
plugins/LightDM/SessionsModel.cpp+1−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
@@ -128,7 +128,6 @@ SessionsModel::SessionsModel(QObject* parent)
128 }
128 }
129
129
130 setModel(m_model);
130 setModel(m_model);
131− setSourceModel(m_model);
132 setSortCaseSensitivity(Qt::CaseInsensitive);
131 setSortCaseSensitivity(Qt::CaseInsensitive);
133 setSortLocaleAware(true);
132 setSortLocaleAware(true);
134 setSortRole(Qt::DisplayRole);
133 setSortRole(Qt::DisplayRole);
plugins/LightDM/SessionsModel.h+4−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>
@@ -30,6 +29,7 @@ class SessionsModel : public UnitySortFilterProxyModelQML
30
29
31 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
30 Q_PROPERTY(QList<QUrl> iconSearchDirectories READ iconSearchDirectories
32 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
31 WRITE setIconSearchDirectories NOTIFY iconSearchDirectoriesChanged)
32+
33Q_SIGNALS:
33Q_SIGNALS:
34 void iconSearchDirectoriesChanged();
34 void iconSearchDirectoriesChanged();
35
35
@@ -54,6 +54,7 @@ public:
54 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
54 Q_INVOKABLE QUrl iconUrl(const QString sessionName) const;
55
55
56 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
56 void setIconSearchDirectories(const QList<QUrl> searchDirectories);
57+
57private:
58private:
58 QLightDM::SessionsModel* m_model;
59 QLightDM::SessionsModel* m_model;
59 QHash<int, QByteArray> m_roleNames;
60 QHash<int, QByteArray> m_roleNames;
@@ -63,5 +64,3 @@ private:
63 QUrl("/usr/share/unity-greeter/")};
64 QUrl("/usr/share/unity-greeter/")};
64
65
65};
66};
66−
67−#endif // UNITY_SESSIONSMODEL_H
plugins/LightDM/UsersModel.cpp+1−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
plugins/LightDM/UsersModel.h+2−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>
@@ -33,5 +30,3 @@ class UsersModel : public UnitySortFilterProxyModelQML
33public:
30public:
34 explicit UsersModel(QObject* parent=0);
31 explicit UsersModel(QObject* parent=0);
35};
32};
36−
37−#endif
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
@@ -42,8 +42,8 @@ macro(unity8_parse_arguments)
42
42
43 set(ld_paths)
43 set(ld_paths)
44 list(APPEND ld_paths
44 list(APPEND ld_paths
45+ ${UNITY_MOCKPATH}/liblightdm
45 ${UNITY_MOCKPATH}/libusermetrics
46 ${UNITY_MOCKPATH}/libusermetrics
46− ${UNITY_MOCKPATH}/LightDM/IntegratedLightDM/liblightdm
47 )
47 )
48
48
49 string(REPLACE ";" ":" ld_library_path "${ld_paths}")
49 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+2−1
@@ -32,8 +32,9 @@ add_subdirectory(Biometryd)
32add_subdirectory(Cursor)
32add_subdirectory(Cursor)
33add_subdirectory(GSettings.1.0)
33add_subdirectory(GSettings.1.0)
34add_subdirectory(indicator-service)
34add_subdirectory(indicator-service)
35+add_subdirectory(liblightdm)
35add_subdirectory(libusermetrics)
36add_subdirectory(libusermetrics)
36−add_subdirectory(LightDM)
37+add_subdirectory(LightDMController)
37add_subdirectory(Lights)
38add_subdirectory(Lights)
38add_subdirectory(MeeGo)
39add_subdirectory(MeeGo)
39add_subdirectory(Powerd)
40add_subdirectory(Powerd)
tests/mocks/LightDM/CMakeLists.txtdeleted−1
@@ -1 +0,0 @@
1−add_subdirectory(IntegratedLightDM)
tests/mocks/LightDM/IntegratedLightDM/CMakeLists.txtdeleted−50
@@ -1,50 +0,0 @@
1−# This is a copy of the normal LightDM plugin, but instead of statically
2−# linking in the lightdm bits, this one uses shared libraries so we can swap
3−# out different sets of users for different tests. When we finally switch to
4−# actually using the system liblightdm in the normal plugin, this version can
5−# be deleted.
6−
7−add_subdirectory(liblightdm)
8−
9−include_directories(
10− ${CMAKE_CURRENT_SOURCE_DIR}
11− ${CMAKE_CURRENT_BINARY_DIR}
12− ${CMAKE_SOURCE_DIR}/plugins/Utils
13− ${CMAKE_SOURCE_DIR}/plugins/LightDM
14− ${CMAKE_SOURCE_DIR}/tests/mocks/libusermetrics
15− ${libunity8-private_SOURCE_DIR}
16−)
17−
18−set(QMLPLUGIN_SRC
19− ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeter.cpp
20− ${CMAKE_SOURCE_DIR}/plugins/LightDM/DBusGreeterList.cpp
21− ${CMAKE_SOURCE_DIR}/plugins/LightDM/Greeter.cpp
22− ${CMAKE_SOURCE_DIR}/plugins/LightDM/SessionsModel.cpp
23− ${CMAKE_SOURCE_DIR}/plugins/LightDM/UsersModel.cpp
24− ${CMAKE_SOURCE_DIR}/plugins/Utils/unitysortfilterproxymodelqml.cpp
25− MockGreeter.cpp
26− MockSessionsModel.cpp
27− MockUsersModel.cpp
28− plugin.cpp
29− )
30−
31−add_library(MockLightDM-qml MODULE
32− ${QMLPLUGIN_SRC}
33− )
34−
35−# We want to link to liblightdm-qt5-3, but we don't want to depend on it being
36−# installed on the system. So we make sure we link to our full fake version
37−# At run time, we can point to whichever version we happen to be using via
38−# LD_LIBRARY_PATH.
39−target_link_libraries(MockLightDM-qml
40− MockLightDM
41− MockUserMetrics
42− unity8-private
43− )
44−
45−qt5_use_modules(MockLightDM-qml DBus Gui Qml)
46−
47−add_unity8_mock(LightDM.IntegratedLightDM 0.1 LightDM/IntegratedLightDM
48− TARGETS MockLightDM-qml
49− ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/liblightdm"
50−)
tests/mocks/LightDM/IntegratedLightDM/MockGreeter.cppdeleted−51
@@ -1,51 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#include "MockGreeter.h"
19−#include <GreeterPrivate.h>
20−
21−QString MockGreeter::mockMode() const
22−{
23− Q_D(const Greeter);
24− return d->m_greeter->mockMode();
25−}
26−
27−void MockGreeter::setMockMode(QString mockMode)
28−{
29− Q_D(Greeter);
30−
31− if (d->m_greeter->mockMode() != mockMode) {
32− d->m_greeter->setMockMode(mockMode);
33− Q_EMIT mockModeChanged(mockMode);
34− }
35−}
36−
37−QString MockGreeter::selectUserHint() const
38−{
39− Q_D(const Greeter);
40− return d->m_greeter->selectUserHint();
41−}
42−
43−void MockGreeter::setSelectUserHint(const QString &selectUserHint)
44−{
45− Q_D(Greeter);
46−
47− if (d->m_greeter->selectUserHint() != selectUserHint) {
48− d->m_greeter->setSelectUserHint(selectUserHint);
49− Q_EMIT selectUserHintChanged();
50− }
51−}
tests/mocks/LightDM/IntegratedLightDM/MockGreeter.hdeleted−42
@@ -1,42 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−// The real, production, Greeter
19−#include <Greeter.h>
20−
21−#ifndef MOCK_UNITY_GREETER_H
22−#define MOCK_UNITY_GREETER_H
23−
24−class MockGreeter : public Greeter {
25− Q_OBJECT
26−
27− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
28− Q_PROPERTY(QString selectUser READ selectUserHint WRITE setSelectUserHint NOTIFY selectUserHintChanged)
29−
30−public:
31− QString mockMode() const;
32− void setMockMode(QString mockMode);
33−
34− QString selectUserHint() const;
35− void setSelectUserHint(const QString &selectUserHint);
36−
37−Q_SIGNALS:
38− void mockModeChanged(QString mode);
39− void selectUserHintChanged();
40−};
41−
42−#endif // MOCK_UNITY_GREETER_H
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.cppdeleted−66
@@ -1,66 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#include "MockSessionsModel.h"
19−#include <QLightDM/SessionsModel>
20−
21−
22−int MockSessionsModel::numSessions() const
23−{
24− QLightDM::SessionsModel* qSessionsModel =
25− static_cast<QLightDM::SessionsModel*>(sourceModel());
26−
27− return qSessionsModel->numSessions();
28−}
29−
30−int MockSessionsModel::numAvailableSessions() const
31−{
32− QLightDM::SessionsModel* qSessionsModel =
33− static_cast<QLightDM::SessionsModel*>(sourceModel());
34−
35− return qSessionsModel->numAvailableSessions();
36−}
37−
38−QString MockSessionsModel::testScenario() const
39−{
40− QLightDM::SessionsModel* qSessionsModel =
41− static_cast<QLightDM::SessionsModel*>(sourceModel());
42−
43− return qSessionsModel->testScenario();
44−}
45−
46−void MockSessionsModel::setNumSessions(const int numSessions)
47−{
48− QLightDM::SessionsModel* qSessionsModel =
49− static_cast<QLightDM::SessionsModel*>(sourceModel());
50−
51− if (qSessionsModel->numSessions() != numSessions) {
52− qSessionsModel->setNumSessions(numSessions);
53− Q_EMIT numSessionsChanged();
54− }
55−}
56−
57−void MockSessionsModel::setTestScenario(const QString testScenario)
58−{
59− QLightDM::SessionsModel* qSessionsModel =
60− static_cast<QLightDM::SessionsModel*>(sourceModel());
61−
62− if (qSessionsModel->testScenario() != testScenario) {
63− qSessionsModel->setTestScenario(testScenario);
64− Q_EMIT testScenarioChanged();
65− }
66−}
tests/mocks/LightDM/IntegratedLightDM/MockSessionsModel.hdeleted−44
@@ -1,44 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#ifndef MOCK_UNITY_SESSIONSMODEL_H
19−#define MOCK_UNITY_SESSIONSMODEL_H
20−
21−#include <SessionsModel.h>
22−
23−class MockSessionsModel : public SessionsModel
24−{
25− Q_OBJECT
26−
27− Q_PROPERTY(int numAvailableSessions READ numAvailableSessions CONSTANT)
28− Q_PROPERTY(int numSessions READ numSessions WRITE setNumSessions NOTIFY numSessionsChanged)
29− Q_PROPERTY(QString testScenario READ testScenario WRITE setTestScenario NOTIFY testScenarioChanged)
30−
31−public:
32− int numAvailableSessions() const;
33− int numSessions() const;
34− QString testScenario() const;
35− void setNumSessions(const int numSessions);
36− void setTestScenario(const QString testScenario);
37−
38−Q_SIGNALS:
39− void numSessionsChanged();
40− void testScenarioChanged();
41−
42−};
43−
44−#endif // MOCK_UNITY_SESSIONSMODEL_H
tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.cppdeleted−44
@@ -1,44 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− */
17−
18−#include "MockUsersModel.h"
19−#include <QLightDM/UsersModel>
20−#include <QSortFilterProxyModel>
21−
22−MockUsersModel::MockUsersModel(QObject* parent)
23− : UsersModel(parent)
24−{
25−}
26−
27−QString MockUsersModel::mockMode() const
28−{
29− QLightDM::UsersModel* qUsersModel =
30− static_cast<QLightDM::UsersModel*>(static_cast<QSortFilterProxyModel*>(sourceModel())->sourceModel());
31−
32− return qUsersModel->mockMode();
33−}
34−
35−void MockUsersModel::setMockMode(QString mockMode)
36−{
37− QLightDM::UsersModel* qUsersModel =
38− static_cast<QLightDM::UsersModel*>(static_cast<QSortFilterProxyModel*>(sourceModel())->sourceModel());
39−
40− if (qUsersModel->mockMode() != mockMode) {
41− qUsersModel->setMockMode(mockMode);
42− Q_EMIT mockModeChanged(mockMode);
43− }
44−}
tests/mocks/LightDM/IntegratedLightDM/QLightDM/Greeterdeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "../liblightdm/Greeter.h"
tests/mocks/LightDM/IntegratedLightDM/QLightDM/SessionsModeldeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "../liblightdm/SessionsModel.h"
tests/mocks/LightDM/IntegratedLightDM/QLightDM/UsersModeldeleted−17
@@ -1,17 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "../liblightdm/UsersModel.h"
tests/mocks/LightDM/IntegratedLightDM/liblightdm/CMakeLists.txtdeleted−21
@@ -1,21 +0,0 @@
1−set(LibLightDM_SOURCES
2− Greeter.cpp
3− SessionsModel.cpp
4− UsersModel.cpp
5− GreeterPrivate.cpp
6− SessionsModelPrivate.cpp
7− UsersModelPrivate.cpp
8− ${CMAKE_SOURCE_DIR}/plugins/Utils/qvariantlistmodel.cpp
9− )
10−
11−add_library(MockLightDM SHARED ${LibLightDM_SOURCES})
12−
13−qt5_use_modules(MockLightDM Gui)
14−
15−set_target_properties(MockLightDM PROPERTIES
16− OUTPUT_NAME lightdm-qt5-3
17− SOVERSION 0)
18−
19−install(TARGETS MockLightDM
20− DESTINATION ${SHELL_INSTALL_QML}/mocks/LightDM/IntegratedLightDM/liblightdm
21− )
tests/mocks/LightDM/IntegratedLightDM/liblightdm/Greeter.cppdeleted−201
@@ -1,201 +0,0 @@
1−/*
2− * Copyright (C) 2014 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "Greeter.h"
18−#include "GreeterPrivate.h"
19−#include <QtCore/QCoreApplication>
20−#include <QTimer>
21−
22−namespace QLightDM
23−{
24−
25−Greeter::Greeter(QObject *parent)
26− : QObject(parent),
27− d_ptr(new GreeterPrivate(this))
28−{
29−}
30−
31−Greeter::~Greeter()
32−{
33−}
34−
35−QString Greeter::authenticationUser() const
36−{
37− Q_D(const Greeter);
38− return d->authenticationUser;
39−}
40−
41−bool Greeter::hasGuestAccountHint() const
42−{
43− return true;
44−}
45−
46−QString Greeter::getHint(const QString &name) const
47−{
48− Q_UNUSED(name)
49− return "";
50−}
51−
52−QString Greeter::defaultSessionHint() const
53−{
54− return QStringLiteral("ubuntu");
55−}
56−
57−bool Greeter::hideUsersHint() const
58−{
59− return false;
60−}
61−
62−bool Greeter::showManualLoginHint() const
63−{
64− return true;
65−}
66−
67−bool Greeter::showRemoteLoginHint() const
68−{
69− return true;
70−}
71−
72−QString Greeter::selectUserHint() const
73−{
74− Q_D(const Greeter);
75− return d->selectUserHint;
76−}
77−
78−void Greeter::setSelectUserHint(const QString &selectUserHint)
79−{
80− Q_D(Greeter);
81− d->selectUserHint = selectUserHint;
82−}
83−
84−bool Greeter::selectGuestHint() const
85−{
86− return false;
87−}
88−
89−QString Greeter::autologinUserHint() const
90−{
91− return "";
92−}
93−
94−bool Greeter::autologinGuestHint() const
95−{
96− return false;
97−}
98−
99−int Greeter::autologinTimeoutHint() const
100−{
101− return 0;
102−}
103−
104−bool Greeter::inAuthentication() const
105−{
106− return false;
107−}
108−
109−QString Greeter::hostname() const
110−{
111− return "hostname1";
112−}
113−
114−bool Greeter::isAuthenticated() const
115−{
116− Q_D(const Greeter);
117− return d->authenticated;
118−}
119−
120−bool Greeter::connectSync()
121−{
122− return true;
123−}
124−
125−void Greeter::authenticate(const QString &username)
126−{
127− Q_D(Greeter);
128−
129− d->authenticated = false;
130− d->authenticationUser = username;
131− d->twoFactorDone = false;
132− QTimer::singleShot(0, this, &Greeter::delayedAuthentication);
133−}
134−
135−void Greeter::delayedAuthentication()
136−{
137− Q_D(Greeter);
138− d->handleAuthenticate();
139−}
140−
141−void Greeter::authenticateAsGuest()
142−{}
143−
144−void Greeter::authenticateAutologin()
145−{}
146−
147−void Greeter::authenticateRemote(const QString &session, const QString &username)
148−{
149− Q_UNUSED(session)
150− Q_UNUSED(username)
151−}
152−
153−void Greeter::cancelAuthentication()
154−{}
155−
156−void Greeter::setLanguage (const QString &language)
157−{
158− Q_UNUSED(language)
159−}
160−
161−bool Greeter::startSessionSync(const QString &session)
162−{
163− Q_UNUSED(session)
164− return true;
165−}
166−
167−void Greeter::respond(const QString &response)
168−{
169− Q_D(Greeter);
170−
171− d->handleRespond(response);
172−}
173−
174−void Greeter::sendAuthenticationComplete()
175−{
176− if (qEnvironmentVariableIsEmpty("UNITY_TESTING")) {
177− // simulate PAM's delay
178− QTimer::singleShot(1000, this, &Greeter::authenticationComplete);
179− } else {
180− Q_EMIT authenticationComplete();
181− }
182−}
183−
184−QString Greeter::mockMode() const
185−{
186− Q_D(const Greeter);
187− return d->mockMode;
188−}
189−
190−
191−void Greeter::setMockMode(QString mockMode)
192−{
193− Q_D(Greeter);
194−
195− if (d->mockMode != mockMode) {
196− d->mockMode = mockMode;
197− Q_EMIT mockModeChanged(mockMode);
198− }
199−}
200−
201−}
tests/mocks/LightDM/IntegratedLightDM/liblightdm/UsersModel.cppdeleted−121
@@ -1,121 +0,0 @@
1−/*
2− * Copyright (C) 2013-2016 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− *
16− * Author: Michael Terry <michael.terry@canonical.com>
17− */
18−
19−// LightDM currently is Qt4 compatible, and so doesn't define setRoleNames.
20−// To use the same method of setting role name that it does, we
21−// set our compatibility to Qt4 here too.
22−#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 0, 0)
23−
24−#include "UsersModel.h"
25−#include "UsersModelPrivate.h"
26−#include <QtCore/QDir>
27−#include <QtCore/QString>
28−#include <QtGui/QIcon>
29−
30−namespace QLightDM
31−{
32−
33−UsersModel::UsersModel(QObject *parent) :
34− QAbstractListModel(parent),
35− d_ptr(new UsersModelPrivate(this))
36−{
37− // Extend roleNames (we want to keep the "display" role)
38− QHash<int, QByteArray> roles = roleNames();
39− roles[NameRole] = "name";
40− roles[RealNameRole] = "realName";
41− roles[LoggedInRole] = "loggedIn";
42− roles[BackgroundRole] = "background";
43− roles[BackgroundPathRole] = "backgroundPath";
44− roles[SessionRole] = "session";
45− roles[HasMessagesRole] = "hasMessages";
46− roles[ImagePathRole] = "imagePath";
47− roles[UidRole] = "uid";
48− setRoleNames(roles);
49−}
50−
51−UsersModel::~UsersModel()
52−{
53− delete d_ptr;
54−}
55−
56−int UsersModel::rowCount(const QModelIndex &parent) const
57−{
58− Q_D(const UsersModel);
59−
60− if (parent.isValid()) {
61− return 0;
62− } else { // parent is root
63− return d->entries.size();
64− }
65−}
66−
67−QVariant UsersModel::data(const QModelIndex &index, int role) const
68−{
69− Q_D(const UsersModel);
70−
71− if (!index.isValid()) {
72− return QVariant();
73− }
74−
75− int row = index.row();
76− switch (role) {
77− case Qt::DisplayRole:
78− return d->entries[row].real_name;
79− case Qt::DecorationRole:
80− return QIcon();
81− case UsersModel::NameRole:
82− return d->entries[row].username;
83− case UsersModel::RealNameRole:
84− return d->entries[row].real_name;
85− case UsersModel::SessionRole:
86− return d->entries[row].session;
87− case UsersModel::LoggedInRole:
88− return d->entries[row].is_active;
89− case UsersModel::BackgroundRole:
90− return QPixmap(d->entries[row].background);
91− case UsersModel::BackgroundPathRole:
92− return d->entries[row].background;
93− case UsersModel::HasMessagesRole:
94− return d->entries[row].has_messages;
95− case UsersModel::ImagePathRole:
96− return "";
97− case UsersModel::UidRole:
98− return d->entries[row].uid;
99− default:
100− return QVariant();
101− }
102−}
103−
104−QString UsersModel::mockMode() const
105−{
106− Q_D(const UsersModel);
107− return d->mockMode;
108−}
109−
110−void UsersModel::setMockMode(QString mockMode)
111−{
112− Q_D(UsersModel);
113−
114− if (d->mockMode != mockMode) {
115− d->mockMode = mockMode;
116− Q_EMIT mockModeChanged(mockMode);
117− d->resetEntries();
118− }
119−}
120−
121−}
tests/mocks/LightDM/IntegratedLightDM/plugin.cppdeleted−79
@@ -1,79 +0,0 @@
1−/*
2− * Copyright (C) 2014, 2015 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−#include "plugin.h"
18−#include <DBusGreeter.h>
19−#include <DBusGreeterList.h>
20−#include "MockGreeter.h"
21−#include "MockSessionsModel.h"
22−#include "MockUsersModel.h"
23−#include <QLightDM/SessionsModel>
24−#include "ColorTheme.h"
25−#include "UserMetrics.h"
26−#include <QLightDM/UsersModel>
27−
28−#include <QAbstractItemModel>
29−#include <QDBusConnection>
30−#include <QtQml/qqml.h>
31−
32−static QObject *greeter_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
33−{
34− Q_UNUSED(engine)
35− Q_UNUSED(scriptEngine)
36−
37− MockGreeter *greeter = new MockGreeter;
38− new DBusGreeter(greeter, "/");
39− new DBusGreeterList(greeter, "/list");
40−
41− return greeter;
42−}
43−
44−static QObject *sessions_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
45−{
46− Q_UNUSED(engine)
47− Q_UNUSED(scriptEngine)
48− return new MockSessionsModel;
49−}
50−
51−static QObject *users_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
52−{
53− Q_UNUSED(engine)
54− Q_UNUSED(scriptEngine)
55− return new MockUsersModel;
56−}
57−
58−static QObject *infographic_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
59−{
60− Q_UNUSED(engine)
61− Q_UNUSED(scriptEngine)
62− return UserMetricsOutput::UserMetrics::getInstance();
63−}
64−
65−void LightDMPlugin::registerTypes(const char *uri)
66−{
67− qmlRegisterType<QAbstractItemModel>();
68− qmlRegisterType<UserMetricsOutput::ColorTheme>();
69−
70− Q_ASSERT(uri == QLatin1String("LightDM.IntegratedLightDM"));
71− qRegisterMetaType<QLightDM::Greeter::MessageType>("QLightDM::Greeter::MessageType");
72− qRegisterMetaType<QLightDM::Greeter::PromptType>("QLightDM::Greeter::PromptType");
73− qmlRegisterSingletonType<MockGreeter>(uri, 0, 1, "Greeter", greeter_provider);
74− qmlRegisterSingletonType<MockSessionsModel>(uri, 0, 1, "Sessions", sessions_provider);
75− qmlRegisterUncreatableType<QLightDM::SessionsModel>(uri, 0, 1, "SessionRoles", "Type is not instantiable");
76− qmlRegisterSingletonType<MockUsersModel>(uri, 0, 1, "Users", users_provider);
77− qmlRegisterUncreatableType<QLightDM::UsersModel>(uri, 0, 1, "UserRoles", "Type is not instantiable");
78− qmlRegisterSingletonType<UserMetricsOutput::UserMetrics>(uri, 0, 1, "Infographic", infographic_provider);
79−}
tests/mocks/LightDM/IntegratedLightDM/qmldirdeleted−2
@@ -1,2 +0,0 @@
1−module LightDM.IntegratedLightDM
2−plugin MockLightDM-qml
tests/mocks/LightDMController/CMakeLists.txtnew file+15
@@ -0,0 +1,15 @@
1+add_library(LightDMController MODULE
2+ plugin.cpp
3+ )
4+
5+target_include_directories(LightDMController PUBLIC
6+ ${CMAKE_SOURCE_DIR}/tests/mocks/liblightdm/
7+ )
8+
9+target_link_libraries(LightDMController
10+ MockLightDM
11+ )
12+
13+qt5_use_modules(LightDMController Qml)
14+
15+add_unity8_mock(LightDMController 0.1 LightDMController TARGETS LightDMController)
tests/mocks/LightDM/IntegratedLightDM/MockUsersModel.h → tests/mocks/LightDMController/plugin.cpprenamed+16−20
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright (C) 2017 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,28 +12,24 @@
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 */
15 */
17
16
18−#ifndef MOCK_UNITY_USERSMODEL_H
19−#define MOCK_UNITY_USERSMODEL_H
20−
21−#include <UsersModel.h>
17+#include "plugin.h"
22−
23−class MockUsersModel : public UsersModel
24−{
25− Q_OBJECT
26
18
27− Q_PROPERTY(QString mockMode READ mockMode WRITE setMockMode NOTIFY mockModeChanged)
19+#include "MockController.h"
28
20
29−public:
21+#include <QtQml/qqml.h>
30− explicit MockUsersModel(QObject* parent=0);
31
22
32− QString mockMode() const;
23+static QObject *mock_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
33− void setMockMode(QString mockMode);
24+{
34−
25+ Q_UNUSED(scriptEngine)
35−Q_SIGNALS:
26+ auto controller = QLightDM::MockController::instance();
36− void mockModeChanged(QString mode);
27+ engine->setObjectOwnership(controller, QQmlEngine::CppOwnership);
28+ return controller;
37−};
29+}
38
30
39−#endif // MOCK_UNITY_USERSMODEL_H
31+void LightDMControllerPlugin::registerTypes(const char *uri)
32+{
33+ Q_ASSERT(uri == QLatin1String("LightDMController"));
34+ qmlRegisterSingletonType<QLightDM::MockController>(uri, 0, 1, "LightDMController", mock_provider);
35+}
tests/mocks/LightDM/IntegratedLightDM/plugin.h → tests/mocks/LightDMController/plugin.hrenamed+5−8
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2014, 2015 Canonical, Ltd.
2+ * Copyright (C) 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
@@ -14,13 +14,12 @@
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 MOCK_LIGHTDM_PLUGIN_H
17+#pragma once
18−#define MOCK_LIGHTDM_PLUGIN_H
19
18
20−#include <QtQml/QQmlEngine>
19+#include <QQmlEngine>
21−#include <QtQml/QQmlExtensionPlugin>
20+#include <QQmlExtensionPlugin>
22
21
23−class LightDMPlugin : public QQmlExtensionPlugin
22+class LightDMControllerPlugin : public QQmlExtensionPlugin
24{
23{
25 Q_OBJECT
24 Q_OBJECT
26 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
25 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
@@ -28,5 +27,3 @@ class LightDMPlugin : public QQmlExtensionPlugin
28public:
27public:
29 void registerTypes(const char *uri) override;
28 void registerTypes(const char *uri) override;
30};
29};
31−
32−#endif
tests/mocks/LightDMController/qmldirnew file+2
@@ -0,0 +1,2 @@
1+module LightDMController
2+plugin LightDMController
tests/mocks/liblightdm/CMakeLists.txtnew file+18
@@ -0,0 +1,18 @@
1+set(MockLightDM_SOURCES
2+ MockController.cpp
3+ MockGreeter.cpp
4+ MockSessionsModel.cpp
5+ MockUsersModel.cpp
6+ )
7+
8+add_library(MockLightDM SHARED ${MockLightDM_SOURCES})
9+
10+qt5_use_modules(MockLightDM DBus Gui)
11+
12+set_target_properties(MockLightDM PROPERTIES
13+ OUTPUT_NAME lightdm-qt5-3
14+ SOVERSION 0)
15+
16+install(TARGETS MockLightDM
17+ DESTINATION ${SHELL_INSTALL_QML}/mocks/liblightdm
18+ )
tests/mocks/LightDM/IntegratedLightDM/liblightdm/GreeterPrivate.cpp → tests/mocks/liblightdm/GreeterPrivate.cpprenamed

The content is the same.

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

The content is the same.

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

The content is the same.

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

The content is the same.

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

The content is the same.

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

The content is the same.

tests/plugins/LightDM/IntegratedLightDM/CMakeLists.txt+3−3
@@ -1,6 +1,7 @@
1include_directories(
1include_directories(
2 ${GLIB_INCLUDE_DIRS}
2 ${GLIB_INCLUDE_DIRS}
3 ${CMAKE_CURRENT_BINARY_DIR}
3 ${CMAKE_CURRENT_BINARY_DIR}
4+ ${CMAKE_SOURCE_DIR}/plugins/LightDM/IntegratedLightDM
4 )
5 )
5
6
6add_executable(GreeterDBusTestExec
7add_executable(GreeterDBusTestExec
@@ -28,7 +29,7 @@ install(FILES greeter.qml
28add_unity8_uitest(GreeterDBus dbus-test-runner
29add_unity8_uitest(GreeterDBus dbus-test-runner
29 ARG_PREFIX "--parameter"
30 ARG_PREFIX "--parameter"
30 ARGS --task $<TARGET_FILE:GreeterDBusTestExec>
31 ARGS --task $<TARGET_FILE:GreeterDBusTestExec>
31− DEPENDS MockLightDM MockLightDM-qml
32+ DEPENDS MockLightDM
32 )
33 )
33
34
34add_executable(GreeterPamTestExec
35add_executable(GreeterPamTestExec
@@ -64,12 +65,12 @@ target_include_directories(GreeterSessionsModelTestExec PUBLIC
64 ${CMAKE_SOURCE_DIR}/plugins/LightDM
65 ${CMAKE_SOURCE_DIR}/plugins/LightDM
65 ${CMAKE_SOURCE_DIR}/plugins/Utils
66 ${CMAKE_SOURCE_DIR}/plugins/Utils
66 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
67 ${CMAKE_SOURCE_DIR}/tests/mocks/LightDM/IntegratedLightDM
68+ ${CMAKE_SOURCE_DIR}/tests/mocks/liblightdm/
67 )
69 )
68install(TARGETS GreeterSessionsModelTestExec
70install(TARGETS GreeterSessionsModelTestExec
69 DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/plugins/LightDM/IntegratedLightDM"
71 DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/plugins/LightDM/IntegratedLightDM"
70 )
72 )
71add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
73add_unity8_uitest(GreeterSessions GreeterSessionsModelTestExec
72− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
73 DEPENDS MockLightDM
74 DEPENDS MockLightDM
74 )
75 )
75
76
@@ -96,7 +97,6 @@ install(TARGETS GreeterUsersModelTestExec
96 DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/plugins/LightDM/IntegratedLightDM"
97 DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/plugins/LightDM/IntegratedLightDM"
97 )
98 )
98add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
99add_unity8_uitest(GreeterUsers GreeterUsersModelTestExec
99− ENVIRONMENT LIBLIGHTDM_MOCK_MODE=full
100 DEPENDS MockLightDM
100 DEPENDS MockLightDM
101 )
101 )
102
102
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+15−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
@@ -16,6 +16,8 @@
16
16
17#include "SessionsModel.h"
17#include "SessionsModel.h"
18
18
19+#include "MockController.h"
20+
19#include <QLightDM/SessionsModel>
21#include <QLightDM/SessionsModel>
20#include <QtCore/QModelIndex>
22#include <QtCore/QModelIndex>
21#include <QtTest>
23#include <QtTest>
@@ -31,14 +33,14 @@ private Q_SLOTS:
31 {
33 {
32 model = new SessionsModel();
34 model = new SessionsModel();
33 QVERIFY(model);
35 QVERIFY(model);
34− sourceModel = new QLightDM::SessionsModel();
36+ mock = QLightDM::MockController::instance();
35− QVERIFY(sourceModel);
37+ QVERIFY(mock);
36 }
38 }
37
39
38 void cleanup()
40 void cleanup()
39 {
41 {
40 delete model;
42 delete model;
41− delete sourceModel;
43+ // mock will be a singleton, doesn't need to be cleaned
42 }
44 }
43
45
44 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
46 static QModelIndex findByKey(QAbstractItemModel *model, const QString& key)
@@ -93,34 +95,34 @@ private Q_SLOTS:
93
95
94 void testMultipleSessionsCountIsCorrect()
96 void testMultipleSessionsCountIsCorrect()
95 {
97 {
96− sourceModel->setTestScenario("multipleSessions");
98+ mock->setProperty("sessionMode", "full");
97− QVERIFY(sourceModel->rowCount(QModelIndex()) > 1);
99+ QVERIFY(model->rowCount(QModelIndex()) > 1);
98 }
100 }
99
101
100 void testNoSessionsCountIsCorrect()
102 void testNoSessionsCountIsCorrect()
101 {
103 {
102− sourceModel->setTestScenario("noSessions");
104+ mock->setProperty("sessionMode", "none");
103− QVERIFY(sourceModel->rowCount(QModelIndex()) == 0);
105+ QVERIFY(model->rowCount(QModelIndex()) == 0);
104 }
106 }
105
107
106 void testSingleSessionCountIsCorrect()
108 void testSingleSessionCountIsCorrect()
107 {
109 {
108− sourceModel->setTestScenario("singleSession");
110+ mock->setProperty("sessionMode", "single");
109− QVERIFY(sourceModel->rowCount(QModelIndex()) == 1);
111+ QVERIFY(model->rowCount(QModelIndex()) == 1);
110 }
112 }
111
113
112 void testSessionNameIsCorrect()
114 void testSessionNameIsCorrect()
113 {
115 {
114 // This is testing the lookup, not the correctness of the strings,
116 // This is testing the lookup, not the correctness of the strings,
115 // so one test should be sufficient
117 // so one test should be sufficient
116− sourceModel->setTestScenario("multipleSessions");
118+ mock->setProperty("sessionMode", "full");
117− QVERIFY(model->data(findByKey(sourceModel, "ubuntu"),
119+ QVERIFY(model->data(findByKey(model, "ubuntu"),
118 Qt::DisplayRole).toString() == "Ubuntu");
120 Qt::DisplayRole).toString() == "Ubuntu");
119 }
121 }
120
122
121private:
123private:
122 SessionsModel *model;
124 SessionsModel *model;
123− QLightDM::SessionsModel *sourceModel;
125+ QObject *mock;
124};
126};
125
127
126QTEST_MAIN(GreeterSessionsModelTest)
128QTEST_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+8
@@ -20,12 +20,20 @@ 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 LightDMController 0.1
24+import LightDM.FullLightDM 0.1 as LightDM
23
25
24Item {
26Item {
25 id: root
27 id: root
26 width: units.gu(80)
28 width: units.gu(80)
27 height: units.gu(80)
29 height: units.gu(80)
28
30
31+ Binding {
32+ target: LightDMController
33+ property: "userMode"
34+ value: "single"
35+ }
36+
29 Shell {
37 Shell {
30 id: shell
38 id: shell
31 width: parent.width / 2
39 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+6−8
@@ -22,7 +22,8 @@ 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 LightDMController 0.1
25−import LightDM.IntegratedLightDM 0.1 as LightDM // This is the mock
26+import LightDM.FullLightDM 0.1 as LightDM
26import Unity.Test 0.1 as UT
27import Unity.Test 0.1 as UT
27
28
28Item {
29Item {
@@ -32,9 +33,6 @@ Item {
32 property url defaultBackground: "/usr/share/backgrounds/warty-final-ubuntu.png"
33 property url defaultBackground: "/usr/share/backgrounds/warty-final-ubuntu.png"
33
34
34 Component.onCompleted: {
35 Component.onCompleted: {
35− // set the mock mode before loading
36− LightDM.Greeter.mockMode = "full";
37− LightDM.Users.mockMode = "full";
38 loader.active = true;
36 loader.active = true;
39 }
37 }
40
38
@@ -146,7 +144,7 @@ Item {
146
144
147 function init() {
145 function init() {
148 greeterSettings.lockedOutTime = 0;
146 greeterSettings.lockedOutTime = 0;
149− LightDM.Greeter.selectUser = "";
147+ LightDMController.selectUserHint = "";
150 greeter.failedLoginsDelayAttempts = 7;
148 greeter.failedLoginsDelayAttempts = 7;
151 greeter.failedLoginsDelayMinutes = 5;
149 greeter.failedLoginsDelayMinutes = 5;
152 teaseSpy.clear();
150 teaseSpy.clear();
@@ -570,20 +568,20 @@ Item {
570 }
568 }
571
569
572 function test_selectUserHint() {
570 function test_selectUserHint() {
573− LightDM.Greeter.selectUser = "info-prompt";
571+ LightDMController.selectUserHint = "info-prompt";
574 resetLoader();
572 resetLoader();
575 var i = verifySelected("info-prompt");
573 var i = verifySelected("info-prompt");
576 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
574 verify(i != 0); // sanity-check that info-prompt isn't default 0 answer
577 }
575 }
578
576
579 function test_selectUserHintUnset() {
577 function test_selectUserHintUnset() {
580− LightDM.Greeter.selectUser = "";
578+ LightDMController.selectUserHint = "";
581 resetLoader();
579 resetLoader();
582 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
580 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
583 }
581 }
584
582
585 function test_selectUserHintInvalid() {
583 function test_selectUserHintInvalid() {
586− LightDM.Greeter.selectUser = "not-a-real-user";
584+ LightDMController.selectUserHint = "not-a-real-user";
587 resetLoader();
585 resetLoader();
588 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
586 verifySelected(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
589 }
587 }
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+9−2
@@ -18,7 +18,8 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import ".."
19import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21+import LightDMController 0.1
21−import LightDM.IntegratedLightDM 0.1 as LightDM
22+import LightDM.FullLightDM 0.1 as LightDM
22import Ubuntu.Components 1.3
23import Ubuntu.Components 1.3
23import Ubuntu.Telephony 0.1 as Telephony
24import Ubuntu.Telephony 0.1 as Telephony
24import Unity.Test 0.1 as UT
25import Unity.Test 0.1 as UT
@@ -30,6 +31,12 @@ Item {
30
31
31 Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark" // use the same theme as the real shell
32 Component.onCompleted: theme.name = "Ubuntu.Components.Themes.SuruDark" // use the same theme as the real shell
32
33
34+ Binding {
35+ target: LightDMController
36+ property: "userMode"
37+ value: "single"
38+ }
39+
33 Row {
40 Row {
34 anchors.fill: parent
41 anchors.fill: parent
35 Loader {
42 Loader {
@@ -252,7 +259,7 @@ Item {
252 Binding {
259 Binding {
253 target: LightDM.Infographic
260 target: LightDM.Infographic
254 property: "username"
261 property: "username"
255− value: "single"
262+ value: "has-password"
256 }
263 }
257
264
258 SignalSpy {
265 SignalSpy {
tests/qmltests/Greeter/tst_WideView.qml+20−30
@@ -18,7 +18,8 @@ import QtQuick 2.4
18import QtTest 1.0
18import QtTest 1.0
19import ".."
19import ".."
20import "../../../qml/Greeter"
20import "../../../qml/Greeter"
21+import LightDMController 0.1
21−import LightDM.IntegratedLightDM 0.1 as LightDM
22+import LightDM.FullLightDM 0.1 as LightDM
22import Ubuntu.Components 1.3
23import Ubuntu.Components 1.3
23import Unity.Test 0.1 as UT
24import Unity.Test 0.1 as UT
24
25
@@ -31,12 +32,6 @@ StyledItem {
31
32
32 theme.name: "Ubuntu.Components.Themes.SuruDark"
33 theme.name: "Ubuntu.Components.Themes.SuruDark"
33
34
34− Binding {
35− target: LightDM.Users
36− property: "mockMode"
37− value: "full"
38− }
39−
40 Row {
35 Row {
41 anchors.fill: parent
36 anchors.fill: parent
42 Loader {
37 Loader {
@@ -271,15 +266,15 @@ StyledItem {
271 id: multipleSessionsCheckbox
266 id: multipleSessionsCheckbox
272 onClicked: {
267 onClicked: {
273 if (checked) {
268 if (checked) {
274− LightDM.Sessions.testScenario = "multipleSessions"
269+ LightDMController.sessionMode = "full";
275 } else {
270 } else {
276− LightDM.Sessions.testScenario = "singleSession"
271+ LightDMController.sessionMode = "single";
277 }
272 }
278 }
273 }
279 Connections {
274 Connections {
280− target: LightDM.Sessions
275+ target: LightDMController
281− onTestScenarioChanged: {
276+ onSessionModeChanged: {
282− if (LightDM.Sessions.testScenario === "multipleSessions") {
277+ if (LightDMController.sessionMode === "full") {
283 multipleSessionsCheckbox.checked = true;
278 multipleSessionsCheckbox.checked = true;
284 } else {
279 } else {
285 multipleSessionsCheckbox.checked = false;
280 multipleSessionsCheckbox.checked = false;
@@ -297,11 +292,11 @@ StyledItem {
297
292
298 width: units.gu(10)
293 width: units.gu(10)
299 minimumValue: 0
294 minimumValue: 0
300− maximumValue: LightDM.Sessions.numAvailableSessions
295+ maximumValue: LightDMController.numAvailableSessions
301− value: LightDM.Sessions.numSessions
296+ value: LightDMController.numSessions
302− visible: LightDM.Sessions.testScenario === "multipleSessions"
297+ visible: LightDMController.sessionMode === "full"
303 Binding {
298 Binding {
304− target: LightDM.Sessions
299+ target: LightDMController
305 property: "numSessions"
300 property: "numSessions"
306 value: numSessionsSlider.value
301 value: numSessionsSlider.value
307 }
302 }
@@ -368,7 +363,8 @@ StyledItem {
368 respondedSpy.clear();
363 respondedSpy.clear();
369 teaseSpy.clear();
364 teaseSpy.clear();
370 emergencySpy.clear();
365 emergencySpy.clear();
371− LightDM.Sessions.testScenario = "multipleSessions"
366+ LightDMController.sessionMode = "full";
367+ LightDM.Sessions.iconSearchDirectories = [testIconDirectory];
372 }
368 }
373
369
374 function cleanup() {
370 function cleanup() {
@@ -426,10 +422,6 @@ StyledItem {
426 }
422 }
427
423
428 function test_sessionIconsAreValid() {
424 function test_sessionIconsAreValid() {
429− LightDM.Sessions.testScenario = "multipleSessions"
430− var originalDirectories = LightDM.Sessions.iconSearchDirectories
431− LightDM.Sessions.iconSearchDirectories = [testIconDirectory]
432−
433 selectUser("has-password");
425 selectUser("has-password");
434
426
435 // Test the login list icon is valid
427 // Test the login list icon is valid
@@ -449,12 +441,10 @@ StyledItem {
449
441
450 function test_choosingNewSessionChangesLoginListIcon() {
442 function test_choosingNewSessionChangesLoginListIcon() {
451 // Ensure the default session is selected (Ubuntu)
443 // Ensure the default session is selected (Ubuntu)
452− loader.active = false;
444+ cleanup();
453− loader.active = true;
454
445
455 selectUser("has-password");
446 selectUser("has-password");
456
447
457− LightDM.Sessions.testScenario = "multipleSessions";
458 var sessionChooserButton = findChild(view, "sessionChooserButton");
448 var sessionChooserButton = findChild(view, "sessionChooserButton");
459 var icon = String(sessionChooserButton.icon);
449 var icon = String(sessionChooserButton.icon);
460 compare(icon.indexOf("ubuntu") > -1, true);
450 compare(icon.indexOf("ubuntu") > -1, true);
@@ -465,25 +455,25 @@ StyledItem {
465 var currentDelegate = findChild(view, delegateName);
455 var currentDelegate = findChild(view, delegateName);
466 var sessionKey = LightDM.Sessions.data(i,LightDM.SessionRoles.KeyRole);
456 var sessionKey = LightDM.Sessions.data(i,LightDM.SessionRoles.KeyRole);
467 if (sessionKey === "gnome-classic") {
457 if (sessionKey === "gnome-classic") {
458+ waitForRendering(currentDelegate);
468 tap(currentDelegate);
459 tap(currentDelegate);
469− var sessionChooserButton = findChild(view, "sessionChooserButton");
470 waitForRendering(sessionChooserButton);
460 waitForRendering(sessionChooserButton);
471− var icon = String(sessionChooserButton.icon);
472 break;
461 break;
473 }
462 }
474 }
463 }
475
464
465+ icon = String(sessionChooserButton.icon);
476 compare(icon.indexOf("gnome") > -1, true,
466 compare(icon.indexOf("gnome") > -1, true,
477 "Expected icon to contain gnome but it was " + icon);
467 "Expected icon to contain gnome but it was " + icon);
478 }
468 }
479
469
480 function test_noSessionsDoesntBreakView() {
470 function test_noSessionsDoesntBreakView() {
481− LightDM.Sessions.testScenario = "noSessions"
471+ LightDMController.sessionMode = "none";
482 compare(LightDM.Sessions.count, 0)
472 compare(LightDM.Sessions.count, 0)
483 }
473 }
484
474
485 function test_sessionIconNotShownWithOneSession() {
475 function test_sessionIconNotShownWithOneSession() {
486− LightDM.Sessions.testScenario = "singleSession"
476+ LightDMController.sessionMode = "single";
487 compare(LightDM.Sessions.count, 1);
477 compare(LightDM.Sessions.count, 1);
488
478
489 var sessionChooserButton = findChild(view, "sessionChooserButton");
479 var sessionChooserButton = findChild(view, "sessionChooserButton");
@@ -491,7 +481,7 @@ StyledItem {
491 }
481 }
492
482
493 function test_sessionIconNotShownWithActiveUser() {
483 function test_sessionIconNotShownWithActiveUser() {
494− LightDM.Sessions.testScenario = "multipleSessions";
484+ LightDMController.sessionMode = "full";
495 compare(LightDM.Sessions.count > 1, true);
485 compare(LightDM.Sessions.count > 1, true);
496
486
497 selectUser("active");
487 selectUser("active");
@@ -501,7 +491,7 @@ StyledItem {
501 }
491 }
502
492
503 function test_sessionIconShownWithMultipleSessions() {
493 function test_sessionIconShownWithMultipleSessions() {
504− LightDM.Sessions.testScenario = "multipleSessions"
494+ LightDMController.sessionMode = "full";
505 compare(LightDM.Sessions.count > 1, true);
495 compare(LightDM.Sessions.count > 1, true);
506
496
507 selectUser("has-password");
497 selectUser("has-password");
tests/qmltests/Tutorial/tst_Tutorial.qml+3−3
@@ -17,7 +17,8 @@
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 LightDMController 0.1
20−import LightDM.IntegratedLightDM 0.1 as LightDM
21+import LightDM.FullLightDM 0.1 as LightDM
21import Ubuntu.Components 1.3
22import Ubuntu.Components 1.3
22import Ubuntu.Components.ListItems 1.3
23import Ubuntu.Components.ListItems 1.3
23import Ubuntu.Telephony 0.1 as Telephony
24import Ubuntu.Telephony 0.1 as Telephony
@@ -85,8 +86,7 @@ Rectangle {
85
86
86 Component.onCompleted: {
87 Component.onCompleted: {
87 // must set the mock mode before loading the Shell
88 // must set the mock mode before loading the Shell
88− LightDM.Greeter.mockMode = "single-pin";
89+ LightDMController.userMode = "single-pin";
89− LightDM.Users.mockMode = "single-pin";
90 shellLoader.active = true;
90 shellLoader.active = true;
91 }
91 }
92
92
tests/qmltests/tst_OrientedShell.qml+8−1
@@ -22,7 +22,8 @@ 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 LightDMController 0.1
25−import LightDM.IntegratedLightDM 0.1 as LightDM
26+import LightDM.FullLightDM 0.1 as LightDM
26import Powerd 0.1
27import Powerd 0.1
27import Unity.InputInfo 0.1
28import Unity.InputInfo 0.1
28import Utils 0.1
29import Utils 0.1
@@ -38,6 +39,12 @@ Rectangle {
38 width: units.gu(160) + controls.width
39 width: units.gu(160) + controls.width
39 height: units.gu(100)
40 height: units.gu(100)
40
41
42+ Binding {
43+ target: LightDMController
44+ property: "userMode"
45+ value: "single"
46+ }
47+
41 QtObject {
48 QtObject {
42 id: applicationArguments
49 id: applicationArguments
43 property string deviceName: "mako"
50 property string deviceName: "mako"
tests/qmltests/tst_Shell.qml+5−7
@@ -18,7 +18,8 @@ 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 LightDMController 0.1
21−import LightDM.IntegratedLightDM 0.1 as LightDM
22+import LightDM.FullLightDM 0.1 as LightDM
22import SessionBroadcast 0.1
23import SessionBroadcast 0.1
23import Ubuntu.Components 1.3
24import Ubuntu.Components 1.3
24import Ubuntu.Components.ListItems 1.3 as ListItem
25import Ubuntu.Components.ListItems 1.3 as ListItem
@@ -48,8 +49,7 @@ Rectangle {
48
49
49 Component.onCompleted: {
50 Component.onCompleted: {
50 // must set the mock mode before loading the Shell
51 // must set the mock mode before loading the Shell
51− LightDM.Greeter.mockMode = "single";
52+ LightDMController.userMode = "single";
52− LightDM.Users.mockMode = "single";
53 shellLoader.active = true;
53 shellLoader.active = true;
54 }
54 }
55
55
@@ -248,8 +248,7 @@ Rectangle {
248 model: ["single", "single-passphrase", "single-pin", "full"]
248 model: ["single", "single-passphrase", "single-pin", "full"]
249 onSelectedIndexChanged: {
249 onSelectedIndexChanged: {
250 testCase.tearDown();
250 testCase.tearDown();
251− LightDM.Greeter.mockMode = model[selectedIndex];
252− LightDM.Users.mockMode = model[selectedIndex];
251+ LightDMController.userMode = model[selectedIndex];
253 shellLoader.active = true;
252 shellLoader.active = true;
254 }
253 }
255 }
254 }
@@ -880,8 +879,7 @@ Rectangle {
880 }
879 }
881
880
882 function setLightDMMockMode(mode) {
881 function setLightDMMockMode(mode) {
883− LightDM.Greeter.mockMode = mode;
882+ LightDMController.userMode = mode;
884− LightDM.Users.mockMode = mode;
885 }
883 }
886
884
887 function test_showInputMethod() {
885 function test_showInputMethod() {
tests/qmltests/tst_ShellWithPin.qml+3−3
@@ -19,7 +19,8 @@ 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 LightDMController 0.1
22−import LightDM.IntegratedLightDM 0.1 as LightDM
23+import LightDM.FullLightDM 0.1 as LightDM
23import Ubuntu.SystemImage 0.1
24import Ubuntu.SystemImage 0.1
24import Ubuntu.Telephony 0.1 as Telephony
25import Ubuntu.Telephony 0.1 as Telephony
25import Unity.Application 0.1
26import Unity.Application 0.1
@@ -35,8 +36,7 @@ Item {
35
36
36 Component.onCompleted: {
37 Component.onCompleted: {
37 // must set the mock mode before loading the Shell
38 // must set the mock mode before loading the Shell
38− LightDM.Greeter.mockMode = "single-pin";
39+ LightDMController.userMode = "single-pin";
39− LightDM.Users.mockMode = "single-pin";
40 shellLoader.active = true;
40 shellLoader.active = true;
41 }
41 }
42
42