@@ -24,6 +24,7 @@ import Unity.Test 0.1 as UT
2424
2525StyledItem {
2626 id: root
27+
2728 width: units.gu(120)
2829 height: units.gu(80)
2930 focus: true
@@ -111,11 +112,9 @@ StyledItem {
111112 color: theme.palette.normal.background
112113 width: units.gu(40)
113114 height: parent.height
114−
115115 Column {
116116 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
117117 spacing: units.gu(1)
118−
119118 Row {
120119 Button {
121120 text: "Show Last Chance"
@@ -266,6 +265,51 @@ StyledItem {
266265 text: "emergency: " + emergencySpy.count
267266 }
268267 }
268+ Row {
269+ id: multipleSessions
270+ CheckBox {
271+ id: multipleSessionsCheckbox
272+ onClicked: {
273+ if (checked) {
274+ LightDM.Sessions.testScenario = "multipleSessions"
275+ } else {
276+ LightDM.Sessions.testScenario = "singleSession"
277+ }
278+ }
279+ Connections {
280+ target: LightDM.Sessions
281+ onTestScenarioChanged: {
282+ if (LightDM.Sessions.testScenario === "multipleSessions") {
283+ multipleSessionsCheckbox.checked = true;
284+ } else {
285+ multipleSessionsCheckbox.checked = false;
286+ }
287+ }
288+ }
289+ }
290+ Label {
291+ text: "Multiple Sessions"
292+ }
293+ }
294+ Row {
295+ Slider {
296+ id: numSessionsSlider
297+
298+ width: units.gu(10)
299+ minimumValue: 0
300+ maximumValue: LightDM.Sessions.numAvailableSessions
301+ value: LightDM.Sessions.numSessions
302+ visible: LightDM.Sessions.testScenario === "multipleSessions"
303+ Binding {
304+ target: LightDM.Sessions
305+ property: "numSessions"
306+ value: numSessionsSlider.value
307+ }
308+ }
309+ Label {
310+ text: "Available Sessions"
311+ }
312+ }
269313 Row {
270314 Button {
271315 text: "Reload View"
@@ -316,6 +360,7 @@ StyledItem {
316360 when: windowShown
317361
318362 property Item view: loader.status === Loader.Ready ? loader.item : null
363+ property url testIconDirectory: Qt.resolvedUrl("../../../qml/Greeter/graphics/session_icons")
319364
320365 function init() {
321366 selectIndex(0); // break binding with text field
@@ -323,6 +368,7 @@ StyledItem {
323368 respondedSpy.clear();
324369 teaseSpy.clear();
325370 emergencySpy.clear();
371+ LightDM.Sessions.testScenario = "multipleSessions"
326372 }
327373
328374 function cleanup() {
@@ -378,6 +424,76 @@ StyledItem {
378424 {tag: "right", x: view.width, offset: 0, count: 1, locked: false},
379425 ]
380426 }
427+
428+ function test_sessionIconsAreValid() {
429+ LightDM.Sessions.testScenario = "multipleSessions"
430+ var originalDirectories = LightDM.Sessions.iconSearchDirectories
431+ LightDM.Sessions.iconSearchDirectories = [testIconDirectory]
432+
433+ // Test the login list icon is valid
434+ var sessionChooserButton = findChild(view, "sessionChooserButton");
435+ compare(sessionChooserButton.visible, true);
436+
437+ var session = String(view.sessionToStart).toLowerCase();
438+ var icon = String(sessionChooserButton.icon);
439+ compare(icon.indexOf(session) > -1, true);
440+
441+ // Test the session list icons are valid
442+ var coverPage = findChild(view, "coverPage");
443+ coverPage.state = "SessionsList"
444+ var sessionsList = findChild(view, "sessionsList");
445+ tryCompare(sessionsList, "visible", true);
446+ }
447+
448+ function test_choosingNewSessionChangesLoginListIcon() {
449+ // Ensure the default session is selected (Ubuntu)
450+ loader.active = false;
451+ loader.active = true;
452+
453+ LightDM.Sessions.testScenario = "multipleSessions";
454+ var sessionChooserButton = findChild(view, "sessionChooserButton");
455+ var icon = String(sessionChooserButton.icon);
456+ compare(icon.indexOf("ubuntu") > -1, true);
457+
458+ tap(sessionChooserButton)
459+ for(var i = 0; i < LightDM.Sessions.count; i++) {
460+ var delegateName = "sessionDelegate" + String(i);
461+ var currentDelegate = findChild(view, delegateName);
462+ var sessionKey = LightDM.Sessions.data(i,LightDM.SessionRoles.KeyRole);
463+ if (sessionKey === "gnome-classic") {
464+ tap(currentDelegate);
465+ var sessionChooserButton = findChild(view, "sessionChooserButton");
466+ waitForRendering(sessionChooserButton);
467+ var icon = String(sessionChooserButton.icon);
468+ break;
469+ }
470+ }
471+
472+ compare(icon.indexOf("gnome") > -1, true,
473+ "Expected icon to contain gnome but it was " + icon);
474+ }
475+
476+ function test_noSessionsDoesntBreakView() {
477+ LightDM.Sessions.testScenario = "noSessions"
478+ compare(LightDM.Sessions.count, 0)
479+ }
480+
481+ function test_sessionIconNotShownWithOneSession() {
482+ LightDM.Sessions.testScenario = "singleSession"
483+ compare(LightDM.Sessions.count, 1);
484+
485+ var sessionChooserButton = findChild(view, "sessionChooserButton");
486+ tryCompare(sessionChooserButton, "visible", false);
487+ }
488+
489+ function test_sessionIconShownWithMultipleSessions() {
490+ LightDM.Sessions.testScenario = "multipleSessions"
491+ compare(LightDM.Sessions.count > 1, true);
492+
493+ var sessionChooserButton = findChild(view, "sessionChooserButton");
494+ tryCompare(sessionChooserButton, "visible", true);
495+ }
496+
381497 function test_tease(data) {
382498 view.locked = data.locked;
383499 view.dragHandleLeftMargin = data.offset;