on xenial help sign in
Share more code between tests
commit0f6fe8704303a61cfd807e6a6e2a08f5a5bec48b authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 5 Dec 2016, 11:56 (10 years ago) parent9f7b1ad
5 files changed+49−61
tests/qmltests/Stage/tst_DesktopStage.qml+1−28 tests/qmltests/Tutorial/tst_Tutorial.qml+3−1 tests/qmltests/tst_Shell.qml+8−20 tests/qmltests/tst_ShellWithPin.qml+4−10 tests/utils/modules/Unity/Test/StageTestCase.qml+33−2
tests/qmltests/Stage/tst_DesktopStage.qml+1−28
@@ -163,6 +163,7 @@ Item {
163163 when: windowShown
164164
165165 stage: stageLoader.status === Loader.Ready ? stageLoader.item : null
166+ topLevelSurfaceList: topSurfaceList
166167
167168 function init() {
168169 // wait until unity8-dash is up and running.
@@ -200,34 +201,6 @@ Item {
200201 mouseEaterSpy.clear();
201202 }
202203
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−
231204 function maximizeAppDelegate(appDelegate) {
232205 var maximizeButton = findChild(appDelegate, "maximizeWindowButton");
233206 if (!maximizeButton) {
tests/qmltests/Tutorial/tst_Tutorial.qml+3−1
@@ -246,7 +246,7 @@ Rectangle {
246246 }
247247 }
248248
249− UT.UnityTestCase {
249+ UT.StageTestCase {
250250 id: testCase
251251 name: "Tutorial"
252252 when: windowShown
@@ -271,6 +271,8 @@ Rectangle {
271271 var tutorialLeftTimer = findInvisibleChild(tutorialLeft, "tutorialLeftTimer");
272272 tutorialLeftTimer.interval = 0;
273273 tryCompare(tutorialLeft, "opacity", 1);
274+
275+ stage = findChild(shell, "stage"); // from StageTestCase
274276 }
275277
276278 function cleanup() {
tests/qmltests/tst_Shell.qml+8−20
@@ -553,7 +553,6 @@ Rectangle {
553553 when: windowShown
554554
555555 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
556− property QtObject topLevelSurfaceList: null
557556
558557 function init() {
559558 if (shellLoader.active) {
@@ -592,10 +591,10 @@ Rectangle {
592591
593592 waitForGreeterToStabilize();
594593
594+ // from StageTestCase
595595 topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
596596 verify(topLevelSurfaceList);
597−
598− stage = findChild(shell, "stage"); // from StageTestCase
597+ stage = findChild(shell, "stage");
599598
600599 // wait until unity8-dash is fully loaded
601600 tryCompare(topLevelSurfaceList, "count", 1);
@@ -715,12 +714,9 @@ Rectangle {
715714 loadShell("phone");
716715 swipeAwayGreeter();
717716 var notifications = findChild(shell, "notificationList");
718− var appSurfaceId = topLevelSurfaceList.nextId;
719− var app = ApplicationManager.startApplication("camera-app");
720− waitUntilAppWindowIsFullyLoaded(appSurfaceId);
721− var stage = findChild(shell, "stage")
717+ var appDelegate = startApplication("camera-app");
722718
723− var appSurface = app.surfaceList.get(0);
719+ var appSurface = appDelegate.surface;
724720 verify(appSurface);
725721
726722 tryCompare(appSurface, "activeFocus", true);
@@ -1047,10 +1043,8 @@ Rectangle {
10471043 function test_surfaceLosesActiveFocusWhilePanelIsOpen() {
10481044 loadShell("phone");
10491045 swipeAwayGreeter();
1050− var appSurfaceId = topLevelSurfaceList.nextId;
1051− var app = ApplicationManager.startApplication("dialer-app");
1052− waitUntilAppWindowIsFullyLoaded(appSurfaceId);
1053− var appSurface = app.surfaceList.get(0);
1046+ var appDelegate = startApplication("dialer-app");
1047+ var appSurface = appDelegate.surface;
10541048 verify(appSurface);
10551049
10561050 tryCompare(appSurface, "activeFocus", true);
@@ -1093,15 +1087,9 @@ Rectangle {
10931087 shell.usageScenario = data.usageScenario;
10941088 swipeAwayGreeter();
10951089
1096− var webAppSurfaceId = topLevelSurfaceList.nextId;
1097− var webApp = ApplicationManager.startApplication("webbrowser-app");
1098− verify(webApp);
1099− waitUntilAppWindowIsFullyLoaded(webAppSurfaceId);
1090+ var appDelegate = startApplication("webbrowser-app");
11001091
1101− var webAppSurface = webApp.surfaceList.get(topLevelSurfaceList.indexForId(webAppSurfaceId));
1102− verify(webAppSurface);
1103−
1104− tryCompare(webAppSurface, "activeFocus", true);
1092+ tryCompare(appDelegate.surface, "activeFocus", true);
11051093 }
11061094
11071095 function test_launchedAppKeepsActiveFocusOnUsageModeChange() {
tests/qmltests/tst_ShellWithPin.qml+4−10
@@ -148,7 +148,6 @@ Item {
148148 when: windowShown
149149
150150 property Item shell: shellLoader.status === Loader.Ready ? shellLoader.item : null
151− property QtObject topLevelSurfaceList: null
152151
153152 function init() {
154153 tryCompare(shell, "waitingOnGreeter", false); // will be set when greeter is all ready
@@ -163,15 +162,12 @@ Item {
163162 verify(!!panel);
164163 panel.dismissTimer = fakeDismissTimer;
165164
166− stage = findChild(shell, "stage"); // from StageTestCase
167−
165+ // from StageTestCase
166+ stage = findChild(shell, "stage");
168167 topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
169168 verify(topLevelSurfaceList);
170169
171− var dashSurfaceId = topLevelSurfaceList.nextId;
172− ApplicationManager.startApplication("unity8-dash");
173− tryCompare(topLevelSurfaceList, "count", 1);
174− waitUntilAppWindowIsFullyLoaded(dashSurfaceId);
170+ startApplication("unity8-dash");
175171 }
176172
177173 function cleanup() {
@@ -491,9 +487,7 @@ Item {
491487 function test_focusRequestedHidesCoverPage() {
492488 showGreeter();
493489
494− var app = ApplicationManager.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);
490+ startApplication("gallery-app");
497491
498492 // New app hides coverPage?
499493 var greeter = findChild(shell, "greeter");
tests/utils/modules/Unity/Test/StageTestCase.qml+33−2
@@ -21,9 +21,12 @@ import Ubuntu.Components 1.3
2121UnityTestCase {
2222 // set from outside
2323 property Item stage
24+ property QtObject topLevelSurfaceList: null
2425
25− // Wait until the ApplicationWindow for the given surface id (from TopLevelWindowModel) is fully loaded
26− // (ie, the real surface has replaced the splash screen)
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+ */
2730 function waitUntilAppWindowIsFullyLoaded(surfaceId) {
2831 var appDelegate = findChild(stage, "appDelegate_" + surfaceId);
2932 verify(appDelegate);
@@ -34,4 +37,32 @@ UnityTestCase {
3437 tryCompare(appWindowStates, "state", "surface");
3538 waitUntilTransitionsEnd(appWindowStates);
3639 }
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+ }
3768}