on xenial help sign in
Add a test for the session chooser icon in the greeter's sessions list

Approved by: Albert Astals Cid, Unity8 CI Bot

commit446b941aceacfe7d9ad8505e6d801e1c85c37be7 authorJosh Arenson <joshua.arenson@canonical.com> dateTue 24 Jan 2017, 07:39 (10 years ago) parent75ef7ac2a3c8ec
7 files changed+110−20
qml/Greeter/LoginList.qml−2 qml/Greeter/WideView.qml+1−4 tests/mocks/liblightdm/MockController.cpp+24 tests/mocks/liblightdm/MockController.h+15 tests/mocks/liblightdm/MockUsersModel.cpp+37−14 tests/mocks/liblightdm/MockUsersModel.h+2 tests/qmltests/Greeter/tst_WideView.qml+31
qml/Greeter/LoginList.qml−2
@@ -36,12 +36,10 @@ StyledItem {
3636 readonly property int cellHeight: units.gu(5)
3737 readonly property int highlightedHeight: units.gu(15)
3838 readonly property int moveDuration: UbuntuAnimation.FastDuration
39− property string selectedSession
4039 property string currentSession
4140 readonly property string currentUser: userList.currentItem.username
4241 property bool wasPrompted: false
4342
44− signal loginListSessionChanged(string session)
4543 signal responded(string response)
4644 signal selected(int index)
4745 signal sessionChooserButtonClicked()
qml/Greeter/WideView.qml+1−4
@@ -125,8 +125,6 @@ FocusScope {
125125 id: loginList
126126 objectName: "loginList"
127127
128− property int selectedUserIndex: 0
129−
130128 width: units.gu(40)
131129 anchors {
132130 left: parent.left
@@ -141,11 +139,10 @@ FocusScope {
141139 Behavior on boxVerticalOffset { UbuntuNumberAnimation {} }
142140
143141 model: root.userModel
144− currentSession: LightDMService.users.data(selectedUserIndex, LightDMService.userRoles.SessionRole);
145142 onResponded: root.responded(response)
146143 onSelected: {
147144 root.selected(index)
148− loginList.selectedUserIndex = index;
145+ currentSession = LightDMService.users.data(index, LightDMService.userRoles.SessionRole);
149146 }
150147 onSessionChooserButtonClicked: parent.state = "SessionsList"
151148
tests/mocks/liblightdm/MockController.cpp+24
@@ -85,6 +85,30 @@ void MockController::setUserMode(const QString &userMode)
8585 }
8686}
8787
88+QString MockController::sessionName() const
89+{
90+ return QString("INVALID - Please read directly from the UserModel");
91+}
92+
93+void MockController::setSessionName(const QString &sessionName)
94+{
95+ // Let the user model deal with this
96+ Q_EMIT sessionNameChanged(sessionName, m_currentUsername);
97+}
98+
99+QString MockController::currentUsername() const
100+{
101+ return m_currentUsername;
102+}
103+
104+void MockController::setCurrentUsername(const QString &username)
105+{
106+ if (m_currentUsername != username) {
107+ m_currentUsername = username;
108+ Q_EMIT currentUsernameChanged();
109+ }
110+}
111+
88112QString MockController::sessionMode() const
89113{
90114 return m_sessionMode;
tests/mocks/liblightdm/MockController.h+15
@@ -34,6 +34,11 @@ class Q_DECL_EXPORT MockController : public QObject
3434 // single, none, full
3535 Q_PROPERTY(QString sessionMode READ sessionMode WRITE setSessionMode NOTIFY sessionModeChanged)
3636
37+ // This would be best as a Q_INVOKABLE, but using a property allows for
38+ // keeping the mock cleaner
39+ Q_PROPERTY(QString sessionName READ sessionName WRITE setSessionName NOTIFY sessionNameChanged)
40+ Q_PROPERTY(QString currentUsername READ currentUsername WRITE setCurrentUsername NOTIFY currentUsernameChanged)
41+
3742 Q_PROPERTY(int numAvailableSessions READ numFullSessions CONSTANT)
3843 Q_PROPERTY(int numSessions READ numSessions WRITE setNumSessions NOTIFY numSessionsChanged)
3944
@@ -50,6 +55,12 @@ public:
5055 QString sessionMode() const;
5156 void setSessionMode(const QString &sessionMode);
5257
58+ QString sessionName() const;
59+ void setSessionName(const QString &userIndex);
60+
61+ QString currentUsername() const;
62+ void setCurrentUsername(const QString &username);
63+
5364 class SessionItem
5465 {
5566 public:
@@ -63,14 +74,18 @@ public:
6374 void setNumSessions(int numSessions);
6475
6576Q_SIGNALS:
77+ void currentUsernameChanged();
6678 void selectUserHintChanged();
6779 void userModeChanged();
6880 void sessionModeChanged();
6981 void numSessionsChanged();
82+ void sessionNameChanged(const QString &sessionName, const QString &username);
7083
7184private:
7285 explicit MockController(QObject* parent=0);
7386
87+ QString m_currentUsername;
88+ QString m_sessionName;
7489 QString m_selectUserHint;
7590 QString m_userMode;
7691 QString m_sessionMode;
tests/mocks/liblightdm/MockUsersModel.cpp+37−14
@@ -67,6 +67,8 @@ UsersModel::UsersModel(QObject *parent)
6767
6868 connect(MockController::instance(), &MockController::userModeChanged,
6969 this, &UsersModel::resetEntries);
70+ connect(MockController::instance(), &MockController::sessionNameChanged,
71+ this, &UsersModel::setCurrentSessionName);
7072 resetEntries();
7173}
7274
@@ -75,6 +77,22 @@ UsersModel::~UsersModel()
7577 delete d_ptr;
7678}
7779
80+void UsersModel::setCurrentSessionName(const QString &sessionName, const QString &username)
81+{
82+ Q_D(UsersModel);
83+
84+ int usersIndex = 0;
85+ for (auto &entry : d->entries) {
86+ if (username == entry.username) {
87+ entry.session = sessionName;
88+ break;
89+ }
90+ usersIndex++;
91+ }
92+
93+ dataChanged(index(usersIndex, 0), index(usersIndex, 0), QVector<int>(SessionRole));
94+}
95+
7896int UsersModel::rowCount(const QModelIndex &parent) const
7997{
8098 Q_D(const UsersModel);
@@ -138,28 +156,33 @@ void UsersModel::resetEntries()
138156 } else if (userMode == "single-pin") {
139157 d->entries = {{"has-pin", "Has PIN", "", 0, false, false, "ubuntu", 0}};
140158 } else if (userMode == "full") {
159+ /*
160+ * Since the real model sorts these entries alphabetically, the model indices
161+ * don't line up correctly. The easiest way to fix this is to ensure that this
162+ * list of entries REMAINS IN ALPHABETICAL ORDER at all times.
163+ */
141164 d->entries = {
165+ { "active", "Active Account", 0, 0, true, false, "ubuntu", 0 },
166+ { "auth-error", "Auth Error", 0, 0, false, false, "ubuntu", 0 },
167+ { "black-background", "Black Background", "#000000", 0, false, false, "ubuntu", 0 },
168+ { "color-background", "Color Background", "#E95420", 0, false, false, "ubuntu", 0 },
169+ { "different-prompt", "Different Prompt", 0, 0, false, false, "ubuntu", 0 },
170+ { "empty-name", "", 0, 0, false, false, "ubuntu", 0 },
142171 { "has-password", "Has Password", 0, 0, false, false, "ubuntu", 0 },
143172 { "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 },
149173 { "html-info-prompt", "HTML Info Prompt", 0, 0, false, false, "ubuntu", 0 },
174+ { "info-prompt", "Info Prompt", 0, 0, false, false, "ubuntu", 0 },
150175 { "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 },
153176 { "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 },
177+ { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "ubuntu", 0 },
158178 { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
159− { "unicode", "가나다라마", 0, 0, false, false, "ubuntu", 0 },
179+ { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
160180 { "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 },
181+ { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
182+ { "unicode", "가나다라마", 0, 0, false, false, "ubuntu", 0 },
183+ // white and black are a bit redundant, but useful for manually testing if UI is still readable
184+ { "white-background", "White Background", "#ffffff", 0, false, false, "ubuntu", 0 },
185+ { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, "ubuntu", 0 }
163186 };
164187 }
165188
tests/mocks/liblightdm/MockUsersModel.h+2
@@ -48,6 +48,8 @@ public:
4848 int rowCount(const QModelIndex &parent) const override;
4949 QVariant data(const QModelIndex &index, int role) const override;
5050
51+ void setCurrentSessionName(const QString &sessionName, const QString &username);
52+
5153private Q_SLOTS:
5254 void resetEntries();
5355
tests/qmltests/Greeter/tst_WideView.qml+31
@@ -411,6 +411,37 @@ StyledItem {
411411 waitForRendering(view);
412412 }
413413
414+ function test_changingSessionSticksToUser() {
415+ LightDMController.sessionMode = "full";
416+
417+ var loginList = findChild(view, "loginList");
418+ var fakeSession1 = "ASessionWillNeverBeCalledThis";
419+ var fakeSession2 = "ASessionWillAlsoNeverBeCalledThis";
420+
421+ // For this test to work, a user has to be selected and the
422+ // mock must be made aware of that user
423+ selectUser("has-password")
424+ LightDMController.currentUsername = "has-password"
425+ compare(LightDM.Sessions.count > 1, true);
426+ compare(loginList.currentSession != fakeSession1, true);
427+ LightDMController.sessionName = fakeSession1;
428+
429+ selectUser("has-pin")
430+ LightDMController.currentUsername = "has-pin"
431+ compare(loginList.currentSession != fakeSession2, true);
432+ LightDMController.sessionName = fakeSession2;
433+
434+ selectUser("has-password")
435+ tryCompare(loginList, "currentSession", fakeSession1);
436+
437+ selectUser("has-pin")
438+ tryCompare(loginList, "currentSession", fakeSession2);
439+
440+ // Force a model reset
441+ LightDMController.userMode = "single";
442+ LightDMController.userMode = "full";
443+ }
444+
414445 function test_tease_data() {
415446 return [
416447 {tag: "locked", x: 0, offset: 0, count: 0, locked: true},