on xenial help sign in
[tests] Connect orientation property to mock surface, and write tests for PhoneStage to exercise it
commit8e19dec686b7a5739807866ea729bcd2d04c00ca authorGerry Boland <gerry.boland@canonical.com> dateWed 3 Sep 2014, 13:35 (12 years ago) parentf3a4e22
4 files changed+69
tests/mocks/Unity/Application/MirSurfaceItem.cpp+4 tests/mocks/Unity/Application/MirSurfaceItem.h+1 tests/mocks/Unity/Application/MirSurfaceItem.qml+7 tests/qmltests/Stages/tst_PhoneStage.qml+57
tests/mocks/Unity/Application/MirSurfaceItem.cpp+4
@@ -128,6 +128,10 @@ void MirSurfaceItem::setOrientation(const Qt::ScreenOrientation orientation)
128128 return;
129129
130130 m_orientation = orientation;
131+
132+ QQmlProperty orientationProp(m_qmlItem, "orientation");
133+ orientationProp.write(QVariant::fromValue(orientation));
134+
131135 Q_EMIT orientationChanged();
132136}
133137
tests/mocks/Unity/Application/MirSurfaceItem.h+1
@@ -126,5 +126,6 @@ private:
126126
127127Q_DECLARE_METATYPE(MirSurfaceItem*)
128128Q_DECLARE_METATYPE(QList<MirSurfaceItem*>)
129+Q_DECLARE_METATYPE(Qt::ScreenOrientation)
129130
130131#endif // MIRSURFACEITEM_H
tests/mocks/Unity/Application/MirSurfaceItem.qml+7
@@ -27,6 +27,7 @@ Rectangle {
2727 implicitHeight: units.gu(70)
2828
2929 property alias screenshotSource: screenshotImage.source
30+ property int orientation: Qt.PortraitOrientation
3031
3132 property bool wantInputMethod: false
3233
@@ -47,6 +48,12 @@ Rectangle {
4748 fontSizeMode: Text.Fit
4849 minimumPixelSize: 10; font.pixelSize: 200
4950 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+ }
5057 }
5158
5259 MultiPointTouchArea {
tests/qmltests/Stages/tst_PhoneStage.qml+57
@@ -31,6 +31,7 @@ Item {
3131 anchors { fill: parent; rightMargin: units.gu(30) }
3232 dragAreaWidth: units.gu(2)
3333 maximizedAppTopMargin: units.gu(3) + units.dp(2)
34+ interactive: true
3435 }
3536
3637 Binding {
@@ -67,6 +68,21 @@ Item {
6768 ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfo.Stopped);
6869 }
6970 }
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+ }
7086 }
7187 ListView {
7288 id: appList
@@ -256,6 +272,46 @@ Item {
256272 compare(ApplicationManager.focusedApplicationId, selectedApp.appId);
257273 }
258274
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+
259315 function cleanup() {
260316 while (ApplicationManager.count > 1) {
261317 var oldCount = ApplicationManager.count;
@@ -263,6 +319,7 @@ Item {
263319 ApplicationManager.stopApplication(ApplicationManager.get(closingIndex).appId)
264320 tryCompare(ApplicationManager, "count", oldCount - 1)
265321 }
322+ phoneStage.orientation = Qt.PortraitOrientation;
266323 }
267324 }
268325}