on xenial help sign in
Make UnityTestCase.touchFlick properly map event coordinates
d6b5b2fDaniel d'Andrada
tests/qmltests/Panel/tst_IndicatorsMenu.qml+3−3
@@ -174,7 +174,7 @@ IndicatorTest {
174 // and expose the header
174 // and expose the header
175 function test_hint() {
175 function test_hint() {
176 var indicatorItem = get_indicator_item(0);
176 var indicatorItem = get_indicator_item(0);
177− var mappedPosition = root.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
177+ var mappedPosition = indicatorsMenu.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
178
178
179 touchPress(indicatorsMenu, mappedPosition.x, indicatorsMenu.minimizedPanelHeight / 2);
179 touchPress(indicatorsMenu, mappedPosition.x, indicatorsMenu.minimizedPanelHeight / 2);
180
180
@@ -195,7 +195,7 @@ IndicatorTest {
195 for (var i = 0; i < root.originalModelData.length; i++) {
195 for (var i = 0; i < root.originalModelData.length; i++) {
196 var indicatorItem = get_indicator_item(i);
196 var indicatorItem = get_indicator_item(i);
197
197
198− var mappedPosition = root.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
198+ var mappedPosition = indicatorsMenu.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
199
199
200 touchFlick(indicatorsMenu,
200 touchFlick(indicatorsMenu,
201 mappedPosition.x, mappedPosition.y,
201 mappedPosition.x, mappedPosition.y,
@@ -227,7 +227,7 @@ IndicatorTest {
227
227
228 // Get the first indicator
228 // Get the first indicator
229 var firstItem = get_indicator_item(0);
229 var firstItem = get_indicator_item(0);
230− var firstItemMappedPosition = root.mapFromItem(firstItem, firstItem.width/2, firstItem.height/2);
230+ var firstItemMappedPosition = indicatorsMenu.mapFromItem(firstItem, firstItem.width/2, firstItem.height/2);
231
231
232 // 1) Drag the mouse down to hint a bit
232 // 1) Drag the mouse down to hint a bit
233 touchFlick(indicatorsMenu,
233 touchFlick(indicatorsMenu,
tests/qmltests/Panel/tst_Panel.qml+5−10
@@ -186,11 +186,10 @@ IndicatorTest {
186 for (var i = 0; i < root.originalModelData.length; i++) {
186 for (var i = 0; i < root.originalModelData.length; i++) {
187 var indicatorItem = get_indicator_item(i);
187 var indicatorItem = get_indicator_item(i);
188
188
189− var startXPosition = root.mapFromItem(indicatorItem, indicatorItem.width / 2, 0).x;
189+ var startXPosition = panel.mapFromItem(indicatorItem, indicatorItem.width / 2, 0).x;
190− var startYPosition = root.mapFromItem(panel, 0, 0).y;
191
190
192 touchFlick(panel,
191 touchFlick(panel,
193− startXPosition, startYPosition,
192+ startXPosition, 0,
194 startXPosition, panel.height,
193 startXPosition, panel.height,
195 true /* beginTouch */, false /* endTouch */, units.gu(5), 15);
194 true /* beginTouch */, false /* endTouch */, units.gu(5), 15);
196
195
@@ -244,17 +243,13 @@ IndicatorTest {
244 // (switches between normal and fullscreen modes are animated)
243 // (switches between normal and fullscreen modes are animated)
245 tryCompareFunction(function() { return indicatorArea.y }, data.indicatorY);
244 tryCompareFunction(function() { return indicatorArea.y }, data.indicatorY);
246
245
247− var startXPosition = root.mapFromItem(panel.indicators, panel.indicators.width / 2, 0).x;
248− var startYPosition = root.mapFromItem(panel, 0, panel.height).y;
249−
250 panel.indicators.show();
246 panel.indicators.show();
251 tryCompare(panel.indicators.showAnimation, "running", false);
247 tryCompare(panel.indicators.showAnimation, "running", false);
252 tryCompare(panel.indicators, "unitProgress", 1);
248 tryCompare(panel.indicators, "unitProgress", 1);
253
249
254−
255 touchFlick(panel.indicators,
250 touchFlick(panel.indicators,
256− startXPosition, startYPosition,
251+ panel.indicators.width / 2, panel.height,
257− startXPosition, 0,
252+ panel.indicators.width / 2, 0,
258 true /* beginTouch */, false /* endTouch */, units.gu(5), 15);
253 true /* beginTouch */, false /* endTouch */, units.gu(5), 15);
259
254
260 // Indicators height should follow the drag, and therefore increase accordingly.
255 // Indicators height should follow the drag, and therefore increase accordingly.
@@ -263,7 +258,7 @@ IndicatorTest {
263 function() {return panel.indicators.height <= panel.height * 0.5},
258 function() {return panel.indicators.height <= panel.height * 0.5},
264 true);
259 true);
265
260
266− touchRelease(panel.indicators, startXPosition, 0);
261+ touchRelease(panel.indicators, panel.indicators.width / 2, 0);
267
262
268 tryCompare(panel.indicators.hideAnimation, "running", true);
263 tryCompare(panel.indicators.hideAnimation, "running", true);
269 tryCompare(panel.indicators.hideAnimation, "running", false);
264 tryCompare(panel.indicators.hideAnimation, "running", false);
tests/qmltests/Stages/tst_SpreadDelegate.qml+2−2
@@ -126,9 +126,9 @@ Rectangle {
126 swipeToCloseCheckbox.checked = data.swipeToClose;
126 swipeToCloseCheckbox.checked = data.swipeToClose;
127 closeableCheckbox.checked = data.closeable;
127 closeableCheckbox.checked = data.closeable;
128
128
129− var dragDistance = spreadDelegateLoader.item.height / 2;
129+ var dragDistance = spreadDelegateLoader.item.height * 0.8;
130 var touchX = spreadDelegateLoader.item.width / 2;
130 var touchX = spreadDelegateLoader.item.width / 2;
131− var fromY = spreadDelegateLoader.item.height / 2;
131+ var fromY = spreadDelegateLoader.item.height * 0.9;
132 var toY = fromY - dragDistance;
132 var toY = fromY - dragDistance;
133 touchFlick(spreadDelegateLoader.item,
133 touchFlick(spreadDelegateLoader.item,
134 touchX /* fromX */, fromY, touchX /* toX */, toY,
134 touchX /* fromX */, fromY, touchX /* toX */, toY,
tests/qmltests/tst_Shell.qml+2−2
@@ -502,8 +502,8 @@ Item {
502 // Swipe upwards over the launcher to ensure that this icon
502 // Swipe upwards over the launcher to ensure that this icon
503 // at the bottom is not folded and faded away.
503 // at the bottom is not folded and faded away.
504 var touchStartX = launcherPanel.width / 2;
504 var touchStartX = launcherPanel.width / 2;
505− var touchStartY = launcherPanel.height / 2;
505+ var touchEndY = launcherPanel.height / 2;
506− touchFlick(launcherPanel, touchStartX, touchStartY, touchStartX, 0);
506+ touchFlick(launcherPanel, touchStartX, 0, touchStartX, touchEndY);
507 tryCompare(launcherPanel, "moving", false);
507 tryCompare(launcherPanel, "moving", false);
508
508
509 tap(appIcon, appIcon.width / 2, appIcon.height / 2);
509 tap(appIcon, appIcon.width / 2, appIcon.height / 2);
tests/utils/modules/Unity/Test/UnityTestCase.qml+11−7
@@ -221,6 +221,10 @@ TestCase {
221 // Make sure the item is rendered
221 // Make sure the item is rendered
222 waitForRendering(item);
222 waitForRendering(item);
223
223
224+ var root = fetchRootItem(item);
225+ var rootFrom = item.mapToItem(root, x, y);
226+ var rootTo = item.mapToItem(root, toX, toY);
227+
224 // Default to true for beginTouch if not present
228 // Default to true for beginTouch if not present
225 beginTouch = (beginTouch !== undefined) ? beginTouch : true
229 beginTouch = (beginTouch !== undefined) ? beginTouch : true
226
230
@@ -233,17 +237,17 @@ TestCase {
233 // Set a default iterations if not specified
237 // Set a default iterations if not specified
234 var iterations = (iterations !== undefined) ? iterations : 5
238 var iterations = (iterations !== undefined) ? iterations : 5
235
239
236− var distance = Math.sqrt(Math.pow(toX - x, 2) + Math.pow(toY - y, 2))
240+ var distance = Math.sqrt(Math.pow(rootTo.x - rootFrom.x, 2) + Math.pow(rootTo.Y - rootFrom.y, 2))
237 var totalTime = (distance / speed) * 1000 /* converting speed to pixels/ms */
241 var totalTime = (distance / speed) * 1000 /* converting speed to pixels/ms */
238
242
239 var timeStep = totalTime / iterations
243 var timeStep = totalTime / iterations
240− var diffX = (toX - x) / iterations
244+ var diffX = (rootTo.x - rootFrom.x) / iterations
241− var diffY = (toY - y) / iterations
245+ var diffY = (rootTo.y - rootFrom.y) / iterations
242 if (beginTouch) {
246 if (beginTouch) {
243 fakeDateTime.currentTimeMs += timeStep
247 fakeDateTime.currentTimeMs += timeStep
244
248
245 var event = touchEvent()
249 var event = touchEvent()
246− event.press(0 /* touchId */, x, y)
250+ event.press(0 /* touchId */, rootFrom.x, rootFrom.y)
247 event.commit()
251 event.commit()
248 }
252 }
249 for (var i = 0; i < iterations; ++i) {
253 for (var i = 0; i < iterations; ++i) {
@@ -253,19 +257,19 @@ TestCase {
253 // the point specified
257 // the point specified
254 wait(iterations / speed)
258 wait(iterations / speed)
255 var event = touchEvent()
259 var event = touchEvent()
256− event.move(0 /* touchId */, toX, toY)
260+ event.move(0 /* touchId */, rootTo.x, rootTo.y)
257 event.commit()
261 event.commit()
258 } else {
262 } else {
259 wait(iterations / speed)
263 wait(iterations / speed)
260 var event = touchEvent()
264 var event = touchEvent()
261− event.move(0 /* touchId */, x + (i + 1) * diffX, y + (i + 1) * diffY)
265+ event.move(0 /* touchId */, rootFrom.x + (i + 1) * diffX, rootFrom.y + (i + 1) * diffY)
262 event.commit()
266 event.commit()
263 }
267 }
264 }
268 }
265 if (endTouch) {
269 if (endTouch) {
266 fakeDateTime.currentTimeMs += timeStep
270 fakeDateTime.currentTimeMs += timeStep
267 var event = touchEvent()
271 var event = touchEvent()
268− event.release(0 /* touchId */, toX, toY)
272+ event.release(0 /* touchId */, rootTo.x, rootTo.y)
269 event.commit()
273 event.commit()
270 }
274 }
271 }
275 }