@@ -1,5 +1,5 @@
11/*
2− * Copyright 2014-2015 Canonical Ltd.
2+ * Copyright 2014-2016 Canonical Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -132,10 +132,12 @@ Rectangle {
132132 property int value: selectedIndex * 90
133133 }
134134 Button {
135+ id: matchShellButton
135136 text: "matchShellOrientation()"
136137 onClicked: { spreadDelegateLoader.item.matchShellOrientation(); }
137138 }
138139 Button {
140+ id: animateToShellButton
139141 text: "animateToShellOrientation()"
140142 onClicked: { spreadDelegateLoader.item.animateToShellOrientation(); }
141143 }
@@ -197,6 +199,77 @@ Rectangle {
197199
198200 }
199201
202+ function waitUntilAppWindowIsFullyLoaded() {
203+ var appWindowStateGroup = findInvisibleChild(spreadDelegate, "applicationWindowStateGroup");
204+ tryCompareFunction(function() { return appWindowStateGroup.state === "surface" }, true);
205+ waitUntilTransitionsEnd(appWindowStateGroup);
206+
207+ var priv = findInvisibleChild(spreadDelegate, "spreadDelegatePriv");
208+ verify(priv);
209+ tryCompare(priv, "startingUp", false);
210+ }
211+
212+ function rotateShellTo(angle) {
213+ shellOrientationAngleSelector.selectedIndex = angle / 90;
214+ }
215+
216+ function waitUntilRotationAnimationStops() {
217+ var orientationChangeAnimation = findInvisibleChild(spreadDelegate, "orientationChangeAnimation");
218+ verify(orientationChangeAnimation);
219+ tryCompare(orientationChangeAnimation, "running", false);
220+ }
221+
222+ function checkAppWindowTransformationMatchesRotation(appWindow, angle) {
223+
224+ var topLeftX = 0;
225+ var topLeftY = 0;
226+ var bottomRightX = 0;
227+ var bottomRightY = 0;
228+
229+ switch (angle) {
230+ case 0:
231+ topLeftX = 0;
232+ topLeftY = 0;
233+ bottomRightX = fakeShell.shortestDimension;
234+ bottomRightY = fakeShell.longestDimension;
235+ break;
236+ case 90:
237+ topLeftX = fakeShell.shortestDimension;
238+ topLeftY = 0;
239+ bottomRightX = 0;
240+ bottomRightY = fakeShell.longestDimension;
241+ break;
242+ default:
243+ // TODO implement 180 and 270 once we need them
244+ verify(false);
245+ }
246+
247+ var appWindowTopLeftInRootCoords = appWindow.mapToItem(root, 0, 0);
248+
249+ if (appWindowTopLeftInRootCoords.x !== topLeftX) {
250+ qtest_fail("appWindow topLeft.x ("+appWindowTopLeftInRootCoords.x+")"
251+ +" doesn't match expectations ("+topLeftX+").", 1);
252+ }
253+ if (appWindowTopLeftInRootCoords.y !== topLeftY) {
254+ qtest_fail("appWindow topLeft.y ("+appWindowTopLeftInRootCoords.y+")"
255+ +" doesn't match expectations ("+topLeftY+").", 1);
256+ }
257+
258+ var appWindowBottomRightInRootCoords = appWindow.mapToItem(root, appWindow.width,
259+ appWindow.height);
260+ compare(appWindowBottomRightInRootCoords.x, bottomRightX);
261+ compare(appWindowBottomRightInRootCoords.y, bottomRightY);
262+
263+ if (appWindowBottomRightInRootCoords.x !== bottomRightX) {
264+ qtest_fail("appWindow bottomRight.x ("+appWindowBottomRightInRootCoords.x+")"
265+ +" doesn't match expectations ("+bottomRightX+").", 1);
266+ }
267+ if (appWindowBottomRightInRootCoords.y !== bottomRightY) {
268+ qtest_fail("appWindow bottomRight.y ("+appWindowBottomRightInRootCoords.y+")"
269+ +" doesn't match expectations ("+bottomRightY+").", 1);
270+ }
271+ }
272+
200273 function test_swipeToClose_data() {
201274 return [
202275 {tag: "swipeToClose=true closeable=true -> appWindow moves away",
@@ -278,11 +351,7 @@ Rectangle {
278351 function test_keepsSceneTransformationWhenShellRotates(data) {
279352 loadWithGalleryApp.clicked();
280353
281− {
282− var priv = findInvisibleChild(spreadDelegate, "spreadDelegatePriv");
283− verify(priv);
284− tryCompare(priv, "startingUp", false);
285− }
354+ waitUntilAppWindowIsFullyLoaded();
286355
287356 var appWindowWithShadow = findChild(spreadDelegate, "appWindowWithShadow");
288357 verify(appWindowWithShadow);
@@ -297,14 +366,7 @@ Rectangle {
297366
298367
299368 // and scene transformation must be the identity (ie, no rotation or translation)
300− var pointInDelegateCoords = appWindowWithShadow.mapToItem(root, 0, 0);
301− compare(pointInDelegateCoords.x, 0);
302− compare(pointInDelegateCoords.y, 0);
303−
304− pointInDelegateCoords = appWindowWithShadow.mapToItem(root,
305− fakeShell.shortestDimension, fakeShell.longestDimension);
306− compare(pointInDelegateCoords.x, fakeShell.shortestDimension);
307− compare(pointInDelegateCoords.y, fakeShell.longestDimension);
369+ checkAppWindowTransformationMatchesRotation(appWindowWithShadow, 0);
308370 }
309371
310372 function waitForCloseAnimationToFinish() {
@@ -320,5 +382,42 @@ Rectangle {
320382 spreadDelegateLoader.item.highlightShown = true;
321383 tryCompare(highlightRect, "visible", true)
322384 }
385+
386+ /*
387+ Checks that the ApplicationWindow position, size and rotation is correct after
388+ a sequence of shell rotations folowed by rotations (immediate or not) to match them
389+ */
390+ function test_animateToShellThenMatchShell() {
391+ loadWithGalleryApp.clicked();
392+ waitUntilAppWindowIsFullyLoaded();
393+
394+ var appWindowWithShadow = findChild(spreadDelegate, "appWindowWithShadow");
395+ verify(appWindowWithShadow);
396+
397+ // appWindow transformation is 0 relative to display
398+ checkAppWindowTransformationMatchesRotation(appWindowWithShadow, 0);
399+
400+ rotateShellTo(90);
401+
402+ // appWindow transformation remains 0 relative to display
403+ checkAppWindowTransformationMatchesRotation(appWindowWithShadow, 0);
404+
405+ animateToShellButton.clicked();
406+ waitUntilRotationAnimationStops();
407+
408+ // appWindow transformation is now 90 relative to display, just like shell
409+ checkAppWindowTransformationMatchesRotation(appWindowWithShadow, 90);
410+
411+ rotateShellTo(0);
412+
413+ // appWindow transformation is remains 90 relative to display.
414+ checkAppWindowTransformationMatchesRotation(appWindowWithShadow, 90);
415+
416+ matchShellButton.clicked();
417+
418+ // appWindow transformation is back to 0 relative to display, just like shell
419+ checkAppWindowTransformationMatchesRotation(appWindowWithShadow, 0);
420+
421+ }
323422 }
324423}