File: tst_textinput_touch.SEGFAULT.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 (333 lines) | stat: -rw-r--r-- 13,076 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
 * Copyright 2014 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.Test 1.0
import Lomiri.Components 1.1

Item {
    id: testMain
    width: units.gu(40)
    height: units.gu(71)

    Column {
        spacing: units.gu(1)
        Label {
            text: "Text fields are awesome"
            width: parent.width
            height: units.gu(10)
            verticalAlignment: Text.AlignVCenter
        }
        TextField {
            id: textField
            text: "This is a single line text input called TextField."
        }
        Label {
            text: "Text areas are even more amazing"
            width: parent.width
            height: units.gu(5)
            verticalAlignment: Text.AlignVCenter
        }
        TextArea {
            id: textArea
            text: "This is a multiline text input component called TextArea. It supports fix size as well as auto-expanding behavior. The content is scrollable only if it exceeds the visible area."
        }
        Flickable {
            id: outerFlicker
            width: parent.width
            height: units.gu(20)
            clip: true
            contentWidth: autoSizeTextArea.width
            contentHeight: autoSizeTextArea.height
            TextArea {
                id: autoSizeTextArea
                autoSize: true
                maximumLineCount: 0
                text: "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
            }
        }
        TextField {
            id: emptyTextField
            text: ""
        }
        TextArea {
            id: emptyTextArea
            text: ""
        }
    }

    LomiriTestCase {
        name: "TextInputTouchTests"
        when: windowShown

        SignalSpy {
            id: popupSpy
            signalName: "pressAndHold"
        }
        SignalSpy {
            id: flickerSpy
            signalName: "movementEnded"
        }

        function guPoint(x, y) {
            return Qt.point(units.gu(x), units.gu(y));
        }

        function initTestCase() {
            TestExtras.registerTouchDevice();
        }

        function init() {
            textField.cursorPosition = 0;
            textArea.cursorPosition = 0;
            emptyTextField.cursorPosition = 0;
            emptyTextArea.cursorPosition = 0;
        }
        function cleanup() {
            textField.cursorPosition = 1;
            textArea.cursorPosition = 1;
            textField.focus = false;
            textArea.focus = false;
            emptyTextField.focus = false;
            emptyTextArea.focus = false;
            autoSizeTextArea.focus = false;
            popupSpy.target = null;
            popupSpy.clear();
            flickerSpy.target = null;
            flickerSpy.clear();
            // provide few milliseconds to cleanup
            waitForRendering(textField, 500);
            waitForRendering(textArea, 500);
        }

        function test_has_caret_when_touchscreen_data() {
            return [
                {tag: "TextField", input: textField},
                {tag: "TextArea", input: textArea},
            ];
        }
        function test_has_caret_when_touchscreen(data) {
            data.input.focus = true;
            waitForRendering(data.input);

            var cursor = findChild(data.input, "textCursor");
            verify(cursor, "Cursor not accessible, FAIL");
            verify(cursor.caret, "No caret is set");
            compare(cursor.caret.visible, true, "Caret is not visible");
        }

        function test_do_not_activate_on_pressed_data() {
            return [
                {tag: "TextField", input: textField},
                {tag: "TextArea", input: textArea},
            ];
        }
        function test_do_not_activate_on_pressed(data) {
            TestExtras.touchPress(0, data.input, centerOf(data.input));
            compare(data.input.focus, false, "Input must not be focused on press");
            // cleanup
            TestExtras.touchRelease(0, data.input, centerOf(data.input));
        }

        function test_activate_on_released_data() {
            return [
                {tag: "TextField", input: textField},
                {tag: "TextArea", input: textArea},
            ];
        }
        function test_activate_on_released(data) {
            TestExtras.touchClick(0, data.input, centerOf(data.input));
            compare(data.input.focus, true, "Input must be focused on release");
        }

        function test_select_text_on_doubletap_data() {
            return [
                {tag: "TextField", input: textField},
                {tag: "TextArea", input: textArea},
            ];
        }
        function test_select_text_on_doubletap(data) {
            data.input.focus = true;
            TestExtras.touchDoubleClick(0, data.input, guPoint(1, 1));
            waitForRendering(data.input);
            verify(data.input.selectedText !== "", "No text selected!");
        }

        function test_longtap_when_inactive_has_no_effect_data() {
            return [
                {tag: "TextField", input: textField},
                {tag: "TextArea", input: textArea},
            ];
        }
        function test_longtap_when_inactive_has_no_effect(data) {
            TestExtras.touchLongPress(0, data.input, guPoint(1, 1));
            waitForRendering(data.input, 500);
            verify(!data.input.focus, "Text input must not get focused");
            verify(data.input.selectedText === "", "There shouldn't be any text selected");
            // cleanup
            TestExtras.touchRelease(0, data.input, guPoint(1, 1));
        }

        function test_select_text_longtap_when_active_data() {
            return [
                {tag: "TextField", input: textField},
                {tag: "TextArea", input: textArea},
            ];
        }
        function test_select_text_longtap_when_active(data) {
            TestExtras.touchClick(0, data.input, centerOf(data.input));
            popupSpy.target = findChild(data.input, "input_handler");

            TestExtras.touchLongPress(0, data.input, guPoint(1, 1));
            waitForRendering(data.input, 500);
            popupSpy.wait();
            verify(data.input.selectedText !== "", "There should be text selected!");

            // cleanup
            TestExtras.touchRelease(0, data.input, guPoint(1, 1));
            // dismiss popover
            TestExtras.touchClick(0, testMain, 0, 0);
        }

        function test_longtap_when_empty_data() {
            return [
                {tag: "TextField", input: emptyTextField},
            ];
        }
        function test_longtap_when_empty(data) {
            TestExtras.touchClick(0, data.input, centerOf(data.input));
            wait(500);

            popupSpy.target = findChild(data.input, "input_handler");

            TestExtras.touchLongPress(0, data.input, guPoint(1, 1));
            waitForRendering(data.input, 500);
            popupSpy.wait();
            compare(popupSpy.count, 1, "Copy/paste popup should be displayed.");

            // cleanup
            TestExtras.touchRelease(0, data.input, guPoint(1, 1));
            // dismiss popover
            TestExtras.touchClick(0, testMain, 0, 0);
            waitForRendering(data.input, 500);
        }

        function test_long_tap_on_selected_text_data() {
            return [
                {tag: "TextField", input: textField},
                {tag: "TextArea", input: textArea},
            ];
        }
        function test_long_tap_on_selected_text(data) {
            data.input.focus = true;
            data.input.selectWord();
            var selectedText = data.input.selectedText;
            verify(selectedText !== "", "No text selected!");

            popupSpy.target = findChild(data.input, "input_handler");
            TestExtras.touchLongPress(0, data.input, guPoint(4, 2));
            waitForRendering(data.input, 500);
            popupSpy.wait();
            compare(data.input.selectedText, selectedText, "Text selection should be the same!");

            // cleanup
            TestExtras.touchRelease(0, data.input, guPoint(2, 2));
            // dismiss popover
            TestExtras.touchClick(0, testMain, guPoint(0, 0));
        }

        function test_drag_cursor_handler_data() {
            return [
                {tag: "TextField", input: textField, delta: guPoint(10, 0)},
                {tag: "TextArea", input: textArea, delta: guPoint(10, 4)},
            ];
        }
        function test_drag_cursor_handler(data) {
            data.input.focus = true;
            data.input.cursorPosition = 0;
            var caret = findChild(data.input, "input_handler").cursorPositionCursor;
            verify(caret, "Caret \"" + data.cursorName + "\" cannot be found!");
            var cursorPosition = data.input.cursorPosition;

            TestExtras.touchDrag(0, caret, centerOf(caret), data.delta);
            waitForRendering(data.input, 500);
            verify(cursorPosition !== data.input.cursorPosition, "Cursor not moved!");
        }

        function test_select_text_by_dragging_cursor_handler_data() {
            return [
                {tag: "TextField", input: textField, initialCursorPosition: 0, cursorName: "selectionEnd", delta: guPoint(10, 0)},
                {tag: "TextArea", input: textArea, initialCursorPosition: 0, cursorName: "selectionEnd", delta: guPoint(10, 5)},
                {tag: "TextField(end)", input: textField, initialCursorPosition: 48, cursorName: "selectionStart", delta: guPoint(-10, 0)},
                {tag: "TextArea(end)", input: textArea, initialCursorPosition: 50, cursorName: "selectionStart", delta: guPoint(-20, -5)},
            ];
        }
        function test_select_text_by_dragging_cursor_handler(data) {
            data.input.focus = true;
            data.input.cursorPosition = data.initialCursorPosition;
            data.input.selectWord();
            verify(data.input.selectedText !== "", "No word selected initially!");
            var selectedText = data.input.selectedText;

            var caret = findChild(data.input, "input_handler")[data.cursorName + "Cursor"];
            verify(caret, "Caret \"" + data.cursorName + "\" cannot be found!");

            // The caret may not receive events right away
            sleep(500)
            TestExtras.touchDrag(0, caret, centerOf(caret), data.delta);
            verify(data.input.selectedText !== "", "Selection cleared!");
            verify(data.input.selectedText != selectedText, "Selection did not change");
        }

        function test_z_scroll_when_tap_dragged_data() {
            return [
                {tag: "TextField", input: textField, withSelectedText: false, from: guPoint(2, 2), delta: guPoint(10, 0)},
                {tag: "TextArea", input: textArea, withSelectedText: false, from: guPoint(2, 2), delta: guPoint(10, 4)},
                {tag: "TextField(selected)", input: textField, withSelectedText: true, from: guPoint(2, 2), delta: guPoint(10, 0)},
                {tag: "TextArea(selected)", input: textArea, withSelectedText: true, from: guPoint(2, 2), delta: guPoint(10, 4)},
            ];
        }
        function test_z_scroll_when_tap_dragged(data) {
            data.input.focus = true;
            data.input.cursorPosition = data.input.text.length;
            flickerSpy.target = findChild(data.input, "input_scroller");
            var selectedText = "";
            if (data.withSelectedText) {
                data.input.selectWord();
                selectedText = data.input.selectedText;
            }
            waitForRendering(data.input, 200);
            TestExtras.touchDrag(0, data.input, data.from, data.delta);
            waitForRendering(data.input, 200);
            flickerSpy.wait();
            compare(selectedText, data.input.selectedText, "Text selection differs!");
        }

        function test_0_drag_autosizing_textarea_drags_parent_flickable_data() {
            return [
                {tag: "when inactive", focused: false },
            ];
        }
        function test_0_drag_autosizing_textarea_drags_parent_flickable(data) {
            flickerSpy.target = outerFlicker;
            autoSizeTextArea.focus = data.focused;
            var editor = findChild(autoSizeTextArea, "text_input");
            TestExtras.touchDrag(0, editor, guPoint(0, 0), guPoint(0, 40));
            flickerSpy.wait();
        }
    }
}