Debian Codegraph @

tests/unit/visual13/tst_combobutton.11.qml

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.0
18 import QtTest 1.0
19 import Lomiri.Test 1.0
20 import Lomiri.Components 1.1
21 import Lomiri.Components.ListItems 1.0
22
23 Item {
24 width: units.gu(40)
25 height: units.gu(71)
26
27 Column {
28 ComboButton {
29 id: combo
30 }
31
32 ComboButton {
33 id: rectCombo
34 onClicked: expanded = false
35
36 Rectangle {
37 id: rect
38 width: parent.width
39 height: units.gu(40)
40 gradient: Gradient {
41 GradientStop {
42 position: 0.0
43 color: "red"
44 }
45 GradientStop {
46 position: 0.5
47 color: "green"
48 }
49 GradientStop {
50 position: 1.0
51 color: "blue"
52 }
53 }
54 }
55 }
56
57 ComboButton {
58 id: columnCombo
59 expandedHeight: -1
60 Column {
61 id: column
62 anchors {
63 left: parent.left
64 right: parent.right
65 }
66 height: childrenRect.height
67 Repeater {
68 model: 5
69 Rectangle {
70 width: parent.width
71 height: units.gu(5)
72 color: Qt.rgba(Math.random(1), Math.random(1), Math.random(1), 1);
73 }
74 }
75 }
76 }
77
78 ComboButton {
79 id: longCombo
80 expandedHeight: units.gu(40)
81 Rectangle {
82 id: longRect
83 height: units.gu(10)
84 color: "cyan"
85 }
86 }
87
88 ComboButton {
89 id: listCombo
90 ListView {
91 id: list
92 model: 20
93 height: listCombo.comboListHeight
94 delegate: Standard {
95 text: modelData
96 }
97 }
98 }
99 }
100
101 SignalSpy { id: spy }
102
103 LomiriTestCase {
104 name: "ComboButton"
105 when: windowShown
106
107 function cleanup() {
108 rectCombo.expanded =
109 columnCombo.expanded =
110 longCombo.expanded =
111 listCombo.expanded = false;
112 spy.clear();
113 spy.signalName = "";
114 spy.target = undefined;
115 }
116
117 function test_0_defaults() {
118 compare(combo.expanded, false, "not expanded by default");
119 compare(combo.collapsedHeight, combo.implicitHeight, "collapsedHeight is implicitHeight");
120 compare(combo.expandedHeight, combo.collapsedHeight + units.gu(19.5), "expanded height default");
121 var lheight = combo.expandedHeight - combo.collapsedHeight - combo.__styleInstance.comboListMargin;
122 compare(combo.comboListHeight, lheight, "comboListHeight default");
123 compare(combo.comboList.length, 0, "comboList is empty");
124 verify(combo.font === Qt.font({family: "Ubuntu", pixelSize: FontUtils.sizeToPixels("medium")}), "Default font differs.");
125 verify(combo.dropdownColor === combo.__styleInstance.defaultDropdownColor, "Default dropdown color differs");
126 }
127
128 function test_dropdownColor() {
129 rectCombo.dropdownColor = rectCombo.expanded ? "red" : "green";
130 rectCombo.expanded = false;
131 var dropdownFace = findChild(rectCombo, "combobutton_dropdown_visuals");
132 verify(dropdownFace, "Dropdown button visuals cannot be reached");
133 verify(dropdownFace.color === rectCombo.dropdownColor, "Dropdon color when collapsed wrong");
134 rectCombo.expanded = true;
135 waitForRendering(rectCombo);
136 verify(dropdownFace.color === rectCombo.dropdownColor, "Dropdon color when expanded wrong");
137 }
138
139 function test_comboListWidth() {
140 var comboListHolder = findChild(rectCombo, "combobutton_combolist");
141 compare(rect.width, comboListHolder.width, "rectCombo list content width is not adjusted");
142 comboListHolder = findChild(columnCombo, "combobutton_combolist");
143 compare(column.width, comboListHolder.width, "columnCombo list content width is not adjusted");
144 comboListHolder = findChild(longCombo, "combobutton_combolist");
145 compare(longRect.width, comboListHolder.width, "longCombo list content width is not adjusted");
146 comboListHolder = findChild(listCombo, "combobutton_combolist");
147 compare(list.width, comboListHolder.width, "listCombo list content width is not adjusted");
148 }
149
150 function test_expandRectComboThroughProperty() {
151 rectCombo.expanded = true;
152 waitForRendering(rectCombo);
153 var comboListPanel = findChild(rectCombo, "combobutton_combopanel");
154 tryCompareFunction(function() { return comboListPanel.opacity}, 1.0);
155 }
156
157 function test_expandRectComboThroughClick() {
158 var dropDown = findChild(rectCombo, "combobutton_dropdown");
159 mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2);
160 waitForRendering(rectCombo);
161 compare(rectCombo.expanded, true, "combo is not expanded");
162 var comboListPanel = findChild(rectCombo, "combobutton_combopanel");
163 tryCompareFunction(function() { return comboListPanel.opacity}, 1.0);
164 }
165
166 function test_autoCollapse() {
167 var dropDown = findChild(rectCombo, "combobutton_dropdown");
168 var comboListPanel = findChild(rectCombo, "combobutton_combopanel");
169 mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2);
170 waitForRendering(rectCombo);
171 compare(rectCombo.expanded, true, "combo is not expanded");
172 tryCompareFunction(function() { return comboListPanel.opacity}, 1.0);
173
174 mouseClick(rectCombo, rectCombo.width / 2, rectCombo.collapsedHeight / 2);
175 waitForRendering(rectCombo);
176 compare(rectCombo.expanded, false, "combo is not collapsed");
177 tryCompareFunction(function() { return comboListPanel.opacity}, 0.0);
178 }
179
180 function test_flickRectCombo() {
181 var dropDown = findChild(rectCombo, "combobutton_dropdown");
182 var comboListPanel = findChild(rectCombo, "combobutton_combopanel");
183 var comboList = findChild(rectCombo, "combobutton_combolist");
184 mouseClick(dropDown, dropDown.width / 2, dropDown.height / 2);
185 waitForRendering(rectCombo);
186 tryCompareFunction(function() { return comboListPanel.opacity}, 1.0);
187 verify(comboList.height > rectCombo.expandedHeight);
188 // comboList flicker is the combolist parent's parent
189 var comboListFlicker = findChild(rectCombo, "combobutton_contentflicker");
190 compare(comboListFlicker.interactive, true, "combo list holder must be interactive");
191
192 // drag the rectangle, the Flickable should be moving
193 var x = comboListFlicker.width / 2;
194 var y = comboListFlicker.height / 2;
195 var dy = comboListFlicker.height / 3;
196 spy.target = comboListFlicker;
197 spy.signalName = "onMovementEnded";
198
199 // Split the draging event into at least 2 mouseMove() instead of
200 // single mouseDrag(), as Qt's Flickable seems not to send out
201 // movement{Started,Ended} if there's only a single mouseMove() event.
202 // https://bugreports.qt.io/browse/QTBUG-92600
203 mousePress(comboList, x, y);
204 mouseMove(comboList, x, y - (dy / 2));
205 mouseMove(comboList, x, y - dy);
206 mouseRelease(comboList, x, y - dy);
207
208 waitForRendering(comboListFlicker);
209 spy.wait();
210 }
211
212 function test_autoExpandHeight() {
213 var comboListPanel = findChild(columnCombo, "combobutton_combopanel");
214 var comboList = findChild(columnCombo, "combobutton_combolist");
215 columnCombo.expanded = true;
216 waitForRendering(columnCombo);
217 tryCompareFunction(function() { return comboListPanel.opacity}, 1.0);
218 var comboListFlicker = findChild(columnCombo, "combobutton_contentflicker");
219 compare(comboListFlicker.interactive, false, "combo list holder must not be interactive");
220 compare(comboListFlicker.height, columnCombo.comboListHeight, "combo list height differs from the holder height");
221 }
222
223 function test_emptyComboExpanded() {
224 var comboListPanel = findChild(combo, "combobutton_combopanel");
225 var comboList = findChild(combo, "combobutton_combolist");
226 combo.expanded = true;
227 waitForRendering(combo);
228 waitForRendering(comboListPanel);
229 tryCompareFunction(function() { return comboListPanel.opacity}, 0.0, 1000);
230 }
231
232 function test_longCombo() {
233 var comboListPanel = findChild(longCombo, "combobutton_combopanel");
234 var comboList = findChild(longCombo, "combobutton_combolist");
235 longCombo.expanded = true;
236 waitForRendering(longCombo);
237 waitForRendering(comboListPanel);
238 tryCompareFunction(function() { return comboListPanel.opacity}, 1.0);
239 verify(comboListPanel.height < longCombo.expandedHeight);
240 }
241
242 function test_listCombo() {
243 var comboListPanel = findChild(listCombo, "combobutton_combopanel");
244 var comboList = findChild(listCombo, "combobutton_combolist");
245 listCombo.expanded = true;
246 waitForRendering(listCombo);
247 waitForRendering(comboListPanel);
248 tryCompareFunction(function() { return comboListPanel.opacity}, 1.0);
249
250 compare(list.height, comboList.height, "list and comboList height differs");
251 }
252 }
253 }