~feng-kylin/unity8/fix-lp1413791

« back to all changes in this revision

Viewing changes to tests/utils/modules/Unity/Test/UnityTestCase.qml

  • Committer: Michael Zanetti
  • Date: 2015-06-17 12:14:27 UTC
  • mfrom: (1595.1.214 unity8)
  • mto: (1595.1.232 unity8)
  • mto: This revision was merged to the branch mainline in revision 1608.
  • Revision ID: michael.zanetti@canonical.com-20150617121427-lgc70azrbtsanejb
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2013 Canonical Ltd.
 
2
 * Copyright 2013-2015 Canonical Ltd.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
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
353
    function touchPinch(item, x1Start, y1Start, x1End, y1End, x2Start, y2Start, x2End, y2End) {
312
354
        // Make sure the item is rendered
313
355
        waitForRendering(item);
419
461
        return qtest_results.waitForRendering(item, timeout);
420
462
    }
421
463
 
 
464
    /*
 
465
      Wait until any transition animation has finished for the given StateGroup or Item
 
466
     */
 
467
    function waitUntilTransitionsEnd(stateGroup) {
 
468
        var transitions = stateGroup.transitions;
 
469
        for (var i = 0; i < transitions.length; ++i) {
 
470
            var transition = transitions[i];
 
471
            tryCompare(transition, "running", false, 2000);
 
472
        }
 
473
    }
422
474
}