on xenial help sign in
Make UnityTestCase.touchFlick properly map event coordinates

Just like tap() already does. It was working so far just because items under test were top-left aligned (ie, had x=0 and y=0). Approved by: Michael Zanetti

commitd6b5b2fee294aff1719b7e3c4316b2e425676f86 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateTue 2 Dec 2014, 09:25 (12 years ago) parent2b506f22eec224
5 files changed+23−24
tests/qmltests/Panel/tst_IndicatorsMenu.qml+3−3 tests/qmltests/Panel/tst_Panel.qml+5−10 tests/qmltests/Stages/tst_SpreadDelegate.qml+2−2 tests/qmltests/tst_Shell.qml+2−2 tests/utils/modules/Unity/Test/UnityTestCase.qml+11−7
tests/qmltests/Panel/tst_IndicatorsMenu.qml+3−3
@@ -174,7 +174,7 @@ IndicatorTest {
174174 // and expose the header
175175 function test_hint() {
176176 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);
178178
179179 touchPress(indicatorsMenu, mappedPosition.x, indicatorsMenu.minimizedPanelHeight / 2);
180180
@@ -195,7 +195,7 @@ IndicatorTest {
195195 for (var i = 0; i < root.originalModelData.length; i++) {
196196 var indicatorItem = get_indicator_item(i);
197197
198− var mappedPosition = root.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
198+ var mappedPosition = indicatorsMenu.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
199199
200200 touchFlick(indicatorsMenu,
201201 mappedPosition.x, mappedPosition.y,
@@ -227,7 +227,7 @@ IndicatorTest {
227227
228228 // Get the first indicator
229229 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);
231231
232232 // 1) Drag the mouse down to hint a bit
233233 touchFlick(indicatorsMenu,
tests/qmltests/Panel/tst_Panel.qml+5−10
@@ -186,11 +186,10 @@ IndicatorTest {
186186 for (var i = 0; i < root.originalModelData.length; i++) {
187187 var indicatorItem = get_indicator_item(i);
188188
189− var startXPosition = root.mapFromItem(indicatorItem, indicatorItem.width / 2, 0).x;
190− var startYPosition = root.mapFromItem(panel, 0, 0).y;
189+ var startXPosition = panel.mapFromItem(indicatorItem, indicatorItem.width / 2, 0).x;
191190
192191 touchFlick(panel,
193− startXPosition, startYPosition,
192+ startXPosition, 0,
194193 startXPosition, panel.height,
195194 true /* beginTouch */, false /* endTouch */, units.gu(5), 15);
196195
@@ -244,17 +243,13 @@ IndicatorTest {
244243 // (switches between normal and fullscreen modes are animated)
245244 tryCompareFunction(function() { return indicatorArea.y }, data.indicatorY);
246245
247− var startXPosition = root.mapFromItem(panel.indicators, panel.indicators.width / 2, 0).x;
248− var startYPosition = root.mapFromItem(panel, 0, panel.height).y;
249−
250246 panel.indicators.show();
251247 tryCompare(panel.indicators.showAnimation, "running", false);
252248 tryCompare(panel.indicators, "unitProgress", 1);
253249
254−
255250 touchFlick(panel.indicators,
256− startXPosition, startYPosition,
257− startXPosition, 0,
251+ panel.indicators.width / 2, panel.height,
252+ panel.indicators.width / 2, 0,
258253 true /* beginTouch */, false /* endTouch */, units.gu(5), 15);
259254
260255 // Indicators height should follow the drag, and therefore increase accordingly.
@@ -263,7 +258,7 @@ IndicatorTest {
263258 function() {return panel.indicators.height <= panel.height * 0.5},
264259 true);
265260
266− touchRelease(panel.indicators, startXPosition, 0);
261+ touchRelease(panel.indicators, panel.indicators.width / 2, 0);
267262
268263 tryCompare(panel.indicators.hideAnimation, "running", true);
269264 tryCompare(panel.indicators.hideAnimation, "running", false);
tests/qmltests/Stages/tst_SpreadDelegate.qml+2−2
@@ -126,9 +126,9 @@ Rectangle {
126126 swipeToCloseCheckbox.checked = data.swipeToClose;
127127 closeableCheckbox.checked = data.closeable;
128128
129− var dragDistance = spreadDelegateLoader.item.height / 2;
129+ var dragDistance = spreadDelegateLoader.item.height * 0.8;
130130 var touchX = spreadDelegateLoader.item.width / 2;
131− var fromY = spreadDelegateLoader.item.height / 2;
131+ var fromY = spreadDelegateLoader.item.height * 0.9;
132132 var toY = fromY - dragDistance;
133133 touchFlick(spreadDelegateLoader.item,
134134 touchX /* fromX */, fromY, touchX /* toX */, toY,
tests/qmltests/tst_Shell.qml+2−2
@@ -502,8 +502,8 @@ Item {
502502 // Swipe upwards over the launcher to ensure that this icon
503503 // at the bottom is not folded and faded away.
504504 var touchStartX = launcherPanel.width / 2;
505− var touchStartY = launcherPanel.height / 2;
506− touchFlick(launcherPanel, touchStartX, touchStartY, touchStartX, 0);
505+ var touchEndY = launcherPanel.height / 2;
506+ touchFlick(launcherPanel, touchStartX, 0, touchStartX, touchEndY);
507507 tryCompare(launcherPanel, "moving", false);
508508
509509 tap(appIcon, appIcon.width / 2, appIcon.height / 2);
tests/utils/modules/Unity/Test/UnityTestCase.qml+11−7
@@ -221,6 +221,10 @@ TestCase {
221221 // Make sure the item is rendered
222222 waitForRendering(item);
223223
224+ var root = fetchRootItem(item);
225+ var rootFrom = item.mapToItem(root, x, y);
226+ var rootTo = item.mapToItem(root, toX, toY);
227+
224228 // Default to true for beginTouch if not present
225229 beginTouch = (beginTouch !== undefined) ? beginTouch : true
226230
@@ -233,17 +237,17 @@ TestCase {
233237 // Set a default iterations if not specified
234238 var iterations = (iterations !== undefined) ? iterations : 5
235239
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))
237241 var totalTime = (distance / speed) * 1000 /* converting speed to pixels/ms */
238242
239243 var timeStep = totalTime / iterations
240− var diffX = (toX - x) / iterations
241− var diffY = (toY - y) / iterations
244+ var diffX = (rootTo.x - rootFrom.x) / iterations
245+ var diffY = (rootTo.y - rootFrom.y) / iterations
242246 if (beginTouch) {
243247 fakeDateTime.currentTimeMs += timeStep
244248
245249 var event = touchEvent()
246− event.press(0 /* touchId */, x, y)
250+ event.press(0 /* touchId */, rootFrom.x, rootFrom.y)
247251 event.commit()
248252 }
249253 for (var i = 0; i < iterations; ++i) {
@@ -253,19 +257,19 @@ TestCase {
253257 // the point specified
254258 wait(iterations / speed)
255259 var event = touchEvent()
256− event.move(0 /* touchId */, toX, toY)
260+ event.move(0 /* touchId */, rootTo.x, rootTo.y)
257261 event.commit()
258262 } else {
259263 wait(iterations / speed)
260264 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)
262266 event.commit()
263267 }
264268 }
265269 if (endTouch) {
266270 fakeDateTime.currentTimeMs += timeStep
267271 var event = touchEvent()
268− event.release(0 /* touchId */, toX, toY)
272+ event.release(0 /* touchId */, rootTo.x, rootTo.y)
269273 event.commit()
270274 }
271275 }