on xenial help sign in
Fix tests under Qt 5.2.
7ee0a6dMichael Zanetti
plugins/DashViews/listviewwithpageheader.cpp+33−10
@@ -91,6 +91,7 @@
91
91
92#include "listviewwithpageheader.h"
92#include "listviewwithpageheader.h"
93
93
94+#include <QCoreApplication>
94#include <QDebug>
95#include <QDebug>
95#include <qqmlinfo.h>
96#include <qqmlinfo.h>
96#include <qqmlengine.h>
97#include <qqmlengine.h>
@@ -477,6 +478,11 @@ void ListViewWithPageHeader::componentComplete()
477 polish();
478 polish();
478}
479}
479
480
481+static inline bool uFuzzyCompare(qreal r1, qreal r2)
482+{
483+ return qFuzzyCompare(r1, r2) || (qFuzzyIsNull(r1) && qFuzzyIsNull(r2));
484+}
485+
480void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
486void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
481{
487{
482 // Check we are not being taken down and don't paint anything
488 // Check we are not being taken down and don't paint anything
@@ -491,11 +497,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
491 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
497 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
492 if (m_headerItem) {
498 if (m_headerItem) {
493 const auto oldHeaderItemShownHeight = m_headerItemShownHeight;
499 const auto oldHeaderItemShownHeight = m_headerItemShownHeight;
494− if (contentY() < -m_minYExtent) {
500+ if (uFuzzyCompare(contentY(), -m_minYExtent) || 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 m_headerItem->setHeight(m_headerItem->implicitHeight());
501 m_headerItem->setHeight(m_headerItem->implicitHeight());
500 // We are going down (but it's not because of the rebound at the end)
502 // We are going down (but it's not because of the rebound at the end)
501 // (but the header was not shown by it's own position)
503 // (but the header was not shown by it's own position)
@@ -509,21 +511,32 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
509 m_headerItemShownHeight = 0;
511 m_headerItemShownHeight = 0;
510 m_headerItem->setY(-m_minYExtent);
512 m_headerItem->setY(-m_minYExtent);
511 } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
513 } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
514+ if (maximizeVisibleAreaRunning && diff > 0) {
512− if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
515+ // If we are maximizing and the header was shown, make sure we hide it
513 m_headerItemShownHeight -= diff;
516 m_headerItemShownHeight -= diff;
514− else
517+ } else {
515 m_headerItemShownHeight += diff;
518 m_headerItemShownHeight += diff;
519+ }
516− if (contentY() == -m_minYExtent) {
520+ if (uFuzzyCompare(contentY(), -m_minYExtent)) {
517 m_headerItemShownHeight = 0;
521 m_headerItemShownHeight = 0;
518 } else {
522 } else {
519 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
523 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
520 }
524 }
521 if (m_headerItemShownHeight > 0) {
525 if (m_headerItemShownHeight > 0) {
526+ if (uFuzzyCompare(m_headerItem->height(), m_headerItemShownHeight)) {
527+ m_headerItem->setY(contentY());
528+ m_headerItemShownHeight = m_headerItem->height();
529+ } else {
522− m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
530+ m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
531+ }
523 } else {
532 } else {
524 m_headerItem->setY(-m_minYExtent);
533 m_headerItem->setY(-m_minYExtent);
525 }
534 }
526 }
535 }
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()));
527 }
540 }
528 // We will be changing the clip item, need to accomadate for it
541 // We will be changing the clip item, need to accomadate for it
529 // otherwise we move the firstItem down/up twice (unless the
542 // otherwise we move the firstItem down/up twice (unless the
@@ -1128,7 +1141,12 @@ void ListViewWithPageHeader::adjustMinYExtent()
1128 nonCreatedHeight = m_firstVisibleIndex * visibleItemsHeight / visibleItems;
1141 nonCreatedHeight = m_firstVisibleIndex * visibleItemsHeight / visibleItems;
1129// qDebug() << m_firstVisibleIndex << visibleItemsHeight << visibleItems << nonCreatedHeight;
1142// qDebug() << m_firstVisibleIndex << visibleItemsHeight << visibleItems << nonCreatedHeight;
1130 }
1143 }
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+ }
1132 }
1150 }
1133}
1151}
1134
1152
@@ -1264,6 +1282,11 @@ void ListViewWithPageHeader::updatePolish()
1264 refill();
1282 refill();
1265
1283
1266 if (m_contentHeightDirty) {
1284 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+
1267 qreal contentHeight;
1290 qreal contentHeight;
1268 if (m_visibleItems.isEmpty()) {
1291 if (m_visibleItems.isEmpty()) {
1269 contentHeight = m_headerItem ? m_headerItem->height() : 0;
1292 contentHeight = m_headerItem ? m_headerItem->height() : 0;
qml/Components/Stage.qml+4−6
@@ -329,13 +329,11 @@ Showable {
329
329
330 ScriptAction {
330 ScriptAction {
331 script: {
331 script: {
332− if (!stage.focusedApplicationWhenUsingScreenshots) {
333− // FIXME: only here to support case where application does
332+ // FIXME: only here to support case where application does
334− // not exist yet but is about to
333+ // not exist yet but is about to
335− return;
334+ if (stage.focusedApplicationWhenUsingScreenshots) {
335+ stage.__focusApplication(stage.focusedApplicationWhenUsingScreenshots);
336 }
336 }
337−
338− stage.__focusApplication(stage.focusedApplicationWhenUsingScreenshots);
339 }
337 }
340 }
338 }
341 }
339 }
tests/plugins/DashViews/listviewwithpageheadertest.cpp−6
@@ -1281,9 +1281,6 @@ private Q_SLOTS:
1281
1281
1282 void testShowHeaderHalfShown()
1282 void testShowHeaderHalfShown()
1283 {
1283 {
1284−#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
1285− QSKIP("This test is extremely unstable in 5.0.x");
1286−#endif
1287 changeContentY(20);
1284 changeContentY(20);
1288
1285
1289 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
1286 QTRY_COMPARE(lvwph->m_visibleItems.count(), 4);
@@ -1860,9 +1857,6 @@ private Q_SLOTS:
1860 model->setProperty(4, "size", 10);
1857 model->setProperty(4, "size", 10);
1861 model->setProperty(5, "size", 10);
1858 model->setProperty(5, "size", 10);
1862 model->setProperty(6, "size", 10);
1859 model->setProperty(6, "size", 10);
1863−#if (QT_VERSION > QT_VERSION_CHECK(5, 0, 3))
1864− QTRY_COMPARE(lvwph->m_minYExtent, 210.);
1865−#endif
1866 QTRY_COMPARE(lvwph->m_headerItem->y(), -lvwph->m_minYExtent);
1860 QTRY_COMPARE(lvwph->m_headerItem->y(), -lvwph->m_minYExtent);
1867 }
1861 }
1868
1862
tests/plugins/DashViews/listviewwithpageheadertestsection.cpp−3
@@ -1486,9 +1486,6 @@ private Q_SLOTS:
1486
1486
1487 void testShowHeaderHalfShown()
1487 void testShowHeaderHalfShown()
1488 {
1488 {
1489−#if (QT_VERSION < QT_VERSION_CHECK(5, 1, 0))
1490− QSKIP("This test is extremely unstable in 5.0.x");
1491−#endif
1492 changeContentY(20);
1489 changeContentY(20);
1493
1490
1494 QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
1491 QTRY_COMPARE(lvwph->m_visibleItems.count(), 3);
tests/qmltests/Components/tst_DragHandle.cpp−1
@@ -126,7 +126,6 @@ QQuickView *tst_DragHandle::createView()
126{
126{
127 QQuickView *window = new QQuickView(0);
127 QQuickView *window = new QQuickView(0);
128 window->setResizeMode(QQuickView::SizeRootObjectToView);
128 window->setResizeMode(QQuickView::SizeRootObjectToView);
129− window->resize(600, 600);
130 window->engine()->addImportPath(QLatin1String(UBUNTU_GESTURES_PLUGIN_DIR));
129 window->engine()->addImportPath(QLatin1String(UBUNTU_GESTURES_PLUGIN_DIR));
131 window->engine()->addImportPath(QLatin1String(TEST_DIR));
130 window->engine()->addImportPath(QLatin1String(TEST_DIR));
132
131
tests/qmltests/Components/tst_LazyImage.qml+1−1
@@ -155,7 +155,7 @@ Rectangle {
155
155
156 if (data.transition) {
156 if (data.transition) {
157 // wait for the transition to complete
157 // wait for the transition to complete
158− var transition = findInvisibleChild(data.image, data.transition);
158+ var transition = findChildIn(data.image, "transitions", data.transition);
159 tryCompare(transition, "running", true);
159 tryCompare(transition, "running", true);
160 tryCompare(transition, "running", false);
160 tryCompare(transition, "running", false);
161 }
161 }
tests/qmltests/Dash/Previews/tst_PreviewVideoPlayback.qml−6
@@ -53,12 +53,6 @@ Rectangle {
53 function test_loadScreenshot() {
53 function test_loadScreenshot() {
54 var screenshot = findChild(videoPlayback, "screenshot");
54 var screenshot = findChild(videoPlayback, "screenshot");
55
55
56− videoPlayback.widgetData = widgetData0;
57− tryCompare(screenshot.visible, false);
58−
59− videoPlayback.widgetData = widgetData1;
60− tryCompare(screenshot.visible, true);
61−
62 videoPlayback.widgetData = widgetData2;
56 videoPlayback.widgetData = widgetData2;
63 var screenshotSource = screenshot.source
57 var screenshotSource = screenshot.source
64 verify(screenshotSource.toString().indexOf("image://thumbnailer/") === 0)
58 verify(screenshotSource.toString().indexOf("image://thumbnailer/") === 0)
tests/qmltests/Dash/Previews/tst_PreviewZoomableImage.qml+3−4
@@ -30,14 +30,13 @@ Rectangle {
30 }
30 }
31
31
32 property var widgetData1: {
32 property var widgetData1: {
33− "source": "../../graphics/phone_background.jpg",
33+ "source": Qt.resolvedUrl("../artwork/checkers.png"),
34 "zoomable": false
34 "zoomable": false
35 }
35 }
36
36
37 PreviewZoomableImage {
37 PreviewZoomableImage {
38 id: zoomableImage
38 id: zoomableImage
39 width: parent.width
39 width: parent.width
40− widgetData: widgetData1
41 }
40 }
42
41
43 UT.UnityTestCase {
42 UT.UnityTestCase {
@@ -48,10 +47,10 @@ Rectangle {
48 var image = findChild(zoomableImage, "image");
47 var image = findChild(zoomableImage, "image");
49
48
50 zoomableImage.widgetData = widgetData0;
49 zoomableImage.widgetData = widgetData0;
51− tryCompare(image.state, "default");
50+ tryCompare(image, "state", "default");
52
51
53 zoomableImage.widgetData = widgetData1;
52 zoomableImage.widgetData = widgetData1;
54− tryCompare(image.state, "ready");
53+ tryCompare(image, "state", "ready");
55 }
54 }
56 }
55 }
57}
56}
tests/qmltests/Dash/tst_CardHeader.qml+1−1
@@ -122,7 +122,7 @@ Rectangle {
122 return [
122 return [
123 { tag: "Column width", object: column, width: cardHeader.width },
123 { tag: "Column width", object: column, width: cardHeader.width },
124 { tag: "Column width with mascot", object: column, width: cardHeader.width - mascot.width - outerRow.margins * 3, mascot: "artwork/avatar.png" },
124 { 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 } },
126 ]
126 ]
127 }
127 }
128
128
tests/qmltests/Dash/tst_DashContent.qml+1−1
@@ -284,7 +284,7 @@ Item {
284 tryCompare(scopesModel, "loaded", true);
284 tryCompare(scopesModel, "loaded", true);
285 var tabbar = findChild(dashContent, "tabbar");
285 var tabbar = findChild(dashContent, "tabbar");
286
286
287− compare(dashContent.currentIndex, 0);
287+ tryCompare(dashContent, "currentIndex", 0);
288 tryCompare(tabbar, "selectedIndex", 0);
288 tryCompare(tabbar, "selectedIndex", 0);
289 tryCompare(tabbar, "selectionMode", false);
289 tryCompare(tabbar, "selectionMode", false);
290
290
tests/qmltests/Dash/tst_GenericPreview.qml+2−2
@@ -22,7 +22,7 @@ import Unity.Test 0.1 as UT
22Item {
22Item {
23 id: root
23 id: root
24 width: units.gu(60)
24 width: units.gu(60)
25− height: units.gu(80)
25+ height: units.gu(90)
26
26
27 property var calls: []
27 property var calls: []
28 property int counter: 0
28 property int counter: 0
@@ -81,7 +81,7 @@ Item {
81
81
82 var actions = get_actions_data();
82 var actions = get_actions_data();
83 for(var i = 0; i < actions.length; i++) {
83 for(var i = 0; i < actions.length; i++) {
84− compare(root.calls[i], actions[i].id);
84+ tryCompare(root.calls, i, actions[i].id);
85 }
85 }
86 }
86 }
87
87
tests/qmltests/Dash/tst_GenericScopeView.qml+3−3
@@ -67,7 +67,7 @@ Item {
67 function init() {
67 function init() {
68 shell.width = units.gu(120)
68 shell.width = units.gu(120)
69 genericScopeView.categoryView.positionAtBeginning();
69 genericScopeView.categoryView.positionAtBeginning();
70− tryCompare(genericScopeView.categoryView.contentY, 0)
70+ tryCompare(genericScopeView.categoryView, "contentY", 0)
71 }
71 }
72
72
73 function test_isCurrent() {
73 function test_isCurrent() {
@@ -184,13 +184,13 @@ Item {
184 categoryListView.positionAtBeginning();
184 categoryListView.positionAtBeginning();
185 waitForRendering(categoryListView);
185 waitForRendering(categoryListView);
186 categoryListView.flick(0, -units.gu(60));
186 categoryListView.flick(0, -units.gu(60));
187− tryCompare(categoryListView.flicking, false);
187+ tryCompare(categoryListView, "flicking", false);
188
188
189 var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
189 var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
190 mouseClick(tile, tile.width / 2, tile.height - 1);
190 mouseClick(tile, tile.width / 2, tile.height - 1);
191 tryCompare(openEffect, "gap", 1);
191 tryCompare(openEffect, "gap", 1);
192
192
193− verify(openEffect.positionPx >= pageHeader.height + categoryListView.stickyHeaderHeight);
193+ verify(openEffect.positionPx >= Math.round(pageHeader.height + categoryListView.stickyHeaderHeight));
194 }
194 }
195
195
196 function test_previewCycle() {
196 function test_previewCycle() {
tests/qmltests/Launcher/tst_Launcher.qml+6−4
@@ -121,8 +121,7 @@ Item {
121 revealer.dragLauncherIntoView()
121 revealer.dragLauncherIntoView()
122
122
123 var listView = findChild(launcher, "launcherListView");
123 var listView = findChild(launcher, "launcherListView");
124− listView.flick(0, units.gu(500));
124+ listView.positionViewAtEnd();
125− tryCompare(listView, "flicking", false);
126
125
127 var appIcon = findChild(launcher, "launcherDelegate0")
126 var appIcon = findChild(launcher, "launcherDelegate0")
128
127
@@ -397,8 +396,11 @@ Item {
397
396
398 // Position launcher to where we need it
397 // Position launcher to where we need it
399 var listView = findChild(launcher, "launcherListView");
398 var listView = findChild(launcher, "launcherListView");
400− listView.flick(0, units.gu(200) * (data.flickTo === "top" ? 1 : -1));
399+ if (data.flickTo == "top") {
401− tryCompare(listView, "flicking", false);
400+ listView.positionViewAtEnd();
401+ } else {
402+ listView.positionViewAtBeginning();
403+ }
402
404
403 // Doing longpress
405 // Doing longpress
404 mousePress(draggedItem, draggedItem.width / 2, draggedItem.height / 2)
406 mousePress(draggedItem, draggedItem.width / 2, draggedItem.height / 2)
tests/qmltests/tst_Shell.qml+2−2
@@ -235,8 +235,8 @@ Item {
235
235
236 var dash = findChild(shell, "dash");
236 var dash = findChild(shell, "dash");
237 // check that dash has normal scale and opacity
237 // check that dash has normal scale and opacity
238− tryCompare(dash.contentScale, 1.0);
238+ tryCompare(dash, "contentScale", 1.0);
239− tryCompare(dash.opacity, 1.0);
239+ tryCompare(dash, "opacity", 1.0);
240
240
241 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
241 touchFlick(shell, touchX, touchY, shell.width * 0.1, touchY,
242 true /* beginTouch */, false /* endTouch */);
242 true /* beginTouch */, false /* endTouch */);
tests/utils/modules/Unity/Test/UnityTestCase.qml+10−16
@@ -71,19 +71,8 @@ TestCase {
71
71
72
72
73 // Find an object with the given name in the children tree of "obj"
73 // Find an object with the given name in the children tree of "obj"
74− function findChild(obj,objectName) {
74+ function findChild(obj, objectName) {
75− var childs = new Array(0);
75+ return findChildIn(obj, "children", objectName);
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;
87 }
76 }
88
77
89 // Find an object with the given name in the children tree of "obj"
78 // Find an object with the given name in the children tree of "obj"
@@ -91,15 +80,20 @@ TestCase {
91 // Note: you should use findChild if you're not sure you need this
80 // Note: you should use findChild if you're not sure you need this
92 // as this tree is much bigger and might contain stuff that goes
81 // as this tree is much bigger and might contain stuff that goes
93 // away randomly.
82 // 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) {
95 var childs = new Array(0);
89 var childs = new Array(0);
96 childs.push(obj)
90 childs.push(obj)
97 while (childs.length > 0) {
91 while (childs.length > 0) {
98 if (childs[0].objectName == objectName) {
92 if (childs[0].objectName == objectName) {
99 return childs[0]
93 return childs[0]
100 }
94 }
101− for (var i in childs[0].data) {
95+ for (var i in childs[0][prop]) {
102− childs.push(childs[0].data[i])
96+ childs.push(childs[0][prop][i])
103 }
97 }
104 childs.splice(0, 1);
98 childs.splice(0, 1);
105 }
99 }