on xenial help sign in
Fix tests under Qt 5.2.
commit7ee0a6d792936bd482636e5eb49f2da503c0037b authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 14 Mar 2014, 15:44 (13 years ago) parent5ff23705943489
15 files changed+66−66
plugins/DashViews/listviewwithpageheader.cpp+33−10 qml/Components/Stage.qml+4−6 tests/plugins/DashViews/listviewwithpageheadertest.cpp−6 tests/plugins/DashViews/listviewwithpageheadertestsection.cpp−3 tests/qmltests/Components/tst_DragHandle.cpp−1 tests/qmltests/Components/tst_LazyImage.qml+1−1 tests/qmltests/Dash/Previews/tst_PreviewVideoPlayback.qml−6 tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+3−4 tests/qmltests/Dash/tst_CardHeader.qml+1−1 tests/qmltests/Dash/tst_DashContent.qml+1−1 tests/qmltests/Dash/tst_GenericPreview.qml+2−2 tests/qmltests/Dash/tst_GenericScopeView.qml+3−3 tests/qmltests/Launcher/tst_Launcher.qml+6−4 tests/qmltests/tst_Shell.qml+2−2 tests/utils/modules/Unity/Test/UnityTestCase.qml+10−16
plugins/DashViews/listviewwithpageheader.cpp+33−10
@@ -91,6 +91,7 @@
9191
9292#include "listviewwithpageheader.h"
9393
94+#include <QCoreApplication>
9495#include <QDebug>
9596#include <qqmlinfo.h>
9697#include <qqmlengine.h>
@@ -477,6 +478,11 @@ void ListViewWithPageHeader::componentComplete()
477478 polish();
478479}
479480
481+static inline bool uFuzzyCompare(qreal r1, qreal r2)
482+{
483+ return qFuzzyCompare(r1, r2) || (qFuzzyIsNull(r1) && qFuzzyIsNull(r2));
484+}
485+
480486void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
481487{
482488 // Check we are not being taken down and don't paint anything
@@ -491,11 +497,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
491497 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
492498 if (m_headerItem) {
493499 const auto oldHeaderItemShownHeight = m_headerItemShownHeight;
494− if (contentY() < -m_minYExtent) {
495− // Stick the header item to the top when dragging down
496− m_headerItem->setY(contentY());
497− m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
498− } else {
500+ if (uFuzzyCompare(contentY(), -m_minYExtent) || contentY() > -m_minYExtent) {
499501 m_headerItem->setHeight(m_headerItem->implicitHeight());
500502 // We are going down (but it's not because of the rebound at the end)
501503 // (but the header was not shown by it's own position)
@@ -509,21 +511,32 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
509511 m_headerItemShownHeight = 0;
510512 m_headerItem->setY(-m_minYExtent);
511513 } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
512− if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
514+ if (maximizeVisibleAreaRunning && diff > 0) {
515+ // If we are maximizing and the header was shown, make sure we hide it
513516 m_headerItemShownHeight -= diff;
514− else
517+ } else {
515518 m_headerItemShownHeight += diff;
516− if (contentY() == -m_minYExtent) {
519+ }
520+ if (uFuzzyCompare(contentY(), -m_minYExtent)) {
517521 m_headerItemShownHeight = 0;
518522 } else {
519523 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
520524 }
521525 if (m_headerItemShownHeight > 0) {
522− m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
526+ if (uFuzzyCompare(m_headerItem->height(), m_headerItemShownHeight)) {
527+ m_headerItem->setY(contentY());
528+ m_headerItemShownHeight = m_headerItem->height();
529+ } else {
530+ m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
531+ }
523532 } else {
524533 m_headerItem->setY(-m_minYExtent);
525534 }
526535 }
536+ } else {
537+ // Stick the header item to the top when dragging down
538+ m_headerItem->setY(contentY());
539+ m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
527540 }
528541 // We will be changing the clip item, need to accomadate for it
529542 // otherwise we move the firstItem down/up twice (unless the
@@ -1128,7 +1141,12 @@ void ListViewWithPageHeader::adjustMinYExtent()
11281141 nonCreatedHeight = m_firstVisibleIndex * visibleItemsHeight / visibleItems;
11291142// qDebug() << m_firstVisibleIndex << visibleItemsHeight << visibleItems << nonCreatedHeight;
11301143 }
1131− m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + (m_headerItem ? m_headerItem->implicitHeight() : 0);
1144+ const qreal headerHeight = (m_headerItem ? m_headerItem->implicitHeight() : 0);
1145+ m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + headerHeight;
1146+ if (m_minYExtent != 0 && qFuzzyIsNull(m_minYExtent)) {
1147+ m_minYExtent = 0;
1148+ m_visibleItems.first()->setY(nonCreatedHeight - m_clipItem->y() + headerHeight);
1149+ }
11321150 }
11331151}
11341152
@@ -1264,6 +1282,11 @@ void ListViewWithPageHeader::updatePolish()
12641282 refill();
12651283
12661284 if (m_contentHeightDirty) {
1285+ // We need to make sure all bindings have updated otherwise
1286+ // we may end up with bindings updating when we call setContentHeight
1287+ // and then everything gets out of sync, i.e. testHeaderPositionBug1240118
1288+ QCoreApplication::instance()->processEvents();
1289+
12671290 qreal contentHeight;
12681291 if (m_visibleItems.isEmpty()) {
12691292 contentHeight = m_headerItem ? m_headerItem->height() : 0;
qml/Components/Stage.qml+4−6
@@ -329,13 +329,11 @@ Showable {
329329
330330 ScriptAction {
331331 script: {
332− if (!stage.focusedApplicationWhenUsingScreenshots) {
333− // FIXME: only here to support case where application does
334− // not exist yet but is about to
335− return;
332+ // FIXME: only here to support case where application does
333+ // not exist yet but is about to
334+ if (stage.focusedApplicationWhenUsingScreenshots) {
335+ stage.__focusApplication(stage.focusedApplicationWhenUsingScreenshots);
336336 }
337−
338− stage.__focusApplication(stage.focusedApplicationWhenUsingScreenshots);
339337 }
340338 }
341339 }
tests/plugins/DashViews/listviewwithpageheadertest.cpp−6
@@ -1281,9 +1281,6 @@ private Q_SLOTS:
12811281
12821282 void testShowHeaderHalfShown()
12831283 {
1284−#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
1285− QSKIP("This test is extremely unstable in 5.0.x");
1286−#endif
12871284 changeContentY(20);
12881285
12891286 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
@@ -1860,9 +1857,6 @@ private Q_SLOTS:
18601857 model->setProperty(4, "size", 10);
18611858 model->setProperty(5, "size", 10);
18621859 model->setProperty(6, "size", 10);
1863−#if (QT_VERSION > QT_VERSION_CHECK(5, 0, 3))
1864− QTRY_COMPARE(lvwph->m_minYExtent, 210.);
1865−#endif
18661860 QTRY_COMPARE(lvwph->m_headerItem->y(), -lvwph->m_minYExtent);
18671861 }
18681862
tests/plugins/DashViews/listviewwithpageheadertestsection.cpp−3
@@ -1486,9 +1486,6 @@ private Q_SLOTS:
14861486
14871487 void testShowHeaderHalfShown()
14881488 {
1489−#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
1490− QSKIP("This test is extremely unstable in 5.0.x");
1491−#endif
14921489 changeContentY(20);
14931490
14941491 QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
tests/qmltests/Components/tst_DragHandle.cpp−1
@@ -126,7 +126,6 @@ QQuickView *tst_DragHandle::createView()
126126{
127127 QQuickView *window = new QQuickView(0);
128128 window->setResizeMode(QQuickView::SizeRootObjectToView);
129− window->resize(600, 600);
130129 window->engine()->addImportPath(QLatin1String(UBUNTU_GESTURES_PLUGIN_DIR));
131130 window->engine()->addImportPath(QLatin1String(TEST_DIR));
132131
tests/qmltests/Components/tst_LazyImage.qml+1−1
@@ -155,7 +155,7 @@ Rectangle {
155155
156156 if (data.transition) {
157157 // wait for the transition to complete
158− var transition = findInvisibleChild(data.image, data.transition);
158+ var transition = findChildIn(data.image, "transitions", data.transition);
159159 tryCompare(transition, "running", true);
160160 tryCompare(transition, "running", false);
161161 }
tests/qmltests/Dash/Previews/tst_PreviewVideoPlayback.qml−6
@@ -53,12 +53,6 @@ Rectangle {
5353 function test_loadScreenshot() {
5454 var screenshot = findChild(videoPlayback, "screenshot");
5555
56− videoPlayback.widgetData = widgetData0;
57− tryCompare(screenshot.visible, false);
58−
59− videoPlayback.widgetData = widgetData1;
60− tryCompare(screenshot.visible, true);
61−
6256 videoPlayback.widgetData = widgetData2;
6357 var screenshotSource = screenshot.source
6458 verify(screenshotSource.toString().indexOf("image://thumbnailer/") === 0)
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+3−4
@@ -30,14 +30,13 @@ Rectangle {
3030 }
3131
3232 property var widgetData1: {
33− "source": "../../graphics/phone_background.jpg",
33+ "source": Qt.resolvedUrl("../artwork/checkers.png"),
3434 "zoomable": false
3535 }
3636
3737 PreviewZoomableImage {
3838 id: zoomableImage
3939 width: parent.width
40− widgetData: widgetData1
4140 }
4241
4342 UT.UnityTestCase {
@@ -48,10 +47,10 @@ Rectangle {
4847 var image = findChild(zoomableImage, "image");
4948
5049 zoomableImage.widgetData = widgetData0;
51− tryCompare(image.state, "default");
50+ tryCompare(image, "state", "default");
5251
5352 zoomableImage.widgetData = widgetData1;
54− tryCompare(image.state, "ready");
53+ tryCompare(image, "state", "ready");
5554 }
5655 }
5756}
tests/qmltests/Dash/tst_CardHeader.qml+1−1
@@ -122,7 +122,7 @@ Rectangle {
122122 return [
123123 { tag: "Column width", object: column, width: cardHeader.width },
124124 { tag: "Column width with mascot", object: column, width: cardHeader.width - mascot.width - outerRow.margins * 3, mascot: "artwork/avatar.png" },
125− { tag: "Header height", object: cardHeader, height: function() { return subtitleLabel.y + subtitleLabel.height + outerRow.margins * 2 } },
125+ { tag: "Header height", object: cardHeader, height: function() { return outerRow.height + outerRow.margins * 2 } },
126126 ]
127127 }
128128
tests/qmltests/Dash/tst_DashContent.qml+1−1
@@ -284,7 +284,7 @@ Item {
284284 tryCompare(scopesModel, "loaded", true);
285285 var tabbar = findChild(dashContent, "tabbar");
286286
287− compare(dashContent.currentIndex, 0);
287+ tryCompare(dashContent, "currentIndex", 0);
288288 tryCompare(tabbar, "selectedIndex", 0);
289289 tryCompare(tabbar, "selectionMode", false);
290290
tests/qmltests/Dash/tst_GenericPreview.qml+2−2
@@ -22,7 +22,7 @@ import Unity.Test 0.1 as UT
2222Item {
2323 id: root
2424 width: units.gu(60)
25− height: units.gu(80)
25+ height: units.gu(90)
2626
2727 property var calls: []
2828 property int counter: 0
@@ -81,7 +81,7 @@ Item {
8181
8282 var actions = get_actions_data();
8383 for(var i = 0; i < actions.length; i++) {
84− compare(root.calls[i], actions[i].id);
84+ tryCompare(root.calls, i, actions[i].id);
8585 }
8686 }
8787
tests/qmltests/Dash/tst_GenericScopeView.qml+3−3
@@ -67,7 +67,7 @@ Item {
6767 function init() {
6868 shell.width = units.gu(120)
6969 genericScopeView.categoryView.positionAtBeginning();
70− tryCompare(genericScopeView.categoryView.contentY, 0)
70+ tryCompare(genericScopeView.categoryView, "contentY", 0)
7171 }
7272
7373 function test_isCurrent() {
@@ -184,13 +184,13 @@ Item {
184184 categoryListView.positionAtBeginning();
185185 waitForRendering(categoryListView);
186186 categoryListView.flick(0, -units.gu(60));
187− tryCompare(categoryListView.flicking, false);
187+ tryCompare(categoryListView, "flicking", false);
188188
189189 var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
190190 mouseClick(tile, tile.width / 2, tile.height - 1);
191191 tryCompare(openEffect, "gap", 1);
192192
193− verify(openEffect.positionPx >= pageHeader.height + categoryListView.stickyHeaderHeight);
193+ verify(openEffect.positionPx >= Math.round(pageHeader.height + categoryListView.stickyHeaderHeight));
194194 }
195195
196196 function test_previewCycle() {
tests/qmltests/Launcher/tst_Launcher.qml+6−4
@@ -121,8 +121,7 @@ Item {
121121 revealer.dragLauncherIntoView()
122122
123123 var listView = findChild(launcher, "launcherListView");
124− listView.flick(0, units.gu(500));
125− tryCompare(listView, "flicking", false);
124+ listView.positionViewAtEnd();
126125
127126 var appIcon = findChild(launcher, "launcherDelegate0")
128127
@@ -397,8 +396,11 @@ Item {
397396
398397 // Position launcher to where we need it
399398 var listView = findChild(launcher, "launcherListView");
400− listView.flick(0, units.gu(200) * (data.flickTo === "top" ? 1 : -1));
401− tryCompare(listView, "flicking", false);
399+ if (data.flickTo == "top") {
400+ listView.positionViewAtEnd();
401+ } else {
402+ listView.positionViewAtBeginning();
403+ }
402404
403405 // Doing longpress
404406 mousePress(draggedItem, draggedItem.width / 2, draggedItem.height / 2)
tests/qmltests/tst_Shell.qml+2−2
@@ -235,8 +235,8 @@ Item {
235235
236236 var dash = findChild(shell, "dash");
237237 // check that dash has normal scale and opacity
238− tryCompare(dash.contentScale, 1.0);
239− tryCompare(dash.opacity, 1.0);
238+ tryCompare(dash, "contentScale", 1.0);
239+ tryCompare(dash, "opacity", 1.0);
240240
241241 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
242242 true /* beginTouch */, false /* endTouch */);
tests/utils/modules/Unity/Test/UnityTestCase.qml+10−16
@@ -71,19 +71,8 @@ TestCase {
7171
7272
7373 // Find an object with the given name in the children tree of "obj"
74− function findChild(obj,objectName) {
75− var childs = new Array(0);
76− childs.push(obj)
77− while (childs.length > 0) {
78− if (childs[0].objectName == objectName) {
79− return childs[0]
80− }
81− for (var i in childs[0].children) {
82− childs.push(childs[0].children[i])
83− }
84− childs.splice(0, 1);
85− }
86− return null;
74+ function findChild(obj, objectName) {
75+ return findChildIn(obj, "children", objectName);
8776 }
8877
8978 // Find an object with the given name in the children tree of "obj"
@@ -91,15 +80,20 @@ TestCase {
9180 // Note: you should use findChild if you're not sure you need this
9281 // as this tree is much bigger and might contain stuff that goes
9382 // away randomly.
94− function findInvisibleChild(obj,objectName) {
83+ function findInvisibleChild(obj, objectName) {
84+ return findChildIn(obj, "data", objectName);
85+ }
86+
87+ // Find a child in the named property
88+ function findChildIn(obj, prop, objectName) {
9589 var childs = new Array(0);
9690 childs.push(obj)
9791 while (childs.length > 0) {
9892 if (childs[0].objectName == objectName) {
9993 return childs[0]
10094 }
101− for (var i in childs[0].data) {
102− childs.push(childs[0].data[i])
95+ for (var i in childs[0][prop]) {
96+ childs.push(childs[0][prop][i])
10397 }
10498 childs.splice(0, 1);
10599 }