aboutsummaryrefslogtreecommitdiff
path: root/AppKit/GTMNSColor+ThemeTest.m
blob: e7d2a771bf8de0c130594097ea4c769f6cf0473d (plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//
//  NSColor+ThemeTest.m
//
//  Copyright 2006-2008 Google Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
//  use this file except in compliance with the License.  You may obtain a copy
//  of the License at
// 
//  http://www.apache.org/licenses/LICENSE-2.0
// 
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//  License for the specific language governing permissions and limitations under
//  the License.
//

#import <SenTestingKit/SenTestingKit.h>
#import "GTMNSColor+Theme.h"
#import "GTMNSWorkspace+Theme.h"
#import "GTMSystemVersion.h"


@interface GTMNSColor_ThemeTest : SenTestCase 
@end

@implementation GTMNSColor_ThemeTest

//METHOD_CHECK(NSWorkspace, themeAppearance);

- (void)testColorWithThemeTextColor {
  float colorValues[][4] = {
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 0.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.449989, 0.449989, 0.449989, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.449989, 0.449989, 0.449989, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.599985, 0.599985, 0.599985, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.599985, 0.599985, 0.599985, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.499992, 0.499992, 0.499992, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 }
  };

  if ([GTMSystemVersion isLeopardOrGreater]) {
    // kThemeTextColorRootMenuDisabled changed to white in Leopard.
    colorValues[35][0] = 1.0;
    colorValues[35][1] = 1.0;
    colorValues[35][2] = 1.0;
  }
  for(int i = kThemeTextColorWhite; i < kThemeTextColorSystemDetail; i++) {
    if (i == 0) continue;  // There is no brush 0
    NSColor *textColor = [NSColor gtm_colorWithThemeTextColor:i];
    float nsComponents[5];
    [textColor getComponents: nsComponents];
    for(int j = 0; j < 4; j++) {
      STAssertEqualsWithAccuracy(nsComponents[j], colorValues[i + 2][j], 0.000001,
                                 @"Theme Text Color %d is wrong", i);
      STAssertEqualObjects([textColor colorSpaceName], NSCalibratedRGBColorSpace,
                           @"Color space must be CalibratedRGB");
    }
  }
}

- (void)testColorWithThemeBrushColor {
  float colorValues[][4] = {
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 0.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.980011, 0.990005, 0.990005, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.709789, 0.835294, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.492195, 0.675792, 0.847669, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.000000, 0.000000, 0.000000, 1.000000 },
    { 0.500008, 0.500008, 0.500008, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.600000, 0.600000, 0.600000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.510002, 0.510002, 0.510002, 1.000000 },
    { 0.760006, 0.760006, 0.760006, 1.000000 },
    { 0.940002, 0.940002, 0.940002, 1.000000 },
    { 0.980011, 0.980011, 0.980011, 1.000000 },
    { 0.670008, 0.670008, 0.670008, 1.000000 },
    { 0.860014, 0.860014, 0.860014, 1.000000 },
    { 0.880003, 0.880003, 0.880003, 1.000000 },
    { 0.880003, 0.880003, 0.880003, 1.000000 },
    { 0.990005, 0.990005, 0.990005, 1.000000 },
    { 0.900008, 0.900008, 0.900008, 1.000000 },
    { 0.930007, 0.930007, 0.930007, 1.000000 },
    { 0.930007, 0.930007, 0.930007, 1.000000 },
    { 0.990005, 0.990005, 0.990005, 1.000000 },
    { 0.540002, 0.540002, 0.540002, 1.000000 },
    { 0.590005, 0.590005, 0.590005, 1.000000 },
    { 0.590005, 0.590005, 0.590005, 1.000000 },
    { 0.730007, 0.730007, 0.730007, 1.000000 },
    { 0.640009, 0.640009, 0.640009, 1.000000 },
    { 0.640009, 0.640009, 0.640009, 1.000000 },
    { 0.820005, 0.820005, 0.820005, 1.000000 },
    { 0.820005, 0.820005, 0.820005, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 1.000000, 1.000000, 1.000000, 1.000000 },
    { 0.925490, 0.952895, 0.996094, 1.000000 }
  };
  
  NSString *theme = [[NSWorkspace sharedWorkspace] gtm_themeAppearance];
  if ([theme isEqualToString:(NSString*)kThemeAppearanceAquaGraphite]) {
    // COV_NF_START
    // These are the only two brushes that change with an appearance change
    // In general we will be testing in blue, so this code won't get run
    colorValues[21][0] = 0.605478;
    colorValues[21][1] = 0.667979;
    colorValues[21][2] = 0.738293;
    colorValues[59][0] = 0.941192;
    colorValues[59][1] = 0.941192;
    colorValues[59][2] = 0.941192;
    // COV_NF_END
  }
  for(int i = kThemeBrushWhite; i < kThemeBrushListViewColumnDivider; i++) {
    // Brush "14" is the selection, so it will change depending on the system
    // There is no brush 0.
    if (i == 0 || i == 14) continue;
    NSColor *brushColor = [NSColor gtm_colorWithThemeBrush:i];
    float nsComponents[5];
    [brushColor getComponents: nsComponents];
    for(int j = 0; j < 4; j++) {
      STAssertEqualsWithAccuracy(nsComponents[j], colorValues[i + 2][j], 0.000001,
                                 @"Theme Text Brush %d is wrong", i + 2);
      STAssertEqualObjects([brushColor colorSpaceName], NSCalibratedRGBColorSpace,
                           @"Color space must be CalibratedRB");
    }
  }
}  

@end