~ci-train-bot/unity8/unity8-ubuntu-zesty-2404

« back to all changes in this revision

Viewing changes to tests/qmltests/tst_OrientedShell.qml

  • Committer: Daniel d'Andrada
  • Date: 2016-04-04 13:37:49 UTC
  • mto: (2328.1.1 horizVertWindowMaximize)
  • mto: This revision was merged to the branch mainline in revision 2336.
  • Revision ID: daniel.dandrada@canonical.com-20160404133749-cktz4197aos6ovdy
Surface-based window management

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import IntegratedLightDM 0.1 as LightDM
25
25
import Powerd 0.1
26
26
import Unity.InputInfo 0.1
 
27
import Utils 0.1
27
28
 
28
29
import "../../qml"
29
30
 
434
435
 
435
436
        property Item orientedShell: orientedShellLoader.status === Loader.Ready ? orientedShellLoader.item : null
436
437
        property Item shell
 
438
        property QtObject topLevelSurfaceList
437
439
 
438
440
        SignalSpy { id: signalSpy }
439
441
        SignalSpy { id: signalSpy2 }
485
487
        function cleanup() {
486
488
            tryCompare(shell, "enabled", true); // make sure greeter didn't leave us in disabled state
487
489
            shell = null;
 
490
            topLevelSurfaceList = null;
488
491
 
489
492
            tearDown();
490
493
        }
533
536
        function test_appSupportingOnlyPrimaryOrientationWillOnlyRotateInLandscape(data) {
534
537
            loadShell(data.deviceName);
535
538
 
 
539
            compare(topLevelSurfaceList.applicationAt(0).appId, "unity8-dash");
 
540
            var dashSurfaceId = topLevelSurfaceList.idAt(0);
 
541
            var dashAppWindow = findAppWindowForSurfaceId(dashSurfaceId);
 
542
 
536
543
            // unity8-dash supports only primary orientation and should be already running
537
 
            var dashAppWindow = findChild(shell, "appWindow_unity8-dash");
538
 
            verify(dashAppWindow);
 
544
 
539
545
            compare(ApplicationManager.focusedApplicationId, "unity8-dash");
540
 
            var dashApp = dashAppWindow.application
 
546
            var dashApp = dashAppWindow.application;
541
547
            verify(dashApp);
542
548
            compare(dashApp.rotatesWindowContents, false);
543
549
            compare(dashApp.supportedOrientations, Qt.PrimaryOrientation);
544
550
            compare(dashApp.stage, ApplicationInfoInterface.MainStage);
545
551
 
546
 
            tryCompareFunction(function(){return dashApp.session.lastSurface != null;}, true);
 
552
            tryCompareFunction(function(){return dashApp.surfaceList.count > 0;}, true);
547
553
            verify(checkAppSurfaceOrientation(dashAppWindow, dashApp, root.primaryOrientationAngle));
548
554
 
549
555
            compare(shell.transformRotationAngle, root.primaryOrientationAngle);
610
616
        }
611
617
        function test_appRotatesWindowContents(data) {
612
618
            loadShell(data.deviceName);
 
619
            var cameraSurfaceId = topLevelSurfaceList.nextId;
613
620
            var cameraApp = ApplicationManager.startApplication("camera-app");
614
621
            verify(cameraApp);
615
622
 
619
626
            compare(cameraApp.supportedOrientations, Qt.PortraitOrientation | Qt.LandscapeOrientation
620
627
                    | Qt.InvertedPortraitOrientation | Qt.InvertedLandscapeOrientation);
621
628
 
622
 
            waitUntilAppSurfaceShowsUp("camera-app")
 
629
            waitUntilAppWindowIsFullyLoaded(cameraSurfaceId);
623
630
 
624
 
            var cameraSurface = cameraApp.session.lastSurface;
 
631
            var cameraSurface = cameraApp.surfaceList.get(0);
625
632
            verify(cameraSurface);
626
633
 
627
634
            var focusChangedSpy = signalSpy;
687
694
        }
688
695
        function test_switchingToAppWithDifferentRotation(data) {
689
696
            loadShell(data.deviceName);
 
697
            var gmailSurfaceId = topLevelSurfaceList.nextId;
690
698
            var gmailApp = ApplicationManager.startApplication("gmail-webapp");
691
699
            verify(gmailApp);
692
700
 
696
704
                    | Qt.InvertedPortraitOrientation | Qt.InvertedLandscapeOrientation);
697
705
            compare(gmailApp.stage, ApplicationInfoInterface.MainStage);
698
706
 
699
 
            waitUntilAppSurfaceShowsUp("gmail-webapp")
 
707
            waitUntilAppWindowIsFullyLoaded(gmailSurfaceId);
700
708
 
 
709
            var musicSurfaceId = topLevelSurfaceList.nextId;
701
710
            var musicApp = ApplicationManager.startApplication("music-app");
702
711
            verify(musicApp);
703
712
 
707
716
                    | Qt.InvertedPortraitOrientation | Qt.InvertedLandscapeOrientation);
708
717
            compare(musicApp.stage, ApplicationInfoInterface.MainStage);
709
718
 
710
 
            waitUntilAppSurfaceShowsUp("music-app")
 
719
            waitUntilAppWindowIsFullyLoaded(musicSurfaceId);
711
720
            tryCompare(shell, "orientationChangesEnabled", true);
712
721
 
713
722
            rotateTo(90);
742
751
         */
743
752
        function test_rotateToUnsupportedDeviceOrientation(data) {
744
753
            loadShell("mako");
 
754
            var twitterSurfaceId = topLevelSurfaceList.nextId;
745
755
            var twitterApp = ApplicationManager.startApplication("twitter-webapp");
746
756
            verify(twitterApp);
747
757
 
750
760
            compare(twitterApp.supportedOrientations, Qt.PortraitOrientation | Qt.LandscapeOrientation
751
761
                    | Qt.InvertedPortraitOrientation | Qt.InvertedLandscapeOrientation);
752
762
 
753
 
            waitUntilAppSurfaceShowsUp("twitter-webapp")
 
763
            waitUntilAppWindowIsFullyLoaded(twitterSurfaceId);
754
764
 
755
765
            rotateTo(data.rotationAngle);
756
766
            tryCompare(shell, "transformRotationAngle", data.rotationAngle);
767
777
 
768
778
        function test_launchLandscapeOnlyAppFromPortrait() {
769
779
            loadShell("mako");
 
780
            var weatherSurfaceId = topLevelSurfaceList.nextId;
770
781
            var weatherApp = ApplicationManager.startApplication("ubuntu-weather-app");
771
782
            verify(weatherApp);
772
783
 
773
784
            // ensure the mock app is as we expect
774
785
            compare(weatherApp.supportedOrientations, Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation);
775
786
 
776
 
            waitUntilAppSurfaceShowsUp("ubuntu-weather-app");
 
787
            waitUntilAppWindowIsFullyLoaded(weatherSurfaceId);
777
788
 
778
789
            var rotationStates = findInvisibleChild(orientedShell, "rotationStates");
779
790
            waitUntilTransitionsEnd(rotationStates);
805
816
         */
806
817
        function test_greeterStaysAwayAfterRotation() {
807
818
            loadShell("mako");
 
819
            var twitterSurfaceId = topLevelSurfaceList.nextId;
808
820
            var twitterApp = ApplicationManager.startApplication("twitter-webapp");
809
821
            verify(twitterApp);
810
822
 
813
825
            compare(twitterApp.supportedOrientations, Qt.PortraitOrientation | Qt.LandscapeOrientation
814
826
                    | Qt.InvertedPortraitOrientation | Qt.InvertedLandscapeOrientation);
815
827
 
816
 
            waitUntilAppSurfaceShowsUp("twitter-webapp");
817
 
            waitUntilAppWindowCanRotate("twitter-webapp");
 
828
            waitUntilAppWindowIsFullyLoaded(twitterSurfaceId);
 
829
            waitUntilAppWindowCanRotate(twitterSurfaceId);
818
830
 
819
831
            // go back to unity8-dash
820
832
            performEdgeSwipeToSwitchToPreviousApp();
830
842
            var greeter = findChild(shell, "greeter");
831
843
            tryCompare(greeter, "animating", false);
832
844
 
833
 
            var twitterDelegate = findChild(shell, "appDelegate1");
 
845
            var twitterDelegate = findChild(shell, "spreadDelegate_" + topLevelSurfaceList.idAt(1));
834
846
            compare(twitterDelegate.application.appId, "twitter-webapp");
835
847
            twitterDelegate.clicked();
836
848
 
1018
1030
        function test_launchedAppHasActiveFocus(data) {
1019
1031
            loadShell(data.deviceName);
1020
1032
 
 
1033
            var gmailSurfaceId = topLevelSurfaceList.nextId;
1021
1034
            var gmailApp = ApplicationManager.startApplication("gmail-webapp");
1022
1035
            verify(gmailApp);
1023
 
            waitUntilAppSurfaceShowsUp("gmail-webapp")
1024
 
 
1025
 
            verify(gmailApp.session.lastSurface);
1026
 
 
1027
 
            tryCompare(gmailApp.session.lastSurface, "activeFocus", true);
 
1036
            waitUntilAppWindowIsFullyLoaded(gmailSurfaceId);
 
1037
 
 
1038
            var gmailSurface = gmailApp.surfaceList.get(0);
 
1039
            verify(gmailSurface);
 
1040
 
 
1041
            tryCompare(gmailSurface, "activeFocus", true);
1028
1042
        }
1029
1043
 
1030
1044
        function test_launchLandscapeOnlyAppOverPortraitOnlyDashThenSwitchToDash() {
1033
1047
            // starts as portrait, as unity8-dash is portrait only
1034
1048
            tryCompare(shell, "transformRotationAngle", 0);
1035
1049
 
 
1050
            var weatherSurfaceId = topLevelSurfaceList.nextId;
1036
1051
            var weatherApp = ApplicationManager.startApplication("ubuntu-weather-app");
1037
1052
            verify(weatherApp);
1038
1053
 
1039
1054
            // ensure the mock app is as we expect
1040
1055
            compare(weatherApp.supportedOrientations, Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation);
1041
1056
 
1042
 
            waitUntilAppSurfaceShowsUp("ubuntu-weather-app");
 
1057
            waitUntilAppWindowIsFullyLoaded(weatherSurfaceId);
1043
1058
 
1044
1059
            // should have rotated to landscape
1045
1060
            tryCompareFunction(function () { return shell.transformRotationAngle == 270
1233
1248
        function test_lockPhoneAfterClosingAppInSpreadThenUnlockAndRotate() {
1234
1249
            loadShell("mako");
1235
1250
 
 
1251
            compare(topLevelSurfaceList.applicationAt(0).appId, "unity8-dash");
 
1252
            var dashSurfaceId = topLevelSurfaceList.idAt(0);
 
1253
 
 
1254
            var gmailSurfaceId = topLevelSurfaceList.nextId;
1236
1255
            var gmailApp = ApplicationManager.startApplication("gmail-webapp");
1237
1256
            verify(gmailApp);
1238
1257
 
1239
 
            waitUntilAppSurfaceShowsUp("gmail-webapp");
 
1258
            waitUntilAppWindowIsFullyLoaded(gmailSurfaceId);
1240
1259
 
1241
1260
            performEdgeSwipeToShowAppSpread();
1242
1261
 
1252
1271
 
1253
1272
            swipeAwayGreeter();
1254
1273
 
1255
 
            verify(isAppSurfaceFocused("unity8-dash"))
 
1274
            verify(isAppSurfaceFocused(dashSurfaceId))
1256
1275
 
1257
1276
            signalSpy.clear();
1258
1277
            signalSpy.target = shell;
1314
1333
            ////
1315
1334
            // Launch a portrait-only application
1316
1335
 
 
1336
            var dialerSurfaceId = topLevelSurfaceList.nextId;
1317
1337
            var dialerApp = ApplicationManager.startApplication("dialer-app");
1318
1338
            verify(dialerApp);
1319
1339
 
1321
1341
            compare(dialerApp.rotatesWindowContents, false);
1322
1342
            compare(dialerApp.supportedOrientations, Qt.PortraitOrientation | Qt.InvertedPortraitOrientation);
1323
1343
 
1324
 
            waitUntilAppSurfaceShowsUp("dialer-app");
1325
 
            waitUntilAppWindowCanRotate("dialer-app");
1326
 
            verify(isAppSurfaceFocused("dialer-app"));
 
1344
            waitUntilAppWindowIsFullyLoaded(dialerSurfaceId);
 
1345
            waitUntilAppWindowCanRotate(dialerSurfaceId);
 
1346
            verify(isAppSurfaceFocused(dialerSurfaceId));
1327
1347
 
1328
1348
            ////
1329
1349
            // check outcome (shell should stay in landscape)
1376
1396
            tryCompare(appWindowStates, "state", "surface");
1377
1397
        }
1378
1398
 
1379
 
        function waitUntilAppSurfaceShowsUp(appId) {
1380
 
            var appWindow = findChild(shell, "appWindow_" + appId);
1381
 
            verify(appWindow);
1382
 
            var appWindowStates = findInvisibleChild(appWindow, "applicationWindowStateGroup");
1383
 
            verify(appWindowStates);
1384
 
            tryCompare(appWindowStates, "state", "surface");
1385
 
        }
1386
 
 
1387
 
        function waitUntilAppWindowCanRotate(appId) {
1388
 
            var appWindow = findChild(shell, "appWindow_" + appId);
1389
 
            verify(appWindow);
 
1399
        function findAppWindowForSurfaceId(surfaceId) {
 
1400
            // for PhoneStage and TabletStage
 
1401
            var delegate = findChild(shell, "spreadDelegate_" + surfaceId);
 
1402
            if (!delegate) {
 
1403
                // for DesktopStage
 
1404
                delegate = findChild(shell, "appDelegate_" + surfaceId);
 
1405
            }
 
1406
            verify(delegate);
 
1407
            var appWindow = findChild(delegate, "appWindow");
 
1408
            return appWindow;
 
1409
        }
 
1410
 
 
1411
        // Wait until the ApplicationWindow for the given Application object is fully loaded
 
1412
        // (ie, the real surface has replaced the splash screen)
 
1413
        function waitUntilAppWindowIsFullyLoaded(surfaceId) {
 
1414
            var appWindow = findAppWindowForSurfaceId(surfaceId);
 
1415
            var appWindowStateGroup = findInvisibleChild(appWindow, "applicationWindowStateGroup");
 
1416
            tryCompareFunction(function() { return appWindowStateGroup.state === "surface" }, true);
 
1417
            waitUntilTransitionsEnd(appWindowStateGroup);
 
1418
        }
 
1419
 
 
1420
        function waitUntilAppWindowCanRotate(surfaceId) {
 
1421
            var appWindow = findAppWindowForSurfaceId(surfaceId);
1390
1422
            tryCompare(appWindow, "orientationChangesEnabled", true);
1391
1423
        }
1392
1424
 
1498
1530
            tryCompare(greeter, "fullyShown", true);
1499
1531
        }
1500
1532
 
1501
 
        function killApps() {
1502
 
            while (ApplicationManager.count > 1) {
1503
 
                var appIndex = ApplicationManager.get(0).appId == "unity8-dash" ? 1 : 0
1504
 
                ApplicationManager.stopApplication(ApplicationManager.get(appIndex).appId);
1505
 
            }
1506
 
            compare(ApplicationManager.count, 1)
1507
 
        }
1508
 
 
1509
1533
        function loadShell(deviceName) {
1510
1534
            applicationArguments.deviceName = deviceName;
1511
1535
 
1517
1541
 
1518
1542
            shell = findChild(orientedShell, "shell");
1519
1543
 
 
1544
            topLevelSurfaceList = findInvisibleChild(shell, "topLevelSurfaceList");
 
1545
            verify(topLevelSurfaceList);
 
1546
 
 
1547
            var stageLoader = findChild(shell, "applicationsDisplayLoader");
 
1548
            verify(stageLoader);
 
1549
 
1520
1550
            tryCompare(shell, "enabled", true); // enabled by greeter when ready
1521
1551
 
1522
1552
            waitUntilShellIsInOrientation(root.physicalOrientation0);
1525
1555
 
1526
1556
            swipeAwayGreeter();
1527
1557
 
1528
 
            var spreadRepeater = findChild(shell, "spreadRepeater");
 
1558
            var spreadRepeater = findChild(stageLoader, "spreadRepeater");
1529
1559
            if (spreadRepeater) {
1530
1560
                spreadRepeaterConnections.target = spreadRepeater;
1531
1561
            }
1546
1576
 
1547
1577
        // expectedAngle is in orientedShell's coordinate system
1548
1578
        function checkAppSurfaceOrientation(item, app, expectedAngle) {
1549
 
            var surface = app.session.lastSurface;
 
1579
            var surface = app.surfaceList.get(0);
1550
1580
            if (!surface) {
1551
1581
                console.warn("no surface");
1552
1582
                return false;
1601
1631
            var spreadView = findChild(shell, "spreadView");
1602
1632
            verify(spreadView);
1603
1633
 
1604
 
            var delegateToClose = findChild(spreadView, "appDelegate0");
 
1634
            var delegateToClose = findChild(spreadView, "spreadDelegate_" + topLevelSurfaceList.idAt(0));
1605
1635
            verify(delegateToClose);
1606
1636
 
1607
1637
            var appIdToClose = ApplicationManager.get(0).appId;;
1627
1657
            compare(ApplicationManager.findApplication(appIdToClose), null);
1628
1658
        }
1629
1659
 
1630
 
        function isAppSurfaceFocused(appId) {
1631
 
            var appWindow = findChild(shell, "appWindow_" + appId);
1632
 
            verify(appWindow);
1633
 
 
1634
 
            var app = ApplicationManager.findApplication(appId);
1635
 
            verify(app);
1636
 
 
1637
 
            var surface = app.session.lastSurface;
 
1660
        function isAppSurfaceFocused(surfaceId) {
 
1661
            var index = topLevelSurfaceList.indexForId(surfaceId);
 
1662
            var surface = topLevelSurfaceList.surfaceAt(index);
1638
1663
            verify(surface);
1639
 
 
1640
 
            var surfaceItem = findSurfaceItem(appWindow, surface);
1641
 
            verify(surfaceItem);
1642
 
 
1643
 
            return surfaceItem.activeFocus;
 
1664
            return surface.activeFocus;
1644
1665
        }
1645
1666
    }
1646
1667
}