on xenial help sign in
Some fixes for the tests

the processEvents is not awesome but can't think how to fix it otherwise A re-write of LVWPH may help, but ...

commit61687ce4cacd7c2e253cf40c91e91828aa5bc575 authorAlbert Astals <albert.astals@canonical.com> dateThu 6 Mar 2014, 18:30 (13 years ago) parente908bd4
3 files changed+26−19
plugins/DashViews/listviewwithpageheader.cpp+26−9 tests/plugins/DashViews/listviewwithpageheadertest.cpp−6 tests/plugins/DashViews/listviewwithpageheadertestsection.cpp−4
plugins/DashViews/listviewwithpageheader.cpp+26−9
@@ -477,6 +477,11 @@ void ListViewWithPageHeader::componentComplete()
477477 polish();
478478}
479479
480+static inline bool uFuzzyCompare(qreal r1, qreal r2)
481+{
482+ return qFuzzyCompare(r1, r2) || (qFuzzyIsNull(r1) && qFuzzyIsNull(r2));
483+}
484+
480485void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
481486{
482487 // Check we are not being taken down and don't paint anything
@@ -491,11 +496,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
491496 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
492497 if (m_headerItem) {
493498 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 {
499+ if (uFuzzyCompare(contentY(), -m_minYExtent) || contentY() > -m_minYExtent) {
499500 m_headerItem->setHeight(m_headerItem->implicitHeight());
500501 // We are going down (but it's not because of the rebound at the end)
501502 // (but the header was not shown by it's own position)
@@ -509,21 +510,32 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
509510 m_headerItemShownHeight = 0;
510511 m_headerItem->setY(-m_minYExtent);
511512 } 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
513+ if (maximizeVisibleAreaRunning && diff > 0) {
514+ // If we are maximizing and the header was shown, make sure we hide it
513515 m_headerItemShownHeight -= diff;
514− else
516+ } else {
515517 m_headerItemShownHeight += diff;
516− if (contentY() == -m_minYExtent) {
518+ }
519+ if (uFuzzyCompare(contentY(), -m_minYExtent)) {
517520 m_headerItemShownHeight = 0;
518521 } else {
519522 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
520523 }
521524 if (m_headerItemShownHeight > 0) {
522− m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
525+ if (uFuzzyCompare(m_headerItem->height(), m_headerItemShownHeight)) {
526+ m_headerItem->setY(contentY());
527+ m_headerItemShownHeight = m_headerItem->height();
528+ } else {
529+ m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
530+ }
523531 } else {
524532 m_headerItem->setY(-m_minYExtent);
525533 }
526534 }
535+ } else {
536+ // Stick the header item to the top when dragging down
537+ m_headerItem->setY(contentY());
538+ m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
527539 }
528540 // We will be changing the clip item, need to accomadate for it
529541 // otherwise we move the firstItem down/up twice (unless the
@@ -1264,6 +1276,11 @@ void ListViewWithPageHeader::updatePolish()
12641276 refill();
12651277
12661278 if (m_contentHeightDirty) {
1279+ // We need to make sure all bindings have updated otherwise
1280+ // we may end up with bindings updating when we call setContentHeight
1281+ // and then everything gets out of sync, i.e. testHeaderPositionBug1240118
1282+ qApp->processEvents();
1283+
12671284 qreal contentHeight;
12681285 if (m_visibleItems.isEmpty()) {
12691286 contentHeight = m_headerItem ? m_headerItem->height() : 0;
tests/plugins/DashViews/listviewwithpageheadertest.cpp−6
@@ -1281,8 +1281,6 @@ private Q_SLOTS:
12811281
12821282 void testShowHeaderHalfShown()
12831283 {
1284− QSKIP("This test is extremely unstable.");
1285−
12861284 changeContentY(20);
12871285
12881286 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
@@ -1850,7 +1848,6 @@ private Q_SLOTS:
18501848
18511849 void testHeaderPositionBug1240118()
18521850 {
1853− QSKIP("This test is unstable.");
18541851 scrollToBottom();
18551852 lvwph->showHeader();
18561853 QTRY_VERIFY(!lvwph->m_contentYAnimation->isRunning());
@@ -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−4
@@ -1486,8 +1486,6 @@ private Q_SLOTS:
14861486
14871487 void testShowHeaderHalfShown()
14881488 {
1489− QSKIP("This test is extremely unstable.");
1490−
14911489 changeContentY(20);
14921490
14931491 QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
@@ -2095,8 +2093,6 @@ private Q_SLOTS:
20952093
20962094 void testDownAndUp()
20972095 {
2098− QSKIP("This test is unstable.");
2099−
21002096 QMetaObject::invokeMethod(model, "removeItems", Q_ARG(QVariant, 1), Q_ARG(QVariant, 5));
21012097
21022098 QTRY_COMPARE(lvwph->m_visibleItems.count(), 1);