~zeller-benjamin/ubuntu-ui-toolkit/mathutils_dont_warn

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Zsombor Egri
  • Date: 2015-11-09 16:03:08 UTC
  • mfrom: (1706.3.18 cppBottomEdgeHint)
  • Revision ID: tarmac-20151109160308-hl5ulbj32dh0wqg2
BottomEdgeHint API changes, deprecating state property, introducing locked property to drive visuals lock and click handling.

Approved by Christian Dywan, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    width: units.gu(40)
25
25
    height: units.gu(71)
26
26
 
 
27
    ListView {
 
28
        id: listView
 
29
        anchors.fill: parent
 
30
        model: 100
 
31
        delegate: Label {
 
32
            height: units.gu(5)
 
33
            text: "Item #" + index
 
34
        }
 
35
    }
 
36
 
27
37
    BottomEdgeHint {
28
38
        id: bottomEdgeHint
29
39
    }
 
40
    BottomEdgeHint {
 
41
        id: floatingHint
 
42
        anchors.bottom: parent.top
 
43
    }
 
44
    Item {
 
45
        id: floatingItem
 
46
    }
30
47
 
31
48
    UbuntuTestCase {
32
49
        name: "BottomEdgeHint"
33
50
        when: windowShown
34
51
 
 
52
        // FIXME: the criteria must be adjusted when QSystemInfo will report
 
53
        // attached mouses, till then we stick to the touch presence
 
54
        property bool hasMouseAttached: QuickUtils.mouseAttached
 
55
 
35
56
        SignalSpy {
36
57
            id: clickSpy
37
58
            target: bottomEdgeHint
38
59
            signalName: "onClicked"
39
60
        }
40
61
 
41
 
        function cleanup() {
42
 
            bottomEdgeHint.iconName = "";
43
 
            bottomEdgeHint.state = "Idle";
44
 
            clickSpy.clear();
45
 
        }
46
 
 
47
 
        function test_0_default_state() {
 
62
        function initTestCase() {
 
63
            // register test touch device
 
64
            TestExtras.registerTouchDevice();
 
65
 
 
66
            // FIXME: this test case must be adjusted after we get the QInputDeviceInfo
 
67
            // available to detect attached mouse
 
68
            // the test must be executed before we register touch device
 
69
            if (!hasMouseAttached) {
 
70
                // we don't have mouse attached, so we should be able to lock/unlock
 
71
                compare(bottomEdgeHint.status, BottomEdgeHint.Inactive, "Wrong initial status when no mouse attached");
 
72
                bottomEdgeHint.status = BottomEdgeHint.Locked;
 
73
                compare(bottomEdgeHint.status, BottomEdgeHint.Locked, "Could not toggle status");
 
74
            } else {
 
75
                // we have the mouse attached, should not be able to unlock it
 
76
                compare(bottomEdgeHint.status, BottomEdgeHint.Locked, "Wrong initial status when mouse attached");
 
77
                bottomEdgeHint.status = BottomEdgeHint.Inactive;
 
78
                compare(bottomEdgeHint.status, BottomEdgeHint.Locked, "The bottom edge must not be unlockable as long as mouse is attached!");
 
79
            }
 
80
            QuickUtils.mouseAttached = !QuickUtils.mouseAttached;
 
81
 
 
82
            // and then turn locked off if possible
 
83
            bottomEdgeHint.status = BottomEdgeHint.Inactive;
 
84
            if (!hasMouseAttached) {
 
85
                compare(bottomEdgeHint.status, BottomEdgeHint.Inactive, "Cannot unlock hint!");
 
86
            }
 
87
 
 
88
            // defaults
48
89
            compare(bottomEdgeHint.iconName, "");
49
90
            compare(bottomEdgeHint.text, "");
50
 
            compare(bottomEdgeHint.state, "Idle");
51
91
            compare(bottomEdgeHint.width, mainView.width);
52
92
            compare(bottomEdgeHint.height, units.gu(4));
53
93
            compare(bottomEdgeHint.y, mainView.height - bottomEdgeHint.height);
 
94
            compare(bottomEdgeHint.flickable, null, "No flickable");
54
95
            compare(clickSpy.count, 0, "The BottomEdgeHint should not have received a click.");
 
96
            compare(bottomEdgeHint.deactivateTimeout, 800, "default deactivationTimeout");
 
97
 
 
98
            // set the flickable
 
99
            bottomEdgeHint.flickable = listView;
 
100
        }
 
101
 
 
102
        function cleanup() {
 
103
            listView.positionViewAtBeginning();
 
104
            bottomEdgeHint.visible = true;
 
105
            bottomEdgeHint.iconName = "";
 
106
            bottomEdgeHint.status = BottomEdgeHint.Inactive;
 
107
            clickSpy.clear();
 
108
            wait(400);
55
109
        }
56
110
 
57
111
        function test_hiding() {
58
 
            bottomEdgeHint.state = "Hidden";
59
 
            tryCompare(bottomEdgeHint, "opacity", 0.0);
60
 
        }
61
 
 
62
 
        function test_clicking() {
63
 
            bottomEdgeHint.state = "Locked";
64
 
            mouseClick(bottomEdgeHint, centerOf(bottomEdgeHint).x, centerOf(bottomEdgeHint).y);
65
 
            clickSpy.wait();
66
 
        }
67
 
 
68
 
        function test_no_clicking_while_unlocked() {
69
 
            mouseClick(bottomEdgeHint, centerOf(bottomEdgeHint).x, centerOf(bottomEdgeHint).y);
70
 
            expectFail("", "No click if not Locked");
71
 
            clickSpy.wait(200);
 
112
            var flickDy = listView.height - units.gu(5);
 
113
            flick(listView, centerOf(listView).x, flickDy, centerOf(listView).x, -flickDy, 0, 6);
 
114
            if (hasMouseAttached) {
 
115
                expectFailContinue("", "No hiding when mouse attached");
 
116
            }
 
117
            tryCompare(bottomEdgeHint, "status", BottomEdgeHint.Hidden);
 
118
        }
 
119
 
 
120
        function test_no_hiding_when_locked() {
 
121
            var flickDy = listView.height - units.gu(10);
 
122
            bottomEdgeHint.status = BottomEdgeHint.Locked;
 
123
            flick(listView, centerOf(listView).x, flickDy, centerOf(listView).x, -flickDy, 0, 6);
 
124
            expectFailContinue("", "No hiding when Locked");
 
125
            tryCompare(bottomEdgeHint, "status", BottomEdgeHint.Hidden, 500);
 
126
        }
 
127
 
 
128
        function test_clicking_data() {
 
129
            return [
 
130
                {tag: "when Locked", status: BottomEdgeHint.Locked, xfail: false},
 
131
                {tag: "when Active", status: BottomEdgeHint.Active, xfail: hasMouseAttached},
 
132
                {tag: "when Inactive", status: BottomEdgeHint.Inactive, xfail: true},
 
133
                {tag: "when Hidden", status: BottomEdgeHint.Hidden, xfail: true},
 
134
            ];
 
135
        }
 
136
        function test_clicking(data) {
 
137
            bottomEdgeHint.status = data.status;
 
138
            compare(bottomEdgeHint.status, data.status);
 
139
            mouseClick(bottomEdgeHint, centerOf(bottomEdgeHint).x, centerOf(bottomEdgeHint).y);
 
140
            if (data.xfail) {
 
141
                expectFailContinue(data.tag, "No click is expected");
 
142
            }
 
143
            clickSpy.wait(500);
 
144
        }
 
145
 
 
146
        function test_alter_deprecated_state_data() {
 
147
            return [
 
148
                {tag: "Hidden", status: BottomEdgeHint.Hidden},
 
149
                {tag: "Visible", status: BottomEdgeHint.Inactive},
 
150
            ];
 
151
        }
 
152
        function test_alter_deprecated_state(data) {
 
153
            ignoreWarning(warningFormat(37, 5, "QML BottomEdgeHint: Overloaded 'state' property deprecated, will be removed from 1.3 release. Use 'status' instead."));
 
154
            bottomEdgeHint.state = data.tag;
 
155
            compare(bottomEdgeHint.status, data.status, "Wrong component status: " + data.status);
 
156
        }
 
157
 
 
158
        function test_anchoring() {
 
159
            compare(floatingHint.anchors.bottom, mainView.top, "Anhors are broken");
 
160
            floatingHint.parent = floatingItem;
 
161
            compare(floatingHint.anchors.bottom, floatingItem.top, "Anhors are broken after reparenting");
 
162
        }
 
163
 
 
164
        function test_no_clicking_data() {
 
165
            return [
 
166
                {tag: "when hidden", property: "visible"},
 
167
                {tag: "when disabled", property: "enabled"},
 
168
            ];
 
169
        }
 
170
        function test_no_clicking(data) {
 
171
            bottomEdgeHint.status = BottomEdgeHint.Locked;
 
172
            bottomEdgeHint[data.property] = false;
 
173
            mouseClick(bottomEdgeHint, centerOf(bottomEdgeHint).x, centerOf(bottomEdgeHint).y);
 
174
            expectFailContinue("", "No click " + data.tag);
 
175
            clickSpy.wait(400);
 
176
        }
 
177
 
 
178
        function test_activate_by_key_data() {
 
179
            return [
 
180
                {tag: "enter and unlocked", key: Qt.Key_Return, status: BottomEdgeHint.Inactive},
 
181
                {tag: "return and unlocked", key: Qt.Key_Enter, status: BottomEdgeHint.Inactive},
 
182
                {tag: "enter and locked", key: Qt.Key_Return, status: BottomEdgeHint.Locked},
 
183
                {tag: "return and locked", key: Qt.Key_Enter, status: BottomEdgeHint.Locked},
 
184
            ];
 
185
        }
 
186
        function test_activate_by_key(data) {
 
187
            if (hasMouseAttached && !data.locked) {
 
188
                skip(data.tag, "Test requires ability to unlock");
 
189
            }
 
190
            bottomEdgeHint.status = data.status;
 
191
            bottomEdgeHint.forceActiveFocus();
 
192
            keyPress(data.key);
 
193
            if (bottomEdgeHint.status != BottomEdgeHint.Locked) {
 
194
                expectFailContinue(data.tag, "should fail");
 
195
            }
 
196
            clickSpy.wait(400);
 
197
            keyRelease(data.key);
 
198
        }
 
199
 
 
200
        // FIXME: must be executed before the test_hiding as flick with mouse affects
 
201
        // the touch drag on ListView for some unknown reason
 
202
        function test_touch_gesture() {
 
203
            if (hasMouseAttached) {
 
204
                skip("", "The test requires touch environment");
 
205
            }
 
206
            bottomEdgeHint.text = "Touch Activated";
 
207
            var gestureStartPoint = Qt.point(centerOf(bottomEdgeHint).x, bottomEdgeHint.height - 1);
 
208
            TestExtras.touchDrag(0, bottomEdgeHint, gestureStartPoint, Qt.point(0, -units.gu(8)), 6);
 
209
            tryCompare(bottomEdgeHint, "status", BottomEdgeHint.Active, 400);
 
210
            // then wait till we get back to Idle
 
211
            tryCompare(bottomEdgeHint, "status", BottomEdgeHint.Inactive, 1000);
72
212
        }
73
213
    }
74
214
}