~ci-train-bot/ubuntu-ui-toolkit/ubuntu-ui-toolkit-ubuntu-zesty-2055

« back to all changes in this revision

Viewing changes to tests/unit/visual/tst_listitem_focus.13.qml

  • Committer: Bileto Bot
  • Date: 2016-08-14 09:06:34 UTC
  • mfrom: (1000.985.35 OTA13-2016-06-29)
  • Revision ID: ci-train-bot@canonical.com-20160814090634-uoxtg7ektrlidwh6
* Fix OptionSelectorTestCase tests.
* Fix more OptionSelector autopilot tests
* Disable documentation building for GLES builds. Fixes LP: #1606222.
* Replace abs with qFabs due to GCC6 breakage. Fixes LP: #1610943.
* Limit s390x dependencies more due to upstart/s390x problems and removed
  packages in archives. Fixes LP: #1610951
* ListItemLayout doc: add elide mode change example and add section about
  labels default properties values. Fixes LP: #1603450.
* ListItemLayout doc: add explicit note about the need to bind ListItem's
  height to layout's height.
* More Scrollbar optimizations: 20% faster creation time. Fixes LP: #1606451
* Scrollbar: fix wrong thumb color on tap/mouse release and increase coverage
  of hover states unit tests. Fixes LP: #1608897
* Fix null pointer property initializer used with 1.3 PageWrapper. 
  Fixes LP: #1604780.
* Fix BottomEdge content URL preloading. Fixes LP: #1604509.
* UCUnits::resolveResource: Prefer image path if it exists. This saves
  searching the disk for @gu images, which is a big speedup. According to
  callgrind loading 100 images from a folder that contains 380 images goes
  from around 3 million instructions per UCUnits::resolveResource call down
  to around 10 thousand. This optimization is ok since it is not correct to
  ship both image.png and image@20.png. You either have to ship gu-enabled
  files or not, but mixing them is not allowed. Searched for cases in which
  that may be happening in my phone and found none. Fixes LP: #1604029.
* Configure colors of the buttons in the ActionBar and PageHeader through
  their Styles. Fixes LP: #1597774.
* Fix assigning of constant values to a grouped property in StyleHints.
  Fixes LP: #1602836.
* Fix list view keyboard navigation for RightToLeft and BottomToTop 
  directions. Fixes LP: #1605634
* Use external QML files instead of embedded QML strings for autopilot tests.
  Fixes LP: #1578319
* Fix failing autopilot header tests.
* Fix ActionSelectionPopover Autopilot CPO tests.
* Include indexes in "offline" docs and filter out link errors.
  Fixes LP: #1603937.
* Increase focus ring thickness from 1dp to 2dp. Fixes LP: #1602690.
* Add a snippet about tests to the toplevel README
* Enter/Return to trigger, Space to expand ComboButton. Fixes LP: #1523817.
* Initialize engine variable before using it in the _engine case.
* Use Qt.rgba instead of #0000 checking ListItem default color. 
  Fixes LP: #1560004
* Don't use a different .desktop file in the gallery tests.
  Fixes LP: #1578319
* Update scaling docs, set QT_SCALE_FACTOR and unset GRID_UNIT_PX.
  Fixes LP: #1610208
* Sections: load Icons asynchronously.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
    property Item activeFocusItem: Window.activeFocusItem
29
29
 
 
30
    PageHeader {
 
31
        id: header
 
32
        title: "ListItem focus test"
 
33
        extension: Sections {
 
34
            id: directionSections
 
35
            width: parent.width
 
36
            selectedIndex: -1
 
37
            function setupListView(showContent, orientation, reverseDirection) {
 
38
                testCase.cleanup();
 
39
                var test = testCase.loadTest(listView);
 
40
                test.orientation = orientation;
 
41
                if (reverseDirection) {
 
42
                    if (orientation === ListView.Horizontal) {
 
43
                        test.layoutDirection = Qt.RightToLeft;
 
44
                    } else {
 
45
                        test.verticalLayoutDirection = ListView.BottomToTop;
 
46
                    }
 
47
                }
 
48
                if (showContent) {
 
49
                    test.delegate = listItemWithContent;
 
50
                } else {
 
51
                    test.delegate = simpleListItem;
 
52
                }
 
53
            }
 
54
 
 
55
            actions: [
 
56
                Action {
 
57
                    text: "TopToBottom"
 
58
                    onTriggered: directionSections.setupListView(switchContentAction.showContent,
 
59
                                                                 ListView.Vertical, false);
 
60
                },
 
61
                Action {
 
62
                    text: "LeftToRight"
 
63
                    onTriggered: directionSections.setupListView(switchContentAction.showContent,
 
64
                                                                 ListView.Horizontal, false);
 
65
                },
 
66
                Action {
 
67
                    text: "BottomToTop"
 
68
                    onTriggered: directionSections.setupListView(switchContentAction.showContent,
 
69
                                                                 ListView.Vertical, true);
 
70
                },
 
71
                Action {
 
72
                    text: "RightToLeft"
 
73
                    onTriggered: directionSections.setupListView(switchContentAction.showContent,
 
74
                                                                 ListView.Horizontal, true);
 
75
                }
 
76
 
 
77
            ]
 
78
        }
 
79
        trailingActionBar.actions: [
 
80
            Action {
 
81
                id: switchContentAction
 
82
                property bool showContent: false
 
83
                iconName: showContent ? "select" : "select-none"
 
84
                onTriggered: {
 
85
                    showContent = !showContent;
 
86
                    if (directionSections.selectedIndex >= 0) {
 
87
                        directionSections.actions[directionSections.selectedIndex].trigger();
 
88
                    }
 
89
                }
 
90
            }
 
91
        ]
 
92
    }
 
93
 
30
94
    Rectangle {
31
 
        id: topItem
32
 
        objectName: "topItem"
 
95
        id: topFocusItem
 
96
        objectName: "topFocusItem"
33
97
        activeFocusOnTab: true
34
 
        width: parent.width
 
98
        anchors {
 
99
            left: parent.left
 
100
            right: parent.right
 
101
            top: header.bottom
 
102
        }
35
103
        height: units.gu(2)
 
104
        border {
 
105
            width: units.dp(3)
 
106
            color: topFocusItem.activeFocus ? UbuntuColors.orange : UbuntuColors.silk
 
107
        }
36
108
    }
37
 
 
38
109
    Loader {
39
110
        id: testLoader
40
111
        anchors {
41
 
            fill: parent
42
 
            topMargin: topItem.height
 
112
            left: parent.left
 
113
            right: parent.right
 
114
            top: topFocusItem.bottom
 
115
            bottom: bottomFocusItem.top
 
116
        }
 
117
        clip: true
 
118
    }
 
119
    Rectangle {
 
120
        id: bottomFocusItem
 
121
        objectName: "bottomFocusItem"
 
122
        activeFocusOnTab: true
 
123
        anchors {
 
124
            left: parent.left
 
125
            right: parent.right
 
126
            bottom: parent.bottom
 
127
        }
 
128
        height: units.gu(2)
 
129
        border {
 
130
            width: units.dp(3)
 
131
            color: bottomFocusItem.activeFocus ? UbuntuColors.orange : UbuntuColors.silk
43
132
        }
44
133
    }
45
134
 
46
135
    Component {
47
136
        id: simpleListItem
48
137
        ListItem {
 
138
            id: listItem
49
139
            objectName: "simple" + index
50
140
            property int itemIndex: index
 
141
            Label {
 
142
                anchors {
 
143
                    left: parent.left
 
144
                    leftMargin: units.gu(2)
 
145
                    verticalCenter: parent.verticalCenter
 
146
                }
 
147
                text: listItem.objectName
 
148
            }
51
149
        }
52
150
    }
53
151
 
61
159
                spacing: units.gu(1)
62
160
                CheckBox { objectName: "checkbox" + listItem.itemIndex }
63
161
                Switch { objectName: "switch" + listItem.itemIndex }
64
 
                Button { objectName: "button" + listItem.itemIndex; text: "test" }
 
162
                Button { objectName: "button" + listItem.itemIndex; text: "test " + itemIndex }
65
163
            }
66
164
            leadingActions: ListItemActions {
67
165
                actions: Action {
100
198
    }
101
199
 
102
200
    ListItemTestCase13 {
 
201
        id: testCase
103
202
        name: "ListItemFocus"
104
203
        when: windowShown
105
204
 
114
213
            wait(200);
115
214
        }
116
215
        function init() {
117
 
            topItem.forceActiveFocus(Qt.TabFocusReason);
 
216
            topFocusItem.forceActiveFocus(Qt.TabFocusReason);
118
217
        }
119
218
 
120
219
        function initTestCase() {
124
223
        // Tab/Backtab focuses the First ListItem in a ListView
125
224
        function test_focusing_listview_focuses_first_item_data() {
126
225
            return [
127
 
                {tag: "Tab, no content", preFocus: topItem, delegate: simpleListItem, key: Qt.Key_Tab, focusItem: "simple0"},
128
 
                {tag: "Tab, with content", preFocus: topItem, delegate: listItemWithContent, key: Qt.Key_Tab, focusItem: "withContent0"},
129
 
                {tag: "Backtab, no content", preFocus: topItem, delegate: simpleListItem, key: Qt.Key_Backtab, focusItem: "simple0"},
130
 
                {tag: "Backtab, with content", preFocus: topItem, delegate: listItemWithContent, key: Qt.Key_Backtab, focusItem: "withContent0"},
 
226
                {tag: "Tab, no content", preFocus: topFocusItem, delegate: simpleListItem, key: Qt.Key_Tab, focusItem: "simple0"},
 
227
                {tag: "Tab, with content", preFocus: topFocusItem, delegate: listItemWithContent, key: Qt.Key_Tab, focusItem: "withContent0"},
 
228
                {tag: "Backtab, no content", preFocus: bottomFocusItem, delegate: simpleListItem, key: Qt.Key_Backtab, focusItem: "simple0"},
 
229
                {tag: "Backtab, with content", preFocus: bottomFocusItem, delegate: listItemWithContent, key: Qt.Key_Backtab, focusItem: "withContent0"},
131
230
            ];
132
231
        }
133
232
        function test_focusing_listview_focuses_first_item(data) {
155
254
                            keyTimes: 3,
156
255
                            focusItems: ["simple1", "simple2", "simple3"]
157
256
                        },
 
257
                        {   tag: "BottomToTop up, no content, bottom to top direction, from beginning",
 
258
                            delegate: simpleListItem,
 
259
                            orientation: ListView.Vertical,
 
260
                            direction: ListView.BottomToTop,
 
261
                            initialIndex: 0,
 
262
                            key: Qt.Key_Up,
 
263
                            keyTimes: 3,
 
264
                            focusItems: ["simple1", "simple2", "simple3"]
 
265
                        },
158
266
                        {
159
267
                            tag: "Down, no contents, near end",
160
268
                            delegate: simpleListItem,
165
273
                            // Don't navigate beyond the last item:
166
274
                            focusItems: ["simple"+(n-2), "simple"+(n-1), "simple"+(n-1)]
167
275
                        },
 
276
                        {
 
277
                            tag: "BottomToTop up, no contents, near end",
 
278
                            delegate: simpleListItem,
 
279
                            orientation: ListView.Vertical,
 
280
                            direction: ListView.BottomToTop,
 
281
                            initialIndex: n - 3,
 
282
                            key: Qt.Key_Up,
 
283
                            keyTimes: 3,
 
284
                            // Don't navigate beyond the last item:
 
285
                            focusItems: ["simple"+(n-2), "simple"+(n-1), "simple"+(n-1)]
 
286
                        },
168
287
                        {   tag: "Up, no content, near beginning",
169
288
                            delegate: simpleListItem,
170
289
                            orientation: ListView.Vertical,
173
292
                            keyTimes: 3,
174
293
                            focusItems: ["simple1", "simple0", "simple0"]
175
294
                        },
 
295
                        {   tag: "BottomToTop down, no content, near beginning",
 
296
                            delegate: simpleListItem,
 
297
                            orientation: ListView.Vertical,
 
298
                            direction: ListView.BottomToTop,
 
299
                            initialIndex: 2,
 
300
                            key: Qt.Key_Down,
 
301
                            keyTimes: 3,
 
302
                            focusItems: ["simple1", "simple0", "simple0"]
 
303
                        },
176
304
                        {
177
305
                            tag: "Up, no contents, from end",
178
306
                            delegate: simpleListItem,
182
310
                            keyTimes: 3,
183
311
                            focusItems: ["simple"+(n-2), "simple"+(n-3), "simple"+(n-4)]
184
312
                        },
 
313
                        {
 
314
                            tag: "BottomToTop down, no contents, from end",
 
315
                            delegate: simpleListItem,
 
316
                            orientation: ListView.Vertical,
 
317
                            direction: ListView.BottomToTop,
 
318
                            initialIndex: n - 1,
 
319
                            key: Qt.Key_Down,
 
320
                            keyTimes: 3,
 
321
                            focusItems: ["simple"+(n-2), "simple"+(n-3), "simple"+(n-4)]
 
322
                        },
185
323
                        {   tag: "Left, no content, near beginning",
186
324
                            delegate: simpleListItem,
187
325
                            orientation: ListView.Horizontal,
190
328
                            keyTimes: 3,
191
329
                            focusItems: ["simple1", "simple0", "simple0"]
192
330
                        },
 
331
                        {   tag: "RightToLeft right, no content, near beginning",
 
332
                            delegate: simpleListItem,
 
333
                            orientation: ListView.Horizontal,
 
334
                            direction: Qt.RightToLeft,
 
335
                            initialIndex: 2,
 
336
                            key: Qt.Key_Right,
 
337
                            keyTimes: 3,
 
338
                            focusItems: ["simple1", "simple0", "simple0"]
 
339
                        },
193
340
                        {   tag: "Left, no content, from end",
194
341
                            delegate: simpleListItem,
195
342
                            orientation: ListView.Horizontal,
198
345
                            keyTimes: 3,
199
346
                            focusItems: ["simple"+(n-2), "simple"+(n-3), "simple"+(n-4)]
200
347
                        },
 
348
                        {   tag: "RightToLeft right, no content, from end",
 
349
                            delegate: simpleListItem,
 
350
                            orientation: ListView.Horizontal,
 
351
                            direction: Qt.RightToLeft,
 
352
                            initialIndex: n - 1,
 
353
                            key: Qt.Key_Right,
 
354
                            keyTimes: 3,
 
355
                            focusItems: ["simple"+(n-2), "simple"+(n-3), "simple"+(n-4)]
 
356
                        },
201
357
                        {   tag: "Right, no content, from beginning",
202
358
                            delegate: simpleListItem,
203
359
                            orientation: ListView.Horizontal,
206
362
                            keyTimes: 5,
207
363
                            focusItems: ["simple1", "simple2", "simple3", "simple4", "simple5"]
208
364
                        },
 
365
                        {   tag: "RightToLeft left, no content, from beginning",
 
366
                            delegate: simpleListItem,
 
367
                            orientation: ListView.Horizontal,
 
368
                            direction: Qt.RightToLeft,
 
369
                            initialIndex: 0,
 
370
                            key: Qt.Key_Left,
 
371
                            keyTimes: 5,
 
372
                            focusItems: ["simple1", "simple2", "simple3", "simple4", "simple5"]
 
373
                        },
209
374
                        {   tag: "Right, no content, near end",
210
375
                            delegate: simpleListItem,
211
376
                            orientation: ListView.Horizontal,
214
379
                            keyTimes: 2,
215
380
                            focusItems: ["simple"+(n-2), "simple"+(n-1), "simple"+(n-1)]
216
381
                        },
 
382
                        {   tag: "RightToLeft left, no content, near end",
 
383
                            delegate: simpleListItem,
 
384
                            orientation: ListView.Horizontal,
 
385
                            direction: Qt.RightToLeft,
 
386
                            initialIndex: n - 3,
 
387
                            key: Qt.Key_Left,
 
388
                            keyTimes: 2,
 
389
                            focusItems: ["simple"+(n-2), "simple"+(n-1), "simple"+(n-1)]
 
390
                        },
217
391
                        {   tag: "Down, with content, from beginning",
218
392
                            delegate: listItemWithContent,
219
393
                            orientation: ListView.Vertical,
222
396
                            keyTimes: 3,
223
397
                            focusItems: ["withContent1", "withContent2", "withContent3"]
224
398
                        },
 
399
                        {   tag: "BottomToTop up, with content, from beginning",
 
400
                            delegate: listItemWithContent,
 
401
                            orientation: ListView.Vertical,
 
402
                            direction: ListView.BottomToTop,
 
403
                            initialIndex: 0,
 
404
                            key: Qt.Key_Up,
 
405
                            keyTimes: 3,
 
406
                            focusItems: ["withContent1", "withContent2", "withContent3"]
 
407
                        },
225
408
                        {   tag: "Down, with content, near end",
226
409
                            delegate: listItemWithContent,
227
410
                            orientation: ListView.Vertical,
230
413
                            keyTimes: 3,
231
414
                            focusItems: ["withContent"+(n-2), "withContent"+(n-1), "withContent"+(n-1)]
232
415
                        },
 
416
                        {   tag: "BottomToTop up, with content, near end",
 
417
                            delegate: listItemWithContent,
 
418
                            orientation: ListView.Vertical,
 
419
                            direction: ListView.BottomToTop,
 
420
                            initialIndex: n - 3,
 
421
                            key: Qt.Key_Up,
 
422
                            keyTimes: 3,
 
423
                            focusItems: ["withContent"+(n-2), "withContent"+(n-1), "withContent"+(n-1)]
 
424
                        },
233
425
                        {   tag: "Up, with content, near beginning",
234
426
                            delegate: listItemWithContent,
235
427
                            orientation: ListView.Vertical,
238
430
                            keyTimes: 3,
239
431
                            focusItems: ["withContent1", "withContent0", "withContent0"]
240
432
                        },
 
433
                        {   tag: "BottomToTop down, with content, near beginning",
 
434
                            delegate: listItemWithContent,
 
435
                            orientation: ListView.Vertical,
 
436
                            direction: ListView.BottomToTop,
 
437
                            initialIndex: 2,
 
438
                            key: Qt.Key_Down,
 
439
                            keyTimes: 3,
 
440
                            focusItems: ["withContent1", "withContent0", "withContent0"]
 
441
                        },
241
442
                        {   tag: "Up, with content, from end",
242
443
                            delegate: listItemWithContent,
243
444
                            orientation: ListView.Vertical,
245
446
                            key: Qt.Key_Up,
246
447
                            keyTimes: 2,
247
448
                            focusItems: ["withContent"+(n-2), "withContent"+(n-3)]
 
449
                        },
 
450
                        {   tag: "BottomToTop down, with content, from end",
 
451
                            delegate: listItemWithContent,
 
452
                            orientation: ListView.Vertical,
 
453
                            direction: ListView.BottomToTop,
 
454
                            initialIndex: n - 1,
 
455
                            key: Qt.Key_Down,
 
456
                            keyTimes: 2,
 
457
                            focusItems: ["withContent"+(n-2), "withContent"+(n-3)]
248
458
                        }
249
459
                        // Horizontal navigation for ListItems with content is not supported.
250
460
            ];
253
463
            var test = loadTest(listView);
254
464
            test.orientation = data.orientation;
255
465
            test.delegate = data.delegate;
 
466
            // The cases where data.direction is set to ListView.BottomtoTop or Qt.RightToLeft
 
467
            //  are regression tests for bug #1605634.
 
468
            if (data.direction) {
 
469
                if (data.orientation === ListView.Horizontal) {
 
470
                    test.layoutDirection = data.direction;
 
471
                } else {
 
472
                    test.verticalLayoutDirection = data.direction;
 
473
                }
 
474
            }
256
475
            test.currentIndex = data.initialIndex;
257
476
            waitForRendering(test, 500);
258
477
            keyClick(Qt.Key_Tab);
296
515
        // Tab/Backtab focuses, next Tab/Backtab focuses out of ListItem in a ListView
297
516
        function test_tab_backtab_navigates_away_of_listview_data() {
298
517
            return [
299
 
                {tag: "Tab, simple", preFocus: topItem, delegate: simpleListItem, key: Qt.Key_Tab},
300
 
                {tag: "Tab, with content", preFocus: topItem, delegate: listItemWithContent, key: Qt.Key_Tab},
301
 
                {tag: "BackTab, simple", preFocus: topItem, delegate: simpleListItem, key: Qt.Key_Backtab},
302
 
                {tag: "BackTab, with content", preFocus: topItem, delegate: listItemWithContent, key: Qt.Key_Backtab},
 
518
                {tag: "Tab, simple", preFocus: topFocusItem, delegate: simpleListItem, key: Qt.Key_Tab},
 
519
                {tag: "Tab, with content", preFocus: topFocusItem, delegate: listItemWithContent, key: Qt.Key_Tab},
 
520
                {tag: "BackTab, simple", preFocus: bottomFocusItem, delegate: simpleListItem, key: Qt.Key_Backtab},
 
521
                {tag: "BackTab, with content", preFocus: bottomFocusItem, delegate: listItemWithContent, key: Qt.Key_Backtab},
303
522
            ];
304
523
        }
305
524
        function test_tab_backtab_navigates_away_of_listview(data) {
310
529
            verify(data.preFocus.activeFocus);
311
530
            // the first tab focuses the ListView and its first child
312
531
            keyClick(data.key);
313
 
            tryCompare(test, "activeFocus", true, 500, "Focus hasn't been gained bythe ListItem");
 
532
            tryCompare(test, "activeFocus", true, 500, "Focus hasn't been gained by the ListItem");
314
533
 
315
534
            // the second tab should leave the ListView
316
535
            keyClick(data.key);
320
539
        // testing Tab/Backtab navigation when in a generic item
321
540
        function test_tab_navigation_when_not_in_listview_data() {
322
541
            return [
323
 
                {tag: "Tabs", firstFocus: topItem, key: Qt.Key_Tab,
 
542
                {tag: "Tabs", firstFocus: topFocusItem, key: Qt.Key_Tab,
324
543
                            focusItems: ["withContent0", "checkbox0", "switch0", "button0"
325
544
                                , "withContent1", "checkbox1", "switch1", "button1"]},
326
 
                {tag: "Backtabs", firstFocus: topItem, key: Qt.Key_Backtab,
 
545
                {tag: "Backtabs", firstFocus: bottomFocusItem, key: Qt.Key_Backtab,
327
546
                            focusItems: ["simple1", "simple0"
328
547
                                , "button1", "switch1", "checkbox1", "withContent1"]},
329
548
            ];
408
627
            return [
409
628
                {tag: "Tabs in ListView", test: listView, delegate: listItemWithContent, testPlan: [
410
629
                        {key: Qt.Key_Tab, focus: "withContent0"},
411
 
                        {key: Qt.Key_Tab, focus: "topItem"},
 
630
                        {key: Qt.Key_Tab, focus: "bottomFocusItem"},
412
631
                        {key: Qt.Key_Backtab, focus: "withContent0"},
413
632
                ]},
414
633
                {tag: "Tab and navigate in ListView", test: listView, delegate: listItemWithContent, testPlan: [
421
640
                        {key: Qt.Key_Right, focus: "switch2"},
422
641
                        {key: Qt.Key_Down, focus: "withContent3"},
423
642
                        {key: Qt.Key_Down, focus: "withContent4"},
424
 
                        {key: Qt.Key_Backtab, focus: "topItem"},
 
643
                        {key: Qt.Key_Backtab, focus: "topFocusItem"},
425
644
                        {key: Qt.Key_Tab, focus: "withContent4"},
426
645
                ]},
427
646
                {tag: "Tab and navigate in generic", test: generic, testPlan: [
434
653
                        {key: Qt.Key_Right, focus: "withContent0"},
435
654
                        {key: Qt.Key_Down, focus: "withContent0"},
436
655
                        {key: Qt.Key_Down, focus: "withContent0"},
437
 
                        {key: Qt.Key_Backtab, focus: "topItem"},
 
656
                        {key: Qt.Key_Backtab, focus: "topFocusItem"},
438
657
                        {key: Qt.Key_Tab, focus: "withContent0"},
439
658
                ]},
440
659
                {tag: "Mixed Tab and navigate keys in generic", test: generic, testPlan: [