on xenial help sign in
[tests] Connect orientation property to mock surface, and write tests for PhoneStage to exercise it
8e19decGerry Boland
tests/mocks/Unity/Application/MirSurfaceItem.cpp+4
@@ -128,6 +128,10 @@ void MirSurfaceItem::setOrientation(const Qt::ScreenOrientation orientation)
128 return;
128 return;
129
129
130 m_orientation = orientation;
130 m_orientation = orientation;
131+
132+ QQmlProperty orientationProp(m_qmlItem, "orientation");
133+ orientationProp.write(QVariant::fromValue(orientation));
134+
131 Q_EMIT orientationChanged();
135 Q_EMIT orientationChanged();
132}
136}
133
137
tests/mocks/Unity/Application/MirSurfaceItem.h+1
@@ -126,5 +126,6 @@ private:
126
126
127Q_DECLARE_METATYPE(MirSurfaceItem*)
127Q_DECLARE_METATYPE(MirSurfaceItem*)
128Q_DECLARE_METATYPE(QList<MirSurfaceItem*>)
128Q_DECLARE_METATYPE(QList<MirSurfaceItem*>)
129+Q_DECLARE_METATYPE(Qt::ScreenOrientation)
129
130
130#endif // MIRSURFACEITEM_H
131#endif // MIRSURFACEITEM_H
tests/mocks/Unity/Application/MirSurfaceItem.qml+7
@@ -27,6 +27,7 @@ Rectangle {
27 implicitHeight: units.gu(70)
27 implicitHeight: units.gu(70)
28
28
29 property alias screenshotSource: screenshotImage.source
29 property alias screenshotSource: screenshotImage.source
30+ property int orientation: Qt.PortraitOrientation
30
31
31 property bool wantInputMethod: false
32 property bool wantInputMethod: false
32
33
@@ -47,6 +48,12 @@ Rectangle {
47 fontSizeMode: Text.Fit
48 fontSizeMode: Text.Fit
48 minimumPixelSize: 10; font.pixelSize: 200
49 minimumPixelSize: 10; font.pixelSize: 200
49 verticalAlignment: Text.AlignVCenter
50 verticalAlignment: Text.AlignVCenter
51+ rotation: {
52+ if (orientation == Qt.PortraitOrientation) return 0;
53+ else if (orientation == Qt.LandscapeOrientation) return 90;
54+ else if (orientation == Qt.InvertedPortraitOrientation) return 180;
55+ else return 270;
56+ }
50 }
57 }
51
58
52 MultiPointTouchArea {
59 MultiPointTouchArea {
tests/qmltests/Stages/tst_PhoneStage.qml+57
@@ -31,6 +31,7 @@ Item {
31 anchors { fill: parent; rightMargin: units.gu(30) }
31 anchors { fill: parent; rightMargin: units.gu(30) }
32 dragAreaWidth: units.gu(2)
32 dragAreaWidth: units.gu(2)
33 maximizedAppTopMargin: units.gu(3) + units.dp(2)
33 maximizedAppTopMargin: units.gu(3) + units.dp(2)
34+ interactive: true
34 }
35 }
35
36
36 Binding {
37 Binding {
@@ -67,6 +68,21 @@ Item {
67 ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfo.Stopped);
68 ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfo.Stopped);
68 }
69 }
69 }
70 }
71+ Button {
72+ anchors { left: parent.left; right: parent.right }
73+ text: "Rotate device \u27F2"
74+ onClicked: {
75+ if (phoneStage.orientation == Qt.PortraitOrientation) {
76+ phoneStage.orientation = Qt.LandscapeOrientation;
77+ } else if (phoneStage.orientation == Qt.LandscapeOrientation) {
78+ phoneStage.orientation = Qt.InvertedPortraitOrientation;
79+ } else if (phoneStage.orientation == Qt.InvertedPortraitOrientation) {
80+ phoneStage.orientation = Qt.InvertedLandscapeOrientation;
81+ } else {
82+ phoneStage.orientation = Qt.PortraitOrientation;
83+ }
84+ }
85+ }
70 }
86 }
71 ListView {
87 ListView {
72 id: appList
88 id: appList
@@ -256,6 +272,46 @@ Item {
256 compare(ApplicationManager.focusedApplicationId, selectedApp.appId);
272 compare(ApplicationManager.focusedApplicationId, selectedApp.appId);
257 }
273 }
258
274
275+ function test_orientation_change_sent_to_focused_app() {
276+ phoneStage.orientation = Qt.PortraitOrientation;
277+ addApps(1);
278+
279+ var spreadView = findChild(phoneStage, "spreadView");
280+ var app = findChild(spreadView, "appDelegate0");
281+ tryCompare(app, "orientation", Qt.PortraitOrientation);
282+
283+ phoneStage.orientation = Qt.LandscapeOrientation;
284+ tryCompare(app, "orientation", Qt.LandscapeOrientation);
285+ }
286+
287+ function test_orientation_change_not_sent_to_apps_while_spread_open() {
288+ phoneStage.orientation = Qt.PortraitOrientation;
289+ addApps(1);
290+
291+ var spreadView = findChild(phoneStage, "spreadView");
292+ var app = findChild(spreadView, "appDelegate0");
293+ tryCompare(app, "orientation", Qt.PortraitOrientation);
294+
295+ goToSpread();
296+ phoneStage.orientation = Qt.LandscapeOrientation;
297+ tryCompare(app, "orientation", Qt.PortraitOrientation);
298+ }
299+
300+ function test_orientation_change_not_sent_to_unfocused_app_until_it_focused() {
301+ phoneStage.orientation = Qt.PortraitOrientation;
302+ addApps(1);
303+
304+ var spreadView = findChild(phoneStage, "spreadView");
305+ var app = findChild(spreadView, "appDelegate0");
306+
307+ goToSpread();
308+ phoneStage.orientation = Qt.LandscapeOrientation;
309+ tryCompare(app, "orientation", Qt.PortraitOrientation);
310+
311+ phoneStage.select(app.application.appId);
312+ tryCompare(app, "orientation", Qt.LandscapeOrientation);
313+ }
314+
259 function cleanup() {
315 function cleanup() {
260 while (ApplicationManager.count > 1) {
316 while (ApplicationManager.count > 1) {
261 var oldCount = ApplicationManager.count;
317 var oldCount = ApplicationManager.count;
@@ -263,6 +319,7 @@ Item {
263 ApplicationManager.stopApplication(ApplicationManager.get(closingIndex).appId)
319 ApplicationManager.stopApplication(ApplicationManager.get(closingIndex).appId)
264 tryCompare(ApplicationManager, "count", oldCount - 1)
320 tryCompare(ApplicationManager, "count", oldCount - 1)
265 }
321 }
322+ phoneStage.orientation = Qt.PortraitOrientation;
266 }
323 }
267 }
324 }
268}
325}