on xenial help sign in
Improve Card creation time by adding loaders that make sure only what's needed is loaded

In my computer it goes from RESULT : qmltestrunner::benchmark_time:"cardTitleArtSubtitleMascotSummaryModel": 3.217 msecs per iteration (total: 3,218, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardTitleArtSubtitleMascotModel": 1.647 msecs per iteration (total: 1,648, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardTitleArtSubtitleModel": 1.514 msecs per iteration (total: 1,515, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardTitleArtModel": 1.471 msecs per iteration (total: 1,471, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardArtModel": 1.447 msecs per iteration (total: 1,448, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardTitleModel": 1.276 msecs per iteration (total: 1,276, iterations: 1000) to RESULT : qmltestrunner::benchmark_time:"cardTitleArtSubtitleMascotSummaryModel": 2.916 msecs per iteration (total: 2,917, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardTitleArtSubtitleMascotModel": 1.504 msecs per iteration (total: 1,504, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardTitleArtSubtitleModel": 1.060 msecs per iteration (total: 1,061, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardTitleArtModel": 1.052 msecs per iteration (total: 1,053, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardArtModel": 0.727 msecs per iteration (total: 728, iterations: 1000) RESULT : qmltestrunner::benchmark_time:"cardTitleModel": 0.817 msecs per iteration (total: 818, iterations: 1000) Fixes: 1297197

commitab4e43d697f16c1e6fabd8c22272bea944111880 authorAlbert Astals <albert.astals@canonical.com> dateWed 16 Apr 2014, 13:44 (13 years ago) parentb24110e6ed5060
10 files changed+269−126
cmake/modules/QmlTest.cmake+16−1 qml/Dash/Card.qml+99−79 qml/Dash/CardCarousel.qml+1−1 qml/Dash/CardFilterGrid.qml+3−2 qml/Dash/CardHeader.qml+41−31 qml/Dash/GenericScopeView.qml+1−1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Dash/tst_Card.qml+12−10 tests/qmltests/Dash/tst_CardBenchmark.qml+94 tests/qmltests/Dash/tst_CardHeader.qml+1−1
cmake/modules/QmlTest.cmake+16−1
@@ -58,7 +58,15 @@ macro(add_manual_qml_test SUBPATH COMPONENT_NAME)
5858
5959endmacro(add_manual_qml_test)
6060
61+macro(add_qml_benchmark SUBPATH COMPONENT_NAME ITERATIONS)
62+ add_qml_test_internal(${SUBPATH} ${COMPONENT_NAME} ${ITERATIONS})
63+endmacro(add_qml_benchmark)
64+
6165macro(add_qml_test SUBPATH COMPONENT_NAME)
66+ add_qml_test_internal(${SUBPATH} ${COMPONENT_NAME} 0)
67+endmacro(add_qml_test)
68+
69+macro(add_qml_test_internal SUBPATH COMPONENT_NAME ITERATIONS)
6270 set(options NO_ADD_TEST NO_TARGETS)
6371 set(multi_value_keywords IMPORT_PATHS TARGETS PROPERTIES ENVIRONMENT)
6472
@@ -88,10 +96,17 @@ macro(add_qml_test SUBPATH COMPONENT_NAME)
8896 set(function_ARGS "")
8997 endif()
9098
99+ if (${ITERATIONS} GREATER 0)
100+ set(ITERATIONS_STRING "-iterations" ${ITERATIONS})
101+ else()
102+ set(ITERATIONS_STRING "")
103+ endif()
104+
91105 set(qmltest_command
92106 env ${qmltest_ENVIRONMENT}
93107 ${qmltestrunner_exe} -input ${CMAKE_CURRENT_SOURCE_DIR}/${qmltest_FILE}.qml
94108 ${qmltestrunner_imports}
109+ ${ITERATIONS_STRING}
95110 -o ${CMAKE_BINARY_DIR}/${qmltest_TARGET}.xml,xunitxml
96111 -o -,txt
97112 ${function_ARGS}
@@ -114,7 +129,7 @@ macro(add_qml_test SUBPATH COMPONENT_NAME)
114129 add_qmltest_target(${qmltest_TARGET} "${qmltest_command}" TRUE ${qmltest_NO_ADD_TEST})
115130 add_qmltest_target(${qmltest_xvfb_TARGET} "${qmltest_xvfb_command}" ${qmltest_NO_TARGETS} TRUE)
116131 add_manual_qml_test(${SUBPATH} ${COMPONENT_NAME} ${ARGN})
117−endmacro(add_qml_test)
132+endmacro(add_qml_test_internal)
118133
119134macro(add_binary_qml_test CLASS_NAME LD_PATH DEPS)
120135 set(testCommand
qml/Dash/Card.qml+99−79
@@ -25,47 +25,53 @@ AbstractButton {
2525 property var components
2626 property var cardData
2727
28− property alias fontScale: header.fontScale
29− property alias headerAlignment: header.headerAlignment
30− property alias headerHeight: header.height
31− readonly property alias title: header.title
28+ property real fontScale: 1.0
29+ property int headerAlignment: Text.AlignLeft
30+ readonly property int headerHeight: headerLoader.item ? headerLoader.item.height : 0
31+ property int fixedHeaderHeight: -1
32+ readonly property string title: cardData && cardData["title"] || ""
3233
3334 property bool showHeader: true
3435
3536 implicitWidth: childrenRect.width
36− implicitHeight: summary.y + summary.height + (summary.text && background.visible ? units.gu(1) : 0)
37+ implicitHeight: summary.y + summary.height + (summary.text && backgroundLoader.active ? units.gu(1) : 0)
3738
38− UbuntuShape {
39− id: background
40− objectName: "background"
41− radius: "medium"
42− visible: template["card-layout"] !== "horizontal" && (template["card-background"] || components["background"]
43− || artAndSummary)
44− property bool artAndSummary: components["art"]["field"] && components["summary"] || false
45− color: getColor(0) || "white"
46− gradientColor: getColor(1) || color
47− anchors.fill: parent
48− image: backgroundImage.source ? backgroundImage : null
39+ Loader {
40+ id: backgroundLoader
41+ objectName: "backgroundLoader"
4942
50− property real luminance: 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b
43+ readonly property bool artAndSummary: components["art"]["field"] && components["summary"] || false
44+ active: template["card-layout"] !== "horizontal" && (template["card-background"] || components["background"] || artAndSummary)
45+ anchors.fill: parent
5146
52− property Image backgroundImage: Image {
53− objectName: "backgroundImage"
54− source: {
55− if (cardData && typeof cardData["background"] === "string") return cardData["background"]
56− else if (template && typeof template["card-background"] === "string") return template["card-background"]
57− else return ""
47+ sourceComponent: UbuntuShape {
48+ objectName: "background"
49+ radius: "medium"
50+ color: getColor(0) || "white"
51+ gradientColor: getColor(1) || color
52+ anchors.fill: parent
53+ image: backgroundImage.source ? backgroundImage : null
54+
55+ property real luminance: 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b
56+
57+ property Image backgroundImage: Image {
58+ objectName: "backgroundImage"
59+ source: {
60+ if (cardData && typeof cardData["background"] === "string") return cardData["background"]
61+ else if (template && typeof template["card-background"] === "string") return template["card-background"]
62+ else return ""
63+ }
5864 }
59− }
6065
61− function getColor(index) {
62− if (cardData && typeof cardData["background"] === "object"
63− && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
64− return cardData["background"]["elements"][index];
65− } else if (template && typeof template["card-background"] === "object"
66− && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
67− return template["card-background"]["elements"][index];
68− } else return undefined;
66+ function getColor(index) {
67+ if (cardData && typeof cardData["background"] === "object"
68+ && (cardData["background"]["type"] === "color" || cardData["background"]["type"] === "gradient")) {
69+ return cardData["background"]["elements"][index];
70+ } else if (template && typeof template["card-background"] === "object"
71+ && (template["card-background"]["type"] === "color" || template["card-background"]["type"] === "gradient")) {
72+ return template["card-background"]["elements"][index];
73+ } else return undefined;
74+ }
6975 }
7076 }
7177
@@ -111,7 +117,7 @@ AbstractButton {
111117 function updateWidthHeightBindings() {
112118 if (isHorizontal) {
113119 width = Qt.binding(function() { return height * artShape.aspect });
114− height = Qt.binding(function() { return header.height });
120+ height = Qt.binding(function() { return root.headerHeight });
115121 } else {
116122 width = Qt.binding(function() { return root.width });
117123 height = Qt.binding(function() { return width / artShape.aspect });
@@ -120,53 +126,58 @@ AbstractButton {
120126 }
121127 }
122128
123− ShaderEffect {
124− id: overlay
129+ Loader {
130+ id: overlayLoader
125131 anchors {
126132 left: artShape.left
127133 right: artShape.right
128134 bottom: artShape.bottom
129135 }
136+ active: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
130137
131− height: header.height
132− opacity: header.opacity * 0.6
133− visible: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
138+ sourceComponent: ShaderEffect {
139+ id: overlay
134140
135− property var source: ShaderEffectSource {
136− id: shaderSource
137− sourceItem: artShape
138− onVisibleChanged: if (visible) scheduleUpdate()
139− live: false
140− sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
141− }
141+ height: headerLoader.item ? headerLoader.item.height : 0
142+ opacity: headerLoader.item ? headerLoader.item.opacity * 0.6 : 0
143+
144+ property var source: ShaderEffectSource {
145+ id: shaderSource
146+ sourceItem: artShape
147+ onVisibleChanged: if (visible) scheduleUpdate()
148+ live: false
149+ sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
150+ }
142151
143− vertexShader: "
144− uniform highp mat4 qt_Matrix;
145− attribute highp vec4 qt_Vertex;
146− attribute highp vec2 qt_MultiTexCoord0;
147− varying highp vec2 coord;
148− void main() {
149− coord = qt_MultiTexCoord0;
150− gl_Position = qt_Matrix * qt_Vertex;
151− }"
152−
153− fragmentShader: "
154− varying highp vec2 coord;
155− uniform sampler2D source;
156− uniform lowp float qt_Opacity;
157− void main() {
158− lowp vec4 tex = texture2D(source, coord);
159− gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
160− }"
152+ vertexShader: "
153+ uniform highp mat4 qt_Matrix;
154+ attribute highp vec4 qt_Vertex;
155+ attribute highp vec2 qt_MultiTexCoord0;
156+ varying highp vec2 coord;
157+ void main() {
158+ coord = qt_MultiTexCoord0;
159+ gl_Position = qt_Matrix * qt_Vertex;
160+ }"
161+
162+ fragmentShader: "
163+ varying highp vec2 coord;
164+ uniform sampler2D source;
165+ uniform lowp float qt_Opacity;
166+ void main() {
167+ lowp vec4 tex = texture2D(source, coord);
168+ gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
169+ }"
170+ }
161171 }
162172
163− CardHeader {
164− id: header
165− objectName: "cardHeader"
173+ Loader {
174+ id: headerLoader
175+ objectName: "cardHeaderLoader"
176+
166177 anchors {
167178 top: {
168179 if (template) {
169− if (template["overlay"]) return overlay.top;
180+ if (template["overlay"]) return overlayLoader.top;
170181 if (template["card-layout"] === "horizontal") return artShape.top;
171182 }
172183 return artShape.bottom;
@@ -179,29 +190,38 @@ AbstractButton {
179190 }
180191 right: parent.right
181192 }
193+ active: cardData && cardData["title"] || cardData && cardData["mascot"] || false
194+
195+ sourceComponent: CardHeader {
196+ id: header
197+ objectName: "cardHeader"
182198
183− mascot: cardData && cardData["mascot"] || ""
184− title: cardData && cardData["title"] || ""
185− subtitle: cardData && cardData["subtitle"] || ""
199+ mascot: cardData && cardData["mascot"] || ""
200+ title: root.title
201+ subtitle: cardData && cardData["subtitle"] || ""
186202
187− titleWeight: components && components["subtitle"] ? Font.DemiBold : Font.Normal
203+ titleWeight: components && components["subtitle"] ? Font.DemiBold : Font.Normal
188204
189− opacity: showHeader ? 1 : 0
190− inOverlay: root.template && root.template["overlay"] === true
191− fontColor: inOverlay ? "white" : summary.color
192− useMascotShape: !background.visible && !inOverlay
205+ opacity: showHeader ? 1 : 0
206+ inOverlay: root.template && root.template["overlay"] === true
207+ fontColor: inOverlay ? "white" : summary.color
208+ useMascotShape: !backgroundLoader.active && !inOverlay
209+ headerAlignment: root.headerAlignment
210+ height: root.fixedHeaderHeight != -1 ? root.fixedHeaderHeight : implicitHeight
211+ fontScale: root.fontScale
193212
194− Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
213+ Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
214+ }
195215 }
196216
197217 Label {
198218 id: summary
199219 objectName: "summaryLabel"
200220 anchors {
201− top: header.visible ? header.bottom : artShape.bottom
221+ top: headerLoader.active ? headerLoader.bottom : artShape.bottom
202222 left: parent.left
203223 right: parent.right
204− margins: background.visible ? units.gu(1) : 0
224+ margins: backgroundLoader.active ? units.gu(1) : 0
205225 topMargin: 0
206226 }
207227 wrapMode: Text.Wrap
@@ -211,6 +231,6 @@ AbstractButton {
211231 height: text ? implicitHeight : 0
212232 fontSize: "small"
213233 // TODO karni: Change "grey" to Ubuntu.Components.Palette color once updated.
214− color: background.visible && background.luminance < 0.7 ? "white" : "grey"
234+ color: backgroundLoader.active && backgroundLoader.item.luminance < 0.7 ? "white" : "grey"
215235 }
216236}
qml/Dash/CardCarousel.qml+1−1
@@ -52,7 +52,7 @@ DashRenderer {
5252 itemComponent: Card {
5353 id: card
5454 objectName: "carouselDelegate" + index
55− headerHeight: carousel.headerHeight
55+ fixedHeaderHeight: carousel.headerHeight
5656 cardData: model
5757 template: cardTool.template
5858 components: cardTool.components
qml/Dash/CardFilterGrid.qml+3−2
@@ -45,14 +45,15 @@ DashRenderer {
4545 collapsedRowCount: Math.min(2, cardTool && cardTool.template && cardTool.template["collapsed-rows"] || 2)
4646 delegateCreationBegin: genericFilterGrid.delegateCreationBegin
4747 delegateCreationEnd: genericFilterGrid.delegateCreationEnd
48− delegate: Item {
48+ delegate: Loader {
49+ asynchronous: true
4950 width: filterGrid.cellWidth
5051 height: filterGrid.cellHeight
5152 Card {
5253 id: card
5354 width: cardTool.cardWidth
5455 height: cardTool.cardHeight
55− headerHeight: cardTool.headerHeight
56+ fixedHeaderHeight: cardTool.headerHeight
5657 anchors.horizontalCenter: parent.horizontalCenter
5758 objectName: "delegate" + index
5859 cardData: model
qml/Dash/CardHeader.qml+41−31
@@ -19,9 +19,9 @@ import Ubuntu.Components 0.1
1919
2020Item {
2121 id: root
22− property alias mascot: mascotImage.source
22+ property url mascot: ""
2323 property alias title: titleLabel.text
24− property alias subtitle: subtitleLabel.text
24+ property var subtitle
2525
2626 property alias titleWeight: titleLabel.font.weight
2727 property alias titleSize: titleLabel.fontSize
@@ -35,8 +35,8 @@ Item {
3535 property bool useMascotShape: true
3636 property color fontColor: Theme.palette.selected.backgroundText
3737
38− visible: mascotImage.status === Image.Ready || title
39− height: row.height > 0 ? row.height + row.margins * 2 : 0
38+ visible: mascot != "" || title
39+ implicitHeight: row.height > 0 ? row.height + row.margins * 2 : 0
4040
4141 Row {
4242 id: row
@@ -44,7 +44,7 @@ Item {
4444
4545 property real margins: units.gu(1)
4646
47− spacing: mascotShape.visible || mascotImage.visible || inOverlay ? margins : 0
47+ spacing: mascotShapeLoader.active || mascotImageLoader.active || inOverlay ? margins : 0
4848 anchors {
4949 top: parent.top; left: parent.left; right: parent.right
5050 margins: margins
@@ -52,33 +52,40 @@ Item {
5252 rightMargin: spacing
5353 }
5454
55− UbuntuShape {
56− id: mascotShape
57− objectName: "mascotShape"
55+ Loader {
56+ id: mascotShapeLoader
57+ objectName: "mascotShapeLoader"
5858
59+ active: useMascotShape && mascotImageLoader.item && mascotImageLoader.item.status === Image.Ready
60+ visible: active
61+ anchors.verticalCenter: parent.verticalCenter
5962 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
6063 width: units.gu(6)
6164 height: units.gu(5.625)
62− anchors.verticalCenter: parent.verticalCenter
63− visible: useMascotShape && image && image.status === Image.Ready
6465 readonly property int maxSize: Math.max(width, height) * 4
6566
66− image: useMascotShape ? mascotImage : null
67+ sourceComponent: UbuntuShape {
68+ image: mascotImageLoader.item
69+ }
6770 }
6871
69− Image {
70− id: mascotImage
71− objectName: "mascotImage"
72−
73− width: source ? mascotShape.width : 0
74− height: mascotShape.height
72+ Loader {
73+ id: mascotImageLoader
74+ active: root.mascot != ""
75+ visible: active && !useMascotShape && item.status === Image.Ready
7576 anchors.verticalCenter: parent.verticalCenter
76− visible: !useMascotShape && status === Image.Ready
77+ sourceComponent: Image {
78+ objectName: "mascotImage"
79+
80+ source: root.mascot
81+ width: source ? mascotShapeLoader.width : 0
82+ height: mascotShapeLoader.height
7783
78− sourceSize { width: mascotShape.maxSize; height: mascotShape.maxSize }
79− fillMode: Image.PreserveAspectCrop
80− horizontalAlignment: Image.AlignHCenter
81− verticalAlignment: Image.AlignVCenter
84+ sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
85+ fillMode: Image.PreserveAspectCrop
86+ horizontalAlignment: Image.AlignHCenter
87+ verticalAlignment: Image.AlignVCenter
88+ }
8289 }
8390
8491 Column {
@@ -100,16 +107,19 @@ Item {
100107 color: fontColor
101108 }
102109
103− Label {
104− id: subtitleLabel
105− objectName: "subtitleLabel"
110+ Loader {
111+ active: titleLabel.text && root.subtitle
106112 anchors { left: parent.left; right: parent.right }
107− elide: Text.ElideRight
108− fontSize: "small"
109− font.weight: Font.Light
110− visible: titleLabel.text && text
111− font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
112− color: fontColor
113+ sourceComponent: Label {
114+ id: subtitleLabel
115+ objectName: "subtitleLabel"
116+ elide: Text.ElideRight
117+ fontSize: "small"
118+ font.weight: Font.Light
119+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
120+ color: fontColor
121+ text: root.subtitle
122+ }
113123 }
114124 }
115125 }
qml/Dash/GenericScopeView.qml+1−1
@@ -242,7 +242,7 @@ FocusScope {
242242 // to the stable position and delete/create items without any reason
243243 if (categoryView.contentY < categoryView.originY) {
244244 return;
245− } else if (categoryView.contentY + categoryView.height > categoryView.contentHeight) {
245+ } else if (categoryView.contentHeight > categoryView.height && categoryView.contentY + categoryView.height > categoryView.contentHeight) {
246246 return;
247247 }
248248
tests/qmltests/CMakeLists.txt+1
@@ -35,6 +35,7 @@ add_qml_test(Components PageHeaderLabel)
3535add_qml_test(Dash Dash IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
3636add_qml_test(Dash DashContent IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
3737add_qml_test(Dash Card)
38+add_qml_benchmark(Dash CardBenchmark 1000)
3839add_qml_test(Dash CardHeader)
3940add_qml_test(Dash CardTool)
4041add_qml_test(Dash GenericScopeView IMPORT_PATHS ${CMAKE_BINARY_DIR}/plugins ${qmltest_DEFAULT_IMPORT_PATHS})
tests/qmltests/Dash/tst_Card.qml+12−10
@@ -182,11 +182,13 @@ Rectangle {
182182 when: windowShown
183183
184184 property Item header: findChild(card, "cardHeader")
185+ property Item headerLoader: findChild(card, "cardHeaderLoader")
185186 property Item title: findChild(header, "titleLabel")
186187 property Item art: findChild(card, "artShape")
187188 property Item artImage: findChild(card, "artImage")
188189 property Item summary: findChild(card, "summaryLabel")
189190 property Item background: findChild(card, "background")
191+ property Item backgroundLoader: findChild(card, "backgroundLoader")
190192 property Item backgroundImage: findChild(card, "backgroundImage")
191193
192194 function initTestCase() {
@@ -244,8 +246,8 @@ Rectangle {
244246 { tag: "Wide", width: units.gu(18.5), aspect: 0.5, index: 0 },
245247 { tag: "Horizontal", width: units.gu(38), index: 5 },
246248 // Make sure card ends with header when there's no summary
247− { tag: "NoSummary", height: function() { return header.y + header.height }, index: 6 },
248− { tag: "HorizontalNoSummary", height: function() { return header.height }, card_layout: "horizontal", index: 6 },
249+ { tag: "NoSummary", height: function() { return headerLoader.y + headerLoader.height }, index: 6 },
250+ { tag: "HorizontalNoSummary", height: function() { return headerLoader.height }, card_layout: "horizontal", index: 6 },
249251 ]
250252 }
251253
@@ -288,7 +290,7 @@ Rectangle {
288290 { tag: "Fit", height: units.gu(38), size: "large", width: units.gu(19), index: 4 },
289291 { tag: "VerticalWidth", width: function() { return header.width }, index: 0 },
290292 { tag: "HorizontalHeight", height: function() { return header.height }, index: 5 },
291− { tag: "HorizontalWidth", width: function() { return header.x }, index: 5 },
293+ { tag: "HorizontalWidth", width: function() { return headerLoader.x }, index: 5 },
292294 ]
293295 }
294296
@@ -332,7 +334,7 @@ Rectangle {
332334 function test_art_layout(data) {
333335 selector.selectedIndex = data.index;
334336
335− tryCompare(testCase.header, "x", data.left());
337+ tryCompare(testCase.headerLoader, "x", data.left());
336338 }
337339
338340 function test_header_layout_data() {
@@ -349,13 +351,13 @@ Rectangle {
349351 function test_header_layout(data) {
350352 selector.selectedIndex = data.index;
351353
352− tryCompareFunction(function() { return testCase.header.y === data.top() }, true);
353− tryCompareFunction(function() { return testCase.header.x === data.left() }, true);
354+ tryCompareFunction(function() { return testCase.headerLoader.y === data.top() }, true);
355+ tryCompareFunction(function() { return testCase.headerLoader.x === data.left() }, true);
354356 }
355357
356358 function test_summary_layout_data() {
357359 return [
358− { tag: "With header", top: function() { return header.y + header.height }, index: 0 },
360+ { tag: "With header", top: function() { return headerLoader.y + headerLoader.height }, index: 0 },
359361 { tag: "Without header", top: function() { return art.y + art.height }, index: 7 },
360362 ]
361363 }
@@ -400,7 +402,7 @@ Rectangle {
400402
401403 waitForRendering(card);
402404
403− tryCompare(background, "visible", data.visible);
405+ tryCompare(backgroundLoader, "active", data.visible);
404406
405407 if (data.hasOwnProperty("color")) {
406408 tryCompare(background, "color", data.color);
@@ -467,13 +469,13 @@ Rectangle {
467469 function test_mascotShape(data) {
468470 selector.selectedIndex = data.index;
469471
470− var shape = findChild(card, "mascotShape");
472+ var shape = findChild(card, "mascotShapeLoader");
471473 var image = findChild(card, "mascotImage");
472474
473475 verify(shape, "Could not find shape.");
474476 verify(image, "Could not find image.");
475477
476− tryCompare(shape, "visible", data.shape);
478+ tryCompare(shape, "active", data.shape);
477479 tryCompare(image, "visible", !data.shape);
478480 }
479481 }
tests/qmltests/Dash/tst_CardBenchmark.qmlnew file+94
@@ -0,0 +1,94 @@
1+/*
2+ * Copyright (C) 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 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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU 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 Ubuntu.Components 0.1
20+import Unity.Test 0.1 as UT
21+import "../../../qml/Dash"
22+import "CardHelpers.js" as Helpers
23+
24+Rectangle {
25+ id: root
26+ width: units.gu(80)
27+ height: units.gu(72)
28+ color: "#88FFFFFF"
29+
30+ property string cardData: '
31+ {
32+ "art": "../../tests/qmltests/Dash/artwork/music-player-design.png",
33+ "mascot": "../../tests/qmltests/Dash/artwork/avatar.png",
34+ "title": "foo",
35+ "subtitle": "bar",
36+ "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
37+ }'
38+
39+ property string currentModel: '{}'
40+ property string cardTitleArtSubtitleMascotSummaryModel: '{ "components": { "title": "title", "art": "art", "subtitle": "subtitle", "mascot": "mascot", "summary": "summary" } }'
41+ property string cardTitleArtSubtitleMascotModel: '{ "components": { "title": "title", "art": "art", "subtitle": "subtitle", "mascot": "mascot" } }'
42+ property string cardTitleArtSubtitleModel: '{ "components": { "title": "title", "art": "art", "subtitle": "subtitle" } }'
43+ property string cardTitleArtModel: '{ "components": { "title": "title", "art": "art" } }'
44+ property string cardArtModel: '{ "components": { "art": "art" } }'
45+ property string cardTitleModel: '{ "components": { "title": "title" } }'
46+
47+ CardTool {
48+ id: cardTool
49+ template: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(currentModel))['template'];
50+ components: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(currentModel))['components'];
51+ viewWidth: units.gu(48)
52+ }
53+
54+ Repeater {
55+ id: cardRepeater
56+ model: 0
57+ Card {
58+ width: cardTool.cardWidth || implicitWidth
59+ height: cardTool.cardHeight || implicitHeight
60+
61+ template: cardTool.template
62+ components: cardTool.components
63+ cardData: Helpers.mapData(root.cardData, components)
64+ }
65+ }
66+
67+ UT.UnityTestCase {
68+ id: testCase
69+ name: "CardBenchmark"
70+
71+ when: windowShown
72+
73+ function init() {
74+ wait(1);
75+ }
76+
77+ function benchmark_time_data() {
78+ return [
79+ { tag: "cardTitleArtSubtitleMascotSummaryModel", model: cardTitleArtSubtitleMascotSummaryModel },
80+ { tag: "cardTitleArtSubtitleMascotModel", model: cardTitleArtSubtitleMascotModel },
81+ { tag: "cardTitleArtSubtitleModel", model: cardTitleArtSubtitleModel },
82+ { tag: "cardTitleArtModel", model: cardTitleArtModel },
83+ { tag: "cardArtModel", model: cardArtModel },
84+ { tag: "cardTitleModel", model: cardTitleModel },
85+ ];
86+ }
87+
88+ function benchmark_time(data) {
89+ currentModel = data.model;
90+ cardRepeater.model = 1;
91+ cardRepeater.model = 0;
92+ }
93+ }
94+}
tests/qmltests/Dash/tst_CardHeader.qml+1−1
@@ -43,7 +43,7 @@ Rectangle {
4343
4444 when: windowShown
4545
46− property Item mascot: findChild(cardHeader, "mascotShape")
46+ property Item mascot: findChild(cardHeader, "mascotShapeLoader")
4747 property Item titleLabel: findChild(cardHeader, "titleLabel")
4848 property Item subtitleLabel: findChild(cardHeader, "subtitleLabel")
4949 property Item oldPriceLabel: findChild(cardHeader, "oldPriceLabel")