on 4e77f91 help sign in
unity8/tests/plugins/Dash/tst_ScopeStyle.qml
151 lines 5.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
22Rectangle {
23 width: units.gu(40)
24 height: units.gu(71)
26 ScopeStyle {
27 id: tool
28 }
30 TestCase {
31 id: testCase
32 name: "ScopeStyle"
33 when: windowShown
35 property color color
36 property var styles: [
37 {},
38 { "foreground-color": "red", "background-color": "black", "page-header": { "logo": "/foo/bar" } },
39 { "foreground-color": "green", "background-color": "white" },
40 { "foreground-color": "blue", "background-color": "darkgrey" },
41 ]
43 function cleanup() {
44 testCase.color = "transparent";
45 }
47 function test_luminance_data() {
48 return [
49 { tag: "#F00", luminance: 0.2126 },
50 { tag: "#0F0", luminance: 0.7152 },
51 { tag: "#00F", luminance: 0.0722 },
52 { tag: "white", luminance: 1.0 },
53 { tag: "black", luminance: 0.0 },
54 { tag: "lightgrey", luminance: 0.8275 },
55 { tag: "grey", luminance: 0.5020 },
56 { tag: "darkgrey", luminance: 0.6627 },
57 ];
58 }
60 function test_luminance(data) {
61 testCase.color = data.tag;
62 compare(tool.luminance(testCase.color).toFixed(4), data.luminance.toFixed(4));
63 }
65 function test_foreground_data() {
66 return [
67 { tag: "default", index: 0, foreground: "grey" },
68 { tag: "red on black", index: 1, foreground: "red" },
69 { tag: "green on white", index: 2, foreground: "green" },
70 { tag: "blue on darkgrey", index: 3, foreground: "blue" },
71 ];
72 }
74 function test_foreground(data) {
75 tool.style = testCase.styles[data.index];
76 verify(Qt.colorEqual(tool.foreground, data.foreground),
77 "Foreground color not equal: %1 != %2".arg(tool.foreground).arg(data.foreground));
78 }
80 function test_background_data() {
81 return [
82 { tag: "default", index: 0, background: "transparent" },
83 { tag: "red on black", index: 1, background: "black" },
84 { tag: "green on white", index: 2, background: "white" },
85 { tag: "blue on darkgrey", index: 3, background: "darkgrey" },
86 ];
87 }
89 function test_background(data) {
90 tool.style = testCase.styles[data.index];
91 verify(Qt.colorEqual(tool.background, data.background),
92 "Background color not equal: %1 != %2".arg(tool.background).arg(data.background));
93 }
95 function test_threshold_data() {
96 return [
97 { tag: "default", index: 0, threshold: 0.5020 },
98 { tag: "red on black", index: 1, threshold: 0.1063 },
99 { tag: "green on white", index: 2, threshold: 0.6795 },
100 { tag: "blue on darkgrey", index: 3, threshold: 0.3675 },
101 ];
102 }
104 function test_threshold(data) {
105 tool.style = testCase.styles[data.index];
106 compare(tool.threshold.toFixed(4), data.threshold.toFixed(4), "Luminance threshold was incorrect.");
107 }
109 function test_light_data() {
110 return [
111 { tag: "default", index: 0, light: "white" },
112 { tag: "red on black", index: 1, light: "red" },
113 { tag: "green on white", index: 2, light: "white" },
114 { tag: "blue on darkgrey", index: 3, light: "darkgrey" },
115 ];
116 }
118 function test_light(data) {
119 tool.style = testCase.styles[data.index];
120 verify(Qt.colorEqual(tool.light, data.light),
121 "Light color not equal: %1 != %2".arg(tool.light).arg(data.light));
122 }
124 function test_dark_data() {
125 return [
126 { tag: "default", index: 0, dark: "grey" },
127 { tag: "red on black", index: 1, dark: "black" },
128 { tag: "green on white", index: 2, dark: "green" },
129 { tag: "blue on darkgrey", index: 3, dark: "blue" },
130 ];
131 }
133 function test_dark(data) {
134 tool.style = testCase.styles[data.index];
135 verify(Qt.colorEqual(tool.dark, data.dark),
136 "Dark color not equal: %1 != %2".arg(tool.dark).arg(data.dark));
137 }
139 function test_headerLogo_data() {
140 return [
141 { tag: "default", index: 0, headerLogo: "" },
142 { tag: "with logo", index: 1, headerLogo: "file:///foo/bar" },
143 ];
144 }
146 function test_headerLogo(data) {
147 tool.style = testCase.styles[data.index];
148 compare(tool.headerLogo, data.headerLogo, "Header logo was incorrect.");
149 }
150 }