@@ -106,7 +106,7 @@ Rectangle {
106106 enabled: parent.promptSurfaceList !== null && parent.promptSurfaceList.count > 0
107107 activeFocusOnPress: false
108108 text: "Remove"
109− onClicked: { parent.promptSurfaceList.get(parent.promptSurfaceList.count - 1).close(); }
109+ onClicked: { parent.promptSurfaceList.get(0).close(); }
110110 }
111111
112112 Button {
@@ -449,20 +449,21 @@ Rectangle {
449449 for (i = 0; i < 3; i++) {
450450 promptSurfaceList.createSurface();
451451 compare(promptSurfaces.count, i+1);
452− waitUntilSurfaceContainerStopsAnimating(promptSurfaces.itemAt(promptSurfaces.count - 1));
452+ waitUntilSurfaceContainerStopsAnimating(promptSurfaces.itemAt(0));
453453 }
454454
455− for (i = 2; i >= 0; --i) {
456− var promptSurface = promptSurfaceList.get(i);
455+ for (i = 3; i > 0; --i) {
456+ var promptSurface = promptSurfaceList.get(0);
457457 compare(promptSurface.activeFocus, true);
458458
459459 promptSurface.close();
460− tryCompareFunction(function() { return promptSurfaces.count; }, i);
460+ promptSurface = null;
461+ tryCompareFunction(function() { return promptSurfaces.count; }, i-1);
461462
462− if (i > 0) {
463− // active focus should have gone to the yongest remaining sibling
464− var previousPromptSurface = promptSurfaceList.get(i-1);
465− tryCompare(previousPromptSurface, "activeFocus", true);
463+ if (promptSurfaces.count > 0) {
464+ // active focus should have gone to the new head of the list
465+ promptSurface = promptSurfaceList.get(0);
466+ tryCompare(promptSurface, "activeFocus", true);
466467 } else {
467468 // active focus should have gone to the application surface
468469 tryCompare(applicationWindow.surface, "activeFocus", true);
@@ -498,5 +499,34 @@ Rectangle {
498499 delegate.surface.close();
499500 tryCompare(promptSurfaces, "count", 0);
500501 }
502+
503+ // Check that the z value of SurfaceContainers for prompt surfaces go from highest
504+ // for index 0 to lowest for the last index in the prompt surface list.
505+ // Regression test for https://bugs.launchpad.net/bugs/1586219
506+ function test_promptSurfacesZOrdering() {
507+ var promptSurfaceList = root.fakeApplication.promptSurfaceList;
508+ var promptSurfaces = testCase.findChild(applicationWindow, "promptSurfacesRepeater");
509+
510+ promptSurfaceList.createSurface();
511+
512+ for (var i = 2; i <= 3; i++) {
513+ promptSurfaceList.createSurface();
514+ tryCompare(promptSurfaces, "count", i);
515+ waitUntilSurfaceContainerStopsAnimating(promptSurfaces.itemAt(0));
516+
517+ for (var j = 1; j < promptSurfaces.count; j++) {
518+ var delegate = promptSurfaces.itemAt(j);
519+ var previousDelegate = promptSurfaces.itemAt(j-1);
520+ verify(previousDelegate.z > delegate.z);
521+ }
522+ }
523+
524+ // clean up
525+ while (promptSurfaceList.count > 0) {
526+ var currentCount = promptSurfaceList.count;
527+ promptSurfaceList.get(0).close();
528+ tryCompare(promptSurfaceList, "count", currentCount - 1);
529+ }
530+ }
501531 }
502532}