File: tst_panel.11.qml

package info (click to toggle)
lomiri-ui-toolkit 1.3.5110%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,436 kB
  • sloc: cpp: 85,830; python: 5,537; sh: 1,344; javascript: 919; ansic: 573; makefile: 204
file content (297 lines) | stat: -rw-r--r-- 12,845 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
 * Copyright 2012 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.0
import QtTest 1.0
import Lomiri.Components 1.1
import Lomiri.Test 1.0

Item {
    width: 200
    height: 200
    id: root

    Panel {
        id: panel
        anchors {
            bottom: parent.bottom
            left: parent.left
            right: parent.right
        }
        height: parent.height / 2
        Rectangle {
            color: "pink"
            anchors.fill: parent
        }
    }

    LomiriTestCase {
        id: testCase
        name: "PanelAPI"
        when: windowShown

        function initTestCase() {
            compare(panel.align, Qt.AlignBottom, "Panel initially aligned at bottom");
            compare(panel.opened, false, "Panel initially not opened");
            compare(panel.locked, false, "Panel initially not locked");
            compare(panel.hintSize, units.gu(2), "Default hintSize is 2 grid units");
            compare(panel.triggerSize, units.gu(2), "Default triggerSize is 2 grid units");
        }

        function test_align() {
            panel.align = Qt.AlignTop;
            compare(panel.align, Qt.AlignTop, "Can set align to top");
            panel.align = Qt.AlignLeft;
            compare(panel.align, Qt.AlignLeft, "Can set align to left");
            panel.align = Qt.AlignRight;
            compare(panel.align, Qt.AlignRight, "Can set align to right");
            panel.align = Qt.AlignBottom;
            compare(panel.align, Qt.AlignBottom, "Can set align to bottom");
        }

        function test_height() {
            var bar = findChild(panel, "bar_item");
            // panel is not opened
            panel.height = 123;
            compare(bar.y, 123, "Panel is properly closed after changing height");
            panel.open(); wait(500);
            compare(bar.y, 0, "Panel opens properly after changing height");
            panel.height = 78;
            compare(bar.y, 0, "Panel stays propery opened after changing height");
            panel.close(); wait(500);
            compare(bar.y, 78, "Panel closes properly after changing height");
            panel.height = root.height / 2;
            compare(bar.y, root.height/2, "Panel stays closed properly after changing height");
        }

        function test_opened() {
            panel.open();
            compare(panel.opened, true, "Can set opened");
            panel.close();
            compare(panel.opened, false, "Can unset opened");
        }

        function test_locked() {
            panel.locked = true;
            compare(panel.locked, true, "Can set locked");
            panel.locked = false;
            compare(panel.locked, false, "Can unset locked");
        }

        function test_hintSize() {
            panel.hintSize = units.gu(1);
            compare(panel.hintSize, units.gu(1), "Can set hintSize");
            panel.hintSize = units.gu(2);
        }

        function test_triggerSize() {
            panel.triggerSize = units.gu(5);
            compare(panel.triggerSize, units.gu(5), "Can set triggerSize");
            panel.triggerSize = units.gu(2);
        }

        function test_swipeBottomPanel() {
            // swipe bottom-aligned panel in and out
            swipeTests.slowMouseMove = false;
            swipeTests.swipeUpDown();
            swipeTests.slowMouseMove = true;
            swipeTests.swipeUpDown();
            swipeTests.slowMouseMove = false;
        }

        function test_swipeLeftPanel() {
            // swipe a left-aligned panel in and out
            panel.align = Qt.AlignLeft;
            swipeTests.slowMouseMove = false;
            swipeTests.swipeRightLeft();
            swipeTests.slowMouseMove = true;
            swipeTests.swipeRightLeft();
            swipeTests.slowMouseMove = false;
            panel.align = Qt.AlignBottom;
        }

        function test_swipeRightPanel() {
            // swipe right-aligned panel in and out
            panel.align = Qt.AlignRight;
            swipeTests.slowMouseMove = false;
            swipeTests.swipeLeftRight();
            swipeTests.slowMouseMove = true;
            swipeTests.swipeLeftRight();
            swipeTests.slowMouseMove = false;
            panel.align = Qt.AlignBottom;
        }

        function test_swipeLeadingPanel() {
            // swipe leading-aligned panel in and out
            panel.align = Qt.AlignLeading;
            swipeTests.swipeRightLeft();
            panel.LayoutMirroring.enabled = true;
            panel.LayoutMirroring.childrenInherit = true;
            swipeTests.slowMouseMove = false;
            swipeTests.swipeLeftRight();
            swipeTests.slowMouseMove = true;
            swipeTests.swipeLeftRight();
            swipeTests.slowMouseMove = false;
            panel.LayoutMirroring.enabled = false;
            panel.align = Qt.AlignBottom;
        }

        function test_swipeTrailingPanel() {
            // swipe trailing-aligned panel in and out
            panel.align = Qt.AlignTrailing;
            swipeTests.swipeLeftRight();
            panel.LayoutMirroring.enabled = true;
            panel.LayoutMirroring.childrenInherit = true;
            swipeTests.slowMouseMove = false;
            swipeTests.swipeRightLeft();
            swipeTests.slowMouseMove = true;
            swipeTests.swipeRightLeft();
            swipeTests.slowMouseMove = false;
            panel.LayoutMirroring.enabled = false;
            panel.align = Qt.AlignBottom;
        }

        function test_swipeTopPanel() {
            // swipe top-aligned panel in and out
            panel.anchors.top = root.top;
            panel.anchors.bottom = undefined;
            panel.align = Qt.AlignTop;

            swipeTests.slowMouseMove = false;
            swipeTests.swipeDownUp();
            swipeTests.slowMouseMove = true;
            swipeTests.swipeDownUp();
            swipeTests.slowMouseMove = false;

            // revert to original state
            panel.anchors.bottom = root.bottom;
            panel.anchors.top = undefined;
            panel.align = Qt.AlignBottom;
        }

        function test_clickToDeactivate() {
            // deprecated test. This functionality is only there for backwards compatibility
            panel.__closeOnContentsClicks = true;
            panel.open();
            compare(panel.opened && panel.align === Qt.AlignBottom, true, "Panel is opened and bottom-aligned");
            mouseClick(root, root.width / 2, 5, Qt.LeftButton);
            compare(panel.opened, false, "Panel is deactivated by clicking in the view outside of the panel");
            // reset property to default value
            panel.__closeOnContentsClicks = false;
        }

        function test_hideTimeout_bug1249031() {
            compare(panel.hideTimeout, -1, "Panel hide timeout is initially negative (no timeout)");
            panel.hideTimeout = 2000;
            panel.open();
            compare(panel.opened, true, "Panel can be made opened");
            wait(panel.hideTimeout + 500); // add 500 ms margin
            compare(panel.opened, false, "Panel automatically closes after timeout");

            // now, wait in total more than hideTimeout, but less than 2*hideTimeout,
            //  and have user interaction half-way to verify that the interaction
            //  resets the timer and the panel is not closed.
            panel.open();
            wait(0.6*panel.hideTimeout);
            mouseClick(panel, panel.width/2, panel.height/2);
            wait(0.6*panel.hideTimeout);
            compare(panel.opened, true, "Interacting with panel contents resets the hide timer");
            // verify that the timer is still running by waiting a bit longer:
            wait(0.6*panel.hideTimeout);
            compare(panel.opened, false, "Interacting with the panel contents does not stop the timer")
            panel.hideTimeout = -1;
        }

        QtObject {
            id: swipeTests

            // waiting time in ms after move, to simulate slow drag vs fast swipe
            property int moveDelay: slowMouseMove ? 400 : 0
            property bool slowMouseMove: false

            function swipeUpDown() {
                testCase.compare(panel.opened, false, "Panel initially not opened")
                var x = root.width / 2; var y = root.height - 1;
                var dx = 0;
                var dy = -panel.height / 2;
                testCase.mousePress(root, x, y, Qt.LeftButton);
                testCase.mouseMove(root, x + dx, y + dy, moveDelay);
                testCase.mouseRelease(root, x + dx, y + dy, Qt.LeftButton);
                testCase.compare(panel.opened, true, "Panel activated by swiping up (delay: "+moveDelay+")")
                x = panel.width / 2;
                y = 10;
                testCase.mousePress(panel, x, y, Qt.LeftButton);
                testCase.mouseMove(panel, x - dx, y - dy, moveDelay);
                testCase.mouseRelease(panel, x - dx, y - dy, Qt.LeftButton);
                testCase.compare(panel.opened, false, "Panel deactivated by swiping down (delay: "+moveDelay+")")
            }

            function swipeRightLeft() {
                testCase.compare(panel.opened, false, "Panel initially not opened")
                var x = 1;
                var y = 3 * root.height / 4;
                var dx = panel.width / 2;
                var dy = 0;
                testCase.mousePress(root, x, y, Qt.LeftButton);
                testCase.mouseMove(root, x + dx, y + dy, moveDelay);
                testCase.mouseRelease(root, x + dx, y + dy, Qt.Leftbutton);
                testCase.compare(panel.opened, true, "Left-aligned panel activated by swiping to the right (delay: "+moveDelay+")");
                x = 3 * panel.width / 4;
                y = panel.height / 2;
                testCase.mousePress(panel, x, y, Qt.LeftButton);
                testCase.mouseMove(root, x - dx, y - dy, moveDelay);
                testCase.mouseRelease(panel, x - dx, y - dy, Qt.LeftButton);
                testCase.compare(panel.opened, false, "Left-aligned panel deactivated by swiping to the left (delay: "+moveDelay+"");
            }

            function swipeLeftRight() {
                testCase.compare(panel.opened, false, "Panel initially not opened")
                var x = root.width - 1;
                var y = 3 * root.height / 4;
                var dx = -panel.width / 2;
                var dy = 0;
                testCase.mousePress(root, x, y, Qt.LeftButton);
                testCase.mouseMove(root, x + dx, y + dy, moveDelay);
                testCase.mouseRelease(root, x + dx, y + dy, Qt.Leftbutton);
                testCase.compare(panel.opened, true, "Right-aligned panel activated by swiping to the left (delay: "+moveDelay+"");
                x = 1;
                y = panel.height / 2;
                testCase.mousePress(panel, x, y, Qt.LeftButton);
                testCase.mouseMove(panel, -dx, -dy, moveDelay);
                testCase.mouseRelease(panel, x - dx, y - dy, Qt.LeftButton);
                testCase.compare(panel.opened, false, "Right-aligned panel deactivating by swiping to the right (delay: "+moveDelay+"");
            }

            function swipeDownUp() {
                testCase.compare(panel.opened, false, "Panel initially not opened")
                var x = root.width / 2;
                var y = 1;
                var dx = 0;
                var dy = panel.height / 2;
                testCase.mousePress(root, x, y, Qt.LeftButton);
                testCase.mouseMove(root, x + dx, y + dy, moveDelay);
                testCase.mouseRelease(root, x + dx, y + dy, Qt.LeftButton);
                testCase.compare(panel.opened, true, "Top-aligned panel activated by swiping down (delay: "+moveDelay+"");
                x = panel.width / 2;
                y = panel.height - 1;
                testCase.mousePress(panel, x, y, Qt.LeftButton);
                testCase.mouseMove(panel, x - dx, y - dy, moveDelay);
                testCase.mouseRelease(panel, x - dx, y - dy, Qt.LeftButton);
                testCase.compare(panel.opened, false, "Top-aligned panel deactivated by swiping up (delay: "+moveDelay+"");
            }
        }
    }
}