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

« back to all changes in this revision

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

  • Committer: CI Train Bot
  • Author(s): Christian Dywan, Zsombor Egri, Zoltán Balogh, Tim Peeters, Albert Astals Cid, Michael Sheldon, Benjamin Zeller
  • Date: 2015-12-17 17:13:49 UTC
  • mfrom: (1000.739.27 OTA9-landing-2015-12-16)
  • Revision ID: ci-train-bot@canonical.com-20151217171349-8xwclnhnx8v9oz4m
OTA9-landing-2015-12-16
Approved by: Zoltan Balogh

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
        }
63
63
        CheckBox {
64
64
            id: checkbox
65
 
            text: "Check me"
66
65
        }
67
66
        Switch {
68
 
            id: switchBox
 
67
            id: switchbox
 
68
        }
 
69
        Button {
 
70
            id: dummy2
 
71
        }
 
72
        ActionBar {
 
73
            id: actions
 
74
            actions: [
 
75
                Action {
 
76
                    iconName: 'share'
 
77
                    objectName: 'actionBarShare'
 
78
                },
 
79
                Action {
 
80
                    iconName: 'starred'
 
81
                }
 
82
            ]
69
83
        }
70
84
        Picker {
71
85
            id: picker
85
99
        Slider {
86
100
            id: slider
87
101
        }
88
 
        StyledItem {
 
102
        Button {
89
103
            id: disabledButton
 
104
            text: 'Disabled'
90
105
            enabled: false
91
106
            width: units.gu(20)
92
107
            height: units.gu(6)
101
116
        Button {
102
117
            id: popoverTest
103
118
            text: "Popovers"
104
 
            property Item popover
 
119
            property var popover
105
120
            property Component popoverComponent
106
121
            onClicked: {
107
122
                popover = PopupUtils.open(popoverComponent)
160
175
            popupCloseSpy.target = null;
161
176
        }
162
177
 
163
 
        // make this as the very first test executed
164
 
        function test_0_transfer_focus_data() {
165
 
            return [
166
 
                {tag: "TextArea", previousFocused: textField, focusOn: textArea, clickToDismiss: false},
167
 
                {tag: "Button", previousFocused: textArea, focusOn: button, clickToDismiss: false},
168
 
                {tag: "Checkbox", previousFocused: button, focusOn: checkbox, clickToDismiss: false},
169
 
                {tag: "Switch", previousFocused: checkbox, focusOn: switchBox, clickToDismiss: false},
170
 
                {tag: "Picker - linear", previousFocused: switchBox, focusOn: picker, clickToDismiss: false},
171
 
                {tag: "Picker - circular", previousFocused: picker, focusOn: roundPicker, clickToDismiss: false},
172
 
                {tag: "PickerPanel", previousFocused: roundPicker, focusOn: pickerPanel, clickToDismiss: true},
173
 
                {tag: "UbuntuListView", previousFocused: pickerPanel, focusOn: listView, clickToDismiss: false},
174
 
                {tag: "Slider", previousFocused: listView, focusOn: slider, clickToDismiss: false},
175
 
                {tag: "ComboButton", previousFocused: slider, focusOn: comboButton, clickToDismiss: false},
176
 
            ];
177
 
        }
178
 
        function test_0_transfer_focus(data) {
179
 
            // perform mouse press on
180
 
            mouseClick(data.focusOn, centerOf(data.focusOn).x, centerOf(data.focusOn).y);
181
 
            compare(data.previousFocused.focus, false, "Previous focus is still set!");
182
 
            compare(data.focusOn.focus, true, data.tag + " is not focused!");
183
 
            if (data.clickToDismiss) {
184
 
                mouseClick(main, 0, 0);
185
 
            }
186
 
            waitForRendering(data.focusOn, 200);
187
 
        }
188
 
 
189
178
        function test_tab_focus_data() {
190
179
            return [
 
180
                // (Shift)Tab via keyboard
191
181
                {tag: "TextField", from: dummy, to: textField, key: Qt.Key_Tab},
192
182
                {tag: "TextField(back)", from: textField, to: dummy, key: Qt.Key_Backtab},
193
183
                {tag: "TextArea", from: textField, to: textArea, key: Qt.Key_Tab},
194
184
                {tag: "TextArea(back)", from: textArea, to: textField, key: Qt.Key_Backtab},
195
185
                {tag: "Button(back)", from: button, to: textArea, key: Qt.Key_Backtab},
 
186
                {tag: "CheckBox", from: checkbox, to: switchbox, key: Qt.Key_Tab},
 
187
                {tag: "CheckBox", from: switchbox, to: checkbox, key: Qt.Key_Backtab},
 
188
                {tag: "Switch", from: switchbox, to: dummy2, key: Qt.Key_Tab},
 
189
                {tag: "Switch(back)", from: dummy2, to: switchbox, key: Qt.Key_Backtab},
 
190
                /* FIXME: Figure out how to test ActionBar delegate focus
 
191
                {tag: "ActionBar", from: 'actionBarShare_button', to: picker, key: Qt.Key_Tab},
 
192
                {tag: "ActionBar(back)", from: picker, to: 'actionBarShare_button', key: Qt.Key_Backtab},
 
193
                */
 
194
                // Left click/ tap
 
195
                {tag: "TextField(click)", from: dummy, to: textField, key: Qt.LeftButton},
 
196
                {tag: "TextArea(click)", from: dummy, to: textArea, key: Qt.LeftButton},
 
197
                // FIXME: lp#1368390: Buttons shouldn't grab input focus on click
 
198
                {tag: "Button(click)", from: dummy, to: button, key: Qt.LeftButton},
 
199
                {tag: "CheckBox(click)", from: dummy, to: checkbox, key: Qt.LeftButton},
 
200
                {tag: "Switch(click)", from: dummy, to: switchbox, key: Qt.LeftButton}
196
201
            ];
197
202
        }
198
203
        function test_tab_focus(data) {
199
204
            data.from.forceActiveFocus();
200
205
            verify(data.from.activeFocus, "Source component is not focused");
201
 
            keyClick(data.key);
 
206
            if (data.key == Qt.LeftButton) {
 
207
                verify(data.to.activeFocusOnPress, "Target doesn't take focus on click");
 
208
                mouseClick(data.to, centerOf(data.to).x, centerOf(data.to).y);
 
209
            } else {
 
210
                verify(data.to.activeFocusOnTab, "Target doesn't take keyboard focus");
 
211
                keyClick(data.key);
 
212
            }
202
213
            waitForRendering(data.to, 500);
203
214
            verify(!data.from.activeFocus, "Source component still keeps focus");
204
215
            verify(data.to.activeFocus, "Target component is not focused");
241
252
            var center = centerOf(dropdownButton);
242
253
            mouseClick(dropdownButton, center.x, center.y);
243
254
            waitForRendering(comboButton);
 
255
            // FIXME: lp#1368390: Buttons shouldn't grab input focus on click
244
256
            compare(dropdownButton.focus, true, "Dropdown button hasn't got focused!");
245
257
            compare(comboButton.focus, true, "ComboButton hasn't been focused!");
246
258
            comboButton.expanded = false;
258
270
            popoverTest.popoverComponent = data.component;
259
271
            var center = centerOf(popoverTest);
260
272
            mouseClick(popoverTest, center.x, center.y);
261
 
            verify(popoverTest.focus, "Button focus not gained.");
 
273
            verify(popoverTest.popover !== undefined, "No popover created");
262
274
            waitForRendering(popoverTest.popover);
 
275
            verify(!popoverTest.focus, "Button focus not lost.");
 
276
            var foreground = findChild(popoverTest.popover, "popover_foreground");
 
277
            verify(foreground, "Popover foreground not ready");
 
278
            verify(foreground.focus, "Popover focus not gained. Focus went to %1".arg(window.activeFocusItem));
263
279
            popupCloseSpy.target = popoverTest.popover.Component;
264
280
 
265
281
            var closeButton = findChildWithProperty(popoverTest.popover, "text", "close");
287
303
        }
288
304
 
289
305
        function test_disabled_component_does_not_focus() {
 
306
            verify(disabledButton.activeFocusOnPress, "Disabled component doesn't take focus on click");
290
307
            mousePress(disabledButton, centerOf(disabledButton).x, centerOf(disabledButton).y);
291
308
            compare(disabledButton.focus, false, "Disabled component shoudl not focus");
292
309
        }