on xenial help sign in
Better trySessionContainer
40ab519Nick Dedekind
tests/mocks/Unity/Application/ApplicationTestInterface.cpp+26−1
@@ -24,6 +24,8 @@
24
24
25#include <paths.h>
25#include <paths.h>
26
26
27+#include <QtDBus/QtDBus>
28+
27quint32 nextId = 0;
29quint32 nextId = 0;
28
30
29ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
31ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
@@ -34,6 +36,29 @@ ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
34 connection.registerObject("/com/canonical/Unity8/Mocks", parent);
36 connection.registerObject("/com/canonical/Unity8/Mocks", parent);
35}
37}
36
38
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+
37quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage)
62quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage)
38{
63{
39 qDebug() << "ApplicationTestInterface::addChildSession to " << appId;
64 qDebug() << "ApplicationTestInterface::addChildSession to " << appId;
@@ -61,7 +86,7 @@ quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32
61 quint32 sessionId = ++nextId;
86 quint32 sessionId = ++nextId;
62 Session* session = SessionManager::singleton()->createSession(
87 Session* session = SessionManager::singleton()->createSession(
63 QString("%1-Child%2").arg(parentSession->name())
88 QString("%1-Child%2").arg(parentSession->name())
64− .arg(sessionId),
89+ .arg(parentSession->childSessions()->count()),
65 screenshotUrl);
90 screenshotUrl);
66 parentSession->addChildSession(session);
91 parentSession->addChildSession(session);
67 session->createSurface();
92 session->createSurface();
tests/mocks/Unity/Application/ApplicationTestInterface.h+5−2
@@ -30,9 +30,12 @@ class ApplicationTestInterface : public QDBusAbstractAdaptor
30public:
30public:
31 ApplicationTestInterface(QObject* parent = 0);
31 ApplicationTestInterface(QObject* parent = 0);
32
32
33+ Q_INVOKABLE Session* addChildSession(Session* existingSession, const QString& surfaceImage);
34+ Q_INVOKABLE void removeSession(Session* existingSession);
35+
33public Q_SLOTS:
36public Q_SLOTS:
34− Q_INVOKABLE quint32 addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage);
37+ quint32 addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage);
35− Q_INVOKABLE void removeSession(quint32 sessionId);
38+ void removeSession(quint32 sessionId);
36
39
37private:
40private:
38 QHash<quint32, Session*> m_childSessions;
41 QHash<quint32, Session*> m_childSessions;
tests/mocks/Unity/Application/Session.h+2
@@ -72,6 +72,8 @@ private:
72 MirSurfaceItem* m_surface;
72 MirSurfaceItem* m_surface;
73 Session* m_parentSession;
73 Session* m_parentSession;
74 SessionModel* m_children;
74 SessionModel* m_children;
75+
76+ friend class ApplicationTestInterface;
75};
77};
76
78
77Q_DECLARE_METATYPE(Session*)
79Q_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 {
90 }
90 }
91 }
91 }
92 }
92 }
93+ Label {
93− Label { text: "Surface" }
94+ text: "Surface"
95+ anchors.verticalCenter: parent.verticalCenter
96+ }
94 }
97 }
95 ListItem.ItemSelector {
98 ListItem.ItemSelector {
96 id: appStateSelector
99 id: appStateSelector
tests/qmltests/Stages/tst_SessionContainer.qml+38−8
@@ -14,7 +14,8 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
15 */
16
16
17−import QtQuick 2.0
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
18import QtTest 1.0
19import QtTest 1.0
19import Unity.Test 0.1 as UT
20import Unity.Test 0.1 as UT
20import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
@@ -24,11 +25,15 @@ import "../../../qml/Stages"
24Rectangle {
25Rectangle {
25 color: "red"
26 color: "red"
26 id: root
27 id: root
27− width: units.gu(70)
28+ width: units.gu(80)
28 height: units.gu(70)
29 height: units.gu(70)
29
30
30− property QtObject fakeApplication: null
31+ Connections {
31−
32+ target: sessionContainerLoader.status === Loader.Ready ? sessionContainerLoader.item : null
33+ onSessionChanged: {
34+ sessionCheckbox.checked = sessionContainerLoader.item.session !== null
35+ }
36+ }
32
37
33 Component {
38 Component {
34 id: sessionContainerComponent
39 id: sessionContainerComponent
@@ -59,11 +64,13 @@ Rectangle {
59 right: parent.right
64 right: parent.right
60 }
65 }
61
66
62− Column {
67+ ColumnLayout {
63 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
68 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
64 spacing: units.gu(1)
69 spacing: units.gu(1)
65− Row {
70+
66− anchors { left: parent.left; right: parent.right }
71+ RowLayout {
72+ Layout.fillWidth: true
73+
67 CheckBox {
74 CheckBox {
68 id: sessionCheckbox;
75 id: sessionCheckbox;
69 checked: false;
76 checked: false;
@@ -80,7 +87,30 @@ Rectangle {
80 }
87 }
81 }
88 }
82 }
89 }
90+
91+ Label {
83− Label { text: "session" }
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+ }
84 }
114 }
85 }
115 }
86 }
116 }