on xenial help sign in
Complete weird test
commitdfa22e1ea92eb2f7244de8e63ef1c87b9afc6118 authorJosh Arenson <joshua.arenson@canonical.com> dateTue 15 Nov 2016, 13:17 (10 years ago) parentbbdd069
3 files changed+48−26
qml/Greeter/WideView.qml+16−3 tests/mocks/liblightdm/MockUsersModel.cpp+24−18 tests/qmltests/Greeter/tst_WideView.qml+8−5
qml/Greeter/WideView.qml+16−3
@@ -142,16 +142,29 @@ FocusScope {
142142
143143 model: root.userModel
144144 currentSession: LightDM.Users.data(selectedUserIndex,
145− LightDM.UserRoles.SessionRole);
145+ LightDM.UserRoles.SessionRole);
146146 onResponded: root.responded(response)
147147 onSelected: {
148− LightDM.Users.mock.currentUsername = currentUser;
148+ if (LightDM.Users.mock) {
149+ LightDM.Users.mock.currentUsername = currentUser;
150+ }
151+
152+ loginList.selectedUserIndex = index;
149153 root.selected(index)
150− selectedUserIndex = index;
151154 }
152155 onSessionChooserButtonClicked: parent.state = "SessionsList"
153156
154157 Keys.forwardTo: [sessionChooserLoader.item]
158+
159+ // This is only for testing
160+ Connections {
161+ // TODO when Qt 5.7
162+ //enabled: LightDM.Users.mock
163+ target: LightDM.Users
164+ onModelReset: {
165+ loginList.currentSession = LightDM.Users.data(loginList.selectedUserIndex, LightDM.UserRoles.SessionRole);
166+ }
167+ }
155168 }
156169
157170 Loader {
tests/mocks/liblightdm/MockUsersModel.cpp+24−18
@@ -81,15 +81,16 @@ void UsersModel::setCurrentSessionName(const QString &sessionName, const QString
8181{
8282 Q_D(UsersModel);
8383
84+ beginResetModel();
85+
8486 for (auto &entry : d->entries) {
8587 if (username == entry.username) {
8688 entry.session = sessionName;
87−
88− // Since the incides are mangled, there is no easy way to emit dataChanged
89− // and that doesn't matter for the limited use of this function
90− return;
89+ break;
9190 }
9291 }
92+
93+ endResetModel();
9394}
9495
9596int UsersModel::rowCount(const QModelIndex &parent) const
@@ -155,28 +156,33 @@ void UsersModel::resetEntries()
155156 } else if (userMode == "single-pin") {
156157 d->entries = {{"has-pin", "Has PIN", "", 0, false, false, "ubuntu", 0}};
157158 } 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+ */
158164 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 },
159171 { "has-password", "Has Password", 0, 0, false, false, "ubuntu", 0 },
160172 { "has-pin", "Has PIN", 0, 0, false, false, "ubuntu", 0 },
161− { "different-prompt", "Different Prompt", 0, 0, false, false, "ubuntu", 0 },
162− { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
163− { "auth-error", "Auth Error", 0, 0, false, false, "ubuntu", 0 },
164− { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
165− { "info-prompt", "Info Prompt", 0, 0, false, false, "ubuntu", 0 },
166173 { "html-info-prompt", "HTML Info Prompt", 0, 0, false, false, "ubuntu", 0 },
174+ { "info-prompt", "Info Prompt", 0, 0, false, false, "ubuntu", 0 },
167175 { "long-info-prompt", "Long Info Prompt", 0, 0, false, false, "ubuntu", 0 },
168− { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, "ubuntu", 0 },
169− { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "ubuntu", 0 },
170176 { "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 },
171− { "color-background", "Color Background", "#E95420", 0, false, false, "ubuntu", 0 },
177+ { "multi-info-prompt", "Multi Info Prompt", 0, 0, false, false, "ubuntu", 0 },
178+ { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
179+ { "no-password", "No Password", 0, 0, false, false, "ubuntu", 0 },
180+ { "no-response", "No Response", 0, 0, false, false, "ubuntu", 0 },
181+ { "two-factor", "Two Factor", 0, 0, false, false, "ubuntu", 0 },
182+ { "unicode", "가나다라마", 0, 0, false, false, "ubuntu", 0 },
172183 // white and black are a bit redundant, but useful for manually testing if UI is still readable
173184 { "white-background", "White Background", "#ffffff", 0, false, false, "ubuntu", 0 },
174− { "black-background", "Black Background", "#000000", 0, false, false, "ubuntu", 0 },
175− { "no-background", "No Background", "", 0, false, false, "ubuntu", 0 },
176− { "unicode", "가나다라마", 0, 0, false, false, "ubuntu", 0 },
177− { "no-response", "No Response", 0, 0, false, false, "ubuntu", 0 },
178− { "empty-name", "", 0, 0, false, false, "ubuntu", 0 },
179− { "active", "Active Account", 0, 0, true, false, "ubuntu", 0 },
185+ { "wide-info-prompt", "Wide Info Prompt", 0, 0, false, false, "ubuntu", 0 }
180186 };
181187 }
182188
tests/qmltests/Greeter/tst_WideView.qml+8−5
@@ -409,18 +409,21 @@ StyledItem {
409409 waitForRendering(view);
410410 }
411411
412− function test_stuff() {
412+ function test_changingSessionSticksToUser() {
413413 LightDM.Sessions.mock.sessionMode = "full";
414414 var loginList = findChild(view, "loginList");
415−
416− var currentUser = loginList.currentUser
417415 var fakeSessionName = "ASessionWillNeverBeCalledThis"
418416
419− compare(LightDM.Users.data(getIndexOf(currentUser), LightDM.UserRoles.SessionRole) != fakeSessionName, true);
417+ compare(LightDM.Sessions.count > 1, true);
418+ compare(loginList.currentSession != fakeSessionName, true);
420419
421420 LightDM.Users.mock.sessionName = fakeSessionName;
421+ tryCompare(loginList, "currentSession", fakeSessionName);
422+
423+ // Force a model reset
424+ LightDM.Users.mock.userMode = "single";
425+ LightDM.Users.mock.userMode = "full";
422426
423− compare(LightDM.Users.data(getIndexOf(currentUser), LightDM.UserRoles.SessionRole) == fakeSessionName, true);
424427 }
425428
426429 function test_tease_data() {