@@ -28,59 +28,15 @@ 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−
68− Component {
69− id: surfaceContainerComponent
70− SurfaceContainer {
71− anchors.fill: parent
72− }
73− }
74− Loader {
75− id: surfaceContainerLoader
31+ SurfaceContainer {
32+ id: surfaceContainer
7633 anchors {
7734 top: parent.top
78− topMargin: fullscreenCheckbox.checked ? 0 : units.gu(3) + units.dp(2)
7935 bottom: parent.bottom
8036 left: parent.left
37+ topMargin: fullscreenCheckbox.checked ? 0 : units.gu(3) + units.dp(2)
8138 }
8239 width: units.gu(40)
83− sourceComponent: surfaceContainerComponent
8440 }
8541
8642 Rectangle {
@@ -88,7 +44,7 @@ Rectangle {
8844 anchors {
8945 top: parent.top
9046 bottom: parent.bottom
91− left: surfaceContainerLoader.right
47+ left: surfaceContainer.right
9248 right: parent.right
9349 }
9450
@@ -98,19 +54,16 @@ Rectangle {
9854 Row {
9955 anchors { left: parent.left; right: parent.right }
10056 CheckBox {
101− id: surfaceCheckbox; checked: false;
57+ id: surfaceCheckbox;
58+ checked: false;
10259 onCheckedChanged: {
103− if (surfaceContainerLoader.status !== Loader.Ready)
104− return;
105−
10660 if (checked) {
107− var fakeSurface = fakeSurfaceComponent.createObject(tempSurfaceHolder);
108− surfaceContainerLoader.item.surface = fakeSurface;
61+ surfaceContainer.surface = SurfaceManager.createSurface("fake-surface",
62+ MirSurfaceItem.Normal,
63+ MirSurfaceItem.Restored,
64+ Qt.resolvedUrl("../Dash/artwork/music-player-design.png"));
10965 } else {
110− var fakeSurface = surfaceContainerLoader.item.surface;
111− surfaceContainerLoader.item.surface = null;
112− fakeSurface.parent = null;
113− fakeSurface.destroy();
66+ surfaceContainer.surface.release();
11467 }
11568 }
11669 }
@@ -124,6 +77,12 @@ Rectangle {
12477 }
12578 }
12679
80+ SignalSpy {
81+ id: surfaceSpy
82+ target: SurfaceManager
83+ signalName: "surfaceDestroyed"
84+ }
85+
12786 UT.UnityTestCase {
12887 id: testCase
12988 name: "SurfaceContainer"
@@ -131,9 +90,10 @@ Rectangle {
13190
13291 function cleanup() {
13392 // reload our test subject to get it in a fresh state once again
134− surfaceContainerLoader.active = false;
13593 surfaceCheckbox.checked = false;
136− surfaceContainerLoader.active = true;
94+ tryCompare(surfaceContainer, "surface", null);
95+ surfaceSpy.clear();
96+
13797 }
13898
13999 /*
@@ -146,68 +106,75 @@ Rectangle {
146106 surfaceCheckbox.checked = true;
147107 surfaceCheckbox.checked = false;
148108 surfaceCheckbox.checked = true;
149− var fakeSurface = surfaceContainerLoader.item.surface;
150− compare(fakeSurface.width, surfaceContainerLoader.item.width);
151− compare(fakeSurface.height, surfaceContainerLoader.item.height);
109+ var fakeSurface = surfaceContainer.surface;
110+ compare(fakeSurface.width, surfaceContainer.width);
111+ compare(fakeSurface.height, surfaceContainer.height);
152112 }
153113
154− // function test_childSurfaces_data() {
155− // return [ { tag: "1", count: 1 },
156− // { tag: "4", count: 4 } ];
157− // }
158−
159− // function test_childSurfaces(data) {
160− // var unity8dash = findChild(shell, "unity8-dash");
161− // compare(unity8dash.childSurfaces.count(), 0);
162−
163− // var i;
164− // var surfaces = [];
165− // for (i = 0; i < data.count; i++) {
166− // surfaces.push(ApplicationTest.addChildSurface("unity8-dash", 0, 0, Qt.resolvedUrl("Dash/artwork/music-player-design.png")));
167− // compare(unity8dash.childSurfaces.count(), i+1);
168− // }
169−
170− // surfaceSpy.clear();
171− // for (i = data.count-1; i >= 0; i--) {
172− // ApplicationTest.removeSurface(surfaces[i]);
173− // tryCompareFunction(function() { return unity8dash.childSurfaces.count(); }, i);
174− // }
175− // tryCompare(surfaceSpy, "count", data.count)
176− // }
177−
178− // function test_tieredChildSurfaces_data() {
179− // return [
180− // { tag: "2", count: 2 },
181− // { tag: "10", count: 10 }
182− // ];
183− // }
184−
185− // function test_tieredChildSurfaces(data) {
186− // var unity8dash = findChild(shell, "unity8-dash");
187− // compare(unity8dash.childSurfaces.count(), 0);
188−
189− // var i;
190− // var surfaces = [];
191− // var lastSurfaceId = 0;
192− // var delegate;
193− // var surfaceContainer = unity8dash;
194− // for (i = 0; i < data.count; i++) {
195− // lastSurfaceId = ApplicationTest.addChildSurface("unity8-dash", 0, lastSurfaceId, Qt.resolvedUrl("Dash/artwork/music-player-design.png"))
196− // surfaces.push(lastSurfaceId);
197−
198− // compare(surfaceContainer.childSurfaces.count(), 1);
199−
200− // delegate = findChild(surfaceContainer, "childDelegate0");
201− // surfaceContainer = findChild(delegate, "surfaceContainer");
202− // }
203−
204− // surfaceSpy.clear();
205− // for (i = data.count-1; i >= 0; i--) {
206− // ApplicationTest.removeSurface(surfaces[i]);
207− // }
208−
209− // compare(unity8dash.childSurfaces.count(), 0);
210− // tryCompare(surfaceSpy, "count", data.count)
211− // }
114+ function test_childSurfaces_data() {
115+ return [ { tag: "1", count: 1 },
116+ { tag: "4", count: 4 } ];
117+ }
118+
119+ function test_childSurfaces(data) {
120+ surfaceCheckbox.checked = true;
121+
122+ var i;
123+ var surfaces = [];
124+ for (i = 0; i < data.count; i++) {
125+ var surface = SurfaceManager.createSurface(surfaceContainer.surface.name + "-Child" + i,
126+ MirSurfaceItem.Normal,
127+ MirSurfaceItem.Restored,
128+ Qt.resolvedUrl("../Dash/artwork/music-player-design.png"));
129+ surfaceContainer.surface.addChildSurface(surface);
130+ compare(surfaceContainer.childSurfaces.count(), i+1);
131+
132+ surfaces.push(surface);
133+ }
134+
135+ for (i = data.count-1; i >= 0; i--) {
136+ surfaces[i].release();
137+ tryCompareFunction(function() { return surfaceContainer.childSurfaces.count(); }, i);
138+ }
139+ tryCompare(surfaceSpy, "count", data.count);
140+ }
141+
142+ function test_nestedChildSurfaces_data() {
143+ return [
144+ { tag: "2", count: 2 },
145+ { tag: "10", count: 10 }
146+ ];
147+ }
148+
149+ function test_nestedChildSurfaces(data) {
150+ surfaceCheckbox.checked = true;
151+
152+ var i;
153+ var surfaces = [];
154+ var lastSurface = surfaceContainer.surface;
155+ var delegate;
156+ var container = surfaceContainer;
157+ for (i = 0; i < data.count; i++) {
158+ var surface = SurfaceManager.createSurface(surfaceContainer.surface.name + "-Child" + i,
159+ MirSurfaceItem.Normal,
160+ MirSurfaceItem.Restored,
161+ Qt.resolvedUrl("../Dash/artwork/music-player-design.png"));
162+ lastSurface.addChildSurface(surface);
163+ compare(container.childSurfaces.count(), 1);
164+ surfaces.push(surface);
165+
166+ delegate = findChild(container, "childDelegate0");
167+ container = findChild(delegate, "surfaceContainer");
168+ lastSurface = surface;
169+ }
170+
171+ surfaceSpy.clear();
172+ for (i = data.count-1; i >= 0; i--) {
173+ surfaces[i].release();
174+ }
175+
176+ compare(surfaceContainer.childSurfaces.count(), 0);
177+ tryCompare(surfaceSpy, "count", data.count)
178+ }
212179 }
213180}