on xenial help sign in
Improve test code
commitbf5e0ed174588d77b2011ef17fcfab952ec12300 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 11 May 2015, 10:59 (11 years ago) parente0ed2ca
3 files changed+77−4
qml/Stages/TabletStage.qml+1 tests/qmltests/tst_OrientedShell.qml+34−4 tests/utils/modules/Unity/Test/UnityTestCase.qml+42
qml/Stages/TabletStage.qml+1
@@ -728,6 +728,7 @@ Rectangle {
728728
729729 DirectionalDragArea {
730730 id: spreadDragArea
731+ objectName: "spreadDragArea"
731732 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
732733 width: root.dragAreaWidth
733734 direction: Direction.Leftwards
tests/qmltests/tst_OrientedShell.qml+34−4
@@ -971,16 +971,31 @@ Rectangle {
971971 // If we swipe too much we will trigger the spread mode
972972 // and we don't want that.
973973 var spreadView = findChild(shell, "spreadView");
974− var swipeLength = (spreadView.positionMarker1 * spreadView.width) * 0.5;
974+ verify(spreadView);
975975
976976 verify(ApplicationManager.count >= 2);
977977 var previousApp = ApplicationManager.get(1);
978978
979979 var touchStartX = shell.width - 1;
980980 var touchStartY = shell.height / 2;
981− touchFlick(shell,
982− touchStartX, touchStartY,
983− touchStartX - swipeLength, touchStartY);
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,
996+ touchStartX, touchStartY,
997+ -units.gu(1), 0,
998+ condition);
984999
9851000 // ensure the app switch animation has ended
9861001 tryCompare(spreadView, "shiftedContentX", 0);
@@ -1063,6 +1078,8 @@ Rectangle {
10631078
10641079 waitUntilShellIsInOrientation(root.physicalOrientation0);
10651080
1081+ waitForGreeterToStabilize();
1082+
10661083 swipeAwayGreeter();
10671084
10681085 var spreadRepeater = findChild(shell, "spreadRepeater");
@@ -1071,6 +1088,19 @@ Rectangle {
10711088 }
10721089 }
10731090
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+
10741104 // expectedAngle is in orientedShell's coordinate system
10751105 function checkAppSurfaceOrientation(app, expectedAngle) {
10761106 var surface = app.session.surface;
tests/utils/modules/Unity/Test/UnityTestCase.qml+42
@@ -308,6 +308,48 @@ TestCase {
308308 }
309309 }
310310
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+
311353 function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
312354 // Make sure the item is rendered
313355 waitForRendering(item);