@@ -66,9 +66,6 @@ Rectangle {
6666 id: availableDesktopAreaItem
6767 anchors.fill: parent
6868 }
69− Component.onCompleted: {
70− ApplicationManager.startApplication("unity8-dash");
71− }
7269 }
7370
7471 Rectangle {
@@ -108,6 +105,22 @@ Rectangle {
108105 }
109106 }
110107
108+ Button {
109+ text: "Drag app to side stage"
110+ activeFocusOnPress: false
111+ onClicked: {
112+ testCase.dragToSideStage();
113+ }
114+ }
115+
116+ Button {
117+ text: "Drag app to main stage"
118+ activeFocusOnPress: false
119+ onClicked: {
120+ testCase.dragToMainStage();
121+ }
122+ }
123+
111124 ApplicationCheckBox {
112125 id: webbrowserCheckBox
113126 appId: "morph-browser"
@@ -144,37 +157,17 @@ Rectangle {
144157 function init() {
145158 stageSaver.clear();
146159
147− ApplicationManager.startApplication("unity8-dash");
148− tryCompare(topSurfaceList, "count", 1);
149− compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
150−
151− // this is very strange, but sometimes the test starts without
152− // Stage components having finished loading themselves
153− var appWindow = null
154− while (!appWindow) {
155− appWindow = findAppWindowForSurfaceId(topSurfaceList.idAt(0));
156− if (!appWindow) {
157− console.log("didn't find unity8-dash appWindow in Stage. Trying again...");
158− wait(50);
159− }
160− }
160+ tryCompare(topSurfaceList, "count", 0);
161161
162162 // wait for Stage to stabilize back into its initial state
163163 var appRepeater = findChild(stage, "appRepeater");
164− tryCompare(appRepeater, "count", 1);
165− tryCompare(appRepeater.itemAt(0), "x", 0);
164+ tryCompare(appRepeater, "count", 0);
166165
167− waitUntilAppSurfaceShowsUp(topSurfaceList.idAt(0));
168166 sideStage.hideNow()
169167 tryCompare(sideStage, "x", stage.width)
170168 }
171169
172170 function cleanup() {
173− ApplicationManager.requestFocusApplication("unity8-dash");
174− tryCompare(ApplicationManager, "focusedApplicationId", "unity8-dash");
175− tryCompare(stage, "state", "stagedWithSideStage");
176− waitForRendering(stage);
177−
178171 killApps();
179172
180173 sideStage.hideNow();
@@ -194,6 +187,9 @@ Rectangle {
194187 }
195188
196189 function findAppWindowForSurfaceId(surfaceId) {
190+ tryVerify(function() {
191+ return findChild(stage, "appDelegate_" + surfaceId);
192+ }, 100, "Found app surface with ID " + surfaceId);
197193 var spreadDelegate = findChild(stage, "appDelegate_" + surfaceId);
198194 if (!spreadDelegate) {
199195 return null;
@@ -203,12 +199,14 @@ Rectangle {
203199 }
204200
205201 function switchToSurface(targetSurfaceId) {
202+ waitForRendering(stage);
206203 performEdgeSwipeToShowAppSpread();
207204
208205 waitUntilAppDelegateStopsMoving(targetSurfaceId);
209206 var targetAppWindow = findAppWindowForSurfaceId(targetSurfaceId);
210207 verify(targetAppWindow);
211208 tap(targetAppWindow, 10, 10);
209+ waitForRendering(stage);
212210 }
213211
214212 function waitUntilAppDelegateStopsMoving(targetSurfaceId)
@@ -241,7 +239,6 @@ Rectangle {
241239
242240 function dragToSideStage(surfaceId) {
243241 sideStage.showNow();
244− var targetAppDelegate = findChild(stage, "appDelegate_" + surfaceId);
245242
246243 var pos = stage.width - sideStage.width - (stage.width - sideStage.width) / 2;
247244 var end_pos = stage.width - sideStage.width / 2;
@@ -252,13 +249,15 @@ Rectangle {
252249 return sideStage.shown && !sideStage.showAnimation.running &&
253250 pos >= end_pos;
254251 });
255− tryCompare(targetAppDelegate, "stage", ApplicationInfoInterface.SideStage);
252+ if (surfaceId != null) {
253+ var targetAppDelegate = findChild(stage, "appDelegate_" + surfaceId);
254+ verify(targetAppDelegate);
255+ tryCompare(targetAppDelegate, "stage", ApplicationInfoInterface.SideStage);
256+ }
256257 }
257258
258259 function dragToMainStage(surfaceId) {
259260 sideStage.showNow();
260− var targetAppDelegate = findChild(stage, "appDelegate_" + surfaceId);
261− verify(targetAppDelegate);
262261
263262 var pos = stage.width - sideStage.width / 2;
264263 var end_pos = stage.width - sideStage.width - (stage.width - sideStage.width) / 2;
@@ -273,15 +272,42 @@ Rectangle {
273272 pos -= units.gu(3);
274273 return pos <= end_pos;
275274 });
276− tryCompare(targetAppDelegate, "stage", ApplicationInfoInterface.MainStage);
275+ if (surfaceId != null) {
276+ var targetAppDelegate = findChild(stage, "appDelegate_" + surfaceId);
277+ verify(targetAppDelegate);
278+ tryCompare(targetAppDelegate, "stage", ApplicationInfoInterface.MainStage);
279+ }
280+ }
281+
282+ // Launch one of the available apps in this test case
283+ // Return the topSurfaceList's ID for the launched app
284+ // Valid values are: "morph", "gallery", "dialer", and "facebook"
285+ // "facebook" will be launched if no name is given
286+ function launchApp(appName) {
287+ var nextAppId = topSurfaceList.nextId;
288+ switch (appName) {
289+ case "morph":
290+ webbrowserCheckBox.checked = true;
291+ break;
292+ case "gallery":
293+ galleryCheckBox.checked = true;
294+ break;
295+ case "dialer":
296+ dialerCheckBox.checked = true;
297+ break;
298+ case "facebook":
299+ default:
300+ facebookCheckBox.checked = true;
301+ break;
302+ }
303+ waitUntilAppSurfaceShowsUp(nextAppId);
304+ return nextAppId;
277305 }
278306
279307 function test_tappingSwitchesFocusBetweenStages() {
280308 WindowStateStorage.saveStage(dialerCheckBox.appId, ApplicationInfoInterface.SideStage)
281309
282− var webbrowserSurfaceId = topSurfaceList.nextId;
283− webbrowserCheckBox.checked = true;
284− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
310+ var webbrowserSurfaceId = launchApp("morph");
285311 var webbrowserDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
286312 verify(webbrowserDelegate);
287313 compare(webbrowserDelegate.stage, ApplicationInfoInterface.MainStage);
@@ -290,9 +316,7 @@ Rectangle {
290316
291317 tryCompare(webbrowserWindow.surface, "activeFocus", true);
292318
293− var dialerSurfaceId = topSurfaceList.nextId;
294− dialerCheckBox.checked = true;
295− waitUntilAppSurfaceShowsUp(dialerSurfaceId);
319+ var dialerSurfaceId = launchApp("dialer");
296320
297321 var dialerApp = ApplicationManager.findApplication(dialerCheckBox.appId);
298322 var dialerDelegate = findChild(stage, "appDelegate_" + dialerSurfaceId);
@@ -322,9 +346,7 @@ Rectangle {
322346 function test_closeAppInSideStage() {
323347 WindowStateStorage.saveStage(dialerCheckBox.appId, ApplicationInfoInterface.SideStage)
324348
325− var dialerSurfaceId = topSurfaceList.nextId;
326− dialerCheckBox.checked = true;
327− waitUntilAppSurfaceShowsUp(dialerSurfaceId);
349+ var dialerSurfaceId = launchApp("dialer");
328350
329351 performEdgeSwipeToShowAppSpread();
330352
@@ -348,18 +370,14 @@ Rectangle {
348370 }
349371
350372 function test_suspendsAndResumesAppsInMainStage() {
351− var webbrowserSurfaceId = topSurfaceList.nextId;
352− webbrowserCheckBox.checked = true;
353− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
373+ var webbrowserSurfaceId = launchApp("morph");
354374 var webbrowserApp = ApplicationManager.findApplication(webbrowserCheckBox.appId);
355375 var webbrowserDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
356376 compare(webbrowserDelegate.stage, ApplicationInfoInterface.MainStage);
357377
358378 tryCompare(webbrowserApp, "state", ApplicationInfoInterface.Running);
359379
360− var gallerySurfaceId = topSurfaceList.nextId;
361− galleryCheckBox.checked = true;
362− waitUntilAppSurfaceShowsUp(gallerySurfaceId);
380+ var gallerySurfaceId = launchApp("gallery");
363381 var galleryApp = ApplicationManager.findApplication(galleryCheckBox.appId);
364382 var galleryDelegate = findChild(stage, "appDelegate_" + gallerySurfaceId);
365383 compare(galleryDelegate.stage, ApplicationInfoInterface.MainStage);
@@ -388,17 +406,13 @@ Rectangle {
388406 // launch two main stage apps
389407 // gallery will be on foreground and webbrowser on background
390408
391− var webbrowserSurfaceId = topSurfaceList.nextId;
392− webbrowserCheckBox.checked = true;
393− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
409+ var webbrowserSurfaceId = launchApp("morph");
394410 var webbrowserDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
395411 verify(webbrowserDelegate);
396412 compare(webbrowserDelegate.stage, ApplicationInfoInterface.MainStage);
397413 var webbrowserApp = ApplicationManager.findApplication(webbrowserCheckBox.appId);
398414
399− var gallerySurfaceId = topSurfaceList.nextId;
400− galleryCheckBox.checked = true;
401− waitUntilAppSurfaceShowsUp(gallerySurfaceId);
415+ var gallerySurfaceId = launchApp("gallery");
402416 var galleryApp = ApplicationManager.findApplication(galleryCheckBox.appId);
403417 var galleryDelegate = findChild(stage, "appDelegate_" + gallerySurfaceId);
404418 compare(galleryDelegate.stage, ApplicationInfoInterface.MainStage);
@@ -408,16 +422,12 @@ Rectangle {
408422 // then launch two side stage apps
409423 // facebook will be on foreground and dialer on background
410424
411− var dialerSurfaceId = topSurfaceList.nextId;
412− dialerCheckBox.checked = true;
413− waitUntilAppSurfaceShowsUp(dialerSurfaceId);
425+ var dialerSurfaceId = launchApp("dialer");
414426 var dialerApp = ApplicationManager.findApplication(dialerCheckBox.appId);
415427 var dialerDelegate = findChild(stage, "appDelegate_" + dialerSurfaceId);
416428 compare(dialerDelegate.stage, ApplicationInfoInterface.SideStage);
417429
418− var facebookSurfaceId = topSurfaceList.nextId;
419− facebookCheckBox.checked = true;
420− waitUntilAppSurfaceShowsUp(facebookSurfaceId);
430+ var facebookSurfaceId = launchApp("facebook");
421431 var facebookApp = ApplicationManager.findApplication(facebookCheckBox.appId);
422432 var facebookDelegate = findChild(stage, "appDelegate_" + facebookSurfaceId);
423433 compare(facebookDelegate.stage, ApplicationInfoInterface.SideStage);
@@ -450,16 +460,12 @@ Rectangle {
450460 function test_foregroundAppsAreSuspendedWhenStageIsSuspended() {
451461 WindowStateStorage.saveStage(dialerCheckBox.appId, ApplicationInfoInterface.SideStage)
452462
453− var webbrowserSurfaceId = topSurfaceList.nextId;
454− webbrowserCheckBox.checked = true;
455− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
463+ var webbrowserSurfaceId = launchApp("morph");
456464 var webbrowserApp = ApplicationManager.findApplication(webbrowserCheckBox.appId);
457465 var webbrowserDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
458466 compare(webbrowserDelegate.stage, ApplicationInfoInterface.MainStage);
459467
460− var dialerSurfaceId = topSurfaceList.nextId;
461− dialerCheckBox.checked = true;
462− waitUntilAppSurfaceShowsUp(dialerSurfaceId);
468+ var dialerSurfaceId = launchApp("dialer");
463469 var dialerApp = ApplicationManager.findApplication(dialerCheckBox.appId);
464470 var dialerDelegate = findChild(stage, "appDelegate_" + dialerSurfaceId);
465471 compare(dialerDelegate.stage, ApplicationInfoInterface.SideStage);
@@ -520,7 +526,7 @@ Rectangle {
520526 function test_applicationLoadsInDefaultStage_data() {
521527 return [
522528 { tag: "MainStage", appId: "morph-browser", mainStageAppId: "morph-browser", sideStageAppId: "" },
523− { tag: "SideStage", appId: "dialer-app", mainStageAppId: "unity8-dash", sideStageAppId: "dialer-app" },
529+ { tag: "SideStage", appId: "dialer-app", mainStageAppId: "facebook-webapp", sideStageAppId: "dialer-app" },
524530 ];
525531 }
526532
@@ -528,7 +534,9 @@ Rectangle {
528534 var stagesPriv = findInvisibleChild(stage, "DesktopStagePrivate");
529535 verify(stagesPriv);
530536
531− tryCompare(stagesPriv, "mainStageAppId", "unity8-dash");
537+ facebookCheckBox.checked = true;
538+
539+ tryCompare(stagesPriv, "mainStageAppId", "facebook-webapp");
532540 tryCompare(stagesPriv, "sideStageAppId", "");
533541
534542 var appSurfaceId = topSurfaceList.nextId;
@@ -542,7 +550,7 @@ Rectangle {
542550 function test_applicationLoadsInSavedStage_data() {
543551 return [
544552 { tag: "MainStage", stage: ApplicationInfoInterface.MainStage, mainStageAppId: "morph-browser", sideStageAppId: ""},
545− { tag: "SideStage", stage: ApplicationInfoInterface.SideStage, mainStageAppId: "unity8-dash", sideStageAppId: "morph-browser" },
553+ { tag: "SideStage", stage: ApplicationInfoInterface.SideStage, mainStageAppId: "facebook-webapp", sideStageAppId: "morph-browser" },
546554 ];
547555 }
548556
@@ -552,12 +560,12 @@ Rectangle {
552560 var stagesPriv = findInvisibleChild(stage, "DesktopStagePrivate");
553561 verify(stagesPriv);
554562
555− tryCompare(stagesPriv, "mainStageAppId", "unity8-dash");
563+ facebookCheckBox.checked = true;
564+
565+ tryCompare(stagesPriv, "mainStageAppId", "facebook-webapp");
556566 tryCompare(stagesPriv, "sideStageAppId", "");
557567
558− var webbrowserSurfaceId = topSurfaceList.nextId;
559− webbrowserCheckBox.checked = true;
560− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
568+ var webbrowserSurfaceId = launchApp("morph");
561569
562570 tryCompare(stagesPriv, "mainStageAppId", data.mainStageAppId);
563571 tryCompare(stagesPriv, "sideStageAppId", data.sideStageAppId);
@@ -577,12 +585,12 @@ Rectangle {
577585 var stagesPriv = findInvisibleChild(stage, "DesktopStagePrivate");
578586 verify(stagesPriv);
579587
580− tryCompare(stagesPriv, "mainStageAppId", "unity8-dash");
588+ facebookCheckBox.checked = true;
589+
590+ tryCompare(stagesPriv, "mainStageAppId", "facebook-webapp");
581591 tryCompare(stagesPriv, "sideStageAppId", "");
582592
583− var webbrowserSurfaceId = topSurfaceList.nextId;
584− webbrowserCheckBox.checked = true;
585− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
593+ var webbrowserSurfaceId = launchApp("morph");
586594
587595 if (data.toStage === ApplicationInfoInterface.SideStage) {
588596 dragToSideStage(webbrowserSurfaceId);
@@ -597,10 +605,7 @@ Rectangle {
597605
598606 function test_loadSideStageByDraggingFromMainStage() {
599607 sideStage.showNow();
600− print("sidestage now shown. launching browser")
601− var webbrowserSurfaceId = topSurfaceList.nextId;
602− webbrowserCheckBox.checked = true;
603− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
608+ var webbrowserSurfaceId = launchApp("morph")
604609
605610 var appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
606611 verify(appDelegate);
@@ -619,9 +624,7 @@ Rectangle {
619624 tryCompareFunction(function() {
620625 return WindowStateStorage.getStage(webbrowserCheckBox.appId, ApplicationInfoInterface.MainStage) === ApplicationInfoInterface.SideStage
621626 }, true);
622− var webbrowserSurfaceId = topSurfaceList.nextId;
623− webbrowserCheckBox.checked = true;
624− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
627+ var webbrowserSurfaceId = launchApp("morph");
625628
626629 var appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
627630 verify(appDelegate);
@@ -643,18 +646,18 @@ Rectangle {
643646 Application gets relaunched. Its new surface will seamlessly replace the screenshot.
644647 */
645648 function test_selectSuspendedAppWithoutSurface() {
646− compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
647− var dashSurfaceId = topSurfaceList.idAt(0);
648− var dashWindow = topSurfaceList.windowAt(0);
649+ launchApp("facebook");
650+ compare(topSurfaceList.applicationAt(0).appId, "facebook-webapp");
651+ var facebookSurfaceId = topSurfaceList.idAt(0);
652+ var facebookWindow = topSurfaceList.windowAt(0);
649653
650654 var webbrowserSurfaceId = topSurfaceList.nextId;
651− webbrowserCheckBox.checked = true;
652− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
655+ launchApp("morph");
653656 var webbrowserApp = ApplicationManager.findApplication(webbrowserCheckBox.appId);
654657
655− switchToSurface(dashSurfaceId);
658+ switchToSurface(facebookSurfaceId);
656659
657− tryCompare(topLevelSurfaceList, "focusedWindow", dashWindow);
660+ tryCompare(topLevelSurfaceList, "focusedWindow", facebookWindow);
658661 tryCompare(webbrowserApp, "state", ApplicationInfoInterface.Suspended);
659662
660663 compare(webbrowserApp.surfaceList.count, 1);
@@ -679,9 +682,7 @@ Rectangle {
679682 }
680683
681684 function test_draggingSurfaceKeepsSurfaceFocus() {
682− var webbrowserSurfaceId = topSurfaceList.nextId;
683− webbrowserCheckBox.checked = true;
684− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
685+ var webbrowserSurfaceId = launchApp("morph");
685686
686687 var appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
687688 verify(appDelegate);
@@ -695,34 +696,9 @@ Rectangle {
695696 tryCompare(appDelegate, "stage", ApplicationInfoInterface.SideStage);
696697 }
697698
698− function test_dashDoesNotDragToSidestage() {
699− sideStage.showNow();
700− compare(topSurfaceList.applicationAt(0).appId, "unity8-dash");
701− var dashSurfaceId = topSurfaceList.idAt(0);
702−
703− var appDelegate = findChild(stage, "appDelegate_" + dashSurfaceId);
704− verify(appDelegate);
705− compare(appDelegate.stage, ApplicationInfoInterface.MainStage);
706−
707− var pos = stage.width - sideStage.width - (stage.width - sideStage.width) / 2;
708− var end_pos = stage.width - sideStage.width / 2;
709−
710− multiTouchDragUntil([0,1,2], stage, pos, stage.height / 2, units.gu(3), 0,
711− function() {
712− pos += units.gu(3);
713− return sideStage.shown && !sideStage.showAnimation.running &&
714− pos >= end_pos;
715− });
716−
717− waitForRendering(stage);
718− tryCompare(appDelegate, "stage", ApplicationInfoInterface.MainStage);
719− }
720−
721699 function test_switchRestoreStageOnRotation() {
722700 WindowStateStorage.saveStage(webbrowserCheckBox.appId, ApplicationInfoInterface.SideStage)
723− var webbrowserSurfaceId = topSurfaceList.nextId;
724− webbrowserCheckBox.checked = true;
725− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
701+ var webbrowserSurfaceId = launchApp("morph");
726702
727703 var appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
728704 verify(appDelegate);
@@ -739,9 +715,7 @@ Rectangle {
739715 }
740716
741717 function test_restoreSavedStageOnCloseReopen() {
742− var webbrowserSurfaceId = topSurfaceList.nextId;
743− webbrowserCheckBox.checked = true;
744− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
718+ var webbrowserSurfaceId = launchApp("morph");
745719
746720 var appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
747721 verify(appDelegate);
@@ -752,14 +726,12 @@ Rectangle {
752726 tryCompare(appDelegate, "stage", ApplicationInfoInterface.MainStage);
753727
754728 webbrowserCheckBox.checked = false;
755− tryCompare(ApplicationManager, "count", 1);
729+ tryCompare(ApplicationManager, "count", 0);
756730
757731 // back to landscape
758732 stage.shellOrientation = Qt.LandscapeOrientation;
759733
760− webbrowserSurfaceId = topSurfaceList.nextId;
761− webbrowserCheckBox.checked = true;
762− waitUntilAppSurfaceShowsUp(webbrowserSurfaceId);
734+ webbrowserSurfaceId = launchApp("morph");
763735
764736 appDelegate = findChild(stage, "appDelegate_" + webbrowserSurfaceId);
765737 verify(appDelegate);
@@ -773,9 +745,8 @@ Rectangle {
773745 the window (and not get eaten by some translucent decoration like in that bug).
774746 */
775747 function test_clickNearTopEdgeGoesToWindow() {
776− compare(topLevelSurfaceList.count, 1); // assume unity8-dash is already there
777−
778− var appDelegate = findChild(stage, "appDelegate_" + topLevelSurfaceList.idAt(0));
748+ var facebookSurfaceId = launchApp("facebook");
749+ var appDelegate = findChild(stage, "appDelegate_" + facebookSurfaceId);
779750 verify(appDelegate);
780751
781752 var surfaceItem = findChild(appDelegate, "surfaceItem");
@@ -784,20 +755,20 @@ Rectangle {
784755 compare(surfaceItem.mousePressCount, 0);
785756 compare(surfaceItem.mouseReleaseCount, 0);
786757
787− mouseClick(appDelegate, 1, 1); // near top left
758+ mouseClick(surfaceItem, 1, 1); // near top left
788759
789− compare(surfaceItem.mousePressCount, 1);
790− compare(surfaceItem.mouseReleaseCount, 1);
760+ tryCompare(surfaceItem, "mousePressCount", 1);
761+ tryCompare(surfaceItem, "mouseReleaseCount", 1);
791762
792− mouseClick(appDelegate, appDelegate.width / 2, 1); // near top
763+ mouseClick(stage, appDelegate.width / 2, 1); // near top
793764
794− compare(surfaceItem.mousePressCount, 2);
795− compare(surfaceItem.mouseReleaseCount, 2);
765+ tryCompare(surfaceItem, "mousePressCount", 2);
766+ tryCompare(surfaceItem, "mouseReleaseCount", 2);
796767
797− mouseClick(appDelegate, appDelegate.width - 1, 1); // near top right
768+ mouseClick(stage, appDelegate.width - 1, 1); // near top right
798769
799− compare(surfaceItem.mousePressCount, 3);
800− compare(surfaceItem.mouseReleaseCount, 3);
770+ tryCompare(surfaceItem, "mousePressCount", 3);
771+ tryCompare(surfaceItem, "mouseReleaseCount", 3);
801772 }
802773 }
803774}