on 6ca9421 help sign in
unity8/tests/plugins/Dash/tst_ScopeStyle.qml
188 lines 8.5 kB history raw
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 */
17import QtQuick 2.2
18import QtTest 1.0
19import Dash 0.1
20import Ubuntu.Components 1.1
21import Utils 0.1
23Rectangle {
24 width: units.gu(40)
25 height: units.gu(71)
27 ScopeStyle {
28 id: tool
29 }
31 TestCase {
32 id: testCase
33 name: "ScopeStyle"
34 when: windowShown
36 property color color
37 property var styles: [
38 {},
39 { "foreground-color": "red", "background-color": "black", "page-header": { "logo": "/foo/bar" },
40 "preview-button-color": "red"},
41 { "foreground-color": "green", "background-color": "white",
42 "page-header": { "foreground-color": "black",
43 "divider-color": "blue" } },
44 { "foreground-color": "blue", "background-color": "darkgrey",
45 "page-header": { "background": "gradient:///white/blue",
46 "navigation-background": "gradient:///white/blue" } },
47 ]
49 function cleanup() {
50 testCase.color = "transparent";
51 }
53 function test_foreground_data() {
54 return [
55 { tag: "default", index: 0, foreground: UbuntuColors.darkGrey, luminance: 0.3647 },
56 { tag: "red on black", index: 1, foreground: "red", luminance: 0.2126 },
57 { tag: "green on white", index: 2, foreground: "green", luminance: 0.3590 },
58 { tag: "blue on darkgrey", index: 3, foreground: "blue", luminance: 0.0722 },
59 ];
60 }
62 function test_foreground(data) {
63 tool.style = testCase.styles[data.index];
64 verify(Qt.colorEqual(tool.foreground, data.foreground),
65 "Foreground color not equal: %1 != %2".arg(tool.foreground).arg(data.foreground));
66 compare(tool.foregroundLuminance.toFixed(4), data.luminance.toFixed(4));
67 }
69 function test_background_data() {
70 return [
71 { tag: "default", index: 0, background: "#00f5f5f5", luminance: 0.9608 },
72 { tag: "red on black", index: 1, background: "black", luminance: 0 },
73 { tag: "green on white", index: 2, background: "white", luminance: 1 },
74 { tag: "blue on darkgrey", index: 3, background: "darkgrey", luminance: 0.6627 },
75 ];
76 }
78 function test_background(data) {
79 tool.style = testCase.styles[data.index];
80 verify(Qt.colorEqual(tool.background, data.background),
81 "Background color not equal: %1 != %2".arg(tool.background).arg(data.background));
82 compare(tool.backgroundLuminance.toFixed(4), data.luminance.toFixed(4));
83 }
85 function test_getTextColor_data() {
86 return [
87 { tag: "default on black", background: "black", index: 0, textColor: "white" },
88 { tag: "default on lightgrey", background: "lightgrey", index: 0, textColor: UbuntuColors.darkGrey },
89 { tag: "default on white", background: "white", index: 0, textColor: UbuntuColors.darkGrey },
90 { tag: "default on yellow", background: "yellow", index: 0, textColor: UbuntuColors.darkGrey },
91 { tag: "red/black on black", background: "black", index: 1, textColor: "red" },
92 { tag: "red/black on lightgrey", background: "lightgrey", index: 1, textColor: "black" },
93 { tag: "red/black on white", background: "white", index: 1, textColor: "black" },
94 { tag: "red/black on yellow", background: "yellow", index: 1, textColor: "black" },
95 { tag: "green/white on black", background: "black", index: 2, textColor: "white" },
96 { tag: "green/white on lightgrey", background: "lightgrey", index: 2, textColor: "green" },
97 { tag: "green/white on white", background: "white", index: 2, textColor: "green" },
98 { tag: "green/white on yellow", background: "yellow", index: 2, textColor: "green" },
99 { tag: "blue/darkgrey on black", background: "black", index: 3, textColor: "darkgrey" },
100 { tag: "blue/darkgrey on lightgrey", background: "lightgrey", index: 3, textColor: "blue" },
101 { tag: "blue/darkgrey on white", background: "white", index: 3, textColor: "blue" },
102 { tag: "blue/darkgrey on yellow", background: "yellow", index: 3, textColor: "blue" },
103 ];
104 }
106 function test_getTextColor(data) {
107 tool.style = testCase.styles[data.index];
108 var textColor = tool.getTextColor(Style.luminance(data.background));
109 verify(Qt.colorEqual(textColor, data.textColor),
110 "TextColor not equal: %1 != %2".arg(textColor).arg(data.textColor));
111 }
113 function test_headerLogo_data() {
114 return [
115 { tag: "default", index: 0, headerLogo: "" },
116 { tag: "with logo", index: 1, headerLogo: "file:///foo/bar" },
117 ];
118 }
120 function test_headerLogo(data) {
121 tool.style = testCase.styles[data.index];
122 compare(tool.headerLogo, data.headerLogo, "Header logo was incorrect.");
123 }
125 function test_headerForeground_data() {
126 return [
127 { tag: "default", index: 0, headerForeground: UbuntuColors.darkGrey },
128 { tag: "black", index: 2, headerForeground: "black" },
129 ];
130 }
132 function test_headerForeground(data) {
133 tool.style = testCase.styles[data.index];
134 verify(Qt.colorEqual(tool.headerForeground, data.headerForeground),
135 "Header foreground not equal: %1 != %2".arg(tool.headerForeground).arg(data.headerForeground));
136 }
138 function test_headerBackground_data() {
139 return [
140 { tag: "default", index: 0, headerBackground: "color:///#f5f5f5" },
141 { tag: "black", index: 3, headerBackground: "gradient:///white/blue" },
142 ];
143 }
145 function test_headerBackground(data) {
146 tool.style = testCase.styles[data.index];
147 compare(tool.headerBackground, data.headerBackground, "Header background was incorrect.");
148 }
150 function test_headerDividerColor_data() {
151 return [
152 { tag: "default", index: 0, headerDividerColor: "#e0e0e0" },
153 { tag: "blue", index: 2, headerDividerColor: "blue" },
154 ];
155 }
157 function test_headerDividerColor(data) {
158 tool.style = testCase.styles[data.index];
159 verify(Qt.colorEqual(tool.headerDividerColor, data.headerDividerColor),
160 "Header divider color not equal: %1 != %2".arg(tool.headerDividerColor).arg(data.headerDividerColor));
161 }
163 function test_navigationBackground_data() {
164 return [
165 { tag: "default", index: 0, navigationBackground: "color:///#f5f5f5" },
166 { tag: "black", index: 3, navigationBackground: "gradient:///white/blue" },
167 ];
168 }
170 function test_navigationBackground(data) {
171 tool.style = testCase.styles[data.index];
172 compare(tool.navigationBackground, data.navigationBackground, "Navigation background was incorrect.");
173 }
175 function test_previewButtonColor_data() {
176 return [
177 { tag: "default", index: 0, previewButtonColor: UbuntuColors.orange },
178 { tag: "red", index: 1, previewButtonColor: "red" },
179 ];
180 }
182 function test_previewButtonColor(data) {
183 tool.style = testCase.styles[data.index];
184 verify(Qt.colorEqual(tool.previewButtonColor, data.previewButtonColor),
185 "Preview button color not equal: %1 != %2".arg(tool.previewButtonColor).arg(data.previewButtonColor));
186 }
187 }