~aacid/unity8/desktopRotatedCamera

« back to all changes in this revision

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

  • Committer: Albert Astals Cid
  • Date: 2016-06-02 07:43:13 UTC
  • mfrom: (2039.198.42 unity8)
  • Revision ID: albert.astals@canonical.com-20160602074313-qycavrlys0yftjfd
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import QtTest 1.0
19
19
import Unity.Application 0.1
20
20
import Ubuntu.Components 1.3
 
21
import Ubuntu.Test 1.0 as UbuntuTest
21
22
import Unity.Test 0.1 as UT
22
23
import Utils 0.1
23
24
 
175
176
 
176
177
 
177
178
    // Find an object with the given name in the children tree of "obj"
178
 
    function findChild(obj, objectName) {
 
179
    function findChild(obj, objectName, timeout) {
179
180
        if (!obj)
180
181
            qtest_fail("no obj given", 1);
181
182
 
182
 
        return findChildIn(obj, "children", objectName);
 
183
        return findChildInWithTimeout(obj, "children", objectName, timeout);
183
184
    }
184
185
 
185
186
    // Find an object with the given name in the children tree of "obj"
187
188
    // Note: you should use findChild if you're not sure you need this
188
189
    // as this tree is much bigger and might contain stuff that goes
189
190
    // away randomly.
190
 
    function findInvisibleChild(obj, objectName) {
191
 
        if (!obj)
192
 
            qtest_fail("no obj given", 1);
193
 
 
194
 
        return findChildIn(obj, "data", objectName);
 
191
    function findInvisibleChild(obj, objectName, timeout) {
 
192
        if (!obj)
 
193
            qtest_fail("no obj given", 1);
 
194
 
 
195
        return findChildInWithTimeout(obj, "data", objectName, timeout);
 
196
    }
 
197
 
 
198
    // Find a child in the named property with timeout
 
199
    function findChildInWithTimeout(obj, prop, objectName, timeout) {
 
200
        if (!obj)
 
201
            qtest_fail("no obj given", 1);
 
202
 
 
203
        var timeSpent = 0
 
204
        if (timeout === undefined)
 
205
            timeout = 5000;
 
206
 
 
207
        var child = findChildIn(obj, prop, objectName);
 
208
 
 
209
        while (timeSpent < timeout && !child) {
 
210
            wait(50)
 
211
            timeSpent += 50
 
212
            child = findChildIn(obj, prop, objectName);
 
213
        }
 
214
        return child;
195
215
    }
196
216
 
197
217
    // Find a child in the named property
572
592
        while (rootItem.parent != undefined) {
573
593
            rootItem = rootItem.parent;
574
594
        }
575
 
        removeTimeConstraintsFromDirectionalDragAreas(rootItem);
 
595
        removeTimeConstraintsFromSwipeAreas(rootItem);
576
596
    }
577
597
 
578
598
    /*
579
599
      In qmltests, sequences of touch events are sent all at once, unlike in "real life".
580
600
      Also qmltests might run really slowly, e.g. when run from inside virtual machines.
581
601
      Thus to remove a variable that qmltests cannot really control, namely time, this
582
 
      function removes all constraints from DirectionalDragAreas that are sensible to
 
602
      function removes all constraints from SwipeAreas that are sensible to
583
603
      elapsed time.
584
604
 
585
 
      This effectively makes DirectionalDragAreas easier to fool.
 
605
      This effectively makes SwipeAreas easier to fool.
586
606
     */
587
 
    function removeTimeConstraintsFromDirectionalDragAreas(item) {
 
607
    function removeTimeConstraintsFromSwipeAreas(item) {
588
608
        if (!item)
589
609
            qtest_fail("no item given", 1);
590
610
 
591
 
        // use duck-typing to identify a DirectionalDragArea
592
 
        if (item.removeTimeConstraints != undefined) {
593
 
            item.removeTimeConstraints();
 
611
        if (UT.Util.isInstanceOf(item, "UCSwipeArea")) {
 
612
            UbuntuTest.TestExtras.removeTimeConstraintsFromSwipeArea(item);
594
613
        } else {
595
614
            for (var i in item.children) {
596
 
                removeTimeConstraintsFromDirectionalDragAreas(item.children[i]);
 
615
                removeTimeConstraintsFromSwipeAreas(item.children[i]);
597
616
            }
598
617
        }
599
618
    }