@@ -0,0 +1,138 @@
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 ".."
22+import "../../../qml/Stages"
23+import Ubuntu.Components 0.1
24+import Ubuntu.Components.ListItems 1.0 as ListItem
25+import Unity.Application 0.1
26+
27+Item {
28+ id: root
29+ height: units.gu(60)
30+ width: units.gu(60)
31+
32+ Rectangle {
33+ id: fakeWindow
34+ height: units.gu(20)
35+ width: units.gu(20)
36+ color: "khaki"
37+ WindowMoveResizeArea {
38+ id: moveResizeArea
39+ target: fakeWindow
40+ resizeHandleWidth: units.gu(0.5)
41+ minWidth: units.gu(15)
42+ minHeight: units.gu(10)
43+ }
44+ }
45+
46+ UT.UnityTestCase {
47+ when: windowShown
48+
49+ function init() {
50+ fakeWindow.x = units.gu(20)
51+ fakeWindow.y = units.gu(20)
52+ fakeWindow.width = units.gu(20)
53+ fakeWindow.height = units.gu(20)
54+ }
55+
56+ function test_dragWindow_data() {
57+ return [
58+ { tag: "up", dx: 0, dy: units.gu(-10) },
59+ { tag: "down", dx: 0, dy: units.gu(10) },
60+ { tag: "left", dx: units.gu(-10), dy: 0 },
61+ { tag: "right", dx: units.gu(10), dy: 0 },
62+ { tag: "right/down", dx: units.gu(10), dy: units.gu(10) },
63+ { tag: "left/down", dx: units.gu(-10), dy: units.gu(10) }
64+ ]
65+ }
66+
67+ function test_dragWindow(data) {
68+ var initialWindowX = fakeWindow.x;
69+ var initialWindowY = fakeWindow.y;
70+ var initialWindowWidth = fakeWindow.width
71+ var initialWindowHeight = fakeWindow.height
72+
73+ var startDragX = initialWindowX + fakeWindow.width / 2;
74+ var startDragY = initialWindowY + fakeWindow.height / 2;
75+ mouseFlick(root, startDragX, startDragY, startDragX + data.dx, startDragY + data.dy, true, true, units.gu(.5), 10)
76+
77+ tryCompare(fakeWindow, "x", initialWindowX + data.dx)
78+ tryCompare(fakeWindow, "y", initialWindowX + data.dy)
79+
80+ compare(fakeWindow.height, initialWindowHeight);
81+ compare(fakeWindow.width, initialWindowWidth);
82+ }
83+
84+ function test_resizeWindowRightBottom_data() {
85+ return [
86+ { tag: "width", dx: units.gu(10), dy: 0 },
87+ { tag: "height", dx: 0, dy: units.gu(10) },
88+ { tag: "both", dx: units.gu(10), dy: units.gu(10) },
89+ { tag: "smaller than minimum size", dx: -units.gu(15), dy: -units.gu(15) }
90+ ]
91+ }
92+
93+ function test_resizeWindowRightBottom(data) {
94+ var initialWindowX = fakeWindow.x;
95+ var initialWindowY = fakeWindow.y;
96+ var initialWindowWidth = fakeWindow.width
97+ var initialWindowHeight = fakeWindow.height
98+
99+ var startDragX = initialWindowX + initialWindowWidth + 1
100+ var startDragY = initialWindowY + initialWindowHeight + 1
101+ mouseFlick(root, startDragX, startDragY, startDragX + data.dx, startDragY + data.dy, true, true, units.gu(.5), 10);
102+
103+ tryCompare(fakeWindow, "width", Math.max(initialWindowWidth + data.dx, moveResizeArea.minWidth));
104+ tryCompare(fakeWindow, "height", Math.max(initialWindowHeight + data.dy, moveResizeArea.minHeight));
105+
106+ compare(fakeWindow.x, initialWindowX);
107+ compare(fakeWindow.y, initialWindowY);
108+ }
109+
110+ function test_resizeWindowLeftTop_data() {
111+ return [
112+ { tag: "width", dx: -units.gu(10), dy: 0 },
113+ { tag: "height", dx: 0, dy: -units.gu(10) },
114+ { tag: "both", dx: -units.gu(10), dy: -units.gu(10) },
115+ { tag: "smaller than minimum size", dx: units.gu(15), dy: units.gu(15) }
116+ ]
117+ }
118+
119+ function test_resizeWindowLeftTop(data) {
120+ var initialWindowX = fakeWindow.x;
121+ var initialWindowY = fakeWindow.y;
122+ var initialWindowWidth = fakeWindow.width
123+ var initialWindowHeight = fakeWindow.height
124+
125+ var startDragX = initialWindowX - 1
126+ var startDragY = initialWindowY - 1
127+ mouseFlick(root, startDragX, startDragY, startDragX + data.dx, startDragY + data.dy, true, true, units.gu(.5), 10);
128+
129+ tryCompare(fakeWindow, "width", Math.max(initialWindowWidth - data.dx, moveResizeArea.minWidth));
130+ tryCompare(fakeWindow, "height", Math.max(initialWindowHeight - data.dy, moveResizeArea.minHeight));
131+
132+ var maxMoveX = initialWindowWidth - moveResizeArea.minWidth;
133+ var maxMoveY = initialWindowHeight - moveResizeArea.minHeight;
134+ compare(fakeWindow.x, Math.min(initialWindowX + data.dx, initialWindowX + maxMoveX));
135+ compare(fakeWindow.y, Math.min(initialWindowY + data.dy, initialWindowY + maxMoveY));
136+ }
137+ }
138+}