on xenial help sign in
Improve test code
bf5e0edDaniel d'Andrada
qml/Stages/TabletStage.qml+1
@@ -728,6 +728,7 @@ Rectangle {
728
728
729 DirectionalDragArea {
729 DirectionalDragArea {
730 id: spreadDragArea
730 id: spreadDragArea
731+ objectName: "spreadDragArea"
731 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
732 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
732 width: root.dragAreaWidth
733 width: root.dragAreaWidth
733 direction: Direction.Leftwards
734 direction: Direction.Leftwards
tests/qmltests/tst_OrientedShell.qml+34−4
@@ -971,16 +971,31 @@ Rectangle {
971 // If we swipe too much we will trigger the spread mode
971 // If we swipe too much we will trigger the spread mode
972 // and we don't want that.
972 // and we don't want that.
973 var spreadView = findChild(shell, "spreadView");
973 var spreadView = findChild(shell, "spreadView");
974− var swipeLength = (spreadView.positionMarker1 * spreadView.width) * 0.5;
974+ verify(spreadView);
975
975
976 verify(ApplicationManager.count >= 2);
976 verify(ApplicationManager.count >= 2);
977 var previousApp = ApplicationManager.get(1);
977 var previousApp = ApplicationManager.get(1);
978
978
979 var touchStartX = shell.width - 1;
979 var touchStartX = shell.width - 1;
980 var touchStartY = shell.height / 2;
980 var touchStartY = shell.height / 2;
981− touchFlick(shell,
981+
982+ var condition;
983+ if (applicationArguments.deviceName === "phone") {
984+ condition = function() {
985+ return spreadView.shiftedContentX > units.gu(2) &&
986+ spreadView.shiftedContentX < spreadView.positionMarker1 * spreadView.width;
987+ };
988+ } else {
989+ condition = function() {
990+ return spreadView.shiftedContentX > spreadView.width * spreadView.positionMarker1
991+ && spreadView.shiftedContentX < spreadView.width * spreadView.positionMarker2;
992+ };
993+ }
994+
995+ touchDragUntil(shell,
982− touchStartX, touchStartY,
996+ touchStartX, touchStartY,
983− touchStartX - swipeLength, touchStartY);
997+ -units.gu(1), 0,
998+ condition);
984
999
985 // ensure the app switch animation has ended
1000 // ensure the app switch animation has ended
986 tryCompare(spreadView, "shiftedContentX", 0);
1001 tryCompare(spreadView, "shiftedContentX", 0);
@@ -1063,6 +1078,8 @@ Rectangle {
1063
1078
1064 waitUntilShellIsInOrientation(root.physicalOrientation0);
1079 waitUntilShellIsInOrientation(root.physicalOrientation0);
1065
1080
1081+ waitForGreeterToStabilize();
1082+
1066 swipeAwayGreeter();
1083 swipeAwayGreeter();
1067
1084
1068 var spreadRepeater = findChild(shell, "spreadRepeater");
1085 var spreadRepeater = findChild(shell, "spreadRepeater");
@@ -1071,6 +1088,19 @@ Rectangle {
1071 }
1088 }
1072 }
1089 }
1073
1090
1091+ function waitForGreeterToStabilize() {
1092+ var greeter = findChild(shell, "greeter");
1093+ verify(greeter);
1094+
1095+ var loginList = findChild(greeter, "loginList");
1096+ // Only present in WideView
1097+ if (loginList) {
1098+ var userList = findChild(loginList, "userList");
1099+ verify(userList);
1100+ tryCompare(userList, "movingInternally", false);
1101+ }
1102+ }
1103+
1074 // expectedAngle is in orientedShell's coordinate system
1104 // expectedAngle is in orientedShell's coordinate system
1075 function checkAppSurfaceOrientation(app, expectedAngle) {
1105 function checkAppSurfaceOrientation(app, expectedAngle) {
1076 var surface = app.session.surface;
1106 var surface = app.session.surface;
tests/utils/modules/Unity/Test/UnityTestCase.qml+42
@@ -308,6 +308,48 @@ TestCase {
308 }
308 }
309 }
309 }
310
310
311+ // perform a drag in the given direction until the given condition is true
312+ // The condition is a function to be evaluated after every step
313+ function touchDragUntil(item, startX, startY, stepX, stepY, condition) {
314+
315+ var root = fetchRootItem(item);
316+ var pos = item.mapToItem(root, startX, startY);
317+
318+ // convert step to scene coords
319+ {
320+ var stepStart = item.mapToItem(root, 0, 0);
321+ var stepEnd = item.mapToItem(root, stepX, stepY);
322+ }
323+ stepX = stepEnd.x - stepStart.x;
324+ stepY = stepEnd.y - stepStart.y;
325+
326+ var event = touchEvent(item)
327+ event.press(0 /* touchId */, pos.x, pos.y)
328+ event.commit()
329+
330+ // we have to stop at some point
331+ var maxSteps = 100;
332+ var stepsDone = 0;
333+
334+ while (!condition() && stepsDone < maxSteps) {
335+ wait(25);
336+ fakeDateTime.currentTimeMs += 25;
337+
338+ pos.x += stepX;
339+ pos.y += stepY;
340+
341+ event = touchEvent(item);
342+ event.move(0 /* touchId */, pos.x, pos.y);
343+ event.commit();
344+
345+ stepsDone += 1;
346+ }
347+
348+ event = touchEvent(item)
349+ event.release(0 /* touchId */, pos.x, pos.y)
350+ event.commit()
351+ }
352+
311 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
353 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
312 // Make sure the item is rendered
354 // Make sure the item is rendered
313 waitForRendering(item);
355 waitForRendering(item);