~ubuntu-sdk-team/ubuntu-ui-toolkit/clipScrollbar

« back to all changes in this revision

Viewing changes to tests/unit_x11/tst_components/tst_focus.qml

  • Committer: Tarmac
  • Author(s): Christian Dywan
  • Date: 2016-06-02 13:12:15 UTC
  • mfrom: (1983.2.2 uut.acceptTheAbstract)
  • Revision ID: tarmac-20160602131215-3pg6cwwvcsc6me5a
UCListItem needs to handle click/trigger by keyboard. Fixes: https://bugs.launchpad.net/bugs/1581027.

Approved by ubuntu-sdk-build-bot, Zsombor Egri.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import Ubuntu.Test 1.0
20
20
import Ubuntu.Components 1.3
21
21
import Ubuntu.Components.Pickers 1.3
22
 
import Ubuntu.Components.ListItems 1.3 as ListItem
23
22
import Ubuntu.Components.Popups 1.3
24
23
 
25
24
Item {
44
43
            height: units.gu(20)
45
44
            clip: true
46
45
            model: 10
47
 
            delegate: ListItem.Standard {
48
 
                text: "Whatever"
 
46
            delegate: ListItem {
 
47
                Label {
 
48
                    text: "Whatever"
 
49
                }
49
50
            }
50
51
        }
51
52
        Button {
81
82
            property bool override: false
82
83
            Keys.onReleased: event.accepted = override
83
84
        }
 
85
        ListItem {
 
86
            id: listItem
 
87
            property bool override: false
 
88
            Keys.onReleased: event.accepted = override
 
89
            Label {
 
90
                text: "Cuddle me"
 
91
            }
 
92
        }
84
93
        CheckBox {
85
94
            id: checkbox
86
95
        }
175
184
            id: popover
176
185
            contentWidth: units.gu(20)
177
186
            contentHeight: item.height
178
 
            ListItem.Standard {
179
 
                id: item
180
 
                text: "close"
 
187
            ListItem {
 
188
                Label {
 
189
                    id: item
 
190
                    text: "close"
 
191
                }
181
192
                onClicked: PopupUtils.close(popover)
182
193
            }
183
194
        }
196
207
        id: popoverItem
197
208
        contentWidth: units.gu(20)
198
209
        contentHeight: item.height
199
 
        ListItem.Standard {
200
 
            id: item
201
 
            text: "close"
 
210
        ListItem {
 
211
            Label {
 
212
                id: item
 
213
                text: "close"
 
214
            }
202
215
            onClicked: popoverItem.hide();
203
216
        }
204
217
    }
235
248
            popupCloseSpy.clear();
236
249
            popupCloseSpy.target = null;
237
250
            popupCloseSpy.signalName = "onDestruction";
 
251
            buttonTriggerSpy.target = null;
 
252
            buttonTriggerSpy.clear();
238
253
        }
239
254
 
240
255
        function test_tab_focus_data() {
248
263
                {tag: "BottomEdgeHint(back)", from: bottomEdgeHint, to: textArea, key: Qt.Key_Backtab},
249
264
                {tag: "Button", from: bottomEdgeHint, to: button, key: Qt.Key_Tab},
250
265
                {tag: "Button(back)", from: button, to: bottomEdgeHint, key: Qt.Key_Backtab},
 
266
                {tag: "ListItem", from: button, to: listItem, key: Qt.Key_Tab},
 
267
                {tag: "ListItem(back)", from: listItem, to: button, key: Qt.Key_Backtab},
251
268
                {tag: "CheckBox", from: checkbox, to: switchbox, key: Qt.Key_Tab},
252
269
                {tag: "CheckBox", from: switchbox, to: checkbox, key: Qt.Key_Backtab},
253
270
                {tag: "Switch", from: switchbox, to: slider, key: Qt.Key_Tab},
423
440
            verify(popoverTest.focus, "Button focus not restored.");
424
441
        }
425
442
 
426
 
        function test_button_trigger_via_keyboard_data() {
 
443
        function test_trigger_via_keyboard_data() {
427
444
            return [
428
 
                {tag: "Enter", key: Qt.Key_Enter},
429
 
                {tag: "Return", key: Qt.Key_Return},
430
 
                {tag: "Space", key: Qt.Key_Space},
 
445
                {tag: "Button/Enter", key: Qt.Key_Enter, item: button, signalName: 'onTriggered'},
 
446
                {tag: "Button/Return", key: Qt.Key_Return, item: button, signalName: 'onTriggered'},
 
447
                {tag: "Button/Space", key: Qt.Key_Space, item: button, signalName: 'onTriggered'},
 
448
                {tag: "ListItem/Enter", key: Qt.Key_Enter, item: listItem, signalName: 'onClicked'},
 
449
                {tag: "ListItem/Return", key: Qt.Key_Return, item: listItem, signalName: 'onClicked'},
 
450
                {tag: "ListItem/Space", key: Qt.Key_Space, item: listItem, signalName: 'onClicked'},
431
451
            ];
432
452
        }
433
 
        function test_button_trigger_via_keyboard(data) {
434
 
            button.override = false;
 
453
        function test_trigger_via_keyboard(data) {
 
454
            data.item.override = false;
435
455
            main.keysReleased = false;
436
 
            buttonTriggerSpy.clear();
437
 
            buttonTriggerSpy.target = button;
438
 
            button.forceActiveFocus();
 
456
            buttonTriggerSpy.signalName = data.signalName;
 
457
            buttonTriggerSpy.target = data.item;
 
458
            data.item.forceActiveFocus();
439
459
            keyClick(data.key);
440
460
            buttonTriggerSpy.wait();
441
461
            compare(main.keysReleased, false, "Parent didn't get Keys.onReleased");
442
462
 
443
463
            // Second attempt but the button will consume Keys.onReleased
444
 
            button.override = true;
 
464
            data.item.override = true;
445
465
            main.keysReleased = false;
446
466
            buttonTriggerSpy.clear();
447
467
            keyClick(data.key);