@@ -0,0 +1,104 @@
1+/*
2+ * Copyright (C) 2021 UBports Foundation
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.4
18+import QtTest 1.0
19+import Ubuntu.Components 1.3
20+import Unity.Test 0.1
21+
22+import "../../../qml/Components"
23+
24+
25+Item {
26+ id: root
27+ width: 150
28+ height: 100
29+
30+ property url defaultBackground: "../../data/unity/backgrounds/20x30.png"
31+ property real sourceSize: 0
32+
33+ Component {
34+ id: wallpaperComponent
35+ Wallpaper {
36+ anchors.fill: parent
37+ source: root.defaultBackground
38+ sourceSize: root.sourceSize
39+ }
40+ }
41+
42+ Component {
43+ id: unsetSourceSizeWallpaperComponent
44+ Wallpaper {
45+ anchors.fill: parent
46+ source: root.defaultBackground
47+ }
48+ }
49+
50+ UnityTestCase {
51+ id: testCase
52+ name: "Wallpaper"
53+ when: windowShown
54+
55+ function init() {
56+ root.sourceSize = 0;
57+ }
58+
59+ // Ensures that the Wallpaper's sourceSize causes the image to be
60+ // scaled while matching its original aspect ratio.
61+ function test_wallpaperGetsSourceSize() {
62+ root.sourceSize = 10;
63+ var wallpaper = createTemporaryObject(wallpaperComponent, root);
64+ var image = findChild(wallpaper, "wallpaperImage");
65+ verify(image);
66+ tryCompare(image, "status", Image.Ready);
67+ tryCompare(image, "implicitWidth", 10.0);
68+ tryCompare(image, "implicitHeight", 15.0);
69+ }
70+
71+ function test_warningOnSizeChange() {
72+ root.sourceSize = 1;
73+ var wallpaper = createTemporaryObject(wallpaperComponent, root);
74+ ignoreWarning(new RegExp(".*source size is changing.*"));
75+ root.sourceSize = 10;
76+ }
77+
78+ // Ensures the Wallpaper's sourceSize is unbounded and the image loads
79+ // when sourceSize is unset
80+ function test_sizeUnset() {
81+ ignoreWarning(new RegExp(".*sourceSize is unset.*"));
82+ var wallpaper = createTemporaryObject(unsetSourceSizeWallpaperComponent, root);
83+ var image = findChild(wallpaper, "wallpaperImage");
84+ // Reading the property is enough to make sure the warning happened
85+ tryCompare(image, "status", Image.Ready);
86+ tryCompare(image, "implicitWidth", 20.0);
87+ tryCompare(image, "implicitHeight", 30.0);
88+ }
89+
90+ function test_warningOnSizeBindingFailed() {
91+ // When a binding fails, it will be undefined or zero. Since
92+ // a 'real' property is read as zero when it is undefined anyway,
93+ // use that.
94+ root.sourceSize = 0;
95+ ignoreWarning(new RegExp(".*will not render.*"));
96+ var wallpaper = createTemporaryObject(wallpaperComponent, root);
97+ // A SignalSpy waiting for the signal that causes the warning would
98+ // be more correct, but hooking up the SignalSpy is sometimes slower
99+ // than the event triggering the warning and we end up waiting
100+ // forever.
101+ wait(3000);
102+ }
103+ }
104+}