2 * Copyright 2016 Canonical Ltd.
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.
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.
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/>.
18 import Unity.Application 0.1
19 import Ubuntu.Components 1.3
24 property QtObject topLevelSurfaceList: null
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)
30 function waitUntilAppWindowIsFullyLoaded(surfaceId) {
31 var appDelegate = findChild(stage, "appDelegate_" + surfaceId);
33 var appWindow = findChild(appDelegate, "appWindow");
35 var appWindowStates = findInvisibleChild(appWindow, "applicationWindowStateGroup");
36 verify(appWindowStates);
37 tryCompare(appWindowStates, "state", "surface");
38 waitUntilTransitionsEnd(appWindowStates);
42 Returns the appDelegate of the first surface created by the app with the specified appId
44 function startApplication(appId) {
46 var app = ApplicationManager.findApplication(appId);
48 for (var i = 0; i < topLevelSurfaceList.count; i++) {
49 if (topLevelSurfaceList.applicationAt(i).appId === appId) {
50 var appRepeater = findChild(stage, "appRepeater");
52 return appRepeater.itemAt(i);
57 var surfaceId = topLevelSurfaceList.nextId;
58 app = ApplicationManager.startApplication(appId);
60 waitUntilAppWindowIsFullyLoaded(surfaceId);
61 compare(app.surfaceList.count, 1);
63 return findChild(stage, "appDelegate_" + surfaceId);
65 throw new Error("startApplication("+appId+") called from line " + util.callerLine(1) + " failed!");