Lomiri
Loading...
Searching...
No Matches
StageTestCase.qml
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
17import QtQuick 2.12
18import QtMir.Application 0.1
19import Lomiri.Components 1.3
20
21LomiriTestCase {
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 var app = ApplicationManager.findApplication(appId);
46 if (app) {
47 for (var i = 0; i < topLevelSurfaceList.count; i++) {
48 if (topLevelSurfaceList.applicationAt(i).appId === appId) {
49 var appRepeater = findChild(stage, "appRepeater");
50 verify(appRepeater);
51 return appRepeater.itemAt(i);
52 }
53 }
54 }
55
56 var surfaceId = topLevelSurfaceList.nextId;
57 app = ApplicationManager.startApplication(appId);
58 verify(app);
59 waitUntilAppWindowIsFullyLoaded(surfaceId);
60 compare(app.surfaceList.count, 1);
61
62 return findChild(stage, "appDelegate_" + surfaceId);
63 }
64}