~zsombi/ubuntu-ui-toolkit/listitemSelectModeBugs

« back to all changes in this revision

Viewing changes to tests/unit_x11/tst_components/tst_slotslayout.qml

  • Committer: Zsombor Egri
  • Date: 2015-11-16 06:35:05 UTC
  • mfrom: (1664.1.1 listitemSelectModeBugs)
  • Revision ID: zsombor.egri@canonical.com-20151116063505-cwn2qfks7qzk10g9
re-sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Author: Andrea Bernabei <andrea.bernabei@canonical.com>
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import QtTest 1.0
 
21
import Ubuntu.Test 1.0
 
22
import Ubuntu.Components 1.3
 
23
import Ubuntu.Components.Styles 1.3
 
24
import QtQml.Models 2.1
 
25
 
 
26
Item {
 
27
    id: main
 
28
    width: units.gu(50)
 
29
    height: units.gu(100)
 
30
 
 
31
    Flickable {
 
32
        anchors.fill: parent
 
33
        Column {
 
34
            id: column
 
35
            Repeater {
 
36
                model: layoutsModel
 
37
            }
 
38
        }
 
39
    }
 
40
 
 
41
    VisualItemModel {
 
42
        id: layoutsModel
 
43
        SlotsLayout {
 
44
            id: layout
 
45
            //these lists define the slots that we expect to be part of the layout
 
46
            //process, and the order in which we expect them to be positioned in the
 
47
            //layout. This is to avoid complicating the layout logic by adding conditions
 
48
            //to the method which tests the position of the slots. If we want to
 
49
            //test that a !visible slot is ignored during the relayout, for instance,
 
50
            //we have to remove it from these lists before we call checkSlotsPosition(layout).
 
51
            //The same applies to changes in the position of a slot.
 
52
            readonly property var leadingSlots: []
 
53
            readonly property var trailingSlots: []
 
54
        }
 
55
        ListItemLayout {
 
56
            id: layoutEmpty
 
57
            readonly property var leadingSlots: []
 
58
            readonly property var trailingSlots: []
 
59
        }
 
60
        ListItemLayout {
 
61
            id: layoutLabels
 
62
            title.text: "test"
 
63
            subtitle.text: "test2"
 
64
            summary.text: "test3"
 
65
            readonly property var leadingSlots: []
 
66
            readonly property var trailingSlots: []
 
67
        }
 
68
        ListItemLayout {
 
69
            id: layoutOneLeading
 
70
            readonly property var leadingSlots: [layoutOneLeading_leading1]
 
71
            readonly property var trailingSlots: []
 
72
            Item { id: layoutOneLeading_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(3); height: units.gu(2) }
 
73
        }
 
74
        ListItemLayout {
 
75
            id: layoutOneTrailing
 
76
            readonly property var leadingSlots: []
 
77
            readonly property var trailingSlots: [layoutOneTrailing_trailing1]
 
78
            Item { id: layoutOneTrailing_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(2) }
 
79
        }
 
80
        ListItemLayout {
 
81
            id: layoutOneLeadingOneTrailing
 
82
            readonly property var leadingSlots: [layoutOneLeadingOneTrailing_leading1]
 
83
            readonly property var trailingSlots: [layoutOneLeadingOneTrailing_trailing1]
 
84
            Item { id: layoutOneLeadingOneTrailing_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(10); height: units.gu(20) }
 
85
            Item { id: layoutOneLeadingOneTrailing_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(1); height: units.gu(5) }
 
86
        }
 
87
        ListItemLayout {
 
88
            id: layoutTwoTrailing
 
89
            readonly property var leadingSlots: []
 
90
            readonly property var trailingSlots: [layoutTwoTrailing_trailing1, layoutTwoTrailing_trailing2]
 
91
            Item { id: layoutTwoTrailing_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(3) }
 
92
            Item { id: layoutTwoTrailing_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(2) }
 
93
        }
 
94
        ListItemLayout {
 
95
            id: layoutOneLeadingTwoTrailing
 
96
            readonly property var leadingSlots: [layoutOneLeadingTwoTrailing_leading1]
 
97
            readonly property var trailingSlots: [layoutOneLeadingTwoTrailing_trailing1, layoutOneLeadingTwoTrailing_trailing2]
 
98
            Item { id: layoutOneLeadingTwoTrailing_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(3); height: units.gu(1) }
 
99
            Item { id: layoutOneLeadingTwoTrailing_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(4); height: units.gu(9) }
 
100
            Item { id: layoutOneLeadingTwoTrailing_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(1); height: units.gu(6) }
 
101
        }
 
102
        ListItemLayout {
 
103
            id: layoutCustomSlotsPadding
 
104
            readonly property var leadingSlots: [layoutCustomSlotsPadding_leading1]
 
105
            readonly property var trailingSlots: [layoutCustomSlotsPadding_trailing1, layoutCustomSlotsPadding_trailing2]
 
106
            Item {
 
107
                id: layoutCustomSlotsPadding_leading1;
 
108
                SlotsLayout.position: SlotsLayout.Leading;
 
109
                SlotsLayout.padding.top: units.gu(30)
 
110
                SlotsLayout.padding.bottom: units.gu(2)
 
111
                width: units.gu(6);
 
112
                height: units.gu(3)
 
113
            }
 
114
            Item {
 
115
                id: layoutCustomSlotsPadding_trailing1;
 
116
                SlotsLayout.position: SlotsLayout.Trailing;
 
117
                SlotsLayout.padding.top: units.gu(30)
 
118
                SlotsLayout.padding.bottom: units.gu(2)
 
119
                width: units.gu(1);
 
120
                height: units.gu(7)
 
121
            }
 
122
            Item {
 
123
                id: layoutCustomSlotsPadding_trailing2;
 
124
                SlotsLayout.position: SlotsLayout.Trailing;
 
125
                SlotsLayout.padding {
 
126
                    leading: units.gu(4)
 
127
                    trailing: units.gu(5)
 
128
                    top: units.gu(5)
 
129
                    bottom: units.gu(2)
 
130
                }
 
131
                width: units.gu(3);
 
132
                height: units.gu(9)
 
133
            }
 
134
        }
 
135
        ListItemLayout {
 
136
            id: layoutCustomPadding
 
137
            readonly property var leadingSlots: [layoutCustomPadding_leading1]
 
138
            readonly property var trailingSlots: [layoutCustomPadding_trailing1, layoutCustomPadding_trailing2]
 
139
            padding {
 
140
                top: units.gu(1)
 
141
                bottom: units.gu(2)
 
142
                leading: units.gu(3)
 
143
                trailing: units.gu(4)
 
144
            }
 
145
            Item { id: layoutCustomPadding_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(6); height: units.gu(3) }
 
146
            Item { id: layoutCustomPadding_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(1); height: units.gu(7) }
 
147
            Item { id: layoutCustomPadding_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(9) }
 
148
        }
 
149
        ListItemLayout {
 
150
            id: layoutTestChangeSlotsSize
 
151
            readonly property var leadingSlots: [layoutTestChangeSlotsSize_leading1]
 
152
            readonly property var trailingSlots: []
 
153
            title.text: "Test"
 
154
            padding {
 
155
                top: units.gu(0)
 
156
                bottom: units.gu(2)
 
157
            }
 
158
            Item { id: layoutTestChangeSlotsSize_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(10); height: 38.5/*units.gu(3.1222)*/ }
 
159
        }
 
160
        ListItemLayout {
 
161
            id: layoutTestMainSlotSize
 
162
            width: units.gu(40)
 
163
            readonly property var leadingSlots: []
 
164
            readonly property var trailingSlots: [layoutTestMainSlotSize_trailing1]
 
165
            title.text: "Test"
 
166
            Item { id: layoutTestMainSlotSize_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(1); height: units.gu(3) }
 
167
        }
 
168
        ListItemLayout {
 
169
            id: layoutTestSmallerTopBottomPadding
 
170
            readonly property var leadingSlots: [layoutTestSmallerTopBottomPadding_leading1]
 
171
            readonly property var trailingSlots: []
 
172
            title.text: "Test"
 
173
            subtitle.text: "test2"
 
174
            summary.text: "test3"
 
175
            Item { id: layoutTestSmallerTopBottomPadding_leading1; SlotsLayout.position: SlotsLayout.Leading;
 
176
                width: units.gu(1); height: Math.max(parent.mainSlot.height, units.gu(4)) }
 
177
        }
 
178
        ListItemLayout {
 
179
            id: layoutTestChangeSlotPosition
 
180
            property var leadingSlots: [layoutTestChangeSlotPosition_leading]
 
181
            property var trailingSlots: []
 
182
            title.text: "Test"
 
183
            subtitle.text: "test2"
 
184
            summary.text: "test3"
 
185
            Item { id: layoutTestChangeSlotPosition_leading; SlotsLayout.position: SlotsLayout.Leading;
 
186
                width: units.gu(4); height: units.gu(4) }
 
187
        }
 
188
        ListItemLayout {
 
189
            id: layoutTestSlotVisibilityChange
 
190
            property var leadingSlots: [layoutTestSlotVisibilityChange_leading]
 
191
            readonly property var trailingSlots: []
 
192
            title.text: "Test"
 
193
            subtitle.text: "test2"
 
194
            summary.text: "test3"
 
195
            //it has to be taller than mainSlot, so that when we make the slot invisible we can test
 
196
            //implicitHeight changes
 
197
            Item { id: layoutTestSlotVisibilityChange_leading; SlotsLayout.position: SlotsLayout.Leading;
 
198
                width: units.gu(4); height: parent.mainSlot.height+10 }
 
199
        }
 
200
        ListItemLayout {
 
201
            //let's test if the layout respects SlotsLayout.position even if that doesn't follow
 
202
            //the stacking order
 
203
            id: layoutTestRelativePositioning
 
204
            //these lists hold the slots in the order we want them to be positioned
 
205
            readonly property var leadingSlots: [layoutTestRelativePositioning_leading1]
 
206
            readonly property var trailingSlots: [layoutTestRelativePositioning_trailing2, layoutTestRelativePositioning_trailing1]
 
207
            Item { id: layoutTestRelativePositioning_leading1; SlotsLayout.position: SlotsLayout.Leading-3; width: units.gu(6); height: units.gu(3) }
 
208
            Item { id: layoutTestRelativePositioning_trailing1; SlotsLayout.position: SlotsLayout.Last; width: units.gu(1); height: units.gu(7) }
 
209
            Item { id: layoutTestRelativePositioning_trailing2; SlotsLayout.position: SlotsLayout.Last-2; width: units.gu(3); height: units.gu(9) }
 
210
        }
 
211
        ListItemLayout {
 
212
            id: layoutTestRelativePositioning2
 
213
            readonly property var leadingSlots: [layoutTestRelativePositioning2_leading1]
 
214
            readonly property var trailingSlots: [layoutTestRelativePositioning2_trailing2, layoutTestRelativePositioning2_trailing1]
 
215
            Item { id: layoutTestRelativePositioning2_leading1; SlotsLayout.position: SlotsLayout.Leading-3; width: units.gu(6); height: units.gu(3) }
 
216
            Item { id: layoutTestRelativePositioning2_trailing1; SlotsLayout.position: SlotsLayout.Trailing+1; width: units.gu(1); height: units.gu(7) }
 
217
            Item { id: layoutTestRelativePositioning2_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(9) }
 
218
        }
 
219
        ListItemLayout {
 
220
            id: layoutTestNullSizeSlots
 
221
            readonly property var leadingSlots: []
 
222
            property var trailingSlots: [layoutNullSizeSlots_trailing1, layoutNullSizeSlots_trailing2]
 
223
            title.text: "Hello"
 
224
            //we will reset the slot which is taller than mainSlot and test height and positions
 
225
            Item { id: layoutNullSizeSlots_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(5); height: parent.mainSlot.height+20 }
 
226
            Item { id: layoutNullSizeSlots_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(4) }
 
227
        }
 
228
        ListItemLayout {
 
229
            id: layoutTestOverrideVerticalPositioning
 
230
            readonly property var leadingSlots: []
 
231
            readonly property var trailingSlots: [layoutTestOverrideVerticalPositioning_trailing1,
 
232
                layoutTestOverrideVerticalPositioning_trailing2]
 
233
            title.text: "Hello"
 
234
            //we will reset the slot which is taller than mainSlot and test height and positions
 
235
            Item {
 
236
                id: layoutTestOverrideVerticalPositioning_trailing1;
 
237
                SlotsLayout.position: SlotsLayout.Trailing;
 
238
                width: units.gu(5);
 
239
                height: units.gu(2)
 
240
            }
 
241
            Item {
 
242
                id: layoutTestOverrideVerticalPositioning_trailing2;
 
243
                SlotsLayout.overrideVerticalPositioning: true
 
244
                SlotsLayout.position: SlotsLayout.Trailing;
 
245
                anchors.bottom: parent.bottom
 
246
                width: units.gu(3);
 
247
                height: parent.mainSlot.height+10
 
248
            }
 
249
        }
 
250
        ListItemLayout {
 
251
            id: layoutTestIgnoreSomeChangesOnMainSlot
 
252
            readonly property var leadingSlots: [layoutTestIgnoreSomeChangesOnMainSlot_leading1]
 
253
            readonly property var trailingSlots: []
 
254
            title.text: "Hello"
 
255
            //we will reset the slot which is taller than mainSlot and test height and positions
 
256
            Item {
 
257
                id: layoutTestIgnoreSomeChangesOnMainSlot_leading1;
 
258
                SlotsLayout.position: SlotsLayout.Leading;
 
259
                width: units.gu(4)
 
260
                height: parent.mainSlot.height + 50
 
261
            }
 
262
        }
 
263
        ListItemLayout {
 
264
            id: layoutTestMainSlotAttachedProps
 
265
            readonly property var leadingSlots: [layoutTestMainSlotAttachedProps_leading1]
 
266
            readonly property var trailingSlots: []
 
267
            title.text: "Hello"
 
268
            //we will reset the slot which is taller than mainSlot and test height and positions
 
269
            Item {
 
270
                id: layoutTestMainSlotAttachedProps_leading1;
 
271
                SlotsLayout.position: SlotsLayout.Leading;
 
272
                width: units.gu(4)
 
273
                height: parent.mainSlot.height + 50
 
274
            }
 
275
        }
 
276
        ListItemLayout {
 
277
            id: layoutTestDefaultSlotsAttachedProps
 
278
            readonly property var leadingSlots: []
 
279
            property var trailingSlots: [layoutTestDefaultSlotsAttachedProps_trailing1]
 
280
            Item { id: layoutTestDefaultSlotsAttachedProps_trailing1 }
 
281
        }
 
282
        //UCLabel initially had REVISION 1 around textSize Q_PROPERTY
 
283
        //That breaks initialization of textSize from QML when done on
 
284
        //the UCLabels we created from C++! (changing textSize works from JS, fyi)
 
285
        //This component makes sure we don't break this usecase again in the future
 
286
        ListItemLayout {
 
287
            id: layoutTestCustomTextSizeInitializationFromQml
 
288
            title.text: "Hello"
 
289
            title.textSize: Label.XLarge
 
290
        }
 
291
    }
 
292
 
 
293
    UbuntuTestCase {
 
294
        name: "SlotsLayout"
 
295
        when: windowShown
 
296
 
 
297
        function warningMsg(msg) {
 
298
            return testUtil.callerFile() + ": " + msg
 
299
        }
 
300
 
 
301
        //Visual rule:
 
302
        //when we have at least one slot which is taller than mainSlot and taller than 4GU,
 
303
        //we want the top and bottom padding to be 1GU instead of 2GU
 
304
        property real topBottomPaddingThreshold: units.gu(4)
 
305
        property real smallerTopBottomPadding: units.gu(1)
 
306
        property real tallerTopBottomPadding: units.gu(2)
 
307
 
 
308
        function standardTestsData() {
 
309
            return [
 
310
                        { tag: "Empty", item: layout  },
 
311
                        { tag: "Labels", item: layoutLabels },
 
312
                        { tag: "One leading slot", item: layoutOneLeading },
 
313
                        { tag: "One trailing slot", item: layoutOneTrailing },
 
314
                        { tag: "One leading, one trailing slots", item: layoutOneLeadingOneTrailing },
 
315
                        { tag: "Two trailing", item: layoutTwoTrailing },
 
316
                        { tag: "One leading, two trailing slots", item: layoutOneLeadingTwoTrailing },
 
317
                        { tag: "One leading, two trailing slots with custom paddings", item: layoutCustomSlotsPadding },
 
318
                    ]
 
319
        }
 
320
 
 
321
        //This excludes mainSlot and the slots which have overrideVerticalPositioning enabled!
 
322
        function maxSlotsHeight(item) {
 
323
            var maxHeight = 0
 
324
            var i = 0
 
325
            for (i = 0; i < item.leadingSlots.length; ++i) {
 
326
                var slot = item.leadingSlots[i]
 
327
                if (!slot.SlotsLayout.overrideVerticalPositioning)  {
 
328
                    maxHeight = Math.max(slot.height + slot.SlotsLayout.padding.top
 
329
                                         + slot.SlotsLayout.padding.bottom, maxHeight)
 
330
                }
 
331
            }
 
332
            for (i = 0; i < item.trailingSlots.length; ++i) {
 
333
                var currSlot = item.trailingSlots[i]
 
334
                if (!currSlot.SlotsLayout.overrideVerticalPositioning)  {
 
335
                    maxHeight = Math.max(currSlot.height + currSlot.SlotsLayout.padding.top
 
336
                                         + currSlot.SlotsLayout.padding.bottom, maxHeight)
 
337
                }
 
338
            }
 
339
            return maxHeight
 
340
        }
 
341
 
 
342
        function expectedImplicitHeight(item) {
 
343
            var height = maxSlotsHeight(item)
 
344
            if (item.mainSlot !== null) {
 
345
                height = Math.max(height, item.mainSlot.height
 
346
                                  + item.mainSlot.SlotsLayout.padding.top
 
347
                                  + item.mainSlot.SlotsLayout.padding.bottom)
 
348
            }
 
349
            return height + item.padding.top + item.padding.bottom
 
350
        }
 
351
 
 
352
        //otherwise center the slots vertically
 
353
        function mustAlignSlotsToTop(item) {
 
354
            if (item.mainSlot === null) {
 
355
                return false
 
356
            }
 
357
            return maxSlotsHeight(item) < (item.mainSlot.height
 
358
                                           + item.mainSlot.SlotsLayout.padding.top
 
359
                                           + item.mainSlot.SlotsLayout.padding.bottom)
 
360
        }
 
361
        function useSmallerTopBottomPadding(item) {
 
362
            return !mustAlignSlotsToTop(item)
 
363
                    && maxSlotsHeight(item) > topBottomPaddingThreshold
 
364
        }
 
365
 
 
366
        function checkDefaultPadding(item) {
 
367
            if (useSmallerTopBottomPadding(item)) {
 
368
                compare(item.padding.top, smallerTopBottomPadding, "Default smaller top padding")
 
369
                compare(item.padding.bottom, smallerTopBottomPadding, "Default smaller bottom padding")
 
370
            } else {
 
371
                compare(item.padding.top, tallerTopBottomPadding, "Default top padding")
 
372
                compare(item.padding.bottom, tallerTopBottomPadding, "Default bottom padding")
 
373
            }
 
374
            compare(item.padding.leading, units.gu(1), "Default leading padding")
 
375
            compare(item.padding.trailing, units.gu(1), "Default trailing padding")
 
376
        }
 
377
 
 
378
        function checkImplicitSize(item) {
 
379
            compare(item.implicitHeight, expectedImplicitHeight(item), "Implicit height check")
 
380
            compare(item.implicitWidth, column.width, "Fill parent's width")
 
381
        }
 
382
 
 
383
        //this functions takes a layouts and checks that the slots in the lists
 
384
        //"leadingSlots" and "trailingSlots" are following the visual rules
 
385
        //NOTE: THIS METHOD DOESN'T IGNORE ANY SLOT (because of visibility or similar).
 
386
        //slots which are expected to be ignored by the cpp implementation should be
 
387
        //removed from "leadingSlots" and "trailingSlots" before calling this method
 
388
        function checkSlotsPosition(item) {
 
389
            var slots = []
 
390
            slots = slots.concat(item.leadingSlots)
 
391
            if (item.mainSlot !== null) {
 
392
                slots = slots.concat(item.mainSlot)
 
393
            }
 
394
            slots = slots.concat(item.trailingSlots)
 
395
 
 
396
            var expectedX = item.padding.leading;
 
397
            var i = 0
 
398
            for (i = 0; i < slots.length; ++i) {
 
399
                var slot = slots[i]
 
400
 
 
401
                expectedX += slot.SlotsLayout.padding.leading
 
402
                compare(slot.x, expectedX, "Slot's horizontal position")
 
403
                expectedX += slot.width
 
404
                expectedX += slot.SlotsLayout.padding.trailing
 
405
 
 
406
                //mainSlot ignores the value of its overrideVerticalPositioning
 
407
                if (slot.SlotsLayout.overrideVerticalPositioning && slot !== item.mainSlot) {
 
408
                    //NOTE: we're assuming the test item doesn't set any custom anchor!!
 
409
                    compare(slot.y, 0, "Override vertical positioning: vertical position")
 
410
                } else {
 
411
                    if (mustAlignSlotsToTop(item)) {
 
412
                        compare(slot.anchors.top, item.top,
 
413
                                "Automatic vertical positioning: top anchor, \"aligned to the top\" positioning mode")
 
414
                        compare(slot.anchors.topMargin, item.padding.top + slot.SlotsLayout.padding.top,
 
415
                                "Automatic vertical positioning: topMargin, \"aligned to the top\" positioning mode")
 
416
                    } else {
 
417
                        compare(slot.anchors.verticalCenter, item.verticalCenter,
 
418
                                "Automatic vertical positioning: verticalCenter anchor, \"vertically centered\" positioning mode ")
 
419
                        compare(slot.anchors.verticalCenterOffset,
 
420
                                (item.padding.top - item.padding.bottom
 
421
                                 + slot.SlotsLayout.padding.top - slot.SlotsLayout.padding.bottom) / 2.0,
 
422
                                "Automatic vertical positioning: verticalCenterOffset, \"vertically centered\" positioning mode ")
 
423
                    }
 
424
                }
 
425
            }
 
426
        }
 
427
 
 
428
        function test_contentPadding_data() {
 
429
            return standardTestsData()
 
430
        }
 
431
        function test_contentPadding(data) {
 
432
            checkDefaultPadding(data.item)
 
433
        }
 
434
 
 
435
        function test_implicitSize_data() {
 
436
            return standardTestsData()
 
437
        }
 
438
        function test_implicitSize(data) {
 
439
            checkImplicitSize(data.item)
 
440
        }
 
441
 
 
442
        function test_layout_data(){
 
443
            return standardTestsData()
 
444
        }
 
445
        function test_layout(data) {
 
446
            checkSlotsPosition(data.item)
 
447
        }
 
448
 
 
449
        function test_customPadding_data(){
 
450
            return [
 
451
                        { tag: "Custom padding", item: layoutCustomPadding },
 
452
                    ]
 
453
        }
 
454
        function test_customPadding(data) {
 
455
            compare(data.item.padding.top, units.gu(1), "Custom padding top")
 
456
            compare(data.item.padding.bottom, units.gu(2), "Custom padding bottom")
 
457
            compare(data.item.padding.leading, units.gu(3), "Custom padding leading")
 
458
            compare(data.item.padding.trailing, units.gu(4), "Custom padding trailing")
 
459
            compare(data.item.implicitHeight, expectedImplicitHeight(data.item),
 
460
                    "Implicit height with custom padding")
 
461
 
 
462
            //trigger relayout
 
463
            var newLeadingSlotHeight = data.item.height + units.gu(2)
 
464
            layoutCustomPadding.leadingSlots[0].height = newLeadingSlotHeight;
 
465
            compare(data.item.leadingSlots[0].height, newLeadingSlotHeight, "Leading slot height update")
 
466
 
 
467
            //check that the padding stays the same, but the height changes
 
468
            compare(data.item.padding.top, units.gu(1), "Custom padding top")
 
469
            compare(data.item.padding.bottom, units.gu(2), "Custom padding bottom")
 
470
            compare(data.item.padding.leading, units.gu(3), "Custom padding leading")
 
471
            compare(data.item.padding.trailing, units.gu(4), "Custom padding trailing")
 
472
            compare(data.item.implicitHeight, newLeadingSlotHeight + data.item.padding.top + data.item.padding.bottom,
 
473
                    "Implicit height with custom padding after relayout")
 
474
            compare(expectedImplicitHeight(data.item), newLeadingSlotHeight + data.item.padding.top + data.item.padding.bottom,
 
475
                    "expectedImplicitHeight test")
 
476
 
 
477
            //check that slots are still in the right position
 
478
            checkSlotsPosition(data.item)
 
479
        }
 
480
 
 
481
        function test_relayoutAfterChangingSlotsSize() {
 
482
            checkSlotsPosition(layoutTestChangeSlotsSize)
 
483
 
 
484
            layoutTestChangeSlotsSize.leadingSlots[0].width = units.gu(12)
 
485
            compare(layoutTestChangeSlotsSize.leadingSlots[0].width, units.gu(12), "Change slot's width")
 
486
            checkSlotsPosition(layoutTestChangeSlotsSize)
 
487
 
 
488
            layoutTestChangeSlotsSize.leadingSlots[0].height = layoutTestChangeSlotsSize.mainSlot.height
 
489
            compare(layoutTestChangeSlotsSize.leadingSlots[0].height,
 
490
                    layoutTestChangeSlotsSize.mainSlot.height, "Change slot's height")
 
491
            compare(layoutTestChangeSlotsSize.implicitHeight,
 
492
                    layoutTestChangeSlotsSize.mainSlot.height
 
493
                    + layoutTestChangeSlotsSize.padding.top
 
494
                    + layoutTestChangeSlotsSize.padding.bottom,
 
495
                    "Layout's implicit height check after slot's height change")
 
496
            checkSlotsPosition(layoutTestChangeSlotsSize)
 
497
            checkImplicitSize(layoutTestChangeSlotsSize)
 
498
        }
 
499
 
 
500
        function test_mainSlotSize() {
 
501
            compare(layoutTestMainSlotSize.mainSlot.width,
 
502
                    layoutTestMainSlotSize.width
 
503
                    - layoutTestMainSlotSize.padding.leading - layoutTestMainSlotSize.padding.trailing
 
504
                    - layoutTestMainSlotSize.trailingSlots[0].width
 
505
                    - layoutTestMainSlotSize.trailingSlots[0].SlotsLayout.padding.leading
 
506
                    - layoutTestMainSlotSize.trailingSlots[0].SlotsLayout.padding.trailing
 
507
                    - layoutTestMainSlotSize.mainSlot.SlotsLayout.padding.leading
 
508
                    - layoutTestMainSlotSize.mainSlot.SlotsLayout.padding.trailing,
 
509
                    "Main slot's width")
 
510
 
 
511
            compare(layoutTestMainSlotSize.mainSlot.height,
 
512
                    layoutTestMainSlotSize.title.height,
 
513
                    "Main slot's height, title only")
 
514
 
 
515
            layoutTestMainSlotSize.subtitle.text = "Test here"
 
516
            compare(layoutTestMainSlotSize.mainSlot.height,
 
517
                    layoutTestMainSlotSize.subtitle.y + layoutTestMainSlotSize.subtitle.height,
 
518
                    "Main slot's height, title+subtitle")
 
519
 
 
520
            layoutTestMainSlotSize.summary.text = "Test here"
 
521
            compare(layoutTestMainSlotSize.mainSlot.height,
 
522
                    layoutTestMainSlotSize.summary.y + layoutTestMainSlotSize.summary.height,
 
523
                    "Main slot's height, title+subtitle+summary")
 
524
 
 
525
            checkSlotsPosition(layoutTestMainSlotSize)
 
526
        }
 
527
 
 
528
        function test_changeSlotPosition() {
 
529
            checkSlotsPosition(layoutTestChangeSlotPosition)
 
530
            layoutTestChangeSlotPosition.leadingSlots[0].SlotsLayout.position = SlotsLayout.Trailing
 
531
            compare(layoutTestChangeSlotPosition.leadingSlots[0].SlotsLayout.position, SlotsLayout.Trailing, "Slot's position change to Trailing")
 
532
 
 
533
            layoutTestChangeSlotPosition.trailingSlots = [layoutTestChangeSlotPosition.leadingSlots[0]]
 
534
            layoutTestChangeSlotPosition.leadingSlots = []
 
535
            compare(layoutTestChangeSlotPosition.leadingSlots.length, 0, "Change slot's position, leading slots array")
 
536
            compare(layoutTestChangeSlotPosition.trailingSlots.length, 1, "Change slot's position, trailing slots array")
 
537
            checkSlotsPosition(layoutTestChangeSlotPosition)
 
538
 
 
539
            layoutTestChangeSlotPosition.trailingSlots[0].SlotsLayout.position = SlotsLayout.First
 
540
            compare(layoutTestChangeSlotPosition.trailingSlots[0].SlotsLayout.position, SlotsLayout.First, "Slot's position change to First")
 
541
            layoutTestChangeSlotPosition.leadingSlots = [layoutTestChangeSlotPosition.trailingSlots[0]]
 
542
            layoutTestChangeSlotPosition.trailingSlots = []
 
543
            compare(layoutTestChangeSlotPosition.leadingSlots.length, 1, "Change slot's position, leading slots array")
 
544
            compare(layoutTestChangeSlotPosition.trailingSlots.length, 0, "Change slot's position, trailing slots array")
 
545
            checkSlotsPosition(layoutTestChangeSlotPosition)
 
546
        }
 
547
 
 
548
        function test_slotVisibilityChange() {
 
549
            layoutTestSlotVisibilityChange.leadingSlots[0].visible = false
 
550
            compare(layoutTestSlotVisibilityChange.leadingSlots[0].visible, false, "Slot's visibility, false")
 
551
            var tmpSlot = layoutTestSlotVisibilityChange.leadingSlots[0]
 
552
            layoutTestSlotVisibilityChange.leadingSlots = []
 
553
            compare(layoutTestSlotVisibilityChange.leadingSlots.length, 0, "Slot's visibility, fake leading slots count")
 
554
            compare(layoutTestSlotVisibilityChange.trailingSlots.length, 0, "Slot's visibility, fake trailing slots count")
 
555
 
 
556
            checkSlotsPosition(layoutTestSlotVisibilityChange)
 
557
            checkImplicitSize(layoutTestSlotVisibilityChange)
 
558
 
 
559
            layoutTestSlotVisibilityChange.leadingSlots = [tmpSlot]
 
560
            layoutTestSlotVisibilityChange.leadingSlots[0].visible = true
 
561
            compare(layoutTestSlotVisibilityChange.leadingSlots[0].visible, true, "Slot's visibility, true")
 
562
            compare(layoutTestSlotVisibilityChange.mainSlot.height
 
563
                    < layoutTestSlotVisibilityChange.leadingSlots[0].height, true, "Visibility test, slot's height")
 
564
            checkSlotsPosition(layoutTestSlotVisibilityChange)
 
565
            checkImplicitSize(layoutTestSlotVisibilityChange)
 
566
        }
 
567
 
 
568
 
 
569
        function test_relativePositioning_data(){
 
570
            return [
 
571
                        { tag: "Relative positioning 1", item: layoutTestRelativePositioning },
 
572
                        { tag: "Relative positioning 2", item: layoutTestRelativePositioning2 }
 
573
                    ]
 
574
        }
 
575
        function test_relativePositioning(data) {
 
576
            checkSlotsPosition(data.item)
 
577
        }
 
578
 
 
579
        function test_nullSizeSlots() {
 
580
            compare(layoutTestNullSizeSlots.trailingSlots.length, 2, "Null size slot test, fake trailing slots list")
 
581
            checkSlotsPosition(layoutTestNullSizeSlots)
 
582
            checkImplicitSize(layoutTestNullSizeSlots)
 
583
 
 
584
            layoutTestNullSizeSlots.trailingSlots[0].height = 0
 
585
            compare(layoutTestNullSizeSlots.trailingSlots[0].height, 0, "Null size slot test, slot's height")
 
586
            //remove that slot from the list of slots we expect to be laid out
 
587
            var tmpSlot = layoutTestNullSizeSlots.trailingSlots[0]
 
588
            layoutTestNullSizeSlots.trailingSlots = [layoutTestNullSizeSlots.trailingSlots[1]]
 
589
            compare(layoutTestNullSizeSlots.trailingSlots.length, 1, "Null size slot test, fake trailing slots list")
 
590
            checkSlotsPosition(layoutTestNullSizeSlots)
 
591
            checkImplicitSize(layoutTestNullSizeSlots)
 
592
 
 
593
            layoutTestNullSizeSlots.trailingSlots[0].width = 0
 
594
            compare(layoutTestNullSizeSlots.trailingSlots[0].width, 0, "Null size slot test, slot's width")
 
595
            var tmpSlot2 = layoutTestNullSizeSlots.trailingSlots[0]
 
596
            layoutTestNullSizeSlots.trailingSlots = []
 
597
            compare(layoutTestNullSizeSlots.trailingSlots.length, 0, "Null size slot test, fake trailing slots list")
 
598
            checkSlotsPosition(layoutTestNullSizeSlots)
 
599
            checkImplicitSize(layoutTestNullSizeSlots)
 
600
 
 
601
            //bring the first slot back
 
602
            tmpSlot.height = 300
 
603
            compare(tmpSlot.height, 300, "Null size slot test, slot's height")
 
604
            layoutTestNullSizeSlots.trailingSlots = [tmpSlot]
 
605
            compare(layoutTestNullSizeSlots.trailingSlots.length, 1, "Null size slot test, fake trailing slots list")
 
606
            checkSlotsPosition(layoutTestNullSizeSlots)
 
607
            checkImplicitSize(layoutTestNullSizeSlots)
 
608
 
 
609
            //bring the second slot back
 
610
            tmpSlot2.width = 22
 
611
            compare(tmpSlot2.width, 22, "Null size slot test, slot's width")
 
612
            layoutTestNullSizeSlots.trailingSlots = [tmpSlot, tmpSlot2]
 
613
            compare(layoutTestNullSizeSlots.trailingSlots.length, 2, "Null size slot test, fake trailing slots list")
 
614
            checkSlotsPosition(layoutTestNullSizeSlots)
 
615
            checkImplicitSize(layoutTestNullSizeSlots)
 
616
        }
 
617
 
 
618
        function test_overrideVerticalPositioning() {
 
619
            //we expect the component to reset the vertical anchors when overrideVerticalPositioning changes value
 
620
            compare(layoutTestOverrideVerticalPositioning.trailingSlots[1].anchors.bottom,
 
621
                    layoutTestOverrideVerticalPositioning.bottom,
 
622
                    "Override vertical positioning test, initial slot's bottom anchor")
 
623
            compare(layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning,
 
624
                    true, "Override vertical positioning test, attached-property's initial value")
 
625
            compare(layoutTestOverrideVerticalPositioning.trailingSlots.length, 2,
 
626
                    "Override vertical positioning test, fake trailing slots list")
 
627
            layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning = false
 
628
            compare(layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning,
 
629
                    false, "Override vertical positioning test, attached-property's new value, false")
 
630
            checkSlotsPosition(layoutTestOverrideVerticalPositioning)
 
631
            checkImplicitSize(layoutTestOverrideVerticalPositioning)
 
632
 
 
633
            layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning = true
 
634
            compare(layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning,
 
635
                    true, "Override vertical positioning test, attached-property's new value, true")
 
636
            checkSlotsPosition(layoutTestOverrideVerticalPositioning)
 
637
            checkImplicitSize(layoutTestOverrideVerticalPositioning)
 
638
        }
 
639
 
 
640
        function test_ignoreSomeChangesOnMainSlot() {
 
641
            compare(layoutTestIgnoreSomeChangesOnMainSlot.leadingSlots.length, 1,
 
642
                    "Ignore some changes on main slot test, fake trailing slots list")
 
643
            compare(layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.overrideVerticalPositioning,
 
644
                    false, "Ignore some changes on main slot test, default override value")
 
645
            //we want main slot to be vertically centered, to check if disabling overrideVerticalPositioning
 
646
            //will cause a change in its position
 
647
            compare(layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.height
 
648
                    < maxSlotsHeight(layoutTestIgnoreSomeChangesOnMainSlot), true,
 
649
                    "Ignore some changes on main slot test, slot's height")
 
650
            checkSlotsPosition(layoutTestIgnoreSomeChangesOnMainSlot)
 
651
            checkImplicitSize(layoutTestIgnoreSomeChangesOnMainSlot)
 
652
 
 
653
            //this shouldn't trigger a relayout
 
654
            layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.overrideVerticalPositioning = true
 
655
            compare(layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.overrideVerticalPositioning,
 
656
                    true, "Ignore some changes on main slot test, new override value")
 
657
            //let's force a relayout, just to make sure changing overrideVerticalPositioning
 
658
            //didn't have any effect on mainSlot
 
659
            layoutTestIgnoreSomeChangesOnMainSlot.leadingSlots[0].height += 100
 
660
            checkSlotsPosition(layoutTestIgnoreSomeChangesOnMainSlot)
 
661
            checkImplicitSize(layoutTestIgnoreSomeChangesOnMainSlot)
 
662
 
 
663
            //let's try to force positioning mainSlot *before* a leading slot. This must fail
 
664
            layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.position =
 
665
                    layoutTestIgnoreSomeChangesOnMainSlot.leadingSlots[0].SlotsLayout.position - 5
 
666
            compare(layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.position,
 
667
                    layoutTestIgnoreSomeChangesOnMainSlot.leadingSlots[0].SlotsLayout.position - 5,
 
668
                    "Ignore some changes on main slot test, change mainSlot's position")
 
669
            checkSlotsPosition(layoutTestIgnoreSomeChangesOnMainSlot)
 
670
            checkImplicitSize(layoutTestIgnoreSomeChangesOnMainSlot)
 
671
        }
 
672
 
 
673
        function test_changeAttachedPropertiesInMainSlot() {
 
674
            checkSlotsPosition(layoutTestMainSlotAttachedProps)
 
675
            checkImplicitSize(layoutTestMainSlotAttachedProps)
 
676
            var mainSlot = layoutTestMainSlotAttachedProps.mainSlot
 
677
 
 
678
            mainSlot.SlotsLayout.padding.top = 300
 
679
            compare(layoutTestMainSlotAttachedProps.mainSlot.SlotsLayout.padding.top, 300,
 
680
                    "Change mainSlot's attached props test, padding.top")
 
681
            checkSlotsPosition(layoutTestMainSlotAttachedProps)
 
682
            checkImplicitSize(layoutTestMainSlotAttachedProps)
 
683
 
 
684
            mainSlot.SlotsLayout.padding.bottom = 180
 
685
            compare(mainSlot.SlotsLayout.padding.bottom, 180,
 
686
                    "Change mainSlot's attached props test, padding.bottom")
 
687
            checkSlotsPosition(layoutTestMainSlotAttachedProps)
 
688
            checkImplicitSize(layoutTestMainSlotAttachedProps)
 
689
        }
 
690
 
 
691
        function test_defaultSlotsAttachedProps() {
 
692
            var slot = layoutTestDefaultSlotsAttachedProps.trailingSlots[0]
 
693
            compare(slot.SlotsLayout.position, SlotsLayout.Trailing,
 
694
                    "Default slots attached props, position")
 
695
            compare(slot.SlotsLayout.overrideVerticalPositioning, false,
 
696
                    "Default slots attached props, overrideVerticalPositioning")
 
697
            compare(slot.SlotsLayout.padding.top, 0,
 
698
                    "Default slots attached props, padding.top")
 
699
            compare(slot.SlotsLayout.padding.bottom, 0,
 
700
                    "Default slots attached props, padding.bottom")
 
701
            compare(slot.SlotsLayout.padding.leading, units.gu(1),
 
702
                    "Default slots attached props, padding.leading")
 
703
            compare(slot.SlotsLayout.padding.trailing, units.gu(1),
 
704
                    "Default slots attached props, padding.trailing")
 
705
        }
 
706
 
 
707
        function checkLabelsY(listitemlayout) {
 
708
            compare(listitemlayout.title.y, 0,
 
709
                    "Default labels positioning, title's y")
 
710
 
 
711
            //we don't care about having the correct Y if the label
 
712
            //is empty or not visible anyway
 
713
            if (listitemlayout.subtitle.text !== ""
 
714
                    && listitemlayout.subtitle.visible) {
 
715
                if (listitemlayout.title.text === "" ||
 
716
                        !listitemlayout.title.visible) {
 
717
                    compare(listitemlayout.subtitle.y, 0,
 
718
                            "Default labels positioning, subtitle's y")
 
719
                } else {
 
720
                    compare(listitemlayout.subtitle.y,
 
721
                            listitemlayout.title.baselineOffset + units.dp(4),
 
722
                            "Default labels positioning, subtitle's y")
 
723
                }
 
724
            }
 
725
 
 
726
            //we don't care about having the correct Y if the label
 
727
            //is empty or not visible anyway
 
728
            if (listitemlayout.summary.text !== ""
 
729
                    && listitemlayout.summary.visible) {
 
730
                if (listitemlayout.subtitle.text === "" ||
 
731
                        !listitemlayout.subtitle.visible) {
 
732
                    if (listitemlayout.title.text === "" ||
 
733
                            !listitemlayout.title.visible) {
 
734
                        compare(listitemlayout.summary.y, 0,
 
735
                                "Default labels positioning, summary's y")
 
736
                    } else {
 
737
                        compare(listitemlayout.summary.y, listitemlayout.title.baselineOffset + units.dp(4),
 
738
                                "Default labels positioning, summary's y")
 
739
                    }
 
740
                } else  {
 
741
                    compare(listitemlayout.summary.y, listitemlayout.subtitle.y + listitemlayout.subtitle.height,
 
742
                            "Default labels positioning, summary's y")
 
743
                }
 
744
            }
 
745
        }
 
746
 
 
747
        function test_defaultMainSlotHeight() {
 
748
            var titleText = layoutLabels.title.text
 
749
            var subtitleText = layoutLabels.subtitle.text
 
750
            var summaryText = layoutLabels.summary.text
 
751
 
 
752
            compare(titleText.length > 0, true, "Default labels positioning, title length")
 
753
            compare(subtitleText.length > 0, true, "Default labels positioning, subtitle length")
 
754
            compare(summaryText.length > 0, true, "Default labels positioning, summary length")
 
755
            checkLabelsY(layoutLabels)
 
756
 
 
757
            var initialHeight = layoutLabels.mainSlot.height
 
758
            compare(initialHeight, layoutLabels.summary.y + layoutLabels.summary.height,
 
759
                    "Default labels positioning, mainSlot's height")
 
760
 
 
761
            //setting text to " " (note, it's NOT empty) should have the same effect as setting it to "blabla"
 
762
            layoutLabels.summary.text = " "
 
763
            compare(layoutLabels.summary.text, " ", "Default labels positioning, summary 1 whitespace text")
 
764
            compare(layoutLabels.mainSlot.height, initialHeight,
 
765
                    "Default labels positioning, mainSlot's height")
 
766
            checkLabelsY(layoutLabels)
 
767
 
 
768
            //empty text -> we ignore summary in the height computation
 
769
            layoutLabels.summary.text = ""
 
770
            compare(layoutLabels.summary.text, "", "Default labels positioning, empty summary text")
 
771
            compare(layoutLabels.mainSlot.height, layoutLabels.subtitle.y + layoutLabels.subtitle.height,
 
772
                    "Default labels positioning, mainSlot's height")
 
773
            checkLabelsY(layoutLabels)
 
774
 
 
775
            layoutLabels.subtitle.text = ""
 
776
            compare(layoutLabels.subtitle.text, "", "Default labels positioning, empty subtitle text")
 
777
            compare(layoutLabels.mainSlot.height, layoutLabels.title.y + layoutLabels.title.height,
 
778
                    "Default labels positioning, mainSlot's height")
 
779
            checkLabelsY(layoutLabels)
 
780
 
 
781
            //all labels are empty now
 
782
            layoutLabels.title.text = ""
 
783
            compare(layoutLabels.title.text, "", "Default labels positioning, empty title text")
 
784
            compare(layoutLabels.subtitle.text, "", "Default labels positioning, empty subtitle text")
 
785
            compare(layoutLabels.summary.text, "", "Default labels positioning, empty summary text")
 
786
            compare(layoutLabels.mainSlot.height, 0,
 
787
                    "Default labels positioning, mainSlot's height")
 
788
            checkLabelsY(layoutLabels)
 
789
 
 
790
            //try title and summary, skipping subtitle
 
791
            layoutLabels.title.text = "test"
 
792
            layoutLabels.summary.text = "test"
 
793
            compare(layoutLabels.title.text, "test", "Default labels positioning, empty title text")
 
794
            compare(layoutLabels.subtitle.text, "", "Default labels positioning, empty subtitle text")
 
795
            compare(layoutLabels.summary.text, "test", "Default labels positioning, empty summary text")
 
796
            compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
 
797
                    "Default labels positioning, mainSlot's height")
 
798
            checkLabelsY(layoutLabels)
 
799
 
 
800
            //let's try with summary only
 
801
            layoutLabels.title.text = ""
 
802
            compare(layoutLabels.title.text, "", "Default labels positioning, empty title text")
 
803
            compare(layoutLabels.subtitle.text, "", "Default labels positioning, empty subtitle text")
 
804
            compare(layoutLabels.summary.text, "test", "Default labels positioning, empty summary text")
 
805
            compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
 
806
                    "Default labels positioning, mainSlot's height")
 
807
            checkLabelsY(layoutLabels)
 
808
 
 
809
            //try to set all texts and test positions again
 
810
            layoutLabels.title.text = titleText
 
811
            layoutLabels.subtitle.text = subtitleText
 
812
            layoutLabels.summary.text = summaryText
 
813
            compare(layoutLabels.mainSlot.height, initialHeight,
 
814
                    "Default labels positioning, mainSlot's height")
 
815
            checkLabelsY(layoutLabels)
 
816
        }
 
817
 
 
818
        function test_fontsizeChange() {
 
819
            var initialHeight = layoutLabels.mainSlot.height
 
820
            compare(layoutLabels.title.textSize, Label.Medium, "Labels textSize change, default title textsize")
 
821
            compare(layoutLabels.subtitle.textSize, Label.Small, "Labels textSize change, default subtitle textsize")
 
822
            compare(layoutLabels.summary.textSize, Label.Small, "Labels textSize change, default summary textsize")
 
823
 
 
824
            compare(layoutLabels.title.text.length > 0, true, "Default labels positioning, title length")
 
825
            compare(layoutLabels.subtitle.text.length > 0, true, "Default labels positioning, subtitle length")
 
826
            compare(layoutLabels.summary.text.length > 0, true, "Default labels positioning, summary length")
 
827
            compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
 
828
                    "Default labels positioning, main slot height")
 
829
 
 
830
            layoutLabels.title.textSize = Label.XLarge
 
831
            compare(layoutLabels.title.textSize, Label.XLarge, "Labels textSize change, new title textsize")
 
832
            compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
 
833
                    "Default labels positioning, main slot height")
 
834
 
 
835
            layoutLabels.subtitle.textSize = Label.XLarge
 
836
            compare(layoutLabels.subtitle.textSize, Label.XLarge, "Labels textSize change, new subtitle textsize")
 
837
            compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
 
838
                    "Default labels positioning, main slot height")
 
839
 
 
840
            layoutLabels.summary.textSize = Label.XLarge
 
841
            compare(layoutLabels.summary.textSize, Label.XLarge, "Labels textSize change, new summary textsize")
 
842
            compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
 
843
                    "Default labels positioning, main slot height")
 
844
        }
 
845
 
 
846
        Label {id: customMainSlot }
 
847
        function test_warningOnAttemptToChangeListItemLayoutMainSlot() {
 
848
            ignoreWarning(warningFormat(60, 9, "QML ListItemLayout: Setting a different mainSlot on ListItemLayout is not supported. Please use SlotsLayout instead."))
 
849
            layoutLabels.mainSlot = customMainSlot
 
850
        }
 
851
 
 
852
 
 
853
        Component {
 
854
            id: layoutTestQmlContextComponent
 
855
            ListItemLayout {
 
856
                id: layoutTestQmlContext
 
857
                title.text: "<html><body><p dir='ltr'>TEST <img align=absmiddle height=\"10\" width=\"10\" src=\"file:///test.png\" /> </p></body></html>"
 
858
                title.textFormat: Text.RichText
 
859
                subtitle.text: "<html><body><p dir='ltr'>TEST <img align=absmiddle height=\"10\" width=\"10\" src=\"file:///test.png\" /> </p></body></html>"
 
860
                subtitle.textFormat: Text.RichText
 
861
                summary.text: "<html><body><p dir='ltr'>TEST <img align=absmiddle height=\"10\" width=\"10\" src=\"file:///test.png\" /> </p></body></html>"
 
862
                summary.textFormat: Text.RichText
 
863
            }
 
864
        }
 
865
        //lp#1514173
 
866
        //this will make the test segfault if there is a regression
 
867
        function test_defaultLabelsQmlContext() {
 
868
            ignoreWarning(warningMsg("QML Label: Cannot open: file:///test.png"))
 
869
            var obj = layoutTestQmlContextComponent.createObject(main)
 
870
            //wait for rendering otherwise we will not get the "cannot find file" warning
 
871
            //because the img is loaded async
 
872
            waitForRendering(obj)
 
873
            compare(obj !== null, true, "QML ListItemLayout: testing labels' QML context.")
 
874
            obj.destroy()
 
875
        }
 
876
    }
 
877
}