on xenial help sign in
Support for nested prompt session. Fixes: 1358388, 1363081
commitafc6ec47dda8d276c0ffd9dc14fcd1ba58a1b427 authorNick Dedekind <nick.dedekind@canonical.com> dateWed 3 Sep 2014, 07:58 (12 years ago) parent538b9bdb60a55e
47 files changed+1840−795
debian/control+1−1 plugins/AccountsService/AccountsService.qmltypes+1 plugins/LightDM/LightDM.qmltypes+2 plugins/Ubuntu/SystemImage/SystemImage.qmltypes+2 plugins/Unity/Indicators/Indicators.qmltypes+6−4 qml/Shell.qml+9 qml/Stages/Animations/BaseSurfaceAnimation.qml → qml/Stages/Animations/BaseSessionAnimation.qml+23−20 qml/Stages/Animations/DarkenAndFadeInAnimation.qml−48 qml/Stages/Animations/SwipeFromBottomAnimation.qml+24−19 qml/Stages/Animations/SwipeUpAnimation.qml−49 qml/Stages/ApplicationWindow.qml+50−71 qml/Stages/SessionContainer.qml+143 qml/Stages/SurfaceContainer.qml+22−67 tests/mocks/AccountsService/AccountsService.qmltypes+1 tests/mocks/LightDM/LightDM.qmltypes+2 tests/mocks/Ubuntu/SystemImage/SystemImage.qmltypes+3−1 tests/mocks/Unity/Application/Application.qmltypes+115−70 tests/mocks/Unity/Application/ApplicationDBusAdaptor.cpp−81 tests/mocks/Unity/Application/ApplicationInfo.cpp+36−85 tests/mocks/Unity/Application/ApplicationInfo.h+11−23 tests/mocks/Unity/Application/ApplicationManager.cpp+9−16 tests/mocks/Unity/Application/ApplicationManager.h+1−2 tests/mocks/Unity/Application/ApplicationTestInterface.cpp+117 tests/mocks/Unity/Application/ApplicationDBusAdaptor.h → tests/mocks/Unity/Application/ApplicationTestInterface.h+13−11 tests/mocks/Unity/Application/CMakeLists.txt+6−1 tests/mocks/Unity/Application/MirSurfaceItem.cpp+19−79 tests/mocks/Unity/Application/MirSurfaceItem.h+24−31 tests/mocks/Unity/Application/MirSurfaceItemModel.h+35 tests/mocks/Unity/Application/ObjectListModel.h+106 tests/mocks/Unity/Application/Session.cpp+174 tests/mocks/Unity/Application/Session.h+90 tests/mocks/Unity/Application/SessionManager.cpp+55 tests/mocks/Unity/Application/SessionManager.h+44 tests/mocks/Unity/Application/SessionModel.h+35 tests/mocks/Unity/Application/SurfaceManager.cpp+20−7 tests/mocks/Unity/Application/SurfaceManager.h+6−2 tests/mocks/Unity/Application/plugin.cpp+37−4 tests/mocks/Unity/Indicators/Indicators.qmltypes+20 tests/mocks/Unity/Unity.qmltypes+30−2 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Panel/tst_ActiveCallHint.qml+1−1 tests/qmltests/Stages/RecursingChildSessionControl.qml+142 tests/qmltests/Stages/tst_ApplicationWindow.qml+99−47 tests/qmltests/Stages/tst_PhoneStage.qml+1−1 tests/qmltests/Stages/tst_SessionContainer.qml+267 tests/qmltests/Stages/tst_SurfaceContainer.qml+28−43 tests/qmltests/tst_Shell.qml+9−9
debian/control+1−1
@@ -85,7 +85,7 @@ Depends: gsettings-desktop-schemas,
8585 qmenumodel-qml (>= 0.2.8),
8686 qml-module-qtquick-xmllistmodel,
8787 qtdeclarative5-gsettings1.0,
88− qtdeclarative5-qtmir-plugin (>= 0.4.1),
88+ qtdeclarative5-qtmir-plugin (>= 0.4.3),
8989 qtdeclarative5-ubuntu-telephony0.1,
9090 unity-launcher-impl-3,
9191 unity8-common (= ${source:Version}),
plugins/AccountsService/AccountsService.qmltypes+1
@@ -26,5 +26,6 @@ Module {
2626 Property { name: "backgroundFile"; type: "string"; isReadonly: true }
2727 Property { name: "statsWelcomeScreen"; type: "bool"; isReadonly: true }
2828 Property { name: "passwordDisplayHint"; type: "PasswordDisplayHint"; isReadonly: true }
29+ Property { name: "failedLogins"; type: "uint" }
2930 }
3031}
plugins/LightDM/LightDM.qmltypes+2
@@ -27,6 +27,7 @@ Module {
2727 name: "showPrompt"
2828 Parameter { name: "text"; type: "string" }
2929 Parameter { name: "isSecret"; type: "bool" }
30+ Parameter { name: "isDefaultPrompt"; type: "bool" }
3031 }
3132 Signal { name: "authenticationComplete" }
3233 Signal {
@@ -34,6 +35,7 @@ Module {
3435 Parameter { name: "user"; type: "string" }
3536 }
3637 Signal { name: "isActiveChanged" }
38+ Signal { name: "isAuthenticatedChanged" }
3739 Signal { name: "showGreeter" }
3840 Signal {
3941 name: "requestAuthenticationUser"
plugins/Ubuntu/SystemImage/SystemImage.qmltypes+2
@@ -11,6 +11,8 @@ Module {
1111 name: "SystemImage"
1212 prototype: "QObject"
1313 exports: ["Ubuntu.SystemImage/SystemImage 0.1"]
14+ isCreatable: false
15+ isSingleton: true
1416 exportMetaObjectRevisions: [0]
1517 Method { name: "factoryReset" }
1618 }
plugins/Unity/Indicators/Indicators.qmltypes+6−4
@@ -219,12 +219,14 @@ Module {
219219 Method {
220220 name: "model"
221221 type: "UnityMenuModel*"
222− Parameter { name: "path"; type: "string" }
222+ Parameter { name: "bus"; type: "QByteArray" }
223+ Parameter { name: "path"; type: "QByteArray" }
224+ Parameter { name: "actions"; type: "QVariantMap" }
223225 }
224226 Method {
225− name: "registerModel"
226− Parameter { name: "path"; type: "string" }
227− Parameter { name: "menuModel"; type: "UnityMenuModel"; isPointer: true }
227+ name: "contains"
228+ type: "bool"
229+ Parameter { name: "path"; type: "QByteArray" }
228230 }
229231 }
230232 Component {
qml/Shell.qml+9
@@ -233,6 +233,15 @@ Item {
233233 }
234234 }
235235 }
236+ Connections {
237+ target: SessionManager
238+ onSessionStopping: {
239+ if (!session.parentSession && !session.application) {
240+ // nothing is using it. delete it right away
241+ session.release();
242+ }
243+ }
244+ }
236245
237246 Lockscreen {
238247 id: lockscreen
qml/Stages/Animations/BaseSurfaceAnimation.qml → qml/Stages/Animations/BaseSessionAnimation.qmlrenamed+23−20
@@ -37,57 +37,60 @@ import QtQuick 2.0
3737 */
3838Item {
3939 id: base
40− property Item surface: null
40+ property var container
41+ objectName: "sessionAnimation"
4142
42− // changes applied when state changes to "in"
43− property list<QtObject> outChanges
44− // transition animations when changing state to "in"
45− property list<QtObject> outAnimations
43+ // changes applied when state changes to "from"
44+ property list<QtObject> fromChanges
45+ // transition animations when changing state to "from"
46+ property list<QtObject> fromAnimations
4647
47− // changes applied when state changes to "out"
48− property list<QtObject> inChanges
49− // transition animations when changing state to "out"
50− property list<QtObject> inAnimations
48+ // changes applied when state changes to "to"
49+ property list<QtObject> toChanges
50+ // transition animations when changing state to "to"
51+ property list<QtObject> toAnimations
5152
5253 function start() {
53− // "prep" state forces outChanges without transition animations.
54+ // "prep" state forces toChanges without transition animations.
5455 state = "prep"
55− state = "in";
56+ state = "to";
5657 }
5758 function end() {
58− state = "out";
59+ state = "from";
5960 }
6061
62+ signal completed()
63+
6164 states: [
6265 State {
6366 name: "baseAnimation"
64− PropertyChanges { target: base.surface; anchors.fill: undefined }
67+ PropertyChanges { target: container; anchors.fill: undefined }
6568 },
6669
6770 State {
6871 name: "prep"
6972 extend: "baseAnimation"
70− changes: outChanges
73+ changes: fromChanges
7174 },
7275 State {
73− name: "out"
76+ name: "from"
7477 extend: "prep"
7578 },
7679 State {
7780 name: "in"
7881 extend: "baseAnimation"
79− changes: inChanges
82+ changes: toChanges
8083 }
8184 ]
8285
8386 transitions: [
8487 Transition {
85− to: "out"
86− animations: outAnimations
88+ to: "from"
89+ animations: fromAnimations
8790 },
8891 Transition {
89− to: "in"
90− animations: inAnimations
92+ to: "to"
93+ animations: toAnimations
9194 }
9295 ]
9396}
qml/Stages/Animations/DarkenAndFadeInAnimation.qmldeleted−48
@@ -1,48 +0,0 @@
1−/*
2− * Copyright (C) 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.0
18−import Ubuntu.Components 1.1
19−
20−BaseSurfaceAnimation {
21− id: animation
22−
23− property Rectangle darkenItem: Rectangle {
24− parent: animation.surface.parent
25− anchors.fill: parent
26− color: Qt.rgba(0,0,0,0.0)
27− }
28−
29− outChanges: [ PropertyChanges { target: animation.surface; opacity: 0.0 } ]
30− outAnimations: [
31− SequentialAnimation {
32− UbuntuNumberAnimation { target: animation.surface; property: "opacity"; duration: UbuntuAnimation.FastDuration }
33− ColorAnimation { target: darkenItem; duration: UbuntuAnimation.FastDuration }
34− ScriptAction { script: { if (animation.parent.removing) animation.surface.release(); } }
35− }
36− ]
37−
38− inChanges: [
39− PropertyChanges { target: darkenItem; color: Qt.rgba(0,0,0,0.7) },
40− PropertyChanges { target: animation.surface; opacity: 1.0 }
41− ]
42− inAnimations: [
43− SequentialAnimation {
44− ColorAnimation { target: darkenItem; duration: UbuntuAnimation.FastDuration }
45− UbuntuNumberAnimation { target: animation.surface; property: "opacity"; duration: UbuntuAnimation.FastDuration }
46− }
47− ]
48−}
qml/Stages/Animations/SwipeFromBottomAnimation.qml+24−19
@@ -15,34 +15,39 @@
1515 */
1616
1717import QtQuick 2.0
18+import Ubuntu.Components 1.1
1819
19−BaseSurfaceAnimation {
20+BaseSessionAnimation {
2021 id: animation
2122
22− outChanges: [ AnchorChanges { target: animation.surface; anchors.top: animation.parent.bottom } ]
23− outAnimations: [
23+ fromChanges: [
24+ AnchorChanges {
25+ target: container;
26+ anchors.top: container.parent.bottom
27+ }
28+ ]
29+ fromAnimations: [
2430 SequentialAnimation {
25− PropertyAction { target: animation.parent; property: "clip"; value: true }
26− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
27− PropertyAction { target: animation.surface; property: "visible"; value: !animation.parent.removing }
28− PropertyAction { target: animation.parent; property: "clip"; value: false }
29− ScriptAction { script: { if (animation.parent.removing) animation.surface.release(); } }
31+ // clip so we don't go out of parent's bounds during spread
32+ PropertyAction { target: container.parent; property: "clip"; value: true }
33+ AnchorAnimation { easing: UbuntuAnimation.StandardEasing; duration: UbuntuAnimation.BriskDuration }
34+ PropertyAction { target: container.parent; property: "clip"; value: false }
35+ ScriptAction { script: { animation.completed(); } }
3036 }
3137 ]
3238
33− inChanges: [
39+ toChanges: [
3440 AnchorChanges {
35− target: animation.surface;
36− anchors.top: animation.parent.top
37− anchors.right: undefined
38− anchors.bottom: undefined
39− anchors.left: undefined
40− } ]
41− inAnimations: [
41+ target: container;
42+ anchors.top: container.parent.top
43+ }
44+ ]
45+ toAnimations: [
4246 SequentialAnimation {
43− PropertyAction { target: animation.parent; property: "clip"; value: true }
44− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
45− PropertyAction { target: animation.parent; property: "clip"; value: false }
47+ // clip so we don't go out of parent's bounds during spread
48+ PropertyAction { target: container.parent; property: "clip"; value: true }
49+ AnchorAnimation { easing: UbuntuAnimation.StandardEasing; duration: UbuntuAnimation.BriskDuration }
50+ PropertyAction { target: container.parent; property: "clip"; value: false }
4651 }
4752 ]
4853}
qml/Stages/Animations/SwipeUpAnimation.qmldeleted−49
@@ -1,49 +0,0 @@
1−/*
2− * Copyright (C) 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.0
18−
19−BaseSurfaceAnimation {
20− id: animation
21−
22− outAnimations: [
23− SequentialAnimation {
24− PropertyAction { target: animation.parent; property: "clip"; value: true }
25− PropertyAction { target: animation.surface; property: "visible"; value: true }
26− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
27− PropertyAction { target: animation.parent; property: "clip"; value: false }
28− ScriptAction { script: { if (animation.parent.removing) animation.surface.release(); } }
29− }
30− ]
31−
32− inChanges: [
33− AnchorChanges {
34− target: animation.surface;
35− anchors.top: undefined
36− anchors.right: undefined
37− anchors.bottom: animation.parent.top
38− anchors.left: undefined
39− }
40− ]
41− inAnimations: [
42− SequentialAnimation {
43− PropertyAction { target: animation.parent; property: "clip"; value: true }
44− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
45− PropertyAction { target: animation.surface; property: "visible"; value: false}
46− PropertyAction { target: animation.parent; property: "clip"; value: false }
47− }
48− ]
49−}
qml/Stages/ApplicationWindow.qml+50−71
@@ -23,9 +23,9 @@ Item {
2323
2424 // to be read from outside
2525 readonly property bool fullscreen: application ? application.fullscreen : false
26+ property alias interactive: sessionContainer.interactive
2627
2728 // to be set from outside
28− property bool interactive: true
2929 property QtObject application
3030
3131 QtObject {
@@ -35,16 +35,14 @@ Item {
3535 // (in order to avoid breaking qml binding due to a javascript exception)
3636 readonly property string name: root.application ? root.application.name : ""
3737 readonly property url icon: root.application ? root.application.icon : ""
38− readonly property Item surface: root.application ? root.application.surface : null
3938 readonly property int applicationState: root.application ? root.application.state : -1
40− readonly property var promptSurfaces: root.application ? root.application.promptSurfaces : null
4139
4240 // Whether the Application had a surface before but lost it.
43− property bool hadSurface: false
41+ property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
4442
4543 property bool needToTakeScreenshot:
46− d.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
47− && d.applicationState === ApplicationInfo.Stopped
44+ sessionContainer.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
45+ && d.applicationState === ApplicationInfoInterface.Stopped
4846 onNeedToTakeScreenshotChanged: {
4947 if (needToTakeScreenshot) {
5048 screenshotImage.take();
@@ -55,12 +53,12 @@ Item {
5553 // might show the UI accommodating due to surface resizes on startup.
5654 // Remove this when possible
5755 property bool surfaceInitialized: false
58− onSurfaceChanged: {
59− if (surface) {
60− surfaceInitTimer.start();
61− } else {
62− hadSurface = true;
63− surfaceInitialized = false;
56+
57+ function forceSurfaceActiveFocusIfReady() {
58+ if (sessionContainer.surface.focus &&
59+ sessionContainer.surface.parent === sessionContainer.surfaceContainer &&
60+ sessionContainer.surface.enabled) {
61+ sessionContainer.surface.forceActiveFocus();
6462 }
6563 }
6664 }
@@ -68,40 +66,16 @@ Item {
6866 Timer {
6967 id: surfaceInitTimer
7068 interval: 100
71− onTriggered: { if (d.surface) {d.surfaceInitialized = true;} }
69+ onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
7270 }
7371
74− Binding {
75− target: d.surface
76− when: d.surface
77− property: "enabled"
78− value: root.interactive
79− }
80− Binding {
81− target: d.surface
82− when: d.surface
83− property: "focus"
84− value: root.interactive
85− }
8672 Connections {
87− target: d.surface
73+ target: sessionContainer.surface
8874 // FIXME: I would rather not need to do this, but currently it doesn't get
8975 // active focus without it and I don't know why.
90− onFocusChanged: forceSurfaceActiveFocusIfReady();
91− onParentChanged: forceSurfaceActiveFocusIfReady();
92− onEnabledChanged: forceSurfaceActiveFocusIfReady();
93− function forceSurfaceActiveFocusIfReady() {
94− if (d.surface.focus && d.surface.parent === surfaceContainer && d.surface.enabled) {
95− d.surface.forceActiveFocus();
96− }
97− }
98− }
99−
100− SurfaceContainer {
101− id: surfaceContainer
102− objectName: "surfaceContainer"
103− anchors.fill: parent
104− surface: d.surface
76+ onFocusChanged: d.forceSurfaceActiveFocusIfReady();
77+ onParentChanged: d.forceSurfaceActiveFocusIfReady();
78+ onEnabledChanged: d.forceSurfaceActiveFocusIfReady();
10579 }
10680
10781 Image {
@@ -126,25 +100,24 @@ Item {
126100 id: splashLoader
127101 visible: active
128102 active: false
129− anchors.fill: surfaceContainer
103+ anchors.fill: parent
130104 sourceComponent: Component {
131105 Splash { name: d.name; image: d.icon }
132106 }
133107 }
134108
135− Repeater {
136− model: d.promptSurfaces
137−
138− delegate: SurfaceContainer {
139− anchors {
140− fill: surfaceContainer
141− }
142−
143− surface: modelData
109+ SessionContainer {
110+ id: sessionContainer
111+ session: application ? application.session : null
112+ anchors.fill: parent
144113
145− Component.onCompleted: {
146− animateIn();
114+ onSurfaceChanged: {
115+ if (sessionContainer.surface) {
116+ surfaceInitTimer.start();
117+ } else {
118+ d.surfaceInitialized = false;
147119 }
120+ d.forceSurfaceActiveFocusIfReady();
148121 }
149122 }
150123
@@ -154,23 +127,23 @@ Item {
154127 State {
155128 name: "void"
156129 when:
157− d.hadSurface && (!d.surface || !d.surfaceInitialized)
130+ d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
158131 &&
159132 screenshotImage.status !== Image.Ready
160133 },
161134 State {
162135 name: "splashScreen"
163136 when:
164− !d.hadSurface && (!d.surface || !d.surfaceInitialized)
137+ !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
165138 &&
166139 screenshotImage.status !== Image.Ready
167140 },
168141 State {
169142 name: "surface"
170143 when:
171− (d.surface && d.surfaceInitialized)
144+ (sessionContainer.surface && d.surfaceInitialized)
172145 &&
173− (d.applicationState !== ApplicationInfo.Stopped
146+ (d.applicationState !== ApplicationInfoInterface.Stopped
174147 || screenshotImage.status !== Image.Ready)
175148 },
176149 State {
@@ -178,8 +151,8 @@ Item {
178151 when:
179152 screenshotImage.status === Image.Ready
180153 &&
181− (d.applicationState === ApplicationInfo.Stopped
182− || !d.surface || !d.surfaceInitialized)
154+ (d.applicationState === ApplicationInfoInterface.Stopped
155+ || !sessionContainer.surface || !d.surfaceInitialized)
183156 }
184157 ]
185158
@@ -187,14 +160,18 @@ Item {
187160 Transition {
188161 from: ""; to: "splashScreen"
189162 PropertyAction { target: splashLoader; property: "active"; value: true }
163+ PropertyAction { target: sessionContainer.surfaceContainer
164+ property: "visible"; value: false }
190165 },
191166 Transition {
192167 from: "splashScreen"; to: "surface"
193168 SequentialAnimation {
194− PropertyAction { target: surfaceContainer
169+ PropertyAction { target: sessionContainer.surfaceContainer
170+ property: "opacity"; value: 0.0 }
171+ PropertyAction { target: sessionContainer.surfaceContainer
195172 property: "visible"; value: true }
196− UbuntuNumberAnimation { target: splashLoader; property: "opacity";
197− from: 1.0; to: 0.0
173+ UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
174+ from: 0.0; to: 1.0
198175 duration: UbuntuAnimation.BriskDuration }
199176 PropertyAction { target: splashLoader; property: "active"; value: false }
200177 }
@@ -203,11 +180,13 @@ Item {
203180 from: "surface"; to: "splashScreen"
204181 SequentialAnimation {
205182 PropertyAction { target: splashLoader; property: "active"; value: true }
206− PropertyAction { target: surfaceContainer
183+ PropertyAction { target: sessionContainer.surfaceContainer
207184 property: "visible"; value: true }
208185 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
209186 from: 0.0; to: 1.0
210187 duration: UbuntuAnimation.BriskDuration }
188+ PropertyAction { target: sessionContainer.surfaceContainer
189+ property: "visible"; value: false }
211190 }
212191 },
213192 Transition {
@@ -218,15 +197,15 @@ Item {
218197 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
219198 from: 0.0; to: 1.0
220199 duration: UbuntuAnimation.BriskDuration }
221− PropertyAction { target: surfaceContainer
200+ PropertyAction { target: sessionContainer.surfaceContainer
222201 property: "visible"; value: false }
223− ScriptAction { script: { if (d.surface) { d.surface.release(); } } }
202+ ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
224203 }
225204 },
226205 Transition {
227206 from: "screenshot"; to: "surface"
228207 SequentialAnimation {
229− PropertyAction { target: surfaceContainer
208+ PropertyAction { target: sessionContainer.surfaceContainer
230209 property: "visible"; value: true }
231210 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
232211 from: 1.0; to: 0.0
@@ -238,16 +217,16 @@ Item {
238217 Transition {
239218 from: "surface"; to: "void"
240219 SequentialAnimation {
241− PropertyAction { target: surfaceContainer; property: "visible"; value: false }
242− ScriptAction { script: { if (d.surface) { d.surface.release(); } } }
220+ PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: false }
221+ ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
243222 }
244223 },
245224 Transition {
246225 from: "void"; to: "surface"
247226 SequentialAnimation {
248− PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
249− PropertyAction { target: surfaceContainer; property: "visible"; value: true }
250− UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
227+ PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
228+ PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
229+ UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
251230 from: 0.0; to: 1.0
252231 duration: UbuntuAnimation.BriskDuration }
253232 }
qml/Stages/SessionContainer.qmlnew file+143
@@ -0,0 +1,143 @@
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 Lesser 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 Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+*/
16+
17+import QtQuick 2.0
18+import "Animations"
19+
20+Item {
21+ id: root
22+ objectName: "sessionContainer"
23+ property QtObject session
24+ readonly property var childSessions: session ? session.childSessions : null
25+ readonly property alias surface: _surfaceContainer.surface
26+ property bool interactive: true
27+
28+ readonly property alias surfaceContainer: _surfaceContainer
29+ SurfaceContainer {
30+ id: _surfaceContainer
31+ anchors.fill: parent
32+ surface: session ? session.surface : null
33+ }
34+
35+ Binding {
36+ target: surfaceContainer.surface
37+ when: surfaceContainer.surface
38+ property: "enabled"
39+ value: root.interactive
40+ }
41+ Binding {
42+ target: surfaceContainer.surface
43+ when: surfaceContainer.surface
44+ property: "focus"
45+ value: root.interactive
46+ }
47+
48+ Repeater {
49+ model: root.childSessions
50+
51+ delegate: Loader {
52+ objectName: "childDelegate" + index
53+ anchors.fill: surfaceContainer
54+
55+ // Only way to do recursive qml items.
56+ source: Qt.resolvedUrl("SessionContainer.qml")
57+
58+ Binding {
59+ target: item; when: item
60+ property: "interactive"; value: root.interactive
61+ }
62+
63+ Binding {
64+ target: item; when: item
65+ property: "session"; value: modelData
66+ }
67+
68+ Binding {
69+ target: item; when: item
70+ property: "width"; value: root.width
71+ }
72+
73+ Binding {
74+ target: item; when: item
75+ property: "height"; value: root.height
76+ }
77+ }
78+ }
79+
80+ states: [
81+ State {
82+ name: "rootSession"
83+ when: root.session && !root.session.parentSession
84+ },
85+
86+ State {
87+ name: "childSession"
88+ when: root.session && root.session.parentSession !== null && root.session.live
89+ && !root.session.surface
90+ },
91+
92+ State {
93+ name: "childSessionReady"
94+ when: root.session && root.session.parentSession !== null && root.session.live
95+ && root.session.surface !== null
96+ },
97+
98+ State {
99+ name: "childSessionZombie"
100+ when: root.session && root.session.parentSession !== null && !root.session.live
101+ }
102+ ]
103+
104+ transitions: [
105+ Transition {
106+ to: "childSessionReady"
107+ ScriptAction { script: { if (!surfaceContainer.hadSurface) { animateIn(swipeFromBottom); } } }
108+ },
109+ Transition {
110+ to: "childSessionZombie"
111+ ScriptAction { script: { animateOut(); } }
112+ }
113+ ]
114+
115+ function animateIn(component) {
116+ var animation = component.createObject(root, { "container": root, });
117+ animation.start();
118+
119+ var tmp = d.animations;
120+ tmp.push(animation);
121+ d.animations = tmp;
122+ }
123+
124+ function animateOut() {
125+ if (d.animations.length > 0) {
126+ var tmp = d.animations;
127+ var popped = tmp.pop();
128+ popped.completed.connect(function() { root.session.release(); } );
129+ popped.end();
130+ d.animations = tmp;
131+ }
132+ }
133+
134+ Component {
135+ id: swipeFromBottom
136+ SwipeFromBottomAnimation {}
137+ }
138+
139+ QtObject {
140+ id: d
141+ property var animations: []
142+ }
143+}
qml/Stages/SurfaceContainer.qml+22−67
@@ -15,86 +15,41 @@
1515*/
1616
1717import QtQuick 2.0
18−import "Animations"
18+import Ubuntu.Components 1.1
1919
2020Item {
21− id: container
21+ id: root
22+ objectName: "surfaceContainer"
2223 property Item surface: null
23− property bool removing: false
24+ property bool hadSurface: false
2425
2526 onSurfaceChanged: {
2627 if (surface) {
27− surface.parent = container;
28− surface.z = 1;
28+ surface.parent = root;
29+ } else {
30+ hadSurface = true;
2931 }
3032 }
3133 Binding {
3234 target: surface
33− property: "anchors.fill"; value: container
35+ property: "anchors.fill"; value: root
3436 }
3537
36− Connections {
37− target: surface
38− onRemoved: {
39− container.removing = true;
40−
41− var childSurfaces = surface.childSurfaces;
42− for (var i=0; i<childSurfaces.length; i++) {
43− childSurfaces[i].removed();
44− }
45−
46− animateOut();
38+ states: [
39+ State {
40+ name: "zombie"
41+ when: surface && !surface.live
4742 }
48− }
49−
50− Repeater {
51− model: surface ? surface.childSurfaces : null
52−
53− delegate: Loader {
54− z: 2
55− anchors {
56− fill: container
57− topMargin: container.surface.anchors.topMargin
58− rightMargin: container.surface.anchors.rightMargin
59− bottomMargin: container.surface.anchors.bottomMargin
60− leftMargin: container.surface.anchors.leftMargin
43+ ]
44+ transitions: [
45+ Transition {
46+ from: ""; to: "zombie"
47+ SequentialAnimation {
48+ UbuntuNumberAnimation { target: surface; property: "opacity"; to: 0.0
49+ duration: UbuntuAnimation.BriskDuration }
50+ PropertyAction { target: surface; property: "visible"; value: false }
51+ ScriptAction { script: { if (root.surface) { root.surface.release(); } } }
6152 }
62−
63− // Only way to do recursive qml items.
64− source: Qt.resolvedUrl("SurfaceContainer.qml")
65− onLoaded: {
66− item.surface = modelData;
67− item.animateIn();
68− }
69− }
70− }
71−
72− function animateIn() {
73− var animation = swipeFromBottom.createObject(container, { "surface": container.surface });
74− animation.start();
75−
76− var tmp = d.animations;
77− tmp.push(animation);
78− d.animations = tmp;
79− }
80−
81− function animateOut() {
82− if (d.animations.length > 0) {
83− var tmp = d.animations;
84− var popped = tmp.pop();
85− popped.end();
86− d.animations = tmp;
8753 }
88− }
89−
90− QtObject {
91− id: d
92− property var animations: []
93− property var currentAnimation: animations.length > 0 ? animations[animations.length-1] : undefined
94− }
95−
96− Component {
97− id: swipeFromBottom
98− SwipeFromBottomAnimation {}
99− }
54+ ]
10055}
tests/mocks/AccountsService/AccountsService.qmltypes+1
@@ -26,5 +26,6 @@ Module {
2626 Property { name: "backgroundFile"; type: "string" }
2727 Property { name: "statsWelcomeScreen"; type: "bool" }
2828 Property { name: "passwordDisplayHint"; type: "PasswordDisplayHint"; isReadonly: true }
29+ Property { name: "failedLogins"; type: "uint" }
2930 }
3031}
tests/mocks/LightDM/LightDM.qmltypes+2
@@ -27,6 +27,7 @@ Module {
2727 name: "showPrompt"
2828 Parameter { name: "text"; type: "string" }
2929 Parameter { name: "isSecret"; type: "bool" }
30+ Parameter { name: "isDefaultPrompt"; type: "bool" }
3031 }
3132 Signal { name: "authenticationComplete" }
3233 Signal {
@@ -34,6 +35,7 @@ Module {
3435 Parameter { name: "user"; type: "string" }
3536 }
3637 Signal { name: "isActiveChanged" }
38+ Signal { name: "isAuthenticatedChanged" }
3739 Signal { name: "showGreeter" }
3840 Signal {
3941 name: "requestAuthenticationUser"
tests/mocks/Ubuntu/SystemImage/SystemImage.qmltypes+3−1
@@ -4,13 +4,15 @@ import QtQuick.tooling 1.1
44// It is used for QML tooling purposes only.
55//
66// This file was auto-generated by:
7−// 'qmlplugindump -notrelocatable Ubuntu.SystemImage 0.1 plugins'
7+// 'qmlplugindump -notrelocatable Ubuntu.SystemImage 0.1 tests/mocks'
88
99Module {
1010 Component {
1111 name: "MockSystemImage"
1212 prototype: "QObject"
1313 exports: ["Ubuntu.SystemImage/SystemImage 0.1"]
14+ isCreatable: false
15+ isSingleton: true
1416 exportMetaObjectRevisions: [0]
1517 Signal { name: "resettingDevice" }
1618 Method { name: "factoryReset" }
tests/mocks/Unity/Application/Application.qmltypes+115−70
@@ -13,58 +13,24 @@ Module {
1313 exports: ["Unity.Application/ApplicationInfo 0.1"]
1414 exportMetaObjectRevisions: [0]
1515 Property { name: "fullscreen"; type: "bool" }
16− Property { name: "stage"; type: "Stage" }
17− Property { name: "surface"; type: "MirSurfaceItem"; isReadonly: true; isPointer: true }
18− Property { name: "promptSurfaces"; type: "MirSurfaceItem"; isList: true; isReadonly: true }
19− Property { name: "imageQml"; type: "string" }
20− Property { name: "windowQml"; type: "string" }
21− Signal {
22− name: "appIdChanged"
23− Parameter { type: "string" }
24− }
25− Signal {
26− name: "nameChanged"
27− Parameter { type: "string" }
28− }
29− Signal {
30− name: "commentChanged"
31− Parameter { type: "string" }
32− }
33− Signal {
34− name: "iconChanged"
35− Parameter { type: "QUrl" }
36− }
16+ Property { name: "session"; type: "Session"; isReadonly: true; isPointer: true }
17+ Property { name: "manualSurfaceCreation"; type: "bool" }
3718 Signal {
38− name: "stageChanged"
39− Parameter { type: "Stage" }
40− }
41− Signal {
42− name: "stateChanged"
43− Parameter { type: "State" }
44− }
45− Signal {
46− name: "focusedChanged"
47− Parameter { type: "bool" }
19+ name: "sessionChanged"
20+ Parameter { type: "Session"; isPointer: true }
4821 }
4922 Signal {
5023 name: "fullscreenChanged"
51− Parameter { type: "bool" }
52− }
53− Signal {
54− name: "imageQmlChanged"
55− Parameter { type: "string" }
56− }
57− Signal {
58− name: "windowQmlChanged"
59− Parameter { type: "string" }
24+ Parameter { name: "value"; type: "bool" }
6025 }
6126 Signal {
62− name: "screenshotChanged"
63− Parameter { type: "QUrl" }
27+ name: "manualSurfaceCreationChanged"
28+ Parameter { name: "value"; type: "bool" }
6429 }
65− Signal {
66− name: "surfaceChanged"
67− Parameter { type: "MirSurfaceItem"; isPointer: true }
30+ Method { name: "createSession" }
31+ Method {
32+ name: "setState"
33+ Parameter { name: "value"; type: "State" }
6834 }
6935 }
7036 Component {
@@ -198,17 +164,50 @@ Module {
198164 type: "bool"
199165 Parameter { name: "appId"; type: "string" }
200166 }
167+ Method { name: "availableApplications"; type: "QStringList" }
201168 Method {
202− name: "updateScreenshot"
203− type: "bool"
169+ name: "add"
170+ type: "ApplicationInfo*"
204171 Parameter { name: "appId"; type: "string" }
205172 }
206− Method { name: "availableApplications"; type: "QStringList" }
173+ }
174+ Component {
175+ name: "ApplicationTestInterface"
176+ prototype: "QDBusAbstractAdaptor"
177+ exports: ["Unity.Application/ApplicationTest 0.1"]
178+ isCreatable: false
179+ isSingleton: true
180+ exportMetaObjectRevisions: [0]
181+ Method {
182+ name: "addChildSession"
183+ type: "uint"
184+ Parameter { name: "appId"; type: "string" }
185+ Parameter { name: "existingSessionId"; type: "uint" }
186+ Parameter { name: "surfaceImage"; type: "string" }
187+ }
188+ Method {
189+ name: "removeSession"
190+ Parameter { name: "sessionId"; type: "uint" }
191+ }
192+ Method {
193+ name: "addChildSession"
194+ type: "Session*"
195+ Parameter { name: "existingSession"; type: "Session"; isPointer: true }
196+ Parameter { name: "surfaceImage"; type: "string" }
197+ }
198+ Method {
199+ name: "removeSession"
200+ Parameter { name: "existingSession"; type: "Session"; isPointer: true }
201+ }
202+ Method {
203+ name: "removeSurface"
204+ Parameter { name: "existingSurface"; type: "MirSurfaceItem"; isPointer: true }
205+ }
207206 }
208207 Component {
209208 name: "MirSurfaceItem"
210209 defaultProperty: "data"
211− prototype: "QQuickPaintedItem"
210+ prototype: "QQuickItem"
212211 exports: ["Unity.Application/MirSurfaceItem 0.1"]
213212 isCreatable: false
214213 exportMetaObjectRevisions: [0]
@@ -238,8 +237,7 @@ Module {
238237 Property { name: "type"; type: "Type"; isReadonly: true }
239238 Property { name: "state"; type: "State"; isReadonly: true }
240239 Property { name: "name"; type: "string"; isReadonly: true }
241− Property { name: "parentSurface"; type: "MirSurfaceItem"; isReadonly: true; isPointer: true }
242− Property { name: "childSurfaces"; type: "MirSurfaceItem"; isList: true; isReadonly: true }
240+ Property { name: "live"; type: "bool"; isReadonly: true }
243241 Signal {
244242 name: "typeChanged"
245243 Parameter { type: "Type" }
@@ -249,22 +247,72 @@ Module {
249247 Parameter { type: "State" }
250248 }
251249 Signal {
252− name: "nameChanged"
253− Parameter { type: "string" }
254− }
255− Signal {
256− name: "parentSurfaceChanged"
257− Parameter { type: "MirSurfaceItem"; isPointer: true }
250+ name: "liveChanged"
251+ Parameter { name: "live"; type: "bool" }
258252 }
259− Signal { name: "removed" }
260253 Signal { name: "inputMethodRequested" }
261254 Signal { name: "inputMethodDismissed" }
255+ Signal { name: "deregister" }
262256 Method {
263257 name: "setState"
264258 Parameter { name: "newState"; type: "State" }
265259 }
266260 Method { name: "release" }
267261 }
262+ Component { name: "QDBusAbstractAdaptor"; prototype: "QObject" }
263+ Component {
264+ name: "Session"
265+ prototype: "QObject"
266+ exports: ["Unity.Application/Session 0.1"]
267+ isCreatable: false
268+ exportMetaObjectRevisions: [0]
269+ Property { name: "name"; type: "string"; isReadonly: true }
270+ Property { name: "surface"; type: "MirSurfaceItem"; isReadonly: true; isPointer: true }
271+ Property { name: "parentSession"; type: "Session"; isReadonly: true; isPointer: true }
272+ Property { name: "childSessions"; type: "SessionModel"; isReadonly: true; isPointer: true }
273+ Property { name: "live"; type: "bool"; isReadonly: true }
274+ Signal {
275+ name: "surfaceChanged"
276+ Parameter { type: "MirSurfaceItem"; isPointer: true }
277+ }
278+ Signal {
279+ name: "parentSessionChanged"
280+ Parameter { type: "Session"; isPointer: true }
281+ }
282+ Signal {
283+ name: "liveChanged"
284+ Parameter { name: "live"; type: "bool" }
285+ }
286+ Signal { name: "deregister" }
287+ Method { name: "createSurface" }
288+ Method { name: "release" }
289+ Method {
290+ name: "addChildSession"
291+ Parameter { name: "session"; type: "Session"; isPointer: true }
292+ }
293+ }
294+ Component {
295+ name: "SessionManager"
296+ prototype: "QObject"
297+ exports: ["Unity.Application/SessionManager 0.1"]
298+ isCreatable: false
299+ isSingleton: true
300+ exportMetaObjectRevisions: [0]
301+ Signal {
302+ name: "sessionStarting"
303+ Parameter { name: "session"; type: "Session"; isPointer: true }
304+ }
305+ Signal {
306+ name: "sessionStopping"
307+ Parameter { name: "session"; type: "Session"; isPointer: true }
308+ }
309+ Method {
310+ name: "createSession"
311+ type: "Session*"
312+ Parameter { name: "name"; type: "string" }
313+ Parameter { name: "screenshot"; type: "QUrl" }
314+ }
315+ }
268316 Component {
269317 name: "SurfaceManager"
270318 prototype: "QObject"
@@ -281,6 +329,14 @@ Module {
281329 name: "surfaceDestroyed"
282330 Parameter { name: "surface"; type: "MirSurfaceItem"; isPointer: true }
283331 }
332+ Method {
333+ name: "createSurface"
334+ type: "MirSurfaceItem*"
335+ Parameter { name: "name"; type: "string" }
336+ Parameter { name: "type"; type: "MirSurfaceItem::Type" }
337+ Parameter { name: "state"; type: "MirSurfaceItem::State" }
338+ Parameter { name: "screenshot"; type: "QUrl" }
339+ }
284340 Method { name: "inputMethodSurface"; type: "MirSurfaceItem*" }
285341 }
286342 Component {
@@ -312,7 +368,6 @@ Module {
312368 Property { name: "stage"; type: "Stage"; isReadonly: true }
313369 Property { name: "state"; type: "State"; isReadonly: true }
314370 Property { name: "focused"; type: "bool"; isReadonly: true }
315− Property { name: "screenshot"; type: "QUrl"; isReadonly: true }
316371 Signal {
317372 name: "nameChanged"
318373 Parameter { name: "name"; type: "string" }
@@ -337,10 +392,6 @@ Module {
337392 name: "focusedChanged"
338393 Parameter { name: "focused"; type: "bool" }
339394 }
340− Signal {
341− name: "screenshotChanged"
342− Parameter { name: "screenshot"; type: "QUrl" }
343− }
344395 }
345396 Component {
346397 name: "unity::shell::application::ApplicationManagerInterface"
@@ -357,8 +408,7 @@ Module {
357408 "RoleIcon": 259,
358409 "RoleStage": 260,
359410 "RoleState": 261,
360− "RoleFocused": 262,
361− "RoleScreenshot": 263
411+ "RoleFocused": 262
362412 }
363413 }
364414 Property { name: "count"; type: "int"; isReadonly: true }
@@ -408,10 +458,5 @@ Module {
408458 type: "bool"
409459 Parameter { name: "appId"; type: "string" }
410460 }
411− Method {
412− name: "updateScreenshot"
413− type: "bool"
414− Parameter { name: "appId"; type: "string" }
415− }
416461 }
417462}
tests/mocks/Unity/Application/ApplicationDBusAdaptor.cppdeleted−81
@@ -1,81 +0,0 @@
1−/*
2− * Copyright (C) 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−#include "ApplicationInfo.h"
18−#include "ApplicationDBusAdaptor.h"
19−#include "ApplicationManager.h"
20−#include "SurfaceManager.h"
21−#include "MirSurfaceItem.h"
22−
23−quint32 nextId = 0;
24−
25−ApplicationDBusAdaptor::ApplicationDBusAdaptor(ApplicationManager* applicationManager)
26− : QDBusAbstractAdaptor(applicationManager)
27− , m_applicationManager(applicationManager)
28−{
29−}
30−
31−MirSurfaceItem* topSurface(MirSurfaceItem* surface)
32−{
33− if (!surface)
34− return nullptr;
35−
36− MirSurfaceItem* child = nullptr;
37− Q_FOREACH (MirSurfaceItem *childSurface, surface->childSurfaceList()) {
38− child = topSurface(childSurface);
39− if (child) {
40− break;
41− }
42− }
43− return child ? child : surface;
44−}
45−
46−quint32 ApplicationDBusAdaptor::addPromptSurface(const QString &appId, const QString &surfaceImage)
47−{
48− qDebug() << "ApplicationDBusAdaptor::addPromptSurface to " << appId;
49−
50− ApplicationInfo* application = m_applicationManager->findApplication(appId);
51− if (!application) {
52− qDebug() << "ApplicationDBusAdaptor::addChildSurface - No application found for " << appId;
53− return 0;
54− }
55− quint32 surfaceId = ++nextId;
56− MirSurfaceItem* surface = new MirSurfaceItem(QString("%1-ChildSurface%2").arg(appId).arg(surfaceId),
57− MirSurfaceItem::Normal,
58− MirSurfaceItem::Maximized,
59− QUrl(surfaceImage));
60− m_childItems[surfaceId] = surface;
61−
62− if (application->promptSurfaceList().count() > 0) {
63− surface->setParentSurface(topSurface(application->promptSurfaceList()[0]));
64− } else {
65− application->addPromptSurface(surface);
66− }
67−
68− return surfaceId;
69−}
70−
71−void ApplicationDBusAdaptor::removeChildSurface(int surfaceId)
72−{
73− qDebug() << "ApplicationDBusAdaptor::removeChildSurface - " << surfaceId;
74−
75− if (!m_childItems.contains(surfaceId)) {
76− qDebug() << "ApplicationDBusAdaptor::removeChildSurface - No added surface for " << surfaceId;
77− return;
78− }
79− MirSurfaceItem* surface = m_childItems.take(surfaceId);
80− Q_EMIT surface->removed();
81−}
tests/mocks/Unity/Application/ApplicationInfo.cpp+36−85
@@ -15,8 +15,8 @@
1515 */
1616
1717#include "ApplicationInfo.h"
18−#include "MirSurfaceItem.h"
19−#include "SurfaceManager.h"
18+#include "Session.h"
19+#include "SessionManager.h"
2020
2121#include <paths.h>
2222
@@ -33,9 +33,8 @@ ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
3333 , m_state(Starting)
3434 , m_focused(false)
3535 , m_fullscreen(false)
36− , m_surface(0)
36+ , m_session(0)
3737 , m_manualSurfaceCreation(false)
38− , m_parentItem(0)
3938{
4039}
4140
@@ -45,107 +44,50 @@ ApplicationInfo::ApplicationInfo(QObject *parent)
4544 , m_state(Starting)
4645 , m_focused(false)
4746 , m_fullscreen(false)
48− , m_surface(0)
47+ , m_session(0)
4948 , m_manualSurfaceCreation(false)
50− , m_parentItem(0)
5149{
5250}
5351
5452ApplicationInfo::~ApplicationInfo()
5553{
56− if (m_surface) {
57− Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(m_surface);
58− m_surface->deleteLater();
59− setSurface(nullptr);
60− }
54+ delete m_session;
6155}
6256
63−void ApplicationInfo::createSurface()
57+void ApplicationInfo::createSession()
6458{
65− if (m_surface || state() == ApplicationInfo::Stopped) return;
59+ if (m_session || state() == ApplicationInfo::Stopped) { return; }
6660
6761 QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
68−
69− setSurface(new MirSurfaceItem(name(),
70− MirSurfaceItem::Normal,
71− fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
72− screenshotUrl));
62+ setSession(SessionManager::singleton()->createSession(appId(), screenshotUrl));
7363}
7464
75−void ApplicationInfo::setSurface(MirSurfaceItem* surface)
65+void ApplicationInfo::setSession(Session* session)
7666{
77− qDebug() << "Application::setSurface - appId=" << appId() << "surface=" << surface;
78− if (m_surface == surface)
67+ qDebug() << "Application::setSession - appId=" << appId() << "session=" << session;
68+ if (m_session == session)
7969 return;
8070
81− if (m_surface) {
82− m_surface->setApplication(nullptr);
83− m_surface->setParent(nullptr);
84− SurfaceManager::singleton()->unregisterSurface(m_surface);
85− }
86−
87− m_surface = surface;
88−
89− if (m_surface) {
90− m_surface->setApplication(this);
91− m_surface->setParent(this);
92− SurfaceManager::singleton()->registerSurface(m_surface);
71+ if (m_session) {
72+ disconnect(this, 0, m_session, 0);
73+ m_session->setApplication(nullptr);
74+ m_session->setParent(nullptr);
75+ Q_EMIT m_session->deregister();
9376 }
9477
95− Q_EMIT surfaceChanged(m_surface);
96− SurfaceManager::singleton()->registerSurface(m_surface);
97−}
78+ m_session = session;
9879
99−void ApplicationInfo::addPromptSurface(MirSurfaceItem* surface)
100−{
101− qDebug() << "ApplicationInfo::addPromptSurface " << surface->name() << " to " << name();
102− if (surface == m_surface || m_promptSurfaces.contains(surface)) return;
80+ if (m_session) {
81+ m_session->setApplication(this);
82+ m_session->setParent(this);
83+ SessionManager::singleton()->registerSession(m_session);
10384
104− surface->setApplication(this);
105− m_promptSurfaces.append(surface);
106− Q_EMIT promptSurfacesChanged();
107−}
108−
109−void ApplicationInfo::removeSurface(MirSurfaceItem* surface)
110−{
111− if (m_surface == surface) {
112− setSurface(nullptr);
113− } else if (m_promptSurfaces.contains(surface)) {
114− qDebug() << "Application::removeSurface " << surface->name() << " from " << name();
115−
116− m_promptSurfaces.removeAll(surface);
117− surface->setApplication(nullptr);
118−
119− Q_EMIT promptSurfacesChanged();
85+ if (!m_manualSurfaceCreation) {
86+ QTimer::singleShot(500, m_session, SLOT(createSurface()));
87+ }
12088 }
121−}
12289
123−QList<MirSurfaceItem*> ApplicationInfo::promptSurfaceList() const
124−{
125− return m_promptSurfaces;
126−}
127−
128−QQmlListProperty<MirSurfaceItem> ApplicationInfo::promptSurfaces()
129−{
130− return QQmlListProperty<MirSurfaceItem>(this,
131− 0,
132− ApplicationInfo::promptSurfaceCount,
133− ApplicationInfo::promptSurfaceAt);
134−}
135−
136−int ApplicationInfo::promptSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop)
137−{
138− ApplicationInfo *p = qobject_cast<ApplicationInfo*>(prop->object);
139− return p->m_promptSurfaces.count();
140−}
141−
142−MirSurfaceItem* ApplicationInfo::promptSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index)
143−{
144− ApplicationInfo *p = qobject_cast<ApplicationInfo*>(prop->object);
145−
146− if (index < 0 || index >= p->m_promptSurfaces.count())
147− return nullptr;
148− return p->m_promptSurfaces[index];
90+ Q_EMIT sessionChanged(m_session);
14991}
15092
15193void ApplicationInfo::setIconId(const QString &iconId)
@@ -157,9 +99,18 @@ void ApplicationInfo::setIconId(const QString &iconId)
15799
158100void ApplicationInfo::setScreenshotId(const QString &screenshotId)
159101{
160− m_screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2@12.png")
102+ QString screenshotFileName = QString("%1/Dash/graphics/phone/screenshots/%2@12.png")
161103 .arg(qmlDirectory())
162104 .arg(screenshotId);
105+
106+ if (screenshotFileName != m_screenshotFileName) {
107+ m_screenshotFileName = screenshotFileName;
108+
109+ QUrl screenshotUrl = QString("file://%1").arg(m_screenshotFileName);
110+ if (m_session) {
111+ m_session->setScreenshot(screenshotUrl);
112+ }
113+ }
163114}
164115
165116void ApplicationInfo::setName(const QString &value)
@@ -193,7 +144,7 @@ void ApplicationInfo::setState(State value)
193144 Q_EMIT stateChanged(value);
194145
195146 if (!m_manualSurfaceCreation && m_state == ApplicationInfo::Running) {
196− QTimer::singleShot(1000, this, SLOT(createSurface()));
147+ QTimer::singleShot(500, this, SLOT(createSession()));
197148 }
198149 }
199150}
tests/mocks/Unity/Application/ApplicationInfo.h+11−23
@@ -17,8 +17,10 @@
1717#ifndef APPLICATION_H
1818#define APPLICATION_H
1919
20+#include "SurfaceManager.h"
21+#include "MirSurfaceItemModel.h"
22+
2023#include <QObject>
21−#include <QQmlComponent>
2224
2325class QQuickItem;
2426class MirSurfaceItem;
@@ -32,8 +34,7 @@ class ApplicationInfo : public ApplicationInfoInterface {
3234 Q_OBJECT
3335
3436 Q_PROPERTY(bool fullscreen READ fullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
35− Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
36− Q_PROPERTY(QQmlListProperty<MirSurfaceItem> promptSurfaces READ promptSurfaces NOTIFY promptSurfacesChanged DESIGNABLE false)
37+ Q_PROPERTY(Session* session READ session NOTIFY sessionChanged)
3738
3839 // Only exists in this fake implementation
3940
@@ -72,32 +73,23 @@ public:
7273 void setFullscreen(bool value);
7374 bool fullscreen() const { return m_fullscreen; }
7475
75− void setSurface(MirSurfaceItem* surface);
76− MirSurfaceItem* surface() const { return m_surface; }
77−
78− void removeSurface(MirSurfaceItem* surface);
79−
80− void addPromptSurface(MirSurfaceItem* surface);
81− QList<MirSurfaceItem*> promptSurfaceList() const;
82− QQmlListProperty<MirSurfaceItem> promptSurfaces();
83−
8476 bool manualSurfaceCreation() const { return m_manualSurfaceCreation; }
8577 void setManualSurfaceCreation(bool value);
8678
79+public:
80+ void setSession(Session* session);
81+ Session* session() const { return m_session; }
82+
8783Q_SIGNALS:
88− void surfaceChanged(MirSurfaceItem*);
89− void promptSurfacesChanged();
84+ void sessionChanged(Session*);
9085 void fullscreenChanged(bool value);
9186 void manualSurfaceCreationChanged(bool value);
9287
9388public Q_SLOTS:
94− Q_INVOKABLE void createSurface();
89+ Q_INVOKABLE void createSession();
9590
9691private:
97− static int promptSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
98− static MirSurfaceItem* promptSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
9992 void setIcon(const QUrl &value);
100− void setScreenshot(const QUrl &value);
10193
10294 QString m_screenshotFileName;
10395
@@ -108,15 +100,11 @@ private:
108100 State m_state;
109101 bool m_focused;
110102 bool m_fullscreen;
111− MirSurfaceItem* m_surface;
103+ Session* m_session;
112104
113105 bool m_manualSurfaceCreation;
114−
115− QQuickItem *m_parentItem;
116− QList<MirSurfaceItem*> m_promptSurfaces;
117106};
118107
119108Q_DECLARE_METATYPE(ApplicationInfo*)
120−Q_DECLARE_METATYPE(QQmlListProperty<MirSurfaceItem>)
121109
122110#endif // APPLICATION_H
tests/mocks/Unity/Application/ApplicationManager.cpp+9−16
@@ -15,9 +15,9 @@
1515 */
1616
1717#include "ApplicationManager.h"
18−#include "ApplicationDBusAdaptor.h"
1918#include "ApplicationInfo.h"
20−#include "MirSurfaceItem.h"
19+#include "Session.h"
20+#include "ApplicationTestInterface.h"
2121
2222#include <paths.h>
2323
@@ -36,11 +36,6 @@ ApplicationManager *ApplicationManager::singleton()
3636{
3737 if (!the_application_manager) {
3838 the_application_manager = new ApplicationManager();
39− new ApplicationDBusAdaptor(the_application_manager);
40−
41− QDBusConnection connection = QDBusConnection::sessionBus();
42− connection.registerService("com.canonical.Unity8");
43− connection.registerObject("/com/canonical/Unity8/Mocks", the_application_manager);
4439 }
4540 return the_application_manager;
4641}
@@ -49,9 +44,8 @@ ApplicationManager::ApplicationManager(QObject *parent)
4944 : ApplicationManagerInterface(parent)
5045 , m_suspended(false)
5146{
52− m_roleNames.insert(RoleSurface, "surface");
47+ m_roleNames.insert(RoleSession, "session");
5348 m_roleNames.insert(RoleFullscreen, "fullscreen");
54− m_roleNames.insert(RoleApplication, "application");
5549
5650 buildListOfAvailableApplications();
5751
@@ -105,12 +99,10 @@ QVariant ApplicationManager::data(const QModelIndex& index, int role) const {
10599 return app->state();
106100 case RoleFocused:
107101 return app->focused();
108− case RoleSurface:
109− return QVariant::fromValue(app->surface());
102+ case RoleSession:
103+ return QVariant::fromValue(app->session());
110104 case RoleFullscreen:
111105 return app->fullscreen();
112− case RoleApplication:
113− return QVariant::fromValue(app);
114106 default:
115107 return QVariant();
116108 }
@@ -154,10 +146,10 @@ void ApplicationManager::add(ApplicationInfo *application) {
154146 Q_EMIT countChanged();
155147 if (count() == 1) Q_EMIT emptyChanged(isEmpty()); // was empty but not anymore
156148
157− connect(application, &ApplicationInfo::surfaceChanged, this, [application, this]() {
149+ connect(application, &ApplicationInfo::sessionChanged, this, [application, this]() {
158150 QModelIndex appIndex = findIndex(application);
159151 if (!appIndex.isValid()) return;
160− Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSurface);
152+ Q_EMIT dataChanged(appIndex, appIndex, QVector<int>() << ApplicationManager::RoleSession);
161153 });
162154 connect(application, &ApplicationInfo::focusedChanged, this, [application, this]() {
163155 QModelIndex appIndex = findIndex(application);
@@ -181,7 +173,7 @@ void ApplicationManager::remove(ApplicationInfo *application) {
181173 Q_EMIT countChanged();
182174 if (isEmpty()) Q_EMIT emptyChanged(isEmpty());
183175 }
184− disconnect(application, 0, this, 0);
176+ application->disconnect(this);
185177}
186178
187179void ApplicationManager::move(int from, int to) {
@@ -464,6 +456,7 @@ void ApplicationManager::buildListOfAvailableApplications()
464456 m_availableApplications.append(application);
465457}
466458
459+
467460QStringList ApplicationManager::availableApplications()
468461{
469462 QStringList appIds;
tests/mocks/Unity/Application/ApplicationManager.h+1−2
@@ -52,9 +52,8 @@ class ApplicationManager : public ApplicationManagerInterface {
5252 static ApplicationManager *singleton();
5353
5454 enum MoreRoles {
55− RoleSurface = RoleFocused+1,
55+ RoleSession = RoleFocused+1,
5656 RoleFullscreen,
57− RoleApplication,
5857 };
5958 enum Role {
6059 Dash, Default, Indicators, Notifications, Greeter, Launcher, OnScreenKeyboard,
tests/mocks/Unity/Application/ApplicationTestInterface.cppnew file+117
@@ -0,0 +1,117 @@
1+/*
2+ * Copyright (C) 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+#include "ApplicationInfo.h"
18+#include "ApplicationTestInterface.h"
19+#include "ApplicationManager.h"
20+#include "SessionManager.h"
21+#include "SurfaceManager.h"
22+#include "Session.h"
23+#include "MirSurfaceItem.h"
24+
25+#include <paths.h>
26+
27+#include <QtDBus/QtDBus>
28+
29+quint32 nextId = 0;
30+
31+ApplicationTestInterface::ApplicationTestInterface(QObject* parent)
32+ : QDBusAbstractAdaptor(parent)
33+{
34+ QDBusConnection connection = QDBusConnection::sessionBus();
35+ connection.registerService("com.canonical.Unity8");
36+ connection.registerObject("/com/canonical/Unity8/Mocks", parent);
37+}
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+ qDebug() << "ApplicationTestInterface::removeSession - " << existingSession;
60+
61+ if (existingSession)
62+ existingSession->setLive(false);
63+}
64+
65+void ApplicationTestInterface::removeSurface(MirSurfaceItem* existingSurface)
66+{
67+ qDebug() << "ApplicationTestInterface::removeSurface - " << existingSurface;
68+
69+ if (existingSurface)
70+ existingSurface->setLive(false);
71+}
72+
73+quint32 ApplicationTestInterface::addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage)
74+{
75+ qDebug() << "ApplicationTestInterface::addChildSession to " << appId;
76+
77+ ApplicationInfo* application = ApplicationManager::singleton()->findApplication(appId);
78+ if (!application) {
79+ qDebug() << "ApplicationTestInterface::addChildSession - No application found for " << appId;
80+ return 0;
81+ }
82+
83+ Session* parentSession = nullptr;
84+ if (m_childSessions.contains(existingSessionId)) {
85+ parentSession = m_childSessions[existingSessionId];
86+ } else if (application->session()) {
87+ parentSession = application->session();
88+ } else {
89+ qDebug() << "ApplicationTestInterface::addChildSession - No session for " << appId << ":" << existingSessionId;
90+ return 0;
91+ }
92+
93+ QUrl screenshotUrl = QString("file://%1/Dash/graphics/phone/screenshots/%2@12.png")
94+ .arg(qmlDirectory())
95+ .arg(surfaceImage);
96+
97+ quint32 sessionId = ++nextId;
98+ Session* session = SessionManager::singleton()->createSession(
99+ QString("%1-Child%2").arg(parentSession->name())
100+ .arg(parentSession->childSessions()->count()),
101+ screenshotUrl);
102+ parentSession->addChildSession(session);
103+ session->createSurface();
104+ m_childSessions[sessionId] = session;
105+
106+ return sessionId;
107+}
108+
109+void ApplicationTestInterface::removeSession(quint32 sessionId)
110+{
111+ if (!m_childSessions.contains(sessionId)) {
112+ qDebug() << "ApplicationTestInterface::removeSession - No added session for " << sessionId;
113+ return;
114+ }
115+ Session* session = m_childSessions.take(sessionId);
116+ removeSession(session);
117+}
tests/mocks/Unity/Application/ApplicationDBusAdaptor.h → tests/mocks/Unity/Application/ApplicationTestInterface.hrenamed+13−11
@@ -14,30 +14,32 @@
1414 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1515 */
1616
17−#ifndef APPLICATIONDBUSADAPTOR_H
18−#define APPLICATIONDBUSADAPTOR_H
17+#ifndef APPLICATIONTESTINTERFACE_H
18+#define APPLICATIONTESTINTERFACE_H
1919
2020#include <QtDBus/QtDBus>
2121
2222class ApplicationManager;
23−class SurfaceManager;
23+class Session;
2424class MirSurfaceItem;
2525
26−class ApplicationDBusAdaptor : public QDBusAbstractAdaptor
26+class ApplicationTestInterface : public QDBusAbstractAdaptor
2727{
2828 Q_OBJECT
2929 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity8.Mocks.Application")
3030public:
31− ApplicationDBusAdaptor(ApplicationManager* applicationManager);
31+ ApplicationTestInterface(QObject* parent = 0);
32+
33+ Q_INVOKABLE Session* addChildSession(Session* existingSession, const QString& surfaceImage);
34+ Q_INVOKABLE void removeSession(Session* existingSession);
35+ Q_INVOKABLE void removeSurface(MirSurfaceItem* existingSurface);
3236
3337public Q_SLOTS:
34− quint32 addPromptSurface(const QString& appId, const QString& surfaceImage);
35− void removeChildSurface(int surfaceId);
38+ quint32 addChildSession(const QString& appId, quint32 existingSessionId, const QString& surfaceImage);
39+ void removeSession(quint32 sessionId);
3640
3741private:
38− ApplicationManager* m_applicationManager;
39−
40− QHash<quint32, MirSurfaceItem*> m_childItems;
42+ QHash<quint32, Session*> m_childSessions;
4143};
4244
43−#endif // APPLICATIONDBUSADAPTOR_H
45+#endif // APPLICATIONTESTINTERFACE_H
tests/mocks/Unity/Application/CMakeLists.txt+6−1
@@ -2,12 +2,17 @@ pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=3)
22
33set(FakeUnityApplicationQml_SOURCES
44 plugin.cpp
5− ApplicationDBusAdaptor.cpp
65 ApplicationInfo.cpp
76 ApplicationManager.cpp
87 ApplicationScreenshotProvider.cpp
8+ ApplicationTestInterface.cpp
99 MirSurfaceItem.cpp
10+ MirSurfaceItemModel.h
11+ ObjectListModel.h
12+ Session.cpp
13+ SessionManager.cpp
1014 SurfaceManager.cpp
15+ SessionModel.h
1116 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
1217 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
1318)
tests/mocks/Unity/Application/MirSurfaceItem.cpp+19−79
@@ -15,7 +15,7 @@
1515 */
1616
1717#include "MirSurfaceItem.h"
18−#include "ApplicationInfo.h"
18+#include "Session.h"
1919
2020#include <paths.h>
2121
@@ -34,11 +34,11 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
3434 const QString &qmlFilePath,
3535 QQuickItem *parent)
3636 : QQuickItem(parent)
37− , m_application(nullptr)
37+ , m_session(nullptr)
3838 , m_name(name)
3939 , m_type(type)
4040 , m_state(state)
41− , m_parentSurface(nullptr)
41+ , m_live(true)
4242 , m_qmlItem(nullptr)
4343 , m_screenshotUrl(screenshot)
4444{
@@ -83,16 +83,9 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
8383MirSurfaceItem::~MirSurfaceItem()
8484{
8585 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
86−
87− QList<MirSurfaceItem*> children(m_children);
88− for (MirSurfaceItem* child : children) {
89− child->setParentSurface(nullptr);
86+ if (m_session) {
87+ m_session->setSurface(nullptr);
9088 }
91− if (m_parentSurface)
92− m_parentSurface->removeChildSurface(this);
93−
94− if (m_application)
95− m_application->removeSurface(this);
9689}
9790
9891void MirSurfaceItem::printComponentErrors()
@@ -105,91 +98,38 @@ void MirSurfaceItem::printComponentErrors()
10598
10699void MirSurfaceItem::release()
107100{
108− QList<MirSurfaceItem*> children(m_children);
109− for (MirSurfaceItem* child : children) {
110− child->release();
111− }
112− if (m_parentSurface) {
113− m_parentSurface->removeChildSurface(this);
114− }
101+ qDebug() << "MirSurfaceItem::release " << name();
115102
116− if (m_application) {
117− m_application->removeSurface(this);
103+ if (m_session) {
104+ m_session->setSurface(nullptr);
118105 }
119106 if (!parent()) {
120107 deleteLater();
121108 }
122109}
123110
124−void MirSurfaceItem::setApplication(ApplicationInfo* application)
111+void MirSurfaceItem::setSession(Session* session)
125112{
126− m_application = application;
113+ m_session = session;
127114}
128115
129−void MirSurfaceItem::setParentSurface(MirSurfaceItem* surface)
116+void MirSurfaceItem::setScreenshot(const QUrl& screenshot)
130117{
131− if (m_parentSurface == surface || surface == this)
132− return;
133−
134− if (m_parentSurface) {
135− m_parentSurface->removeChildSurface(this);
136− }
137−
138− m_parentSurface = surface;
139−
140− if (m_parentSurface) {
141− m_parentSurface->addChildSurface(this);
118+ m_screenshotUrl = screenshot;
119+ if (m_qmlItem) {
120+ QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
121+ screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
142122 }
143− Q_EMIT parentSurfaceChanged(surface);
144123}
145124
146−void MirSurfaceItem::addChildSurface(MirSurfaceItem* surface)
125+void MirSurfaceItem::setLive(bool live)
147126{
148− qDebug() << "MirSurfaceItem::addChildSurface " << surface->name() << " to " << name();
149−
150− m_children.append(surface);
151− Q_EMIT childSurfacesChanged();
152−}
153−
154−void MirSurfaceItem::removeChildSurface(MirSurfaceItem* surface)
155−{
156− qDebug() << "MirSurfaceItem::removeChildSurface " << surface->name() << " from " << name();
157−
158− if (m_children.contains(surface)) {
159− m_children.removeOne(surface);
160− Q_EMIT childSurfacesChanged();
127+ if (m_live != live) {
128+ m_live = live;
129+ Q_EMIT liveChanged(m_live);
161130 }
162131}
163132
164−QList<MirSurfaceItem*> MirSurfaceItem::childSurfaceList()
165−{
166− return m_children;
167−}
168−
169−QQmlListProperty<MirSurfaceItem> MirSurfaceItem::childSurfaces()
170−{
171− return QQmlListProperty<MirSurfaceItem>(this,
172− 0,
173− MirSurfaceItem::childSurfaceCount,
174− MirSurfaceItem::childSurfaceAt);
175−}
176−
177−int MirSurfaceItem::childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop)
178−{
179− MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
180− return p->m_children.count();
181−}
182−
183−MirSurfaceItem* MirSurfaceItem::childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index)
184−{
185− MirSurfaceItem *p = qobject_cast<MirSurfaceItem*>(prop->object);
186−
187− if (index < 0 || index >= p->m_children.count())
188− return nullptr;
189− return p->m_children[index];
190−}
191−
192−
193133void MirSurfaceItem::onQmlWantInputMethodChanged()
194134{
195135 QQmlProperty prop(m_qmlItem, "wantInputMethod");
tests/mocks/Unity/Application/MirSurfaceItem.h+24−31
@@ -17,11 +17,12 @@
1717#ifndef MIRSURFACEITEM_H
1818#define MIRSURFACEITEM_H
1919
20+#include "MirSurfaceItemModel.h"
21+
2022#include <QQuickItem>
21−#include <QQmlComponent>
2223#include <QUrl>
2324
24−class ApplicationInfo;
25+class Session;
2526
2627class MirSurfaceItem : public QQuickItem
2728{
@@ -31,9 +32,8 @@ class MirSurfaceItem : public QQuickItem
3132
3233 Q_PROPERTY(Type type READ type NOTIFY typeChanged)
3334 Q_PROPERTY(State state READ state NOTIFY stateChanged)
34− Q_PROPERTY(QString name READ name NOTIFY nameChanged)
35− Q_PROPERTY(MirSurfaceItem* parentSurface READ parentSurface NOTIFY parentSurfaceChanged)
36− Q_PROPERTY(QQmlListProperty<MirSurfaceItem> childSurfaces READ childSurfaces NOTIFY childSurfacesChanged DESIGNABLE false)
35+ Q_PROPERTY(QString name READ name CONSTANT)
36+ Q_PROPERTY(bool live READ live NOTIFY liveChanged)
3737
3838public:
3939 enum Type {
@@ -56,24 +56,18 @@ public:
5656 Fullscreen,
5757 };
5858
59− explicit MirSurfaceItem(const QString& name,
60− Type type,
61− State state,
62− const QUrl& screenshot,
63− const QString &qmlFilePath = QString(),
64− QQuickItem *parent = 0);
6559 ~MirSurfaceItem();
6660
6761 //getters
68− ApplicationInfo* application() const { return m_application; }
62+ Session* session() const { return m_session; }
6963 Type type() const { return m_type; }
7064 State state() const { return m_state; }
7165 QString name() const { return m_name; }
72− MirSurfaceItem* parentSurface() const { return m_parentSurface; }
73− QList<MirSurfaceItem*> childSurfaceList();
66+ bool live() const { return m_live; }
7467
75− void setApplication(ApplicationInfo* item);
76− void setParentSurface(MirSurfaceItem* item);
68+ void setSession(Session* item);
69+ void setScreenshot(const QUrl& screenshot);
70+ void setLive(bool live);
7771
7872 Q_INVOKABLE void setState(State newState);
7973 Q_INVOKABLE void release();
@@ -81,42 +75,41 @@ public:
8175Q_SIGNALS:
8276 void typeChanged(Type);
8377 void stateChanged(State);
84− void nameChanged(QString);
85− void parentSurfaceChanged(MirSurfaceItem*);
86− void childSurfacesChanged();
87−
88− void removed();
78+ void liveChanged(bool live);
8979
9080 void inputMethodRequested();
9181 void inputMethodDismissed();
9282
83+ // internal mock use
84+ void deregister();
85+
9386private Q_SLOTS:
9487 void onFocusChanged();
9588 void onComponentStatusChanged(QQmlComponent::Status status);
9689 void onQmlWantInputMethodChanged();
9790
9891private:
99− void addChildSurface(MirSurfaceItem* surface);
100− void removeChildSurface(MirSurfaceItem* surface);
101−
102− QQmlListProperty<MirSurfaceItem> childSurfaces();
103− static int childSurfaceCount(QQmlListProperty<MirSurfaceItem> *prop);
104− static MirSurfaceItem* childSurfaceAt(QQmlListProperty<MirSurfaceItem> *prop, int index);
92+ explicit MirSurfaceItem(const QString& name,
93+ Type type,
94+ State state,
95+ const QUrl& screenshot,
96+ const QString &qmlFilePath = QString(),
97+ QQuickItem *parent = 0);
10598
10699 void createQmlContentItem();
107100 void printComponentErrors();
108101
109− ApplicationInfo* m_application;
102+ Session* m_session;
110103 const QString m_name;
111104 const Type m_type;
112105 State m_state;
113−
114− MirSurfaceItem* m_parentSurface;
115− QList<MirSurfaceItem*> m_children;
106+ bool m_live;
116107
117108 QQmlComponent *m_qmlContentComponent;
118109 QQuickItem *m_qmlItem;
119110 QUrl m_screenshotUrl;
111+
112+ friend class SurfaceManager;
120113};
121114
122115Q_DECLARE_METATYPE(MirSurfaceItem*)
tests/mocks/Unity/Application/MirSurfaceItemModel.hnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef MIRSURFACEITEMMODEL_H
18+#define MIRSURFACEITEMMODEL_H
19+
20+// Local
21+#include "ObjectListModel.h"
22+
23+class MirSurfaceItem;
24+class MirSurfaceItemModel: public ObjectListModel<MirSurfaceItem>
25+{
26+ Q_OBJECT
27+public:
28+ MirSurfaceItemModel(QObject *parent = 0): ObjectListModel(parent) {}
29+
30+ Q_INVOKABLE int count() const { return rowCount(); }
31+};
32+
33+Q_DECLARE_METATYPE(MirSurfaceItemModel*)
34+
35+#endif // MIRSURFACEITEMMODEL_H
tests/mocks/Unity/Application/ObjectListModel.hnew file+106
@@ -0,0 +1,106 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef OBJECTLISTMODEL_H
18+#define OBJECTLISTMODEL_H
19+
20+// Qt
21+#include <QAbstractListModel>
22+
23+template<class TYPE>
24+class ObjectListModel : public QAbstractListModel
25+{
26+public:
27+ ObjectListModel(QObject *parent = 0)
28+ : QAbstractListModel(parent)
29+ {}
30+
31+ enum Roles {
32+ RoleModelData = Qt::UserRole,
33+ };
34+
35+ const QList<TYPE*>& list() const { return m_items; }
36+ bool contains(TYPE* item) const { return m_items.contains(item); }
37+
38+ void insert(uint index, TYPE* item)
39+ {
40+ index = qMin(index, (uint)m_items.count());
41+
42+ int existingIndex = m_items.indexOf(item);
43+ if (existingIndex != -1) {
44+ move(existingIndex, qMin(index, (uint)(m_items.count()-1)));
45+ } else {
46+ beginInsertRows(QModelIndex(), index, index);
47+ m_items.insert(index, item);
48+ endInsertRows();
49+ }
50+ }
51+
52+ void remove(TYPE* item)
53+ {
54+ int existingIndex = m_items.indexOf(item);
55+ if (existingIndex != -1) {
56+ beginRemoveRows(QModelIndex(), existingIndex, existingIndex);
57+ m_items.removeAt(existingIndex);
58+ endRemoveRows();
59+ }
60+ }
61+
62+ // from QAbstractItemModel
63+ int rowCount(const QModelIndex& = QModelIndex()) const override
64+ {
65+ return m_items.count();
66+ }
67+
68+ QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override
69+ {
70+ if (index.row() >= 0 && index.row() < m_items.count()) {
71+ if (role == RoleModelData) {
72+ TYPE *item = m_items.at(index.row());
73+ return QVariant::fromValue(item);
74+ }
75+ }
76+ return QVariant();
77+ }
78+
79+ QHash<int, QByteArray> roleNames() const
80+ {
81+ QHash<int, QByteArray> roleNames;
82+ roleNames.insert(RoleModelData, "modelData");
83+ return roleNames;
84+ }
85+
86+protected:
87+ void move(int from, int to)
88+ {
89+ if (from == to) return;
90+
91+ if (from >= 0 && from < m_items.size() && to >= 0 && to < m_items.size()) {
92+ QModelIndex parent;
93+ /* When moving an item down, the destination index needs to be incremented
94+ by one, as explained in the documentation:
95+ http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
96+
97+ beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
98+ m_items.move(from, to);
99+ endMoveRows();
100+ }
101+ }
102+
103+ QList<TYPE*> m_items;
104+};
105+
106+#endif // OBJECTLISTMODEL_H
tests/mocks/Unity/Application/Session.cppnew file+174
@@ -0,0 +1,174 @@
1+/*
2+ * Copyright (C) 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+#include "Session.h"
18+#include "ApplicationInfo.h"
19+#include "SessionManager.h"
20+#include "SurfaceManager.h"
21+
22+#include <QPainter>
23+#include <QQmlEngine>
24+#include <QTimer>
25+
26+Session::Session(const QString &name,
27+ const QUrl& screenshot,
28+ QObject *parent)
29+ : QObject(parent)
30+ , m_name(name)
31+ , m_live(true)
32+ , m_screenshot(screenshot)
33+ , m_application(nullptr)
34+ , m_surface(nullptr)
35+ , m_parentSession(nullptr)
36+ , m_children(new SessionModel(this))
37+{
38+ qDebug() << "Session::Session() " << this->name();
39+
40+ QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
41+}
42+
43+Session::~Session()
44+{
45+ qDebug() << "Session::~Session() " << name();
46+
47+ QList<Session*> children(m_children->list());
48+ for (Session* child : children) {
49+ delete child;
50+ }
51+ if (m_parentSession) {
52+ m_parentSession->removeChildSession(this);
53+ }
54+ if (m_application) {
55+ m_application->setSession(nullptr);
56+ }
57+ delete m_surface;
58+ delete m_children;
59+}
60+
61+void Session::release()
62+{
63+ qDebug() << "Session::release " << name();
64+
65+ if (m_parentSession) {
66+ m_parentSession->removeChildSession(this);
67+ }
68+ if (m_application) {
69+ m_application->setSession(nullptr);
70+ }
71+ if (!parent()) {
72+ deleteLater();
73+ }
74+}
75+
76+void Session::setApplication(ApplicationInfo* application)
77+{
78+ if (m_application == application)
79+ return;
80+
81+ m_application = application;
82+ Q_EMIT applicationChanged(application);
83+}
84+
85+void Session::setSurface(MirSurfaceItem* surface)
86+{
87+ qDebug() << "Session::setSurface - session=" << name() << "surface=" << surface;
88+ if (m_surface == surface)
89+ return;
90+
91+ if (m_surface) {
92+ m_surface->setSession(nullptr);
93+ m_surface->setParent(nullptr);
94+ Q_EMIT m_surface->deregister();
95+ }
96+
97+ m_surface = surface;
98+
99+ if (m_surface) {
100+ m_surface->setSession(this);
101+ m_surface->setParent(this);
102+ SurfaceManager::singleton()->registerSurface(m_surface);
103+ }
104+
105+ Q_EMIT surfaceChanged(m_surface);
106+}
107+
108+void Session::setScreenshot(const QUrl& screenshot)
109+{
110+ if (screenshot != m_screenshot) {
111+ m_screenshot = screenshot;
112+ if (m_surface) {
113+ m_surface->setScreenshot(m_screenshot);
114+ }
115+ }
116+}
117+
118+void Session::setLive(bool live)
119+{
120+ if (m_live != live) {
121+ m_live = live;
122+ Q_EMIT liveChanged(m_live);
123+ }
124+}
125+
126+void Session::setParentSession(Session* session)
127+{
128+ if (m_parentSession == session || session == this)
129+ return;
130+
131+ m_parentSession = session;
132+ Q_EMIT parentSessionChanged(session);
133+}
134+
135+void Session::createSurface()
136+{
137+ if (m_surface) return;
138+
139+ setSurface(SurfaceManager::singleton()->createSurface(name(),
140+ MirSurfaceItem::Normal,
141+ m_application && m_application->fullscreen() ? MirSurfaceItem::Fullscreen :
142+ MirSurfaceItem::Maximized,
143+ m_screenshot));
144+}
145+
146+void Session::addChildSession(Session* session)
147+{
148+ insertChildSession(m_children->rowCount(), session);
149+}
150+
151+void Session::insertChildSession(uint index, Session* session)
152+{
153+ qDebug() << "Session::insertChildSession - " << session->name() << " to " << name() << " @ " << index;
154+
155+ session->setParentSession(this);
156+ m_children->insert(index, session);
157+ SessionManager::singleton()->registerSession(session);
158+}
159+
160+void Session::removeChildSession(Session* session)
161+{
162+ qDebug() << "Session::removeChildSession - " << session->name() << " from " << name();
163+
164+ if (m_children->contains(session)) {
165+ m_children->remove(session);
166+ session->setParentSession(nullptr);
167+ Q_EMIT session->deregister();
168+ }
169+}
170+
171+SessionModel* Session::childSessions() const
172+{
173+ return m_children;
174+}
tests/mocks/Unity/Application/Session.hnew file+90
@@ -0,0 +1,90 @@
1+/*
2+ * Copyright (C) 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+#ifndef SESSION_H
18+#define SESSION_H
19+
20+#include "SessionModel.h"
21+
22+#include <QQuickItem>
23+
24+class ApplicationInfo;
25+class MirSurfaceItem;
26+
27+class Session : public QObject
28+{
29+ Q_OBJECT
30+ Q_PROPERTY(QString name READ name CONSTANT)
31+ Q_PROPERTY(MirSurfaceItem* surface READ surface NOTIFY surfaceChanged)
32+ Q_PROPERTY(ApplicationInfo* application READ application NOTIFY applicationChanged)
33+ Q_PROPERTY(Session* parentSession READ parentSession NOTIFY parentSessionChanged DESIGNABLE false)
34+ Q_PROPERTY(SessionModel* childSessions READ childSessions DESIGNABLE false CONSTANT)
35+ Q_PROPERTY(bool live READ live NOTIFY liveChanged)
36+
37+public:
38+ explicit Session(const QString &name,
39+ const QUrl& screenshot,
40+ QObject *parent = 0);
41+ ~Session();
42+
43+ Q_INVOKABLE void release();
44+
45+ //getters
46+ QString name() const { return m_name; }
47+ bool live() const { return m_live; }
48+ ApplicationInfo* application() const { return m_application; }
49+ MirSurfaceItem* surface() const { return m_surface; }
50+ Session* parentSession() const { return m_parentSession; }
51+
52+ void setApplication(ApplicationInfo* item);
53+ void setSurface(MirSurfaceItem* surface);
54+ void setScreenshot(const QUrl& m_screenshot);
55+ void setLive(bool live);
56+
57+ Q_INVOKABLE void addChildSession(Session* session);
58+ void insertChildSession(uint index, Session* session);
59+ void removeChildSession(Session* session);
60+
61+Q_SIGNALS:
62+ void applicationChanged(ApplicationInfo*);
63+ void surfaceChanged(MirSurfaceItem*);
64+ void parentSessionChanged(Session*);
65+ void liveChanged(bool live);
66+
67+ // internal mock use
68+ void deregister();
69+
70+public Q_SLOTS:
71+ Q_INVOKABLE void createSurface();
72+
73+private:
74+ SessionModel* childSessions() const;
75+ void setParentSession(Session* session);
76+
77+ QString m_name;
78+ bool m_live;
79+ QUrl m_screenshot;
80+ ApplicationInfo* m_application;
81+ MirSurfaceItem* m_surface;
82+ Session* m_parentSession;
83+ SessionModel* m_children;
84+
85+ friend class ApplicationTestInterface;
86+};
87+
88+Q_DECLARE_METATYPE(Session*)
89+
90+#endif // SESSION_H
tests/mocks/Unity/Application/SessionManager.cppnew file+55
@@ -0,0 +1,55 @@
1+/*
2+ * Copyright (C) 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+#include "SessionManager.h"
18+
19+#include "Session.h"
20+
21+SessionManager *SessionManager::the_session_manager = nullptr;
22+
23+SessionManager *SessionManager::singleton()
24+{
25+ if (!the_session_manager) {
26+ the_session_manager = new SessionManager();
27+ }
28+ return the_session_manager;
29+}
30+
31+SessionManager::SessionManager(QObject *parent) :
32+ QObject(parent)
33+{
34+}
35+
36+
37+Session *SessionManager::createSession(const QString& name,
38+ const QUrl& screenshot)
39+{
40+ Session* session = new Session(name, screenshot);
41+ Q_EMIT sessionStarting(session);
42+ return session;
43+}
44+
45+void SessionManager::registerSession(Session *session)
46+{
47+ connect(session, &Session::deregister, this, [this] {
48+ Session* session = qobject_cast<Session*>(sender());
49+
50+ disconnect(session, 0, this, 0);
51+
52+ session->setLive(false);
53+ Q_EMIT sessionStopping(session);
54+ });
55+}
tests/mocks/Unity/Application/SessionManager.hnew file+44
@@ -0,0 +1,44 @@
1+/*
2+ * Copyright (C) 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+#ifndef SESSIONMANAGER_H
18+#define SESSIONMANAGER_H
19+
20+#include <QObject>
21+
22+class Session;
23+
24+class SessionManager : public QObject
25+{
26+ Q_OBJECT
27+public:
28+ explicit SessionManager(QObject *parent = 0);
29+
30+ static SessionManager *singleton();
31+
32+ Q_INVOKABLE Session* createSession(const QString& name, const QUrl& screenshot);
33+
34+ void registerSession(Session *session);
35+
36+Q_SIGNALS:
37+ void sessionStarting(Session *session);
38+ void sessionStopping(Session *session);
39+
40+private:
41+ static SessionManager *the_session_manager;
42+};
43+
44+#endif // SESSIONMANAGER_H
tests/mocks/Unity/Application/SessionModel.hnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef SESSIONMODEL_H
18+#define SESSIONMODEL_H
19+
20+// Local
21+#include "ObjectListModel.h"
22+
23+class Session;
24+class SessionModel: public ObjectListModel<Session>
25+{
26+ Q_OBJECT
27+public:
28+ SessionModel(QObject *parent = 0): ObjectListModel(parent) {}
29+
30+ Q_INVOKABLE int count() const { return rowCount(); }
31+};
32+
33+Q_DECLARE_METATYPE(SessionModel*)
34+
35+#endif // SESSIONMODEL_H
tests/mocks/Unity/Application/SurfaceManager.cpp+20−7
@@ -35,19 +35,32 @@ SurfaceManager::SurfaceManager(QObject *parent) :
3535{
3636}
3737
38+MirSurfaceItem *SurfaceManager::createSurface(const QString& name,
39+ MirSurfaceItem::Type type,
40+ MirSurfaceItem::State state,
41+ const QUrl& screenshot)
42+{
43+ MirSurfaceItem* surface = new MirSurfaceItem(name,
44+ type,
45+ state,
46+ screenshot);
47+ Q_EMIT surfaceCreated(surface);
48+ return surface;
49+}
50+
3851void SurfaceManager::registerSurface(MirSurfaceItem *surface)
3952{
53+ connect(surface, &MirSurfaceItem::deregister, this, [this] {
54+ MirSurfaceItem* surface = qobject_cast<MirSurfaceItem*>(sender());
55+ disconnect(surface, 0, this, 0);
56+
57+ surface->setLive(false);
58+ Q_EMIT surfaceDestroyed(surface);
59+ });
4060 connect(surface, &MirSurfaceItem::inputMethodRequested,
4161 this, &SurfaceManager::showInputMethod);
4262 connect(surface, &MirSurfaceItem::inputMethodDismissed,
4363 this, &SurfaceManager::hideInputMethod);
44− Q_EMIT surfaceCreated(surface);
45−}
46−
47−void SurfaceManager::unregisterSurface(MirSurfaceItem *surface)
48−{
49− disconnect(surface, 0, this, 0);
50− Q_EMIT surfaceDestroyed(surface);
5164}
5265
5366void SurfaceManager::showInputMethod()
tests/mocks/Unity/Application/SurfaceManager.h+6−2
@@ -19,7 +19,7 @@
1919
2020#include <QObject>
2121
22−class MirSurfaceItem;
22+#include "MirSurfaceItem.h"
2323
2424class SurfaceManager : public QObject
2525{
@@ -29,9 +29,13 @@ public:
2929
3030 static SurfaceManager *singleton();
3131
32+ Q_INVOKABLE MirSurfaceItem *createSurface(const QString& name,
33+ MirSurfaceItem::Type type,
34+ MirSurfaceItem::State state,
35+ const QUrl& screenshot);
36+
3237 // Internal mock use
3338 void registerSurface(MirSurfaceItem *surface);
34− void unregisterSurface(MirSurfaceItem *surface);
3539
3640 // To be used in the tests
3741 Q_INVOKABLE MirSurfaceItem *inputMethodSurface();
tests/mocks/Unity/Application/plugin.cpp+37−4
@@ -18,8 +18,12 @@
1818#include "ApplicationInfo.h"
1919#include "ApplicationManager.h"
2020#include "ApplicationScreenshotProvider.h"
21+#include "Session.h"
2122#include "MirSurfaceItem.h"
23+#include "MirSurfaceItemModel.h"
2224#include "SurfaceManager.h"
25+#include "SessionManager.h"
26+#include "ApplicationTestInterface.h"
2327
2428#include <qqml.h>
2529#include <QQmlEngine>
@@ -36,18 +40,45 @@ static QObject* surfaceManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEng
3640 return SurfaceManager::singleton();
3741}
3842
43+static QObject* sessionManagerSingleton(QQmlEngine* engine, QJSEngine* scriptEngine) {
44+ Q_UNUSED(engine);
45+ Q_UNUSED(scriptEngine);
46+ return SessionManager::singleton();
47+}
48+
49+ApplicationTestInterface* s_appTestInterface = nullptr;
50+
51+static QObject* applicationTestInterface(QQmlEngine* engine, QJSEngine* scriptEngine) {
52+ Q_UNUSED(engine);
53+ Q_UNUSED(scriptEngine);
54+ if (!s_appTestInterface) {
55+ s_appTestInterface = new ApplicationTestInterface(engine);
56+ }
57+ return s_appTestInterface;
58+}
59+
3960void FakeUnityApplicationQmlPlugin::registerTypes(const char *uri)
4061{
62+ qRegisterMetaType<Session*>("Session*");
63+ qRegisterMetaType<ApplicationInfo*>("ApplicationInfo*");
64+ qRegisterMetaType<MirSurfaceItemModel*>("SessionModel*");
4165 qRegisterMetaType<MirSurfaceItem*>("MirSurfaceItem*");
66+ qRegisterMetaType<MirSurfaceItemModel*>("MirSurfaceItemModel*");
4267
4368 qmlRegisterUncreatableType<unity::shell::application::ApplicationManagerInterface>(uri, 0, 1, "ApplicationManagerInterface", "Abstract interface. Cannot be created in QML");
44− qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
45− qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
46−
4769 qmlRegisterUncreatableType<unity::shell::application::ApplicationInfoInterface>(uri, 0, 1, "ApplicationInfoInterface", "Abstract interface. Cannot be created in QML");
70+ qmlRegisterUncreatableType<Session>(uri, 0, 1, "Session", "Session can't be instantiated from QML");
71+ qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
72+
4873 qmlRegisterType<ApplicationInfo>(uri, 0, 1, "ApplicationInfo");
4974
50− qmlRegisterUncreatableType<MirSurfaceItem>(uri, 0, 1, "MirSurfaceItem", "MirSurfaceItem can't be instantiated from QML");
75+ qmlRegisterSingletonType<ApplicationManager>(uri, 0, 1, "ApplicationManager", applicationManagerSingleton);
76+ qmlRegisterSingletonType<SurfaceManager>(uri, 0, 1, "SurfaceManager", surfaceManagerSingleton);
77+ qmlRegisterSingletonType<SessionManager>(uri, 0, 1, "SessionManager", sessionManagerSingleton);
78+ qmlRegisterSingletonType<ApplicationTestInterface>(uri, 0, 1, "ApplicationTest", applicationTestInterface);
79+
80+ qRegisterMetaType<MirSurfaceItem::Type>("MirSurfaceItem::Type");
81+ qRegisterMetaType<MirSurfaceItem::State>("MirSurfaceItem::State");
5182}
5283
5384void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
@@ -55,4 +86,6 @@ void FakeUnityApplicationQmlPlugin::initializeEngine(QQmlEngine *engine, const c
5586 QQmlExtensionPlugin::initializeEngine(engine, uri);
5687
5788 engine->addImageProvider(QLatin1String("application"), new ApplicationScreenshotProvider(ApplicationManager::singleton()));
89+ // make sure we initialise our test interface.
90+ applicationTestInterface(engine, nullptr);
5891}
tests/mocks/Unity/Indicators/Indicators.qmltypes+20
@@ -159,6 +159,26 @@ Module {
159159 Property { name: "sourceModel"; type: "QAbstractItemModel"; isPointer: true }
160160 }
161161 Component { name: "QIdentityProxyModel"; prototype: "QAbstractProxyModel" }
162+ Component {
163+ name: "UnityMenuModelCache"
164+ prototype: "QObject"
165+ exports: ["Unity.Indicators/UnityMenuModelCache 0.1"]
166+ isCreatable: false
167+ isSingleton: true
168+ exportMetaObjectRevisions: [0]
169+ Method {
170+ name: "model"
171+ type: "UnityMenuModel*"
172+ Parameter { name: "bus"; type: "QByteArray" }
173+ Parameter { name: "path"; type: "QByteArray" }
174+ Parameter { name: "actions"; type: "QVariantMap" }
175+ }
176+ Method {
177+ name: "contains"
178+ type: "bool"
179+ Parameter { name: "path"; type: "QByteArray" }
180+ }
181+ }
162182 Component {
163183 name: "UnityMenuModelStack"
164184 prototype: "QObject"
tests/mocks/Unity/Unity.qmltypes+30−2
@@ -36,6 +36,10 @@ Module {
3636 prototype: "unity::shell::scopes::PreviewModelInterface"
3737 exports: ["Unity/FakePreviewModel 0.2"]
3838 exportMetaObjectRevisions: [0]
39+ Method {
40+ name: "setLoaded"
41+ Parameter { type: "bool" }
42+ }
3943 }
4044 Component {
4145 name: "PreviewStack"
@@ -59,9 +63,9 @@ Module {
5963 Component {
6064 name: "ResultsModel"
6165 prototype: "unity::shell::scopes::ResultsModelInterface"
62− exports: ["Unity/ResultsModel 0.2"]
66+ exports: ["Unity/FakeResultsModel 0.2", "Unity/ResultsModel 0.2"]
6367 isCreatable: false
64− exportMetaObjectRevisions: [0]
68+ exportMetaObjectRevisions: [0, 0]
6569 }
6670 Component {
6771 name: "Scope"
@@ -134,7 +138,13 @@ Module {
134138 }
135139 Method { name: "clear" }
136140 Method { name: "load" }
141+ Method {
142+ name: "getScopeFromAll"
143+ type: "Scope*"
144+ Parameter { name: "scope_id"; type: "string" }
145+ }
137146 }
147+ Component { name: "SettingsModel"; prototype: "unity::shell::scopes::SettingsModelInterface" }
138148 Component {
139149 name: "unity::shell::scopes::CategoriesInterface"
140150 prototype: "QAbstractListModel"
@@ -402,4 +412,22 @@ Module {
402412 Parameter { name: "scopeId"; type: "string" }
403413 }
404414 }
415+ Component {
416+ name: "unity::shell::scopes::SettingsModelInterface"
417+ prototype: "QAbstractListModel"
418+ exports: ["Unity/SettingsModel 0.2"]
419+ isCreatable: false
420+ exportMetaObjectRevisions: [0]
421+ Enum {
422+ name: "Roles"
423+ values: {
424+ "RoleSettingId": 0,
425+ "RoleDisplayName": 1,
426+ "RoleType": 2,
427+ "RoleProperties": 3,
428+ "RoleValue": 4
429+ }
430+ }
431+ Property { name: "count"; type: "int"; isReadonly: true }
432+ }
405433}
tests/qmltests/CMakeLists.txt+1
@@ -86,3 +86,4 @@ add_qml_test(Stages ApplicationWindow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINAR
8686add_qml_test(Stages PhoneStage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
8787add_qml_test(Stages SpreadDelegate ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
8888add_qml_test(Stages SurfaceContainer ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
89+add_qml_test(Stages SessionContainer ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/libusermetrics:${CMAKE_BINARY_DIR}/tests/mocks/LightDM/single")
tests/qmltests/Panel/tst_ActiveCallHint.qml+1−1
@@ -97,7 +97,7 @@ Item {
9797 var application = ApplicationManager.startApplication("dialer-app");
9898 ApplicationManager.focusApplication("dialer-app");
9999 tryCompare(ApplicationManager, "focusedApplicationId", "dialer-app");
100− tryCompare(application, "state", ApplicationInfo.Running);
100+ tryCompare(application, "state", ApplicationInfoInterface.Running);
101101
102102 if (!data.focused) { ApplicationManager.unfocusCurrentApplication(); }
103103 }
tests/qmltests/Stages/RecursingChildSessionControl.qmlnew file+142
@@ -0,0 +1,142 @@
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+ property alias surfaceCheckbox: _surfaceCheckbox
29+
30+ property var screenshotIds: [ "gallery", "map", "facebook", "camera", "browser", "music", "twitter"]
31+
32+ onSessionChanged: {
33+ if (!session) surfaceCheckbox.checked = false;
34+ }
35+
36+ Column {
37+ id: column
38+ Layout.fillWidth: true
39+ visible: repeater.count
40+ spacing: units.gu(1)
41+
42+ Repeater {
43+ id: repeater
44+ model: root.childSessions
45+ delegate: Rectangle {
46+ border {
47+ color: "black"
48+ width: 1
49+ }
50+ anchors {
51+ left: column.left
52+ right: column.right
53+ leftMargin: units.gu(1)
54+ rightMargin: units.gu(1)
55+ }
56+ height: loader.height
57+
58+ Rectangle {
59+ anchors.fill: parent
60+ color: Qt.rgba(Math.random(), Math.random(), Math.random(), 0.4 )
61+ }
62+
63+ Loader {
64+ id: loader
65+ visible: status == Loader.Ready
66+ source: Qt.resolvedUrl("RecursingChildSessionControl.qml")
67+
68+ anchors {
69+ left: parent.left
70+ right: parent.right
71+ }
72+
73+ onLoaded: {
74+ item.session = modelData;
75+ item.removable = true;
76+ }
77+ }
78+ }
79+ }
80+ }
81+
82+ ColumnLayout {
83+ Layout.fillWidth: true
84+ spacing: units.gu(1)
85+
86+ RowLayout {
87+ Layout.fillWidth: true
88+
89+ CheckBox {
90+ id: _surfaceCheckbox;
91+ checked: false;
92+ enabled: root.session
93+ onCheckedChanged: {
94+ if (checked) {
95+ root.session.createSurface();
96+ } else if (root.session.surface) {
97+ ApplicationTest.removeSurface(root.session.surface);
98+ }
99+ }
100+
101+ Connections {
102+ target: root.session ? root.session : null
103+ onSurfaceChanged: {
104+ surfaceCheckbox.checked = root.session.surface !== null
105+ }
106+ }
107+ }
108+
109+ Label {
110+ text: "Surface"
111+ anchors.verticalCenter: parent.verticalCenter
112+ }
113+ }
114+
115+ RowLayout {
116+ id: buttonLayout
117+
118+ Button {
119+ enabled: root.session
120+ text: removable ? "Remove" : "Release"
121+ onClicked: {
122+ if (removable) {
123+ // release the surface first. simulates mir app closing
124+ if (root.session.surface) ApplicationTest.removeSurface(root.session.surface);
125+ ApplicationTest.removeSession(root.session);
126+ } else {
127+ root.session.release();
128+ }
129+ }
130+ }
131+
132+ Button {
133+ enabled: root.session !== null
134+ text: "Add Child"
135+ onClicked: {
136+ var screenshot = Math.round(Math.random()*100 % (screenshotIds.length-1));
137+ var session = ApplicationTest.addChildSession(root.session, root.screenshotIds[screenshot]);
138+ }
139+ }
140+ }
141+ }
142+}
tests/qmltests/Stages/tst_ApplicationWindow.qml+99−47
@@ -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 ".."
@@ -32,14 +33,15 @@ Rectangle {
3233 Component.onCompleted: {
3334 root.fakeApplication = ApplicationManager.add("gallery-app");
3435 root.fakeApplication.manualSurfaceCreation = true;
35− root.fakeApplication.setState(ApplicationInfo.Starting);
36+ root.fakeApplication.setState(ApplicationInfoInterface.Starting);
3637 }
3738 property QtObject fakeApplication: null
39+ readonly property var fakeSession: fakeApplication ? fakeApplication.session : null
3840
3941 Connections {
4042 target: fakeApplication
41− onSurfaceChanged: {
42− surfaceCheckbox.checked = fakeApplication.surface !== null;
43+ onSessionChanged: {
44+ sessionCheckbox.checked = fakeApplication.session !== null
4345 }
4446 }
4547
@@ -50,15 +52,20 @@ Rectangle {
5052 application: fakeApplication
5153 }
5254 }
53− Loader {
54− id: applicationWindowLoader
55+ FocusScope {
56+ id: appFocus
5557 anchors {
5658 top: parent.top
5759 bottom: parent.bottom
5860 left: parent.left
5961 }
6062 width: units.gu(40)
61− sourceComponent: applicationWindowComponent
63+
64+ Loader {
65+ id: applicationWindowLoader
66+ anchors.fill: parent
67+ sourceComponent: applicationWindowComponent
68+ }
6269 }
6370
6471 Rectangle {
@@ -66,30 +73,55 @@ Rectangle {
6673 anchors {
6774 top: parent.top
6875 bottom: parent.bottom
69− left: applicationWindowLoader.right
76+ left: appFocus.right
7077 right: parent.right
7178 }
7279
73− Column {
80+ ColumnLayout {
7481 anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
7582 spacing: units.gu(1)
76− Row {
77− anchors { left: parent.left; right: parent.right }
83+
84+ RowLayout {
85+ Layout.fillWidth: true
86+
7887 CheckBox {
79− id: surfaceCheckbox; checked: false
88+ id: sessionCheckbox; checked: false
8089 onCheckedChanged: {
8190 if (applicationWindowLoader.status !== Loader.Ready)
8291 return;
8392
84− if (checked && !fakeApplication.surface) {
85− fakeApplication.createSurface();
86− } else if (!checked && fakeApplication.surface) {
87− fakeApplication.surface.release();
93+ if (checked && !fakeApplication.session) {
94+ fakeApplication.createSession();
95+ } else if (!checked && fakeApplication.session) {
96+ fakeApplication.session.release();
8897 }
8998 }
9099 }
91− Label { text: "Surface" }
100+ Label {
101+ text: "Session"
102+ anchors.verticalCenter: parent.verticalCenter
103+ }
92104 }
105+
106+ Rectangle {
107+ border {
108+ color: "black"
109+ width: 1
110+ }
111+ anchors {
112+ left: parent.left
113+ right: parent.right
114+ }
115+ Layout.preferredHeight: sessionControl.height
116+
117+ RecursingChildSessionControl {
118+ id: sessionControl
119+ anchors { left: parent.left; right: parent.right; }
120+
121+ session: fakeSession
122+ }
123+ }
124+
93125 ListItem.ItemSelector {
94126 id: appStateSelector
95127 anchors { left: parent.left; right: parent.right }
@@ -100,13 +132,13 @@ Rectangle {
100132 "Stopped"]
101133 property int selectedApplicationState: {
102134 if (model[selectedIndex] === "Starting") {
103− return ApplicationInfo.Starting;
135+ return ApplicationInfoInterface.Starting;
104136 } else if (model[selectedIndex] === "Running") {
105− return ApplicationInfo.Running;
137+ return ApplicationInfoInterface.Running;
106138 } else if (model[selectedIndex] === "Suspended") {
107− return ApplicationInfo.Suspended;
139+ return ApplicationInfoInterface.Suspended;
108140 } else {
109− return ApplicationInfo.Stopped;
141+ return ApplicationInfoInterface.Stopped;
110142 }
111143 }
112144 onSelectedApplicationStateChanged: {
@@ -114,6 +146,7 @@ Rectangle {
114146 fakeApplication.setState(selectedApplicationState);
115147 }
116148 }
149+
117150 }
118151 }
119152
@@ -123,10 +156,10 @@ Rectangle {
123156 when: windowShown
124157
125158 // just to make them shorter
126− property int appStarting: ApplicationInfo.Starting
127− property int appRunning: ApplicationInfo.Running
128− property int appSuspended: ApplicationInfo.Suspended
129− property int appStopped: ApplicationInfo.Stopped
159+ property int appStarting: ApplicationInfoInterface.Starting
160+ property int appRunning: ApplicationInfoInterface.Running
161+ property int appSuspended: ApplicationInfoInterface.Suspended
162+ property int appStopped: ApplicationInfoInterface.Stopped
130163
131164 function setApplicationState(appState) {
132165 switch (appState) {
@@ -170,6 +203,14 @@ Rectangle {
170203 findInterestingApplicationWindowChildren();
171204 }
172205
206+ function initSession() {
207+ sessionCheckbox.checked = true;
208+ sessionControl.surfaceCheckbox.checked = true;
209+ }
210+ function cleanupSession() {
211+ sessionCheckbox.checked = false;
212+ }
213+
173214 function cleanup() {
174215 forgetApplicationWindowChildren();
175216
@@ -177,10 +218,10 @@ Rectangle {
177218 applicationWindowLoader.active = false;
178219
179220 appStateSelector.selectedIndex = 0;
180− surfaceCheckbox.checked = false;
221+ cleanupSession();
181222
182− if (fakeApplication.surface)
183− fakeApplication.surface.release();
223+ if (fakeApplication.session)
224+ fakeApplication.session.release();
184225
185226 applicationWindowLoader.active = true;
186227 }
@@ -197,7 +238,7 @@ Rectangle {
197238 verify(stateGroup.state === "splashScreen");
198239
199240 if (data.swapInitOrder) {
200− surfaceCheckbox.checked = true;
241+ initSession();
201242 } else {
202243 setApplicationState(appRunning);
203244 }
@@ -207,14 +248,14 @@ Rectangle {
207248 if (data.swapInitOrder) {
208249 setApplicationState(appRunning);
209250 } else {
210− surfaceCheckbox.checked = true;
251+ initSession();
211252 }
212253
213254 tryCompare(stateGroup, "state", "surface");
214255 }
215256
216257 function test_suspendedAppShowsSurface() {
217− surfaceCheckbox.checked = true;
258+ initSession();
218259 setApplicationState(appRunning);
219260
220261 tryCompare(stateGroup, "state", "surface");
@@ -228,7 +269,7 @@ Rectangle {
228269 }
229270
230271 function test_killedAppShowsScreenshot() {
231− surfaceCheckbox.checked = true;
272+ initSession();
232273 setApplicationState(appRunning);
233274 tryCompare(stateGroup, "state", "surface");
234275
@@ -241,13 +282,13 @@ Rectangle {
241282 setApplicationState(appStopped);
242283
243284 tryCompare(stateGroup, "state", "screenshot");
244− tryCompare(fakeApplication, "surface", null);
285+ tryCompare(fakeApplication, "session", null);
245286 }
246287
247288 function test_restartApp() {
248289 var screenshotImage = findChild(applicationWindowLoader.item, "screenshotImage");
249290
250− surfaceCheckbox.checked = true;
291+ initSession();
251292 setApplicationState(appRunning);
252293 tryCompare(stateGroup, "state", "surface");
253294 waitUntilTransitionsEnd();
@@ -259,28 +300,28 @@ Rectangle {
259300
260301 tryCompare(stateGroup, "state", "screenshot");
261302 waitUntilTransitionsEnd();
262− tryCompare(fakeApplication, "surface", null);
303+ tryCompare(fakeApplication, "session", null);
263304
264305 // and restart it
265306 setApplicationState(appStarting);
266307
267308 waitUntilTransitionsEnd();
268309 verify(stateGroup.state === "screenshot");
269− verify(fakeApplication.surface === null);
310+ verify(fakeSession === null);
270311
271312 setApplicationState(appRunning);
272313
273314 waitUntilTransitionsEnd();
274315 verify(stateGroup.state === "screenshot");
275316
276− surfaceCheckbox.checked = true;
317+ initSession();
277318
278319 tryCompare(stateGroup, "state", "surface");
279320 tryCompare(screenshotImage, "status", Image.Null);
280321 }
281322
282323 function test_appCrashed() {
283− surfaceCheckbox.checked = true;
324+ initSession();
284325 setApplicationState(appRunning);
285326 tryCompare(stateGroup, "state", "surface");
286327 waitUntilTransitionsEnd();
@@ -289,39 +330,39 @@ Rectangle {
289330 setApplicationState(appStopped);
290331
291332 tryCompare(stateGroup, "state", "screenshot");
292− tryCompare(fakeApplication, "surface", null);
333+ tryCompare(fakeApplication, "session", null);
293334 }
294335
295336 function test_keepSurfaceWhileInvisible() {
296− surfaceCheckbox.checked = true;
337+ initSession();
297338 setApplicationState(appRunning);
298339 tryCompare(stateGroup, "state", "surface");
299340 waitUntilTransitionsEnd();
300− verify(fakeApplication.surface !== null);
341+ verify(fakeSession.surface !== null);
301342
302343 applicationWindowLoader.item.visible = false;
303344
304345 waitUntilTransitionsEnd();
305346 verify(stateGroup.state === "surface");
306− verify(fakeApplication.surface !== null);
347+ verify(fakeSession.surface !== null);
307348
308349 applicationWindowLoader.item.visible = true;
309350
310351 waitUntilTransitionsEnd();
311352 verify(stateGroup.state === "surface");
312− verify(fakeApplication.surface !== null);
353+ verify(fakeSession.surface !== null);
313354 }
314355
315356 function test_touchesReachSurfaceWhenItsShown() {
316357 setApplicationState(appRunning);
317− surfaceCheckbox.checked = true;
358+ initSession();
318359
319360 tryCompare(stateGroup, "state", "surface");
320361
321362 waitUntilTransitionsEnd();
322363
323364 // Because doing stuff in C++ is a PITA we keep the counter in the interal qml impl.
324− var fakeSurface = findChild(fakeApplication.surface, "fakeSurfaceQML");
365+ var fakeSurface = findChild(fakeSession.surface, "fakeSurfaceQML");
325366 fakeSurface.touchPressCount = 0;
326367 fakeSurface.touchReleaseCount = 0;
327368
@@ -333,14 +374,25 @@ Rectangle {
333374 }
334375
335376 function test_showNothingOnSuddenSurfaceLoss() {
336− surfaceCheckbox.checked = true;
377+ initSession();
337378 setApplicationState(appRunning);
338379 tryCompare(stateGroup, "state", "surface");
339380 waitUntilTransitionsEnd();
340381
341− surfaceCheckbox.checked = false;
382+ cleanupSession();
342383
343384 verify(stateGroup.state === "void");
344385 }
386+
387+ // should be forcing active focus when interactive changes,
388+ // which will cause a FocusScope higher in the object hierarchy tp be given the focus
389+ function test_forceActiveFocusFollowsInterative() {
390+ fakeApplication.createSession();
391+ applicationWindowLoader.item.interactive = false;
392+ applicationWindowLoader.item.interactive = true;
393+ fakeSession.createSurface();
394+
395+ compare(appFocus.focus, true);
396+ }
345397 }
346398}
tests/qmltests/Stages/tst_PhoneStage.qml+1−1
@@ -64,7 +64,7 @@ Item {
6464 anchors { left: parent.left; right: parent.right }
6565 text: "Stop Selected"
6666 onClicked: {
67− ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfo.Stopped);
67+ ApplicationManager.get(appList.selectedAppIndex).setState(ApplicationInfoInterface.Stopped);
6868 }
6969 }
7070 }
tests/qmltests/Stages/tst_SessionContainer.qmlnew file+267
@@ -0,0 +1,267 @@
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 QtTest 1.0
20+import Unity.Test 0.1 as UT
21+import Ubuntu.Components 0.1
22+import Unity.Application 0.1
23+import "../../../qml/Stages"
24+
25+Rectangle {
26+ color: "red"
27+ id: root
28+ width: units.gu(80)
29+ height: units.gu(70)
30+
31+ Connections {
32+ target: sessionContainerLoader.status === Loader.Ready ? sessionContainerLoader.item : null
33+ onSessionChanged: {
34+ sessionCheckbox.checked = sessionContainerLoader.item.session !== null
35+ }
36+ }
37+
38+ Component {
39+ id: sessionContainerComponent
40+
41+ SessionContainer {
42+ id: sessionContainer
43+ anchors.fill: parent
44+ }
45+ }
46+
47+ Loader {
48+ id: sessionContainerLoader
49+ anchors {
50+ top: parent.top
51+ bottom: parent.bottom
52+ left: parent.left
53+ }
54+ width: units.gu(40)
55+ sourceComponent: sessionContainerComponent
56+ }
57+
58+ Rectangle {
59+ color: "white"
60+ anchors {
61+ top: parent.top
62+ bottom: parent.bottom
63+ left: sessionContainerLoader.right
64+ right: parent.right
65+ }
66+
67+ ColumnLayout {
68+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: units.gu(1) }
69+ spacing: units.gu(1)
70+
71+ RowLayout {
72+ Layout.fillWidth: true
73+
74+ CheckBox {
75+ id: sessionCheckbox;
76+ checked: false;
77+ onCheckedChanged: {
78+ if (sessionContainerLoader.status !== Loader.Ready)
79+ return;
80+
81+ if (checked) {
82+ var fakeSession = SessionManager.createSession("music-player", Qt.resolvedUrl("../Dash/artwork/music-player-design.png"));
83+ sessionContainerLoader.item.session = fakeSession;
84+ fakeSession.createSurface();
85+ } else {
86+ sessionContainerLoader.item.session.release();
87+ }
88+ }
89+ }
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+ Layout.preferredHeight: sessionChildrenControl.height
107+
108+ RecursingChildSessionControl {
109+ id: sessionChildrenControl
110+ anchors { left: parent.left; right: parent.right; }
111+
112+ session: sessionContainerLoader.item ? sessionContainerLoader.item.session : null
113+ }
114+ }
115+ }
116+ }
117+
118+ SignalSpy {
119+ id: sessionSpy
120+ target: SessionManager
121+ signalName: "sessionStopping"
122+ }
123+
124+ UT.UnityTestCase {
125+ id: testCase
126+ name: "SessionContainer"
127+
128+ function init() {
129+ // reload our test subject to get it in a fresh state once again
130+ sessionContainerLoader.active = false;
131+ sessionCheckbox.checked = false;
132+ sessionContainerLoader.active = true;
133+
134+ tryCompare(sessionContainerLoader.item, "session", null);
135+ sessionSpy.clear();
136+ }
137+
138+ when: windowShown
139+
140+ function test_addChildSession_data() {
141+ return [ { tag: "count=1", count: 1 },
142+ { tag: "count=4", count: 4 } ];
143+ }
144+
145+ function test_addChildSession(data) {
146+ sessionCheckbox.checked = true;
147+ var sessionContainer = sessionContainerLoader.item;
148+ compare(sessionContainer.childSessions.count(), 0);
149+
150+ var i;
151+ var sessions = [];
152+ for (i = 0; i < data.count; i++) {
153+ var session = ApplicationTest.addChildSession(sessionContainer.session,
154+ "gallery");
155+ session.createSurface();
156+ sessionContainer.session.addChildSession(session);
157+ compare(sessionContainer.childSessions.count(), i+1);
158+
159+ sessions.push(session);
160+ }
161+
162+ for (i = data.count-1; i >= 0; i--) {
163+ ApplicationTest.removeSession(sessions[i]);
164+ tryCompareFunction(function() { return sessionContainer.childSessions.count(); }, i);
165+ }
166+ tryCompare(sessionSpy, "count", data.count);
167+ }
168+
169+ function test_nestedChildSessions_data() {
170+ return [ { tag: "depth=2", depth: 2 },
171+ { tag: "depth=8", depth: 8 }
172+ ];
173+ }
174+
175+ function test_nestedChildSessions(data) {
176+ sessionCheckbox.checked = true;
177+ var sessionContainer = sessionContainerLoader.item;
178+ compare(sessionContainer.childSessions.count(), 0);
179+
180+ var i;
181+ var sessions = [];
182+ var lastSession = sessionContainer.session;
183+ var delegate;
184+ var container = sessionContainer;
185+ for (i = 0; i < data.depth; i++) {
186+ var session = ApplicationTest.addChildSession(lastSession,
187+ "gallery");
188+ session.createSurface();
189+ lastSession.addChildSession(session);
190+ compare(container.childSessions.count(), 1);
191+ sessions.push(session);
192+
193+ delegate = findChild(container, "childDelegate0");
194+ container = findChild(delegate, "sessionContainer");
195+ lastSession = session;
196+ }
197+
198+ for (i = data.depth-1; i >= 0; i--) {
199+ ApplicationTest.removeSession(sessions[i]);
200+ }
201+
202+ tryCompareFunction(function() { return sessionContainer.childSessions.count(); }, 0);
203+ tryCompare(sessionSpy, "count", data.depth);
204+ }
205+
206+ function test_childrenAdjustForParentSize() {
207+ sessionCheckbox.checked = true;
208+ var sessionContainer = sessionContainerLoader.item;
209+
210+ var session = ApplicationTest.addChildSession(sessionContainer.session,
211+ "gallery");
212+ session.createSurface();
213+ sessionContainer.session.addChildSession(session);
214+
215+ var delegate = findChild(sessionContainer, "childDelegate0");
216+ var childContainer = findChild(delegate, "sessionContainer");
217+
218+ tryCompareFunction(function() { return childContainer.height === sessionContainer.height; }, true);
219+ tryCompareFunction(function() { return childContainer.width === sessionContainer.width; }, true);
220+ tryCompareFunction(function() { return childContainer.x === 0; }, true);
221+ tryCompareFunction(function() { return childContainer.y === 0; }, true);
222+
223+ sessionContainer.anchors.margins = units.gu(2);
224+
225+ tryCompareFunction(function() { return childContainer.height === sessionContainer.height; }, true);
226+ tryCompareFunction(function() { return childContainer.width === sessionContainer.width; }, true);
227+ tryCompareFunction(function() { return childContainer.x === 0; }, true);
228+ tryCompareFunction(function() { return childContainer.y === 0; }, true);
229+ }
230+
231+ function isContainerAnimating(container) {
232+ var animation = findInvisibleChild(container, "sessionAnimation");
233+ if (!animation) return false;
234+
235+ var animating = false;
236+ for (var i = 0; i < animation.transitions.length; ++i) {
237+ if (animation.transitions[i].running) {
238+ return true;
239+ }
240+ }
241+ return false;
242+ }
243+
244+ function test_childrenAnimate() {
245+ sessionCheckbox.checked = true;
246+ var sessionContainer = sessionContainerLoader.item;
247+
248+ var session = ApplicationTest.addChildSession(sessionContainer.session,
249+ "gallery");
250+
251+ var delegate = findChild(sessionContainer, "childDelegate0");
252+ var childContainer = findChild(delegate, "sessionContainer");
253+
254+ // wait for animation to begin
255+ tryCompareFunction(function() { return isContainerAnimating(childContainer); }, true);
256+ // wait for animation to end
257+ tryCompareFunction(function() { return isContainerAnimating(childContainer); }, false);
258+
259+ ApplicationTest.removeSession(session);
260+
261+ // wait for animation to begin
262+ tryCompareFunction(function() { return isContainerAnimating(childContainer); }, true);
263+ // wait for animation to end
264+ tryCompareFunction(function() { return isContainerAnimating(childContainer); }, false);
265+ }
266+ }
267+}
tests/qmltests/Stages/tst_SurfaceContainer.qml+28−43
@@ -28,43 +28,6 @@ Rectangle {
2828 width: units.gu(70)
2929 height: units.gu(70)
3030
31− Component {
32− id: fakeSurfaceComponent
33− Rectangle {
34− color: "green"
35−
36− Rectangle {
37− color: "blue"
38− anchors.fill: parent
39− anchors.margins: units.gu(2)
40− Text {
41− anchors.fill: parent
42− text: "Surface"
43− color: "green"
44− font.bold: true
45− fontSizeMode: Text.Fit
46− minimumPixelSize: 10; font.pixelSize: 200
47− verticalAlignment: Text.AlignVCenter
48− }
49− }
50−
51− width: units.gu(1)
52− height: units.gu(1)
53−
54− property int type: MirSurfaceItem.Normal
55− property int state: MirSurfaceItem.Restored
56− property string name: "Fake Surface"
57− property Item parentSurface: null
58− property list<Item> childSurfaces
59− function release() {}
60− signal removed();
61− }
62− }
63−
64− Item {
65− id: tempSurfaceHolder
66− }
67−
6831 Component {
6932 id: surfaceContainerComponent
7033 SurfaceContainer {
@@ -98,19 +61,20 @@ Rectangle {
9861 Row {
9962 anchors { left: parent.left; right: parent.right }
10063 CheckBox {
101− id: surfaceCheckbox; checked: false;
64+ id: surfaceCheckbox;
65+ checked: false;
10266 onCheckedChanged: {
10367 if (surfaceContainerLoader.status !== Loader.Ready)
10468 return;
10569
10670 if (checked) {
107− var fakeSurface = fakeSurfaceComponent.createObject(tempSurfaceHolder);
71+ var fakeSurface = SurfaceManager.createSurface("fake-surface",
72+ MirSurfaceItem.Normal,
73+ MirSurfaceItem.Restored,
74+ Qt.resolvedUrl("../Dash/artwork/music-player-design.png"));
10875 surfaceContainerLoader.item.surface = fakeSurface;
10976 } else {
110− var fakeSurface = surfaceContainerLoader.item.surface;
111− surfaceContainerLoader.item.surface = null;
112− fakeSurface.parent = null;
113− fakeSurface.destroy();
77+ ApplicationTest.removeSurface(surfaceContainerLoader.item.surface);
11478 }
11579 }
11680 }
@@ -124,6 +88,12 @@ Rectangle {
12488 }
12589 }
12690
91+ SignalSpy {
92+ id: surfaceSpy
93+ target: SurfaceManager
94+ signalName: "surfaceDestroyed"
95+ }
96+
12797 UT.UnityTestCase {
12898 id: testCase
12999 name: "SurfaceContainer"
@@ -134,6 +104,9 @@ Rectangle {
134104 surfaceContainerLoader.active = false;
135105 surfaceCheckbox.checked = false;
136106 surfaceContainerLoader.active = true;
107+
108+ tryCompare(surfaceContainerLoader.item, "surface", null);
109+ surfaceSpy.clear();
137110 }
138111
139112 /*
@@ -150,5 +123,17 @@ Rectangle {
150123 compare(fakeSurface.width, surfaceContainerLoader.item.width);
151124 compare(fakeSurface.height, surfaceContainerLoader.item.height);
152125 }
126+
127+ function test_animateRemoval() {
128+ surfaceCheckbox.checked = true;
129+ var surfaceContainer = surfaceContainerLoader.item;
130+
131+ verify(surfaceContainer.surface !== null);
132+
133+ ApplicationTest.removeSurface(surfaceContainer.surface);
134+
135+ compare(surfaceContainer.state, "zombie");
136+ tryCompare(surfaceContainer, "surface", null);
137+ }
153138 }
154139}
tests/qmltests/tst_Shell.qml+9−9
@@ -144,7 +144,7 @@ Item {
144144 verify(mainAppId != "");
145145 var mainApp = ApplicationManager.findApplication(mainAppId);
146146 verify(mainApp);
147− tryCompare(mainApp, "state", ApplicationInfo.Running);
147+ tryCompare(mainApp, "state", ApplicationInfoInterface.Running);
148148
149149 // Try to suspend while proximity is engaged...
150150 Powerd.displayPowerStateChange(Powerd.Off, Powerd.Proximity);
@@ -157,7 +157,7 @@ Item {
157157 tryCompare(greeter, "showProgress", 1);
158158
159159 tryCompare(ApplicationManager, "suspended", true);
160− compare(mainApp.state, ApplicationInfo.Suspended);
160+ compare(mainApp.state, ApplicationInfoInterface.Suspended);
161161
162162 // And wake up
163163 Powerd.displayPowerStateChange(Powerd.On, 0);
@@ -166,7 +166,7 @@ Item {
166166 // Swipe away greeter to focus app
167167 swipeAwayGreeter();
168168 tryCompare(ApplicationManager, "suspended", false);
169− compare(mainApp.state, ApplicationInfo.Running);
169+ compare(mainApp.state, ApplicationInfoInterface.Running);
170170 tryCompare(ApplicationManager, "focusedApplicationId", mainAppId);
171171 }
172172
@@ -237,9 +237,9 @@ Item {
237237 function test_surfaceLosesFocusWhilePanelIsOpen() {
238238 var app = ApplicationManager.startApplication("dialer-app");
239239 // wait until the app is fully loaded (ie, real surface replaces splash screen)
240− tryCompareFunction(function() { return app.surface != null }, true);
240+ tryCompareFunction(function() { return app.session !== null && app.session.surface !== null }, true);
241241
242− tryCompare(app.surface, "focus", true);
242+ tryCompare(app.session.surface, "focus", true);
243243
244244 // Drag the indicators panel half-open
245245 var touchX = shell.width / 2;
@@ -250,7 +250,7 @@ Item {
250250 true /* beginTouch */, false /* endTouch */);
251251 verify(indicators.partiallyOpened);
252252
253− tryCompare(app.surface, "focus", false);
253+ tryCompare(app.session.surface, "focus", false);
254254
255255 // And finish getting it open
256256 touchFlick(indicators,
@@ -259,11 +259,11 @@ Item {
259259 false /* beginTouch */, true /* endTouch */);
260260 tryCompare(indicators, "fullyOpened", true);
261261
262− tryCompare(app.surface, "focus", false);
262+ tryCompare(app.session.surface, "focus", false);
263263
264264 dragToCloseIndicatorsPanel();
265265
266− tryCompare(app.surface, "focus", true);
266+ tryCompare(app.session.surface, "focus", true);
267267 }
268268
269269 // Wait for the whole UI to settle down
@@ -361,7 +361,7 @@ Item {
361361
362362 var app = ApplicationManager.startApplication("dialer-app");
363363 // wait until the app is fully loaded (ie, real surface replaces splash screen)
364− tryCompareFunction(function() { return app.surface != null }, true);
364+ tryCompareFunction(function() { return app.session !== null && app.session.surface !== null }, true);
365365
366366 // Minimize the application we just launched
367367 swipeFromLeftEdge(units.gu(26) + 1);