on xenial help sign in
Share more code between tests
0f6fe87Daniel d'Andrada
tests/qmltests/Stage/tst_DesktopStage.qml+1−28
@@ -163,6 +163,7 @@ Item {
163 when: windowShown
163 when: windowShown
164
164
165 stage: stageLoader.status === Loader.Ready ? stageLoader.item : null
165 stage: stageLoader.status === Loader.Ready ? stageLoader.item : null
166+ topLevelSurfaceList: topSurfaceList
166
167
167 function init() {
168 function init() {
168 // wait until unity8-dash is up and running.
169 // wait until unity8-dash is up and running.
@@ -200,34 +201,6 @@ Item {
200 mouseEaterSpy.clear();
201 mouseEaterSpy.clear();
201 }
202 }
202
203
203− /*
204− Returns the appDelegate of the first surface created by the app with the specified appId
205− */
206− function startApplication(appId) {
207− try {
208− var app = ApplicationManager.findApplication(appId);
209− if (app) {
210− for (var i = 0; i < topSurfaceList.count; i++) {
211− if (topSurfaceList.applicationAt(i).appId === appId) {
212− var appRepeater = findChild(stage, "appRepeater");
213− verify(appRepeater);
214− return appRepeater.itemAt(i);
215− }
216− }
217− }
218−
219− var surfaceId = topSurfaceList.nextId;
220− app = ApplicationManager.startApplication(appId);
221− verify(app);
222− waitUntilAppWindowIsFullyLoaded(surfaceId);
223− compare(app.surfaceList.count, 1);
224−
225− return findChild(stage, "appDelegate_" + surfaceId);
226− } catch(err) {
227− throw new Error("startApplication("+appId+") called from line " + util.callerLine(1) + " failed!");
228− }
229− }
230−
231 function maximizeAppDelegate(appDelegate) {
204 function maximizeAppDelegate(appDelegate) {
232 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
205 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
233 if (!maximizeButton) {
206 if (!maximizeButton) {
tests/qmltests/Tutorial/tst_Tutorial.qml+3−1
@@ -246,7 +246,7 @@ Rectangle {
246 }
246 }
247 }
247 }
248
248
249− UT.UnityTestCase {
249+ UT.StageTestCase {
250 id: testCase
250 id: testCase
251 name: "Tutorial"
251 name: "Tutorial"
252 when: windowShown
252 when: windowShown
@@ -271,6 +271,8 @@ Rectangle {
271 var tutorialLeftTimer = findInvisibleChild(tutorialLeft, "tutorialLeftTimer");
271 var tutorialLeftTimer = findInvisibleChild(tutorialLeft, "tutorialLeftTimer");
272 tutorialLeftTimer.interval = 0;
272 tutorialLeftTimer.interval = 0;
273 tryCompare(tutorialLeft, "opacity", 1);
273 tryCompare(tutorialLeft, "opacity", 1);
274+
275+ stage = findChild(shell, "stage"); // from StageTestCase
274 }
276 }
275
277
276 function cleanup() {
278 function cleanup() {
tests/qmltests/tst_Shell.qml+8−20
@@ -553,7 +553,6 @@ Rectangle {
553 when: windowShown
553 when: windowShown
554
554
555 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
555 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
556− property QtObject topLevelSurfaceList: null
557
556
558 function init() {
557 function init() {
559 if (shellLoader.active) {
558 if (shellLoader.active) {
@@ -592,10 +591,10 @@ Rectangle {
592
591
593 waitForGreeterToStabilize();
592 waitForGreeterToStabilize();
594
593
594+ // from StageTestCase
595 topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
595 topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
596 verify(topLevelSurfaceList);
596 verify(topLevelSurfaceList);
597−
598− stage = findChild(shell, "stage"); // from StageTestCase
597+ stage = findChild(shell, "stage");
599
598
600 // wait until unity8-dash is fully loaded
599 // wait until unity8-dash is fully loaded
601 tryCompare(topLevelSurfaceList, "count", 1);
600 tryCompare(topLevelSurfaceList, "count", 1);
@@ -715,12 +714,9 @@ Rectangle {
715 loadShell("phone");
714 loadShell("phone");
716 swipeAwayGreeter();
715 swipeAwayGreeter();
717 var notifications = findChild(shell, "notificationList");
716 var notifications = findChild(shell, "notificationList");
718− var appSurfaceId = topLevelSurfaceList.nextId;
719− var app = ApplicationManager.startApplication("camera-app");
717+ var appDelegate = startApplication("camera-app");
720− waitUntilAppWindowIsFullyLoaded(appSurfaceId);
721− var stage = findChild(shell, "stage")
722
718
723− var appSurface = app.surfaceList.get(0);
719+ var appSurface = appDelegate.surface;
724 verify(appSurface);
720 verify(appSurface);
725
721
726 tryCompare(appSurface, "activeFocus", true);
722 tryCompare(appSurface, "activeFocus", true);
@@ -1047,10 +1043,8 @@ Rectangle {
1047 function test_surfaceLosesActiveFocusWhilePanelIsOpen() {
1043 function test_surfaceLosesActiveFocusWhilePanelIsOpen() {
1048 loadShell("phone");
1044 loadShell("phone");
1049 swipeAwayGreeter();
1045 swipeAwayGreeter();
1050− var appSurfaceId = topLevelSurfaceList.nextId;
1051− var app = ApplicationManager.startApplication("dialer-app");
1046+ var appDelegate = startApplication("dialer-app");
1052− waitUntilAppWindowIsFullyLoaded(appSurfaceId);
1053− var appSurface = app.surfaceList.get(0);
1047+ var appSurface = appDelegate.surface;
1054 verify(appSurface);
1048 verify(appSurface);
1055
1049
1056 tryCompare(appSurface, "activeFocus", true);
1050 tryCompare(appSurface, "activeFocus", true);
@@ -1093,15 +1087,9 @@ Rectangle {
1093 shell.usageScenario = data.usageScenario;
1087 shell.usageScenario = data.usageScenario;
1094 swipeAwayGreeter();
1088 swipeAwayGreeter();
1095
1089
1096− var webAppSurfaceId = topLevelSurfaceList.nextId;
1097− var webApp = ApplicationManager.startApplication("webbrowser-app");
1090+ var appDelegate = startApplication("webbrowser-app");
1098− verify(webApp);
1099− waitUntilAppWindowIsFullyLoaded(webAppSurfaceId);
1100
1091
1101− var webAppSurface = webApp.surfaceList.get(topLevelSurfaceList.indexForId(webAppSurfaceId));
1102− verify(webAppSurface);
1103−
1104− tryCompare(webAppSurface, "activeFocus", true);
1092+ tryCompare(appDelegate.surface, "activeFocus", true);
1105 }
1093 }
1106
1094
1107 function test_launchedAppKeepsActiveFocusOnUsageModeChange() {
1095 function test_launchedAppKeepsActiveFocusOnUsageModeChange() {
tests/qmltests/tst_ShellWithPin.qml+4−10
@@ -148,7 +148,6 @@ Item {
148 when: windowShown
148 when: windowShown
149
149
150 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
150 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
151− property QtObject topLevelSurfaceList: null
152
151
153 function init() {
152 function init() {
154 tryCompare(shell, "waitingOnGreeter", false); // will be set when greeter is all ready
153 tryCompare(shell, "waitingOnGreeter", false); // will be set when greeter is all ready
@@ -163,15 +162,12 @@ Item {
163 verify(!!panel);
162 verify(!!panel);
164 panel.dismissTimer = fakeDismissTimer;
163 panel.dismissTimer = fakeDismissTimer;
165
164
165+ // from StageTestCase
166− stage = findChild(shell, "stage"); // from StageTestCase
166+ stage = findChild(shell, "stage");
167−
168 topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
167 topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
169 verify(topLevelSurfaceList);
168 verify(topLevelSurfaceList);
170
169
171− var dashSurfaceId = topLevelSurfaceList.nextId;
172− ApplicationManager.startApplication("unity8-dash");
170+ startApplication("unity8-dash");
173− tryCompare(topLevelSurfaceList, "count", 1);
174− waitUntilAppWindowIsFullyLoaded(dashSurfaceId);
175 }
171 }
176
172
177 function cleanup() {
173 function cleanup() {
@@ -491,9 +487,7 @@ Item {
491 function test_focusRequestedHidesCoverPage() {
487 function test_focusRequestedHidesCoverPage() {
492 showGreeter();
488 showGreeter();
493
489
494− var app = ApplicationManager.startApplication("gallery-app");
490+ startApplication("gallery-app");
495− // wait until the app is fully loaded (ie, real surface replaces splash screen)
496− tryCompareFunction(function() { return app.session !== null && app.surfaceList.count > 0 }, true);
497
491
498 // New app hides coverPage?
492 // New app hides coverPage?
499 var greeter = findChild(shell, "greeter");
493 var greeter = findChild(shell, "greeter");
tests/utils/modules/Unity/Test/StageTestCase.qml+33−2
@@ -21,9 +21,12 @@ import Ubuntu.Components 1.3
21UnityTestCase {
21UnityTestCase {
22 // set from outside
22 // set from outside
23 property Item stage
23 property Item stage
24+ property QtObject topLevelSurfaceList: null
24
25
26+ /*
25− // Wait until the ApplicationWindow for the given surface id (from TopLevelWindowModel) is fully loaded
27+ Wait until the ApplicationWindow for the given surface id (from TopLevelWindowModel) is fully loaded
26− // (ie, the real surface has replaced the splash screen)
28+ (ie, the real surface has replaced the splash screen)
29+ */
27 function waitUntilAppWindowIsFullyLoaded(surfaceId) {
30 function waitUntilAppWindowIsFullyLoaded(surfaceId) {
28 var appDelegate = findChild(stage, "appDelegate_" + surfaceId);
31 var appDelegate = findChild(stage, "appDelegate_" + surfaceId);
29 verify(appDelegate);
32 verify(appDelegate);
@@ -34,4 +37,32 @@ UnityTestCase {
34 tryCompare(appWindowStates, "state", "surface");
37 tryCompare(appWindowStates, "state", "surface");
35 waitUntilTransitionsEnd(appWindowStates);
38 waitUntilTransitionsEnd(appWindowStates);
36 }
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+ }
37}
68}