on xenial help sign in
fix testDecoratedWindow
6b9253eMichael Zanetti
tests/qmltests/Stage/tst_DecoratedWindow.qml+34−143
@@ -50,7 +50,7 @@ Rectangle {
50 rotation: orientationAngle
50 rotation: orientationAngle
51
51
52 Loader {
52 Loader {
53− id: spreadDelegateLoader
53+ id: loader
54 property int windowedX: units.gu(1)
54 property int windowedX: units.gu(1)
55 property int windowedY: units.gu(1)
55 property int windowedY: units.gu(1)
56 property int windowedWidth: units.gu(50)
56 property int windowedWidth: units.gu(50)
@@ -66,22 +66,22 @@ Rectangle {
66 sourceComponent: DecoratedWindow {
66 sourceComponent: DecoratedWindow {
67 anchors.fill: parent
67 anchors.fill: parent
68 application: fakeApplication
68 application: fakeApplication
69− requestedWidth: spreadDelegateLoader.windowedWidth
69+ requestedWidth: loader.windowedWidth
70− requestedHeight: spreadDelegateLoader.windowedHeight
70+ requestedHeight: loader.windowedHeight
71 surface: fakeApplication && fakeApplication.surfaceList.count > 0 ? fakeApplication.surfaceList.get(0) : null
71 surface: fakeApplication && fakeApplication.surfaceList.count > 0 ? fakeApplication.surfaceList.get(0) : null
72
72
73 Component.onDestruction: {
73 Component.onDestruction: {
74− spreadDelegateLoader.itemDestroyed = true;
74+ loader.itemDestroyed = true;
75 }
75 }
76 Component.onCompleted: {
76 Component.onCompleted: {
77− spreadDelegateLoader.itemDestroyed = false;
77+ loader.itemDestroyed = false;
78 }
78 }
79 }
79 }
80
80
81 Rectangle { anchors.fill: parent; color: "green"; opacity: 1 }
81 Rectangle { anchors.fill: parent; color: "green"; opacity: 1 }
82 }
82 }
83 WindowResizeArea {
83 WindowResizeArea {
84− target: spreadDelegateLoader
84+ target: loader
85 borderThickness: units.gu(2)
85 borderThickness: units.gu(2)
86 }
86 }
87 }
87 }
@@ -110,18 +110,13 @@ Rectangle {
110 text: "Load with gallery-app"
110 text: "Load with gallery-app"
111 onClicked: { testCase.restartWithApp("gallery-app"); }
111 onClicked: { testCase.restartWithApp("gallery-app"); }
112 }
112 }
113− Row {
114− anchors { left: parent.left; right: parent.right }
115− CheckBox { id: swipeToCloseCheckbox; checked: false; }
116− Label { text: "swipeToCloseEnabled" }
117− }
118 Button {
113 Button {
119 text: "toggle has decoration"
114 text: "toggle has decoration"
120− onClicked: spreadDelegateLoader.item.hasDecoration = !spreadDelegateLoader.item.hasDecoration
115+ onClicked: loader.item.hasDecoration = !loader.item.hasDecoration
121 }
116 }
122 Button {
117 Button {
123 text: "show/hide decoration"
118 text: "show/hide decoration"
124− onClicked: spreadDelegateLoader.item.showDecoration = !spreadDelegateLoader.item.showDecoration
119+ onClicked: loader.item.showDecoration = !loader.item.showDecoration
125 }
120 }
126 Label {
121 Label {
127 text: "scale to preview progress"
122 text: "scale to preview progress"
@@ -132,18 +127,7 @@ Rectangle {
132 minimumValue: 0
127 minimumValue: 0
133 maximumValue: 1
128 maximumValue: 1
134 live: true
129 live: true
135− onValueChanged: spreadDelegateLoader.item.scaleToPreviewProgress = value
130+ onValueChanged: loader.item.scaleToPreviewProgress = value
136− }
137−
138−// Button {
139−// text: "toggle scaleToPreview"
140−// onClicked: spreadDelegateLoader.item.scaleToPreviewProgress == !spreadDelegateLoader.item.scaleToPreview
141−// }
142−
143− Row {
144− anchors { left: parent.left; right: parent.right }
145− CheckBox { id: closeableCheckbox; checked: false }
146− Label { text: "closeable" }
147 }
131 }
148 ListItem.ItemSelector {
132 ListItem.ItemSelector {
149 id: shellOrientationAngleSelector
133 id: shellOrientationAngleSelector
@@ -154,138 +138,56 @@ Rectangle {
154 }
138 }
155 Button {
139 Button {
156 text: "matchShellOrientation()"
140 text: "matchShellOrientation()"
157− onClicked: { spreadDelegateLoader.item.matchShellOrientation(); }
141+ onClicked: { loader.item.matchShellOrientation(); }
158 }
142 }
159 Button {
143 Button {
160 text: "animateToShellOrientation()"
144 text: "animateToShellOrientation()"
161− onClicked: { spreadDelegateLoader.item.animateToShellOrientation(); }
145+ onClicked: { loader.item.animateToShellOrientation(); }
162 }
146 }
163 }
147 }
164 }
148 }
165
149
166 UT.UnityTestCase {
150 UT.UnityTestCase {
167 id: testCase
151 id: testCase
168− name: "SpreadDelegate"
152+ name: "DecoratedWindow"
169 when: windowShown
153 when: windowShown
170
154
171− SignalSpy {
155+ property Item decoratedWindow: loader.item
172− id: spyClosedSignal
173− target: spreadDelegateLoader.item
174− signalName: "closeClicked"
175− }
176−
177− property var dragArea
178− property Item spreadDelegate: spreadDelegateLoader.item
179
156
180 function init() {
157 function init() {
181 }
158 }
182
159
183 function cleanup() {
160 function cleanup() {
184− unloadSpreadDelegate();
161+ unloadWindow();
185− spyClosedSignal.clear();
186− shellOrientationAngleSelector.selectedIndex = 0;
187 root.fakeApplication = null;
162 root.fakeApplication = null;
188 killApps();
163 killApps();
189 }
164 }
190
165
191 function restartWithApp(appId) {
166 function restartWithApp(appId) {
192− if (spreadDelegateLoader.active) {
167+ if (loader.active) {
193− unloadSpreadDelegate();
168+ unloadWindow();
194 }
169 }
195 if (root.fakeApplication) {
170 if (root.fakeApplication) {
196 ApplicationManager.stopApplication(root.fakeApplication.appId);
171 ApplicationManager.stopApplication(root.fakeApplication.appId);
197 }
172 }
198
173
199 root.fakeApplication = ApplicationManager.startApplication(appId);
174 root.fakeApplication = ApplicationManager.startApplication(appId);
200− spreadDelegateLoader.active = true;
175+ loader.active = true;
201− tryCompare(spreadDelegateLoader, "status", Loader.Ready);
176+ tryCompare(loader, "status", Loader.Ready);
202−
203− dragArea = findInvisibleChild(spreadDelegate, "dragArea");
204− dragArea.__dateTime = fakeDateTime;
205 }
177 }
206
178
207− function unloadSpreadDelegate() {
179+ function unloadWindow() {
208− spreadDelegateLoader.active = false;
180+ loader.active = false;
209− tryCompare(spreadDelegateLoader, "status", Loader.Null);
181+ tryCompare(loader, "status", Loader.Null);
210− tryCompare(spreadDelegateLoader, "item", null);
182+ tryCompare(loader, "item", null);
211 // Loader.status might be Loader.Null and Loader.item might be null but the Loader
183 // Loader.status might be Loader.Null and Loader.item might be null but the Loader
212 // item might still be alive. So if we set Loader.active back to true
184 // item might still be alive. So if we set Loader.active back to true
213 // again right now we will get the very same Shell instance back. So no reload
185 // again right now we will get the very same Shell instance back. So no reload
214 // actually took place. Likely because Loader waits until the next event loop
186 // actually took place. Likely because Loader waits until the next event loop
215 // iteration to do its work. So to ensure the reload, we will wait until the
187 // iteration to do its work. So to ensure the reload, we will wait until the
216 // Shell instance gets destroyed.
188 // Shell instance gets destroyed.
217− tryCompare(spreadDelegateLoader, "itemDestroyed", true);
189+ tryCompare(loader, "itemDestroyed", true);
218−
219− }
220−
221− function test_swipeToClose_data() {
222− return [
223− {tag: "swipeToClose=true closeable=true -> appWindow moves away",
224− swipeToClose: true, closeable: true },
225−
226− {tag: "swipeToClose=true closeable=false -> appWindow bounces back",
227− swipeToClose: true, closeable: false },
228−
229− {tag: "swipeToClose=false -> appWindow stays put",
230− swipeToClose: false, closeable: true },
231− ]
232− }
233
190
234− function test_swipeToClose(data) {
235− loadWithGalleryApp.clicked();
236− var displacedAppWindowWithShadow = findChild(spreadDelegateLoader.item, "displacedAppWindowWithShadow");
237−
238− verify(displacedAppWindowWithShadow.y === 0);
239−
240− swipeToCloseCheckbox.checked = data.swipeToClose;
241− closeableCheckbox.checked = data.closeable;
242−
243− var dragDistance = spreadDelegateLoader.item.height * 0.8;
244− var touchX = spreadDelegateLoader.item.width / 2;
245− var fromY = spreadDelegateLoader.item.height * 0.9;
246− var toY = fromY - dragDistance;
247− touchFlick(spreadDelegateLoader.item,
248− touchX /* fromX */, fromY, touchX /* toX */, toY,
249− true /* beginTouch */, false /* endTouch */, dragArea.minSpeedToClose * 1.1 /* speed */);
250−
251− if (data.swipeToClose) {
252− verify(displacedAppWindowWithShadow.y < 0);
253− var threshold = findChild(spreadDelegateLoader.item, "dragArea").threshold
254− if (data.closeable) {
255− // Verify that the delegate started moving exactly "threshold" after the finger movement
256− // and did not jump up to the finger, but lags the threshold behind
257− compare(Math.abs(Math.abs(displacedAppWindowWithShadow.y) - dragDistance), threshold);
258− } else {
259− verify(Math.abs(Math.abs(displacedAppWindowWithShadow.y) - dragDistance) > threshold);
260− }
261−
262− touchRelease(spreadDelegateLoader.item, touchX, toY - units.gu(1));
263−
264− waitForCloseAnimationToFinish();
265−
266− if (data.closeable) {
267− verify(spyClosedSignal.count === 1);
268− } else {
269− verify(spyClosedSignal.count === 0);
270− tryCompare(displacedAppWindowWithShadow, "y", 0);
271− }
272−
273− } else {
274− verify(displacedAppWindowWithShadow.y === 0);
275−
276− touchRelease(spreadDelegateLoader.item, touchX, toY);
277− }
278− }
279−
280− function test_loadingLandscapeOnlyAppWhenShellInPortrait() {
281− loadWithWeatherApp.clicked();
282−
283− var appWindow = findChild(spreadDelegate, "appWindow");
284− verify(appWindow);
285−
286− // It must have landscape dimensions as it does not support portrait
287− tryCompare(appWindow, "width", fakeShell.height);
288− tryCompare(appWindow, "height", fakeShell.width - spreadDelegate.maximizedAppTopMargin);
289 }
191 }
290
192
291 function test_keepsSceneTransformationWhenShellRotates_data() {
193 function test_keepsSceneTransformationWhenShellRotates_data() {
@@ -299,42 +201,31 @@ Rectangle {
299 function test_keepsSceneTransformationWhenShellRotates(data) {
201 function test_keepsSceneTransformationWhenShellRotates(data) {
300 loadWithGalleryApp.clicked();
202 loadWithGalleryApp.clicked();
301
203
302− var appWindowWithShadow = findChild(spreadDelegate, "appWindowWithShadow");
303− verify(appWindowWithShadow);
304−
305 // Wait until it reaches the state we are interested on.
204 // Wait until it reaches the state we are interested on.
306 // It begins with "startingUp"
205 // It begins with "startingUp"
307− tryCompare(appWindowWithShadow, "state", "keepSceneRotation");
206+ tryCompare(decoratedWindow, "counterRotate", false);
207+ var oldWidth = decoratedWindow.width
208+ var oldHeight = decoratedWindow.height
209+ var oldX = decoratedWindow.x
210+ var oldY = decoratedWindow.y
308
211
309 shellOrientationAngleSelector.selectedIndex = data.selectedIndex;
212 shellOrientationAngleSelector.selectedIndex = data.selectedIndex;
310
213
311 // must keep same aspect ratio
214 // must keep same aspect ratio
312− compare(appWindowWithShadow.width, fakeShell.shortestDimension);
215+ compare(decoratedWindow.width, oldWidth);
313− compare(appWindowWithShadow.height, fakeShell.longestDimension);
216+ compare(decoratedWindow.height, oldHeight);
314
217
315
218
316 // and scene transformation must be the identity (ie, no rotation or translation)
219 // and scene transformation must be the identity (ie, no rotation or translation)
317− var pointInDelegateCoords = appWindowWithShadow.mapToItem(root, 0, 0);
220+ compare(decoratedWindow.x, oldX);
318− compare(pointInDelegateCoords.x, 0);
221+ compare(decoratedWindow.y, oldY);
319− compare(pointInDelegateCoords.y, 0);
320−
321− pointInDelegateCoords = appWindowWithShadow.mapToItem(root,
322− fakeShell.shortestDimension, fakeShell.longestDimension);
323− compare(pointInDelegateCoords.x, fakeShell.shortestDimension);
324− compare(pointInDelegateCoords.y, fakeShell.longestDimension);
325− }
326−
327− function waitForCloseAnimationToFinish() {
328− var closeAnimation = findInvisibleChild(spreadDelegateLoader.item, "closeAnimation");
329− wait(closeAnimation.duration * 1.5);
330− tryCompare(closeAnimation, "running", false);
331 }
222 }
332
223
333 function test_showHighLight() {
224 function test_showHighLight() {
334 loadWithGalleryApp.clicked();
225 loadWithGalleryApp.clicked();
335− var highlightRect = findChild(spreadDelegateLoader.item, "selectionHighlight")
226+ var highlightRect = findChild(loader.item, "selectionHighlight")
336 tryCompare(highlightRect, "visible", false)
227 tryCompare(highlightRect, "visible", false)
337− spreadDelegateLoader.item.showHighlight = true;
228+ loader.item.showHighlight = true;
338 tryCompare(highlightRect, "visible", true)
229 tryCompare(highlightRect, "visible", true)
339 }
230 }
340 }
231 }
tests/qmltests/Stage/tst_PhoneStage.qml+26
@@ -463,6 +463,32 @@ Item {
463 tryCompare(webbrowserApp.surfaceList, "count", 1);
463 tryCompare(webbrowserApp.surfaceList, "count", 1);
464 }
464 }
465
465
466+ function test_swipeToClose_data() {
467+ return [
468+ { tag: "closeable", closeable: true },
469+ { tag: "not closeable", closeable: false }
470+ ]
471+ }
472+
473+ function test_swipeToClose(data) {
474+ var surface1Id = topLevelSurfaceList.nextId;
475+ var webbrowserApp = ApplicationManager.startApplication("webbrowser-app");
476+ waitUntilAppSurfaceShowsUp(surface1Id);
477+
478+ performEdgeSwipeToShowAppSpread();
479+
480+ var appDelegate = findChild(stage, "appDelegate_" + surface1Id);
481+ var dragArea = findChild(appDelegate, "dragArea")
482+ verify(dragArea);
483+ dragArea.closeable = data.closeable;
484+
485+ var oldCount = ApplicationManager.count;
486+
487+ swipeSurfaceUpwards(surface1Id);
488+
489+ tryCompare(ApplicationManager, "count", data.closeable ? oldCount - 1 : oldCount);
490+ }
491+
466 /*
492 /*
467 1- Suspended app gets killed behind the scenes, causing its surface to go zombie.
493 1- Suspended app gets killed behind the scenes, causing its surface to go zombie.
468 2- Surface gets screenshotted and removed. Its slot in the topLevelSurfaceList remains,
494 2- Surface gets screenshotted and removed. Its slot in the topLevelSurfaceList remains,