651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
1 |
/*
|
1807.1.1
by Daniel d'Andrada
s/Theme.palette/theme.palette |
2 |
* Copyright 2014,2015 Canonical Ltd.
|
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
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 |
||
1807.3.1
by Albert Astals Cid
Move to importing QtQuick 2.4 & friends |
17 |
import QtQuick 2.4 |
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
18 |
import QtTest 1.0 |
19 |
import "../../../../qml/Dash/Previews" |
|
20 |
import Unity.Test 0.1 as UT |
|
557.8.1
by Michał Sawicz
Adapt to scopes_ng. |
21 |
import Unity 0.2 as Unity |
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
22 |
|
23 |
Rectangle { |
|
24 |
id: root
|
|
25 |
width: units.gu(60) |
|
868.2.13
by Andrea Cimitan
Fix testPreview |
26 |
height: units.gu(60) |
1807.1.1
by Daniel d'Andrada
s/Theme.palette/theme.palette |
27 |
color: theme.palette.selected.background |
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
28 |
|
29 |
Item { |
|
30 |
id: shell
|
|
31 |
||
32 |
anchors.fill: parent |
|
33 |
property var applicationManager: null |
|
34 |
}
|
|
35 |
||
36 |
Unity.FakePreviewModel { |
|
37 |
id: mockPreviewModel
|
|
38 |
}
|
|
39 |
||
2704.2.1
by Albert Astals Cid
Bring back fix for 1517830 |
40 |
ListModel { |
41 |
id: tracksModel
|
|
42 |
Component.onCompleted:
|
|
43 |
{
|
|
44 |
tracksModel.append( { "type" : "audio1", |
|
45 |
"widgetId" : "audiopw1", |
|
46 |
"properties" : { "tracks" : [ |
|
47 |
{ title: "Some track name", length: "30", source: "/not/existinga/path/testsound1" } |
|
48 |
]
|
|
49 |
}
|
|
50 |
}
|
|
51 |
);
|
|
52 |
tracksModel.append( |
|
53 |
{ "type" : "audio", |
|
54 |
"widgetId" : "audiopw", |
|
55 |
"properties" : { "tracks" : [ |
|
56 |
{ title: "Some track name", length: "30", source: "/not/existing/path/testsound1" }, |
|
57 |
{ title: "Some other track name", subtitle: "Subtitle", length: "83", source: "/not/existing/path/testsound2" }, |
|
58 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound3" }, |
|
59 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound4" }, |
|
60 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound5" }, |
|
61 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound6" }, |
|
62 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound7" }, |
|
63 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound8" }, |
|
64 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound9" }, |
|
65 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound10" }, |
|
66 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound11" }, |
|
67 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound12" }, |
|
68 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound13" }, |
|
69 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound14" }, |
|
70 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound15" }, |
|
71 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound16" }, |
|
72 |
{ title: "And another one", length: "7425", source: "/not/existing/path/testsound17" } |
|
73 |
]
|
|
74 |
}
|
|
75 |
} ); |
|
76 |
}
|
|
77 |
}
|
|
78 |
||
79 |
QtObject { |
|
80 |
id: audiosModel
|
|
81 |
property int widgetColumnCount: 1 |
|
82 |
property var columnModel: { tracksModel } |
|
83 |
}
|
|
84 |
||
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
85 |
Preview { |
86 |
id: preview
|
|
87 |
anchors.fill: parent |
|
88 |
||
89 |
previewModel: mockPreviewModel |
|
90 |
}
|
|
91 |
||
92 |
SignalSpy { |
|
93 |
id: triggeredSpy
|
|
94 |
target: mockPreviewModel |
|
557.37.11
by Albert Astals
This makes qmluitests pass here |
95 |
signalName: "triggered" |
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
96 |
}
|
97 |
||
98 |
UT.UnityTestCase { |
|
99 |
name: "Preview" |
|
100 |
when: windowShown |
|
101 |
||
1595.3.1
by Albert Astals Cid
Test for bug #1316660 |
102 |
function init() { |
103 |
var widget = findChild(preview, "previewListRow0"); |
|
104 |
widget.positionViewAtBeginning(); |
|
2704.2.1
by Albert Astals Cid
Bring back fix for 1517830 |
105 |
preview.previewModel = mockPreviewModel; |
1595.3.1
by Albert Astals Cid
Test for bug #1316660 |
106 |
}
|
107 |
||
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
108 |
function test_triggered() { |
651.3.29
by Michał Sawicz
Add more tests and fix review comments. |
109 |
waitForRendering(preview); |
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
110 |
var widget = findChild(preview, "widget-3"); |
111 |
||
112 |
compare(typeof widget, "object", "Could not find the widget object."); |
|
113 |
||
557.37.11
by Albert Astals
This makes qmluitests pass here |
114 |
compare(triggeredSpy.count, 0) |
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
115 |
widget.triggered(widget.widgetId, "mockAction", {"mock": "data"}); |
557.37.11
by Albert Astals
This makes qmluitests pass here |
116 |
compare(triggeredSpy.count, 1) |
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
117 |
|
118 |
var args = triggeredSpy.signalArguments[0]; |
|
119 |
||
120 |
compare(args[0], "widget-3", "Widget id not passed correctly."); |
|
121 |
compare(args[1], "mockAction", "Action id not passed correctly."); |
|
122 |
compare(args[2]["mock"], "data", "Data not passed correctly."); |
|
123 |
}
|
|
651.3.28
by Michał Sawicz
Fix and add test for processingMouseArea. |
124 |
|
651.3.29
by Michał Sawicz
Add more tests and fix review comments. |
125 |
function test_containOnFocus() { |
126 |
waitForRendering(preview); |
|
1010.1.1
by Michael Zanetti
fix make testPreview on larger GRID_UNIT_PX values |
127 |
var widget = findChild(preview, "widget-10"); |
557.38.1
by Albert Astals
Make tests pass a bit more |
128 |
|
129 |
var bottomLeft = preview.mapFromItem(widget, 0, widget.height); |
|
130 |
verify(bottomLeft.y > preview.height); |
|
651.3.29
by Michał Sawicz
Add more tests and fix review comments. |
131 |
|
132 |
widget.forceActiveFocus(); |
|
133 |
||
557.38.1
by Albert Astals
Make tests pass a bit more |
134 |
tryCompareFunction(function () { |
135 |
var bottomLeft = preview.mapFromItem(widget, 0, widget.height); |
|
2657.1.9
by Andrea Cimitan
fix flaky tests |
136 |
return bottomLeft.y <= preview.height + 1 // FIXME the +1 is to workaround https://bugreports.qt.io/browse/QTBUG-56961 |
557.38.1
by Albert Astals
Make tests pass a bit more |
137 |
}, true); |
651.3.29
by Michał Sawicz
Add more tests and fix review comments. |
138 |
}
|
139 |
||
140 |
function test_containOnGrow() { |
|
141 |
waitForRendering(preview); |
|
142 |
var widget = findChild(preview, "widget-13"); |
|
143 |
||
557.38.1
by Albert Astals
Make tests pass a bit more |
144 |
var bottomLeft = preview.mapFromItem(widget, 0, widget.height); |
145 |
verify(bottomLeft.y > preview.height); |
|
146 |
||
147 |
root.height += units.gu(50); |
|
651.3.29
by Michał Sawicz
Add more tests and fix review comments. |
148 |
|
149 |
tryCompareFunction(function () { |
|
150 |
var bottomLeft = preview.mapFromItem(widget, 0, widget.height); |
|
2657.1.9
by Andrea Cimitan
fix flaky tests |
151 |
return bottomLeft.y <= preview.height + 1 // FIXME the +1 is to workaround https://bugreports.qt.io/browse/QTBUG-56961 |
651.3.29
by Michał Sawicz
Add more tests and fix review comments. |
152 |
}, true); |
153 |
}
|
|
1595.3.1
by Albert Astals Cid
Test for bug #1316660 |
154 |
|
155 |
function test_comboEnsureVisible() { |
|
156 |
waitForRendering(preview); |
|
157 |
||
158 |
// Scroll down
|
|
159 |
var previewListRow0 = findChild(preview, "previewListRow0"); |
|
1657.1.3
by Albert Astals Cid
A bit of refactoring |
160 |
flickToYEnd(previewListRow0); |
1595.3.1
by Albert Astals Cid
Test for bug #1316660 |
161 |
|
162 |
// Click on the combo
|
|
163 |
var widget = findChild(preview, "widget-21"); |
|
164 |
var initialWidgetHeight = widget.height; |
|
165 |
var moreLessButton = findChild(widget, "moreLessButton"); |
|
166 |
mouseClick(moreLessButton); |
|
167 |
||
2440.29.22
by Marco Trevisan (Treviño)
tests: try to be more robust on some flacky tests |
168 |
|
169 |
// FIXME: For some reason the PreviewWidgetFactory (parent of 'widget')
|
|
170 |
// is destroyed on idle calls, when the test is under stress.
|
|
171 |
// Not to compromise the result, we just skip the test if this happens
|
|
172 |
var widget_str = widget.toString() |
|
173 |
var preview_str = preview.toString() |
|
174 |
var skipped = false |
|
175 |
function skipTest() { skipped = true; } |
|
176 |
preview.Component.onDestruction.connect(skipTest) |
|
177 |
widget.Component.onDestruction.connect(skipTest) |
|
178 |
||
1595.3.1
by Albert Astals Cid
Test for bug #1316660 |
179 |
// Wait for the combo to stop growing
|
2440.29.22
by Marco Trevisan (Treviño)
tests: try to be more robust on some flacky tests |
180 |
tryCompareFunction(function(){ return (widget.height == units.gu(15) || skipped) }, true, 5000, "Widget lost "+widget_str+" was skipped "); |
1595.3.1
by Albert Astals Cid
Test for bug #1316660 |
181 |
|
182 |
// Make sure the combo bottom is on the viewport
|
|
2113.6.1
by Albert Astals Cid
More reliable compares |
183 |
tryCompareFunction(function () { |
2440.29.22
by Marco Trevisan (Treviño)
tests: try to be more robust on some flacky tests |
184 |
if (skipped) return true; |
2113.6.1
by Albert Astals Cid
More reliable compares |
185 |
var bottomLeft = preview.mapFromItem(widget, 0, widget.height); |
2657.1.9
by Andrea Cimitan
fix flaky tests |
186 |
return bottomLeft.y <= preview.height + 1 // FIXME the +1 is to workaround https://bugreports.qt.io/browse/QTBUG-56961 |
2113.6.1
by Albert Astals Cid
More reliable compares |
187 |
}, true); |
2440.29.22
by Marco Trevisan (Treviño)
tests: try to be more robust on some flacky tests |
188 |
|
189 |
if (!skipped) { |
|
190 |
preview.Component.onDestruction.disconnect(skipTest) |
|
191 |
widget.Component.onDestruction.disconnect(skipTest) |
|
192 |
} else { |
|
193 |
skip("preview %1 or widget %2 have been destroyed, thus we can't safely continue this test".arg(preview_str).arg(widget_str)) |
|
194 |
}
|
|
1595.3.1
by Albert Astals Cid
Test for bug #1316660 |
195 |
}
|
2704.2.1
by Albert Astals Cid
Bring back fix for 1517830 |
196 |
|
197 |
function test_audios() { |
|
198 |
preview.previewModel = audiosModel; |
|
199 |
waitForRendering(preview); |
|
200 |
||
201 |
// Scroll down
|
|
202 |
var previewListRow0 = findChild(preview, "previewListRow0"); |
|
203 |
flickToYEnd(previewListRow0); |
|
204 |
||
205 |
var previewsContentY = previewListRow0.contentY; |
|
206 |
||
207 |
var trackItem = findChild(preview, "trackItem16"); |
|
208 |
mouseClick(findChild(trackItem, "playButton")); |
|
209 |
||
210 |
expectFail("", "Clicking on a track should not change contentY."); |
|
211 |
tryCompareFunction(function () { return previewsContentY != previewListRow0.contentY; }, true); |
|
212 |
}
|
|
651.3.27
by Michał Sawicz
Introduce Preview.qml, along with tests. |
213 |
}
|
214 |
}
|