Merge lp:~gerboland/unity/lvwph-tests into lp:unity/phablet

Proposed by Gerry Boland
Status: Merged
Approved by: Michael Zanetti
Approved revision: no longer in the source branch.
Merged at revision: 592
Proposed branch: lp:~gerboland/unity/lvwph-tests
Merge into: lp:unity/phablet
Diff against target: 396 lines (+357/-2)
4 files modified
Components/ListViewWithPageHeader.qml (+4/-0)
tests/qmluitests/Components/CMakeLists.txt (+1/-0)
tests/qmluitests/Components/tst_ListViewWithPageHeader.qml (+350/-0)
tests/qmluitests/UnityTestCase.qml (+2/-2)
To merge this branch: bzr merge lp:~gerboland/unity/lvwph-tests
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michael Zanetti (community) Approve
Review via email: mp+158336@code.launchpad.net

Commit message

[tests] Add ListViewWithPageHeader tests

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

The above failure should go away with lp:~saviq/unity/phablet.add-python3-dep

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

looks good to me. Jenkins seems happy too

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Components/ListViewWithPageHeader.qml'
2--- Components/ListViewWithPageHeader.qml 2013-02-27 17:36:32 +0000
3+++ Components/ListViewWithPageHeader.qml 2013-04-12 15:11:26 +0000
4@@ -64,6 +64,10 @@
5 headerAnimation.start()
6 }
7
8+ function flick(xVelocity, yVelocity) {
9+ flicker.flick(xVelocity, yVelocity);
10+ }
11+
12 onPageHeaderChanged: {
13 pageHeader.parent = pageHeaderContainer;
14 pageHeader.anchors.fill = pageHeaderContainer;
15
16=== modified file 'tests/qmluitests/Components/CMakeLists.txt'
17--- tests/qmluitests/Components/CMakeLists.txt 2013-04-12 12:49:20 +0000
18+++ tests/qmluitests/Components/CMakeLists.txt 2013-04-12 15:11:26 +0000
19@@ -1,5 +1,6 @@
20 add_qml_test(DraggingArea)
21 add_qml_test(FilterGrid IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins)
22+add_qml_test(ListViewWithPageHeader)
23 add_qml_test(ResponsiveFlowView)
24 add_qml_test(ResponsiveGridView)
25 add_qml_test(Revealer)
26
27=== added file 'tests/qmluitests/Components/tst_ListViewWithPageHeader.qml'
28--- tests/qmluitests/Components/tst_ListViewWithPageHeader.qml 1970-01-01 00:00:00 +0000
29+++ tests/qmluitests/Components/tst_ListViewWithPageHeader.qml 2013-04-12 15:11:26 +0000
30@@ -0,0 +1,350 @@
31+/*
32+ * Copyright 2013 Canonical Ltd.
33+ *
34+ * This program is free software; you can redistribute it and/or modify
35+ * it under the terms of the GNU General Public License as published by
36+ * the Free Software Foundation; version 3.
37+ *
38+ * This program is distributed in the hope that it will be useful,
39+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
40+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41+ * GNU General Public License for more details.
42+ *
43+ * You should have received a copy of the GNU General Public License
44+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
45+ */
46+
47+import QtQuick 2.0
48+import QtTest 1.0
49+import ".."
50+import "../../../Components"
51+import Ubuntu.Components.ListItems 0.1 as ListItem
52+import Ubuntu.Components 0.1
53+
54+Item {
55+ id: root
56+ width: units.gu(40)
57+ height: units.gu(80)
58+
59+ ListModel {
60+ id: animalsModel
61+ ListElement { name: "Parrot"; size: "Small" }
62+ ListElement { name: "Guinea pig"; size: "Small" }
63+ ListElement { name: "Mouse"; size: "Small" }
64+ ListElement { name: "Sparrow"; size: "Small" }
65+ ListElement { name: "Dog"; size: "Medium" }
66+ ListElement { name: "Cat"; size: "Medium" }
67+ ListElement { name: "Dolphin"; size: "Medium" }
68+ ListElement { name: "Seal"; size: "Medium" }
69+ ListElement { name: "Elephant"; size: "Large" }
70+ ListElement { name: "Blue whale"; size: "Large" }
71+ ListElement { name: "Rhino"; size: "Large" }
72+ ListElement { name: "Ostrich"; size: "Large" }
73+ ListElement { name: "Sperm whale"; size: "Large" }
74+ ListElement { name: "Giraffe"; size: "Large" }
75+ ListElement { name: "Parrot"; size: "Small" }
76+ ListElement { name: "Guinea pig"; size: "Small" }
77+ ListElement { name: "Mouse"; size: "Small" }
78+ ListElement { name: "Sparrow"; size: "Small" }
79+ ListElement { name: "Dog"; size: "Medium" }
80+ ListElement { name: "Cat"; size: "Medium" }
81+ ListElement { name: "Dolphin"; size: "Medium" }
82+ ListElement { name: "Seal"; size: "Medium" }
83+ ListElement { name: "Elephant"; size: "Large" }
84+ ListElement { name: "Blue whale"; size: "Large" }
85+ ListElement { name: "Rhino"; size: "Large" }
86+ ListElement { name: "Ostrich"; size: "Large" }
87+ ListElement { name: "Sperm whale"; size: "Large" }
88+ ListElement { name: "Giraffe"; size: "Large" }
89+ ListElement { name: "Parrot"; size: "Small" }
90+ ListElement { name: "Guinea pig"; size: "Small" }
91+ ListElement { name: "Mouse"; size: "Small" }
92+ ListElement { name: "Sparrow"; size: "Small" }
93+ ListElement { name: "Dog"; size: "Medium" }
94+ ListElement { name: "Cat"; size: "Medium" }
95+ ListElement { name: "Dolphin"; size: "Medium" }
96+ ListElement { name: "Seal"; size: "Medium" }
97+ ListElement { name: "Elephant"; size: "Large" }
98+ ListElement { name: "Blue whale"; size: "Large" }
99+ ListElement { name: "Rhino"; size: "Large" }
100+ ListElement { name: "Ostrich"; size: "Large" }
101+ ListElement { name: "Sperm whale"; size: "Large" }
102+ ListElement { name: "Giraffe"; size: "Large" }
103+ ListElement { name: "Parrot"; size: "Small" }
104+ ListElement { name: "Guinea pig"; size: "Small" }
105+ ListElement { name: "Mouse"; size: "Small" }
106+ ListElement { name: "Sparrow"; size: "Small" }
107+ ListElement { name: "Dog"; size: "Medium" }
108+ ListElement { name: "Cat"; size: "Medium" }
109+ ListElement { name: "Dolphin"; size: "Medium" }
110+ ListElement { name: "Seal"; size: "Medium" }
111+ ListElement { name: "Elephant"; size: "Large" }
112+ ListElement { name: "Blue whale"; size: "Large" }
113+ ListElement { name: "Rhino"; size: "Large" }
114+ ListElement { name: "Ostrich"; size: "Large" }
115+ ListElement { name: "Sperm whale"; size: "Large" }
116+ ListElement { name: "Giraffe"; size: "Large" }
117+ }
118+
119+ ListViewWithPageHeader {
120+ id: listView
121+ anchors.fill: parent
122+ model: animalsModel
123+
124+ delegate: Item {
125+ height: units.gu(6)
126+ anchors {
127+ left: parent.left
128+ right: parent.right
129+ }
130+
131+ Label {
132+ id: label
133+ anchors.fill: parent
134+ text: name
135+ verticalAlignment: Text.AlignVCenter
136+ }
137+ }
138+
139+ sectionProperty: "size"
140+ sectionDelegate: Rectangle {
141+ anchors {
142+ left: (parent) ? parent.left : undefined
143+ right: (parent) ? parent.right : undefined
144+ }
145+ height: units.gu(5)
146+ color: "lightsteelblue"
147+
148+ Label {
149+ id: label
150+ anchors.fill: parent
151+ text: section
152+ verticalAlignment: Text.AlignVCenter
153+ }
154+ }
155+
156+ pageHeader: PageHeader {
157+ id: pageHeader
158+ anchors {
159+ left: parent.left
160+ right: parent.right
161+ }
162+ text: "Animals"
163+ }
164+ }
165+
166+
167+
168+
169+ UnityTestCase {
170+ name: "ListViewWithPageHeader"
171+ when: windowShown
172+
173+ readonly property real xPos: listView.width / 2
174+ readonly property real headerHeight: pageHeader.height
175+
176+ /**************************** Helper functions ****************************/
177+ function listViewFirstSectionHeaderYPosition() {
178+ return Math.round(listView.pageHeader.mapToItem(listView).y); //round as using floats
179+ }
180+
181+ function firstSectionHeaderYPosition() {
182+ return Math.round(listView.view.children[0].mapToItem(listView).y);
183+ }
184+
185+ function cleanup() {
186+ listView.positionAtBeginning();
187+ // wait for list position to reset
188+ tryCompareFunction(listViewFirstSectionHeaderYPosition, 0);
189+ tryCompare(listView.view.contentY, 0);
190+ }
191+
192+ // these functions are hand-crafted to move the Flickable down/up one pixel
193+ function swipeDown1Pixel(item) {
194+ mousePress(item, xPos, 15);
195+ mouseMove(item, xPos, 14, 100);
196+ mouseMove(item, xPos, 10, 100);
197+ mouseMove(item, xPos, 6, 100);
198+ mouseMove(item, xPos, 3, 100);
199+ mouseMove(item, xPos, 1, 100);
200+ mouseMove(item, xPos, 0, 100);
201+ mouseRelease(item, xPos, 0);
202+ }
203+
204+ function swipeUp1Pixel(item) {
205+ mousePress(item, xPos, 0);
206+ mouseMove(item, xPos, 1, 100);
207+ mouseMove(item, xPos, 5, 100);
208+ mouseMove(item, xPos, 9, 100);
209+ mouseMove(item, xPos, 12, 100);
210+ mouseMove(item, xPos, 14, 100);
211+ mouseMove(item, xPos, 15, 100);
212+ mouseRelease(item, xPos, 15);
213+ }
214+
215+ /******************************* Test cases *******************************/
216+
217+ /* Check the initial positions of components are correct */
218+ function test_initialState() {
219+ compare(listViewFirstSectionHeaderYPosition(), 0);
220+ compare(listView.view.contentY, 0);
221+
222+ // Check that the section delegate is positioned underneath the header
223+ // First section delegate is the first child of the view
224+ tryCompareFunction(firstSectionHeaderYPosition, headerHeight);
225+ }
226+
227+ /* Check the header moves up one pixel when the view is moved up by one pixel */
228+ function test_headerPositionAfterDownMoveByOnePixel() {
229+ swipeDown1Pixel(listView)
230+
231+ tryCompareFunction(listViewFirstSectionHeaderYPosition, -1);
232+ tryCompareFunction(firstSectionHeaderYPosition, headerHeight - 1);
233+ tryCompare(listView.view.contentY, -1);
234+ }
235+
236+ /* Check the header position is y=0 when view moved up and then down by one pixel */
237+ function test_headerPositionAfterDownAndThenUpMoveByOne() {
238+ swipeDown1Pixel(listView)
239+
240+ tryCompareFunction(listViewFirstSectionHeaderYPosition, -1);
241+ tryCompare(listView.view.contentY, -1);
242+
243+ // these operations move the Flickabe up one pixel
244+ swipeUp1Pixel(listView);
245+
246+ tryCompare(listView.view.contentY, 0);
247+ // tryCompareFunction(listViewFirstSectionHeaderYPosition, 0) //FIXME - this fails due to bug in LVWPH
248+ tryCompareFunction(firstSectionHeaderYPosition, headerHeight)
249+ }
250+
251+ /* Check after a big flick the header is moved off-screen, with the header bottom
252+ placed just above the view */
253+ function test_headerPositionAfterDownMove() {
254+ // move the Flickabe up to hide header
255+ listView.flick(0, -10000);
256+
257+ // wait for flick to finish
258+ tryCompare(listView.moving, false);
259+
260+ tryCompareFunction(listViewFirstSectionHeaderYPosition, -headerHeight);
261+ }
262+
263+ /* Check when header off-screen, moving down the view by one pixel moves the header
264+ down by one pixel */
265+ function test_hiddenHeaderPositionAfterUpMoveByOnePixel() {
266+ // move the Flickabe up to hide header
267+ listView.flick(0, -10000);
268+
269+ // wait for flick to fully hide header
270+ tryCompareFunction(listViewFirstSectionHeaderYPosition, -headerHeight);
271+
272+ swipeUp1Pixel(listView);
273+
274+ tryCompareFunction( function() {
275+ return Math.floor( listViewFirstSectionHeaderYPosition() ); // need to round to make test more robust
276+ }, -headerHeight + 1);
277+ }
278+
279+ /* Check if up swipe causes list to bounces at the bottom, header stays hidden */
280+ function test_upSwipeCausingBounceKeepsHeaderHidden() {
281+ // move list to the bottom (will bounce)
282+ listView.flick(0, -1000000);
283+
284+ // wait for bounce to complete
285+ tryCompare(listView.moving, false);
286+ tryCompare(listView.view.atYEnd, true);
287+
288+ tryCompareFunction(listViewFirstSectionHeaderYPosition, -headerHeight);
289+ }
290+
291+ /* Check if up swipe causes list to bounces at the bottom, header stays hidden */
292+ function test_downSwipeCausingBounceKeepsHeaderVisible() {
293+ // move list to the bottom (will bounce)
294+ listView.flick(0, -1000000);
295+
296+ // wait for bounce to complete
297+ tryCompare(listView.moving, false);
298+ tryCompare(listView.view.atYBeginning, true);
299+
300+ tryCompareFunction(listViewFirstSectionHeaderYPosition, 0);
301+ }
302+
303+ /* Check if list at top is pulled down further, that the list contents move but the
304+ header remains at the top of the view */
305+ function test_topDragOverBoundsKeepsHeaderVisible() {
306+ // drag list up - but don't release yet
307+ mouseFlick(listView,
308+ xPos, // from_x
309+ 0, // from_y
310+ xPos, // to_x
311+ 100, true, false, 0.2);
312+
313+ // wait for gesture to occur
314+ tryCompareFunction(function() { return listView.view.contentY < 20; }, true);
315+ tryCompareFunction(listViewFirstSectionHeaderYPosition, 0);
316+
317+ mouseRelease(listView, xPos, 400);
318+
319+ // ensure list moving to recover from over-bound drag keeps header unchanged
320+ tryCompare(listView.view.contentY, 0);
321+ tryCompareFunction(listViewFirstSectionHeaderYPosition, 0);
322+ }
323+
324+ /* Check if list at top is pulled down further, that the list contents move but the
325+ header remains at the top of the view */
326+ function test_bottomDragOverBoundsKeepsHeaderHidden() {
327+ // move list to the bottom (will bounce)
328+ listView.flick(0, -1000000);
329+
330+ // wait for bounce to complete
331+ tryCompare(listView.moving, false);
332+ tryCompare(listView.view.atYEnd, true);
333+
334+ // drag list up but don't release
335+ mouseFlick(listView,
336+ xPos, // from_x
337+ 0, // from_y
338+ xPos, // to_x
339+ -listView.height, true, false);
340+
341+ tryCompareFunction(listViewFirstSectionHeaderYPosition, -headerHeight);
342+
343+ mouseRelease(listView, xPos, -listView.height);
344+ // wait for list to reset position
345+ tryCompare(listView.moving, false);
346+ tryCompare(listView.view.atYEnd, true);
347+
348+ // ensure list moving to recover from over-bound drag keeps header unchanged
349+ tryCompareFunction(listViewFirstSectionHeaderYPosition, -headerHeight);
350+ }
351+
352+ /* Check positionAtBeginning() works resets list and header position */
353+ function test_positionAtBeginning() {
354+ // move the Flickabe up to hide header
355+ listView.flick(0, -10000);
356+
357+ // wait for gesture to complete
358+ tryCompare(listView.moving, false);
359+
360+ listView.positionAtBeginning();
361+ tryCompareFunction(listViewFirstSectionHeaderYPosition, 0);
362+ tryCompare(listView.view.contentY, 0);
363+ }
364+
365+ /* Check showHeader forces header to appear but list position remains unchanged */
366+ function test_showHeader() {
367+ // move the Flickabe up to hide header
368+ listView.flick(0, -10000);
369+
370+ // wait for gesture to complete
371+ tryCompare(listView.moving, false);
372+
373+ var listContentY = listView.view.contentY;
374+
375+ listView.showHeader();
376+ tryCompareFunction(listViewFirstSectionHeaderYPosition, 0);
377+ tryCompare(listView.view.contentY, listContentY);
378+ }
379+ }
380+}
381
382=== modified file 'tests/qmluitests/UnityTestCase.qml'
383--- tests/qmluitests/UnityTestCase.qml 2013-04-05 11:03:11 +0000
384+++ tests/qmluitests/UnityTestCase.qml 2013-04-12 15:11:26 +0000
385@@ -54,9 +54,9 @@
386 if (i === nIterations - 1) {
387 // Avoid any rounding errors by making the last move be at precisely
388 // the point specified
389- mouseMove(item, toX, toY)
390+ mouseMove(item, toX, toY, nIterations / speed)
391 } else {
392- mouseMove(item, x + (i + 1) * diffX, y + (i + 1) * diffY)
393+ mouseMove(item, x + (i + 1) * diffX, y + (i + 1) * diffY, nIterations / speed)
394 }
395 }
396 if (releaseMouse) {

Subscribers

People subscribed via source and target branches