File: tst_icon.11.qml

package info (click to toggle)
lomiri-ui-toolkit 1.3.5110%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,436 kB
  • sloc: cpp: 85,830; python: 5,537; sh: 1,344; javascript: 919; ansic: 573; makefile: 204
file content (154 lines) | stat: -rw-r--r-- 5,449 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * Copyright 2012 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.0
import QtTest 1.0
import Lomiri.Components 1.1
import Lomiri.Test 1.0

Item {
    width: units.gu(50)
    height: units.gu(50)

    Row {
        anchors.centerIn: parent
        height: units.gu(10)
        width: childrenRect.width

        Icon {
            // Fails to load the icon when suru-icon-theme or libqt5svg5 are
            // not installed. This causes a warning and rejection
            // by jenkins continuous integration.
            name: "add"
            height: parent.height
            width: height
        }
        Icon {
            // Fails when the icon is becoming invisible when non-atomic updates
            // cause sourceSize.width or sourceSize.height to be 0 before other
            // properties are updated.
            id: icon
            width: visible ? units.gu(10) : 0
            height: width
            name: "toolkit_input-search"
        }
        Icon {
            id: icon2
            width: units.gu(10)
            height: width
        }
        Icon {
            // Regression test for bug #1371509
            // Will print "QML QQuickImage: Failed to get image from provider" when broken.
            id: icon3
            width: units.gu(10)
            height: width
            source: Qt.resolvedUrl("tst_icon-select.png")
        }

        // Regression test for bug #1421293
        Icon {
            id: icon4
            height: units.gu(2)
            source: Qt.resolvedUrl("logo.png")
        }
        Icon {
            id: icon5
            height: units.gu(2)
            width: implicitWidth > 0 && implicitHeight > 0 ? (implicitWidth / implicitHeight * height) : implicitWidth
            source: Qt.resolvedUrl("logo.png")
        }
    }

    LomiriTestCase {
        name: "Icon"
        when: windowShown

        SignalSpy {
            id: shaderSpy
            signalName: 'onStatusChanged'
        }

        function cleanup() {
            icon2.name = "";
        }

        function test_updateIconSize_bug1349769() {
            icon.visible = false;
            // causes "QML Image: Failed to get image from provider: image://theme/toolkit_input-search"
            // warning when sourceSize.width or sourceSize.height becomes 0 while
            // while still trying to render the icon. Tests will pass with the warning, but
            // the MR is rejected by jenkins continuous integration.
        }

        function test_name() {
            icon2.name = "toolkit_input-search";

            var image = findChild(icon2, "image");
            compare(image.source, "image://theme/toolkit_input-search",
                    "Source of the image should be image://theme/{name}.");
        }

        function test_source() {
            icon2.name = "toolkit_input-search";
            icon2.source = "/usr/share/icons/suru/actions/scalable/edit-find.svg";

            var image = findChild(icon2, "image");
            compare(image.source,
                    "file:///usr/share/icons/suru/actions/scalable/edit-find.svg",
                    "Source of the image should equal icon2.source.");
        }

        function test_keyColor() {
            icon.visible = true;
            var image = findChild(icon, "image");
            var shader = findChild(icon, "shader");
            shaderSpy.target = shader;

            compare(icon.name, "toolkit_input-search");
            compare(shader.visible, false);
            compare(shader.status, ShaderEffect.Uncompiled)
            icon.color = LomiriColors.orange;
            shaderSpy.wait();
            compare(shader.log, '')
            // https://bugreports.qt.io/browse/QTBUG-49713
            // status may be Error with no log even if successful
            verify(shader.status !== ShaderEffect.Uncompiled)
            compare(shader.keyColorOut, icon.color);
            compare(shader.visible, true);
            compare(shader.source, image);
            icon.keyColor = LomiriColors.purple;
            compare(shader.keyColorIn, icon.keyColor);
            // Unsetting the icon name should disable the shader
            icon.name = '';
            compare(icon.source, '');
            compare(shader.visible, false);
            // Let's get back to a valid source
            icon.name = "toolkit_input-search";
            compare(shader.visible, true);
            compare(shader.source, image);
            // Unsetting the keyColor should also disable the shader
            icon.color = Qt.rgba(0.0, 0.0, 0.0, 0.0);
            compare(shader.visible, false);
        }

        function test_iconScaling_bug1421293() {
            // make sure both icons end up the same size
            compare(icon4.width, icon5.width);
            compare(icon4.height, icon5.height);
        }
    }
}