@@ -0,0 +1,151 @@
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+ */
16+
17+import QtQuick 2.2
18+import QtTest 1.0
19+import Dash 0.1
20+import Ubuntu.Components 1.1
21+
22+Rectangle {
23+ width: units.gu(40)
24+ height: units.gu(71)
25+
26+ ScopeStyle {
27+ id: tool
28+ }
29+
30+ TestCase {
31+ id: testCase
32+ name: "ScopeStyle"
33+ when: windowShown
34+
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+ ]
42+
43+ function cleanup() {
44+ testCase.color = "transparent";
45+ }
46+
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+ }
59+
60+ function test_luminance(data) {
61+ testCase.color = data.tag;
62+ compare(tool.luminance(testCase.color).toFixed(4), data.luminance.toFixed(4));
63+ }
64+
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+ }
73+
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+ }
79+
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+ }
88+
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+ }
94+
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+ }
103+
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+ }
108+
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+ }
117+
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+ }
123+
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+ }
132+
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+ }
138+
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+ }
145+
146+ function test_headerLogo(data) {
147+ tool.style = testCase.styles[data.index];
148+ compare(tool.headerLogo, data.headerLogo, "Header logo was incorrect.");
149+ }
150+ }
151+}