on xenial help sign in
fix testDecoratedWindow
commit6b9253e33f2da2a0cf8d63381cb55bd72e90e6f7 authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 21 Sep 2016, 18:41 (10 years ago) parent4180aa2
2 files changed+60−143
tests/qmltests/Stage/tst_DecoratedWindow.qml+34−143 tests/qmltests/Stage/tst_PhoneStage.qml+26
tests/qmltests/Stage/tst_DecoratedWindow.qml+34−143
@@ -50,7 +50,7 @@ Rectangle {
5050 rotation: orientationAngle
5151
5252 Loader {
53− id: spreadDelegateLoader
53+ id: loader
5454 property int windowedX: units.gu(1)
5555 property int windowedY: units.gu(1)
5656 property int windowedWidth: units.gu(50)
@@ -66,22 +66,22 @@ Rectangle {
6666 sourceComponent: DecoratedWindow {
6767 anchors.fill: parent
6868 application: fakeApplication
69− requestedWidth: spreadDelegateLoader.windowedWidth
70− requestedHeight: spreadDelegateLoader.windowedHeight
69+ requestedWidth: loader.windowedWidth
70+ requestedHeight: loader.windowedHeight
7171 surface: fakeApplication && fakeApplication.surfaceList.count > 0 ? fakeApplication.surfaceList.get(0) : null
7272
7373 Component.onDestruction: {
74− spreadDelegateLoader.itemDestroyed = true;
74+ loader.itemDestroyed = true;
7575 }
7676 Component.onCompleted: {
77− spreadDelegateLoader.itemDestroyed = false;
77+ loader.itemDestroyed = false;
7878 }
7979 }
8080
8181 Rectangle { anchors.fill: parent; color: "green"; opacity: 1 }
8282 }
8383 WindowResizeArea {
84− target: spreadDelegateLoader
84+ target: loader
8585 borderThickness: units.gu(2)
8686 }
8787 }
@@ -110,18 +110,13 @@ Rectangle {
110110 text: "Load with gallery-app"
111111 onClicked: { testCase.restartWithApp("gallery-app"); }
112112 }
113− Row {
114− anchors { left: parent.left; right: parent.right }
115− CheckBox { id: swipeToCloseCheckbox; checked: false; }
116− Label { text: "swipeToCloseEnabled" }
117− }
118113 Button {
119114 text: "toggle has decoration"
120− onClicked: spreadDelegateLoader.item.hasDecoration = !spreadDelegateLoader.item.hasDecoration
115+ onClicked: loader.item.hasDecoration = !loader.item.hasDecoration
121116 }
122117 Button {
123118 text: "show/hide decoration"
124− onClicked: spreadDelegateLoader.item.showDecoration = !spreadDelegateLoader.item.showDecoration
119+ onClicked: loader.item.showDecoration = !loader.item.showDecoration
125120 }
126121 Label {
127122 text: "scale to preview progress"
@@ -132,18 +127,7 @@ Rectangle {
132127 minimumValue: 0
133128 maximumValue: 1
134129 live: true
135− onValueChanged: spreadDelegateLoader.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" }
130+ onValueChanged: loader.item.scaleToPreviewProgress = value
147131 }
148132 ListItem.ItemSelector {
149133 id: shellOrientationAngleSelector
@@ -154,138 +138,56 @@ Rectangle {
154138 }
155139 Button {
156140 text: "matchShellOrientation()"
157− onClicked: { spreadDelegateLoader.item.matchShellOrientation(); }
141+ onClicked: { loader.item.matchShellOrientation(); }
158142 }
159143 Button {
160144 text: "animateToShellOrientation()"
161− onClicked: { spreadDelegateLoader.item.animateToShellOrientation(); }
145+ onClicked: { loader.item.animateToShellOrientation(); }
162146 }
163147 }
164148 }
165149
166150 UT.UnityTestCase {
167151 id: testCase
168− name: "SpreadDelegate"
152+ name: "DecoratedWindow"
169153 when: windowShown
170154
171− SignalSpy {
172− id: spyClosedSignal
173− target: spreadDelegateLoader.item
174− signalName: "closeClicked"
175− }
176−
177− property var dragArea
178− property Item spreadDelegate: spreadDelegateLoader.item
155+ property Item decoratedWindow: loader.item
179156
180157 function init() {
181158 }
182159
183160 function cleanup() {
184− unloadSpreadDelegate();
185− spyClosedSignal.clear();
186− shellOrientationAngleSelector.selectedIndex = 0;
161+ unloadWindow();
187162 root.fakeApplication = null;
188163 killApps();
189164 }
190165
191166 function restartWithApp(appId) {
192− if (spreadDelegateLoader.active) {
193− unloadSpreadDelegate();
167+ if (loader.active) {
168+ unloadWindow();
194169 }
195170 if (root.fakeApplication) {
196171 ApplicationManager.stopApplication(root.fakeApplication.appId);
197172 }
198173
199174 root.fakeApplication = ApplicationManager.startApplication(appId);
200− spreadDelegateLoader.active = true;
201− tryCompare(spreadDelegateLoader, "status", Loader.Ready);
202−
203− dragArea = findInvisibleChild(spreadDelegate, "dragArea");
204− dragArea.__dateTime = fakeDateTime;
175+ loader.active = true;
176+ tryCompare(loader, "status", Loader.Ready);
205177 }
206178
207− function unloadSpreadDelegate() {
208− spreadDelegateLoader.active = false;
209− tryCompare(spreadDelegateLoader, "status", Loader.Null);
210− tryCompare(spreadDelegateLoader, "item", null);
179+ function unloadWindow() {
180+ loader.active = false;
181+ tryCompare(loader, "status", Loader.Null);
182+ tryCompare(loader, "item", null);
211183 // Loader.status might be Loader.Null and Loader.item might be null but the Loader
212184 // item might still be alive. So if we set Loader.active back to true
213185 // again right now we will get the very same Shell instance back. So no reload
214186 // actually took place. Likely because Loader waits until the next event loop
215187 // iteration to do its work. So to ensure the reload, we will wait until the
216188 // Shell instance gets destroyed.
217− tryCompare(spreadDelegateLoader, "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− }
189+ tryCompare(loader, "itemDestroyed", true);
233190
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);
289191 }
290192
291193 function test_keepsSceneTransformationWhenShellRotates_data() {
@@ -299,42 +201,31 @@ Rectangle {
299201 function test_keepsSceneTransformationWhenShellRotates(data) {
300202 loadWithGalleryApp.clicked();
301203
302− var appWindowWithShadow = findChild(spreadDelegate, "appWindowWithShadow");
303− verify(appWindowWithShadow);
304−
305204 // Wait until it reaches the state we are interested on.
306205 // 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
308211
309212 shellOrientationAngleSelector.selectedIndex = data.selectedIndex;
310213
311214 // must keep same aspect ratio
312− compare(appWindowWithShadow.width, fakeShell.shortestDimension);
313− compare(appWindowWithShadow.height, fakeShell.longestDimension);
215+ compare(decoratedWindow.width, oldWidth);
216+ compare(decoratedWindow.height, oldHeight);
314217
315218
316219 // and scene transformation must be the identity (ie, no rotation or translation)
317− var pointInDelegateCoords = appWindowWithShadow.mapToItem(root, 0, 0);
318− compare(pointInDelegateCoords.x, 0);
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);
220+ compare(decoratedWindow.x, oldX);
221+ compare(decoratedWindow.y, oldY);
331222 }
332223
333224 function test_showHighLight() {
334225 loadWithGalleryApp.clicked();
335− var highlightRect = findChild(spreadDelegateLoader.item, "selectionHighlight")
226+ var highlightRect = findChild(loader.item, "selectionHighlight")
336227 tryCompare(highlightRect, "visible", false)
337− spreadDelegateLoader.item.showHighlight = true;
228+ loader.item.showHighlight = true;
338229 tryCompare(highlightRect, "visible", true)
339230 }
340231 }
tests/qmltests/Stage/tst_PhoneStage.qml+26
@@ -463,6 +463,32 @@ Item {
463463 tryCompare(webbrowserApp.surfaceList, "count", 1);
464464 }
465465
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+
466492 /*
467493 1- Suspended app gets killed behind the scenes, causing its surface to go zombie.
468494 2- Surface gets screenshotted and removed. Its slot in the topLevelSurfaceList remains,