~unity-team/unity8/trunk

« back to all changes in this revision

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

  • Committer: Bileto Bot
  • Author(s): Daniel d'Andrada
  • Date: 2016-12-15 16:16:59 UTC
  • mfrom: (2742.1.1 miral)
  • Revision ID: ci-train-bot@canonical.com-20161215161659-546z6ml81osdy4qz
Let the model deal with some window management decisions

eg: which window to focus, whether to change surface state

unity8 requests and reacts to changes in the model instead of applying them (LP: #1346633)

Approved by: Emanuele Antonio Faraone, Lukáš Tinkl

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.4
 
18
import Unity.Application 0.1
 
19
import Ubuntu.Components 1.3
 
20
 
 
21
UnityTestCase {
 
22
    // set from outside
 
23
    property Item stage
 
24
    property QtObject topLevelSurfaceList: null
 
25
 
 
26
    /*
 
27
       Wait until the ApplicationWindow for the given surface id (from TopLevelWindowModel)  is fully loaded
 
28
       (ie, the real surface has replaced the splash screen)
 
29
     */
 
30
    function waitUntilAppWindowIsFullyLoaded(surfaceId) {
 
31
        var appDelegate = findChild(stage, "appDelegate_" + surfaceId);
 
32
        verify(appDelegate);
 
33
        var appWindow = findChild(appDelegate, "appWindow");
 
34
        verify(appWindow);
 
35
        var appWindowStates = findInvisibleChild(appWindow, "applicationWindowStateGroup");
 
36
        verify(appWindowStates);
 
37
        tryCompare(appWindowStates, "state", "surface");
 
38
        waitUntilTransitionsEnd(appWindowStates);
 
39
    }
 
40
 
 
41
    /*
 
42
        Returns the appDelegate of the first surface created by the app with the specified appId
 
43
     */
 
44
    function startApplication(appId) {
 
45
        try {
 
46
            var app = ApplicationManager.findApplication(appId);
 
47
            if (app) {
 
48
                for (var i = 0; i < topLevelSurfaceList.count; i++) {
 
49
                    if (topLevelSurfaceList.applicationAt(i).appId === appId) {
 
50
                        var appRepeater = findChild(stage, "appRepeater");
 
51
                        verify(appRepeater);
 
52
                        return appRepeater.itemAt(i);
 
53
                    }
 
54
                }
 
55
            }
 
56
 
 
57
            var surfaceId = topLevelSurfaceList.nextId;
 
58
            app = ApplicationManager.startApplication(appId);
 
59
            verify(app);
 
60
            waitUntilAppWindowIsFullyLoaded(surfaceId);
 
61
            compare(app.surfaceList.count, 1);
 
62
 
 
63
            return findChild(stage, "appDelegate_" + surfaceId);
 
64
        } catch(err) {
 
65
            throw new Error("startApplication("+appId+") called from line " +  util.callerLine(1) + " failed!");
 
66
        }
 
67
    }
 
68
}