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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Font settings API test
// Run with browser_tests --gtest_filter=ExtensionApiTest.FontSettings
var fs = chrome.experimental.fontSettings;
var CONTROLLABLE_BY_THIS_EXTENSION = 'controllable_by_this_extension';
function expect(expected, message) {
return chrome.test.callbackPass(function(value) {
chrome.test.assertEq(expected, value, message);
});
}
chrome.test.runTests([
// This test may fail on Windows if the font is not installed on the
// system. See crbug.com/122303
function setPerScriptFont() {
var script = 'Hang';
var genericFamily = 'standard';
var fontName = 'Verdana';
chrome.test.listenOnce(fs.onFontChanged, function(details) {
chrome.test.assertEq(details, {
script: script,
genericFamily: genericFamily,
fontName: fontName,
levelOfControl: 'controlled_by_this_extension'
});
});
fs.setFont({
script: script,
genericFamily: genericFamily,
fontName: fontName
}, chrome.test.callbackPass());
},
function getPerScriptFontName() {
var expected = 'Verdana';
var message = 'Setting for Hangul standard font should be ' + expected;
fs.getFont({
script: 'Hang',
genericFamily: 'standard'
}, expect({fontName: expected}, message));
},
// This test may fail on Windows if the font is not installed on
// the system. See crbug.com/122303
function setGlobalFontName() {
var fontName = 'Tahoma';
var genericFamily = 'sansserif';
chrome.test.listenOnce(fs.onFontChanged, function(details) {
chrome.test.assertEq(details, {
genericFamily: genericFamily,
fontName: fontName,
levelOfControl: 'controlled_by_this_extension'
});
});
fs.setFont({
genericFamily: 'sansserif',
fontName: 'Tahoma'
}, chrome.test.callbackPass());
},
function getGlobalFontName() {
var expected = 'Tahoma';
var message =
'Setting for global sansserif font should be ' + expected;
fs.getFont({
genericFamily: 'sansserif'
}, expect({fontName: expected}, message));
},
function getFontList() {
var message = 'getFontList should return an array of objects with ' +
'fontName and localizedName properties.';
fs.getFontList(chrome.test.callbackPass(function(value) {
chrome.test.assertTrue(value.length > 0,
"Font list is not expected to be empty.");
chrome.test.assertEq('string', typeof(value[0].fontName), message);
chrome.test.assertEq('string', typeof(value[0].localizedName), message);
}));
},
function setDefaultFontSize() {
var pixelSize = 22;
chrome.test.listenOnce(fs.onDefaultFontSizeChanged, function(details) {
chrome.test.assertEq(details, {
pixelSize: pixelSize,
levelOfControl: 'controlled_by_this_extension'
});
});
fs.setDefaultFontSize({
pixelSize: pixelSize
}, chrome.test.callbackPass());
},
function setDefaultFixedFontSize() {
var pixelSize = 42;
chrome.test.listenOnce(fs.onDefaultFixedFontSizeChanged, function(details) {
chrome.test.assertEq(details, {
pixelSize: pixelSize,
levelOfControl: 'controlled_by_this_extension'
});
});
fs.setDefaultFixedFontSize({
pixelSize: pixelSize
}, chrome.test.callbackPass());
},
function setMinimumFontSize() {
var pixelSize = 7;
chrome.test.listenOnce(fs.onMinimumFontSizeChanged, function(details) {
chrome.test.assertEq(details, {
pixelSize: pixelSize,
levelOfControl: 'controlled_by_this_extension'
});
});
fs.setMinimumFontSize({
pixelSize: pixelSize
}, chrome.test.callbackPass());
},
function setDefaultCharacterSet() {
var charset = 'GBK';
chrome.test.listenOnce(fs.onDefaultCharacterSetChanged, function(details) {
chrome.test.assertEq(details, {
charset: charset,
levelOfControl: 'controlled_by_this_extension'
});
});
fs.setDefaultCharacterSet({
charset: charset
}, chrome.test.callbackPass());
},
function getDefaultFontSize() {
var expected = 22;
var message = 'Setting for default font size should be ' + expected;
fs.getDefaultFontSize({}, expect({pixelSize: expected}, message));
},
function getDefaultFontSizeOmitDetails() {
var expected = 22;
var message = 'Setting for default font size should be ' + expected;
fs.getDefaultFontSize(expect({pixelSize: expected}, message));
},
function getDefaultFixedFontSize() {
var expected = 42;
var message = 'Setting for default fixed font size should be ' + expected;
fs.getDefaultFixedFontSize({}, expect({pixelSize: expected}, message));
},
function getMinimumFontSize() {
var expected = 7;
var message = 'Setting for minimum font size should be ' + expected;
fs.getMinimumFontSize({}, expect({pixelSize: expected}, message));
},
function getDefaultCharacterSet() {
var expected = 'GBK';
var message = 'Setting for default character set should be ' + expected;
fs.getDefaultCharacterSet(expect({charset: expected}, message));
},
// This test may fail on Windows if the font is not installed on the
// system. See crbug.com/122303
function clearPerScriptFont() {
var script = 'Hang';
var genericFamily = 'standard';
var fontName = 'Tahoma';
chrome.test.listenOnce(fs.onFontChanged, function(details) {
chrome.test.assertEq(details, {
script: script,
genericFamily: genericFamily,
fontName: fontName,
levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION
});
});
fs.clearFont({
script: script,
genericFamily: genericFamily,
}, chrome.test.callbackPass());
},
// This test may fail on Windows if the font is not installed on the
// system. See crbug.com/122303
function clearGlobalFont() {
var genericFamily = 'sansserif';
var fontName = 'Arial';
chrome.test.listenOnce(fs.onFontChanged, function(details) {
chrome.test.assertEq(details, {
genericFamily: genericFamily,
fontName: fontName,
levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION
});
});
fs.clearFont({
genericFamily: genericFamily,
}, chrome.test.callbackPass());
},
function clearDefaultFontSize() {
var pixelSize = 16;
chrome.test.listenOnce(fs.onDefaultFontSizeChanged, function(details) {
chrome.test.assertEq(details, {
pixelSize: pixelSize,
levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION
});
});
fs.clearDefaultFontSize({}, chrome.test.callbackPass());
},
function clearDefaultFixedFontSize() {
var pixelSize = 14;
chrome.test.listenOnce(fs.onDefaultFixedFontSizeChanged, function(details) {
chrome.test.assertEq(details, {
pixelSize: pixelSize,
levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION
});
});
fs.clearDefaultFixedFontSize({}, chrome.test.callbackPass());
},
function clearMinimumFontSize() {
var pixelSize = 8;
chrome.test.listenOnce(fs.onMinimumFontSizeChanged, function(details) {
chrome.test.assertEq(details, {
pixelSize: pixelSize,
levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION
});
});
fs.clearMinimumFontSize({}, chrome.test.callbackPass());
},
function clearDefaultCharacterSet() {
var charset = 'Shift_JIS';
chrome.test.listenOnce(fs.onDefaultCharacterSetChanged, function(details) {
chrome.test.assertEq(details, {
charset: charset,
levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION
});
});
fs.clearDefaultCharacterSet({}, chrome.test.callbackPass());
},
]);
|