on xenial help sign in
Better trySessionContainer
commit40ab519d0e3a61612d340a3fb9b1b814b72956a4 authorNick Dedekind <nicholas.dedekind@gmail.com> dateThu 28 Aug 2014, 11:56 (12 years ago) parent7af764c
6 files changed+182−12
tests/mocks/Unity/Application/ApplicationTestInterface.cpp+26−1 tests/mocks/Unity/Application/ApplicationTestInterface.h+5−2 tests/mocks/Unity/Application/Session.h+2 tests/qmltests/Stages/RecursingChildSessionControl.qml+107 tests/qmltests/Stages/tst_ApplicationWindow.qml+4−1 tests/qmltests/Stages/tst_SessionContainer.qml+38−8
tests/mocks/Unity/Application/ApplicationTestInterface.cpp+26−1
@@ -24,6 +24,8 @@
2424
2525#include <paths.h>
2626
27+#include <QtDBus/QtDBus>
28+
2729quint32 nextId = 0;
2830
2931ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
@@ -34,6 +36,29 @@ ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
3436 connection.registerObject("/com/canonical/Unity8/Mocks", parent);
3537}
3638
39+Session* ApplicationTestInterface::addChildSession(Session* existingSession, const QString& surfaceImage)
40+{
41+ if (!existingSession) return nullptr;
42+
43+ QUrl screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
44+ .arg(qmlDirectory())
45+ .arg(surfaceImage);
46+
47+ Session* session = SessionManager::singleton()->createSession(
48+ QString("%1-Child%2").arg(existingSession->name())
49+ .arg(existingSession->childSessions()->count()),
50+ screenshotUrl);
51+ existingSession->addChildSession(session);
52+ session->createSurface();
53+
54+ return session;
55+}
56+
57+void ApplicationTestInterface::removeSession(Session* existingSession)
58+{
59+ Q_EMIT existingSession->removed();
60+}
61+
3762quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage)
3863{
3964 qDebug() << "ApplicationTestInterface::addChildSession to " << appId;
@@ -61,7 +86,7 @@ quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32
6186 quint32 sessionId = ++nextId;
6287 Session* session = SessionManager::singleton()->createSession(
6388 QString("%1-Child%2").arg(parentSession->name())
64− .arg(sessionId),
89+ .arg(parentSession->childSessions()->count()),
6590 screenshotUrl);
6691 parentSession->addChildSession(session);
6792 session->createSurface();
tests/mocks/Unity/Application/ApplicationTestInterface.h+5−2
@@ -30,9 +30,12 @@ class ApplicationTestInterface : public QDBusAbstractAdaptor
3030public:
3131 ApplicationTestInterface(QObject* parent = 0);
3232
33+ Q_INVOKABLE Session* addChildSession(Session* existingSession, const QString& surfaceImage);
34+ Q_INVOKABLE void removeSession(Session* existingSession);
35+
3336public Q_SLOTS:
34− Q_INVOKABLE quint32 addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage);
35− Q_INVOKABLE void removeSession(quint32 sessionId);
37+ quint32 addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage);
38+ void removeSession(quint32 sessionId);
3639
3740private:
3841 QHash<quint32, Session*> m_childSessions;
tests/mocks/Unity/Application/Session.h+2
@@ -72,6 +72,8 @@ private:
7272 MirSurfaceItem* m_surface;
7373 Session* m_parentSession;
7474 SessionModel* m_children;
75+
76+ friend class ApplicationTestInterface;
7577};
7678
7779Q_DECLARE_METATYPE(Session*)
tests/qmltests/Stages/RecursingChildSessionControl.qmlnew file+107
@@ -0,0 +1,107 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
19+import Ubuntu.Components 0.1
20+import Unity.Application 0.1
21+
22+ColumnLayout {
23+ id: root
24+
25+ property var session
26+ property var childSessions: session ? session.childSessions : 0
27+ property bool removable: false
28+
29+ property var screenshotIds: [ "gallery", "map", "facebook", "camera", "browser", "music", "twitter"]
30+
31+ Column {
32+ Layout.fillWidth: true
33+ visible: repeater.count
34+ spacing: units.gu(1)
35+
36+ Repeater {
37+ id: repeater
38+ model: root.childSessions
39+ delegate: Rectangle {
40+ border {
41+ color: "black"
42+ width: 1
43+ }
44+ anchors {
45+ left: parent.left
46+ right: parent.right
47+ leftMargin: units.gu(1)
48+ rightMargin: units.gu(1)
49+ }
50+ height: loader.height
51+
52+ Rectangle {
53+ anchors.fill: parent
54+ color: Qt.rgba(Math.random(), Math.random(), Math.random(), 0.4 )
55+ }
56+
57+ Loader {
58+ id: loader
59+ visible: status == Loader.Ready
60+ source: Qt.resolvedUrl("RecursingChildSessionControl.qml")
61+
62+ anchors {
63+ left: parent.left
64+ right: parent.right
65+ }
66+
67+ onLoaded: {
68+ item.session = modelData;
69+ item.removable = true;
70+ }
71+ }
72+ }
73+ }
74+ }
75+
76+ Item {
77+ Layout.fillWidth: true
78+ Layout.preferredHeight: buttonLayout.height + units.gu(1)
79+
80+ RowLayout {
81+ id: buttonLayout
82+ anchors {
83+ top: parent.top; topMargin: units.gu(0.5)
84+ left: parent.left; leftMargin: units.gu(1)
85+ }
86+
87+ Button {
88+ enabled: root.session
89+ text: removable ? "Remove" : "Release"
90+ onClicked: {
91+ if (removable) root.session.removed();
92+ else root.session.release();
93+ }
94+ }
95+
96+ Button {
97+ enabled: root.session !== null
98+ text: "Add Child"
99+ onClicked: {
100+ var screenshot = Math.round(Math.random() * screenshotIds.length);
101+ console.log(screenshot)
102+ var session = ApplicationTest.addChildSession(root.session, root.screenshotIds[screenshot]);
103+ }
104+ }
105+ }
106+ }
107+}
tests/qmltests/Stages/tst_ApplicationWindow.qml+4−1
@@ -90,7 +90,10 @@ Rectangle {
9090 }
9191 }
9292 }
93− Label { text: "Surface" }
93+ Label {
94+ text: "Surface"
95+ anchors.verticalCenter: parent.verticalCenter
96+ }
9497 }
9598 ListItem.ItemSelector {
9699 id: appStateSelector
tests/qmltests/Stages/tst_SessionContainer.qml+38−8
@@ -14,7 +14,8 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−import QtQuick 2.0
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
1819import QtTest 1.0
1920import Unity.Test 0.1 as UT
2021import Ubuntu.Components 0.1
@@ -24,11 +25,15 @@ import "../../../qml/Stages"
2425Rectangle {
2526 color: "red"
2627 id: root
27− width: units.gu(70)
28+ width: units.gu(80)
2829 height: units.gu(70)
2930
30− property QtObject fakeApplication: null
31−
31+ Connections {
32+ target: sessionContainerLoader.status === Loader.Ready ? sessionContainerLoader.item : null
33+ onSessionChanged: {
34+ sessionCheckbox.checked = sessionContainerLoader.item.session !== null
35+ }
36+ }
3237
3338 Component {
3439 id: sessionContainerComponent
@@ -59,11 +64,13 @@ Rectangle {
5964 right: parent.right
6065 }
6166
62− Column {
67+ ColumnLayout {
6368 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
6469 spacing: units.gu(1)
65− Row {
66− anchors { left: parent.left; right: parent.right }
70+
71+ RowLayout {
72+ Layout.fillWidth: true
73+
6774 CheckBox {
6875 id: sessionCheckbox;
6976 checked: false;
@@ -80,7 +87,30 @@ Rectangle {
8087 }
8188 }
8289 }
83− Label { text: "session" }
90+
91+ Label {
92+ text: "session"
93+ anchors.verticalCenter: parent.verticalCenter
94+ }
95+ }
96+
97+ Rectangle {
98+ border {
99+ color: "black"
100+ width: 1
101+ }
102+ anchors {
103+ left: parent.left
104+ right: parent.right
105+ }
106+ height: sessionChildrenControl.height
107+
108+ RecursingChildSessionControl {
109+ id: sessionChildrenControl
110+ anchors { left: parent.left; right: parent.right; }
111+
112+ session: sessionContainerLoader.item.session
113+ }
84114 }
85115 }
86116 }