OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Font settings API test | 5 // Font settings API test |
6 // Run with browser_tests --gtest_filter=ExtensionApiTest.FontSettings | 6 // Run with browser_tests --gtest_filter=ExtensionApiTest.FontSettings |
7 | 7 |
8 var fs = chrome.experimental.fontSettings; | 8 var fs = chrome.experimental.fontSettings; |
9 var CONTROLLED_BY_THIS_EXTENSION = 'controlled_by_this_extension'; | 9 var CONTROLLED_BY_THIS_EXTENSION = 'controlled_by_this_extension'; |
10 var CONTROLLABLE_BY_THIS_EXTENSION = 'controllable_by_this_extension'; | 10 var CONTROLLABLE_BY_THIS_EXTENSION = 'controllable_by_this_extension'; |
11 | 11 |
12 function expect(expected, message) { | 12 function expect(expected, message) { |
13 return chrome.test.callbackPass(function(value) { | 13 return chrome.test.callbackPass(function(value) { |
14 chrome.test.assertEq(expected, value, message); | 14 chrome.test.assertEq(expected, value, message); |
15 }); | 15 }); |
16 } | 16 } |
17 | 17 |
18 chrome.test.runTests([ | 18 chrome.test.runTests([ |
19 // This test may fail on Windows if the font is not installed on the | 19 // This test may fail on Windows if the font is not installed on the |
20 // system. See crbug.com/122303 | 20 // system. See crbug.com/122303 |
21 function setPerScriptFont() { | 21 function setPerScriptFont() { |
22 var script = 'Hang'; | 22 var script = 'Hang'; |
23 var genericFamily = 'standard'; | 23 var genericFamily = 'standard'; |
24 var fontName = 'Verdana'; | 24 var fontId = 'Verdana'; |
25 | 25 |
26 chrome.test.listenOnce(fs.onFontChanged, function(details) { | 26 chrome.test.listenOnce(fs.onFontChanged, function(details) { |
27 chrome.test.assertEq({ | 27 chrome.test.assertEq({ |
28 script: script, | 28 script: script, |
29 genericFamily: genericFamily, | 29 genericFamily: genericFamily, |
30 fontName: fontName, | 30 fontId: fontId, |
31 levelOfControl: CONTROLLED_BY_THIS_EXTENSION | 31 levelOfControl: CONTROLLED_BY_THIS_EXTENSION |
32 }, details); | 32 }, details); |
33 }); | 33 }); |
34 | 34 |
35 fs.setFont({ | 35 fs.setFont({ |
36 script: script, | 36 script: script, |
37 genericFamily: genericFamily, | 37 genericFamily: genericFamily, |
38 fontName: fontName | 38 fontId: fontId |
39 }, chrome.test.callbackPass()); | 39 }, chrome.test.callbackPass()); |
40 }, | 40 }, |
41 | 41 |
42 // This test may fail on Windows if the font is not installed on | 42 // This test may fail on Windows if the font is not installed on |
43 // the system. See crbug.com/122303 | 43 // the system. See crbug.com/122303 |
44 function setGlobalFontName() { | 44 function setGlobalFontName() { |
45 var genericFamily = 'sansserif'; | 45 var genericFamily = 'sansserif'; |
46 var fontName = 'Tahoma'; | 46 var fontId = 'Tahoma'; |
47 | 47 |
48 chrome.test.listenOnce(fs.onFontChanged, function(details) { | 48 chrome.test.listenOnce(fs.onFontChanged, function(details) { |
49 chrome.test.assertEq({ | 49 chrome.test.assertEq({ |
50 genericFamily: genericFamily, | 50 genericFamily: genericFamily, |
51 fontName: fontName, | 51 fontId: fontId, |
52 script: 'Zyyy', | 52 script: 'Zyyy', |
53 levelOfControl: CONTROLLED_BY_THIS_EXTENSION | 53 levelOfControl: CONTROLLED_BY_THIS_EXTENSION |
54 }, details); | 54 }, details); |
55 }); | 55 }); |
56 | 56 |
57 fs.setFont({ | 57 fs.setFont({ |
58 genericFamily: genericFamily, | 58 genericFamily: genericFamily, |
59 fontName: fontName | 59 fontId: fontId |
60 }, chrome.test.callbackPass()); | 60 }, chrome.test.callbackPass()); |
61 }, | 61 }, |
62 | 62 |
63 function setDefaultFontSize() { | 63 function setDefaultFontSize() { |
64 var pixelSize = 22; | 64 var pixelSize = 22; |
65 chrome.test.listenOnce(fs.onDefaultFontSizeChanged, function(details) { | 65 chrome.test.listenOnce(fs.onDefaultFontSizeChanged, function(details) { |
66 chrome.test.assertEq({ | 66 chrome.test.assertEq({ |
67 pixelSize: pixelSize, | 67 pixelSize: pixelSize, |
68 levelOfControl: CONTROLLED_BY_THIS_EXTENSION | 68 levelOfControl: CONTROLLED_BY_THIS_EXTENSION |
69 }, details); | 69 }, details); |
(...skipping 27 matching lines...) Expand all Loading... |
97 }, details); | 97 }, details); |
98 }); | 98 }); |
99 | 99 |
100 fs.setMinimumFontSize({ | 100 fs.setMinimumFontSize({ |
101 pixelSize: pixelSize | 101 pixelSize: pixelSize |
102 }, chrome.test.callbackPass()); | 102 }, chrome.test.callbackPass()); |
103 }, | 103 }, |
104 | 104 |
105 function getFontList() { | 105 function getFontList() { |
106 var message = 'getFontList should return an array of objects with ' + | 106 var message = 'getFontList should return an array of objects with ' + |
107 'fontName and localizedName properties.'; | 107 'fontId and displayName properties.'; |
108 fs.getFontList(chrome.test.callbackPass(function(value) { | 108 fs.getFontList(chrome.test.callbackPass(function(value) { |
109 chrome.test.assertTrue(value.length > 0, | 109 chrome.test.assertTrue(value.length > 0, |
110 'Font list is not expected to be empty.'); | 110 'Font list is not expected to be empty.'); |
111 chrome.test.assertEq('string', typeof(value[0].fontName), message); | 111 chrome.test.assertEq('string', typeof(value[0].fontId), message); |
112 chrome.test.assertEq('string', typeof(value[0].localizedName), message); | 112 chrome.test.assertEq('string', typeof(value[0].displayName), message); |
113 })); | 113 })); |
114 }, | 114 }, |
115 | 115 |
116 function getPerScriptFontName() { | 116 function getPerScriptFontName() { |
117 fs.getFont({ | 117 fs.getFont({ |
118 script: 'Hang', | 118 script: 'Hang', |
119 genericFamily: 'standard' | 119 genericFamily: 'standard' |
120 }, expect({ | 120 }, expect({ |
121 fontName: 'Verdana', | 121 fontId: 'Verdana', |
122 levelOfControl: CONTROLLED_BY_THIS_EXTENSION | 122 levelOfControl: CONTROLLED_BY_THIS_EXTENSION |
123 })); | 123 })); |
124 }, | 124 }, |
125 | 125 |
126 function getGlobalFontName() { | 126 function getGlobalFontName() { |
127 fs.getFont({ | 127 fs.getFont({ |
128 genericFamily: 'sansserif' | 128 genericFamily: 'sansserif' |
129 }, expect({ | 129 }, expect({ |
130 fontName: 'Tahoma', | 130 fontId: 'Tahoma', |
131 levelOfControl: CONTROLLED_BY_THIS_EXTENSION | 131 levelOfControl: CONTROLLED_BY_THIS_EXTENSION |
132 })); | 132 })); |
133 }, | 133 }, |
134 | 134 |
135 function getDefaultFontSize() { | 135 function getDefaultFontSize() { |
136 fs.getDefaultFontSize({}, expect({ | 136 fs.getDefaultFontSize({}, expect({ |
137 pixelSize: 22, | 137 pixelSize: 22, |
138 levelOfControl: CONTROLLED_BY_THIS_EXTENSION | 138 levelOfControl: CONTROLLED_BY_THIS_EXTENSION |
139 })); | 139 })); |
140 }, | 140 }, |
(...skipping 17 matching lines...) Expand all Loading... |
158 pixelSize: 7, | 158 pixelSize: 7, |
159 levelOfControl: CONTROLLED_BY_THIS_EXTENSION | 159 levelOfControl: CONTROLLED_BY_THIS_EXTENSION |
160 })); | 160 })); |
161 }, | 161 }, |
162 | 162 |
163 // This test may fail on Windows if the font is not installed on the | 163 // This test may fail on Windows if the font is not installed on the |
164 // system. See crbug.com/122303 | 164 // system. See crbug.com/122303 |
165 function clearPerScriptFont() { | 165 function clearPerScriptFont() { |
166 var script = 'Hang'; | 166 var script = 'Hang'; |
167 var genericFamily = 'standard'; | 167 var genericFamily = 'standard'; |
168 var fontName = 'Tahoma'; | 168 var fontId = 'Tahoma'; |
169 | 169 |
170 chrome.test.listenOnce(fs.onFontChanged, function(details) { | 170 chrome.test.listenOnce(fs.onFontChanged, function(details) { |
171 chrome.test.assertEq({ | 171 chrome.test.assertEq({ |
172 script: script, | 172 script: script, |
173 genericFamily: genericFamily, | 173 genericFamily: genericFamily, |
174 fontName: fontName, | 174 fontId: fontId, |
175 levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION | 175 levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION |
176 }, details); | 176 }, details); |
177 }); | 177 }); |
178 | 178 |
179 fs.clearFont({ | 179 fs.clearFont({ |
180 script: script, | 180 script: script, |
181 genericFamily: genericFamily, | 181 genericFamily: genericFamily, |
182 }, chrome.test.callbackPass()); | 182 }, chrome.test.callbackPass()); |
183 }, | 183 }, |
184 | 184 |
185 // This test may fail on Windows if the font is not installed on the | 185 // This test may fail on Windows if the font is not installed on the |
186 // system. See crbug.com/122303 | 186 // system. See crbug.com/122303 |
187 function clearGlobalFont() { | 187 function clearGlobalFont() { |
188 var script = 'Zyyy'; | 188 var script = 'Zyyy'; |
189 var genericFamily = 'sansserif'; | 189 var genericFamily = 'sansserif'; |
190 var fontName = 'Arial'; | 190 var fontId = 'Arial'; |
191 | 191 |
192 chrome.test.listenOnce(fs.onFontChanged, function(details) { | 192 chrome.test.listenOnce(fs.onFontChanged, function(details) { |
193 chrome.test.assertEq({ | 193 chrome.test.assertEq({ |
194 script: script, | 194 script: script, |
195 genericFamily: genericFamily, | 195 genericFamily: genericFamily, |
196 fontName: fontName, | 196 fontId: fontId, |
197 levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION | 197 levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION |
198 }, details); | 198 }, details); |
199 }); | 199 }); |
200 | 200 |
201 fs.clearFont({ | 201 fs.clearFont({ |
202 genericFamily: genericFamily, | 202 genericFamily: genericFamily, |
203 }, chrome.test.callbackPass()); | 203 }, chrome.test.callbackPass()); |
204 }, | 204 }, |
205 | 205 |
206 function clearDefaultFontSize() { | 206 function clearDefaultFontSize() { |
(...skipping 25 matching lines...) Expand all Loading... |
232 chrome.test.listenOnce(fs.onMinimumFontSizeChanged, function(details) { | 232 chrome.test.listenOnce(fs.onMinimumFontSizeChanged, function(details) { |
233 chrome.test.assertEq({ | 233 chrome.test.assertEq({ |
234 pixelSize: pixelSize, | 234 pixelSize: pixelSize, |
235 levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION | 235 levelOfControl: CONTROLLABLE_BY_THIS_EXTENSION |
236 }, details); | 236 }, details); |
237 }); | 237 }); |
238 | 238 |
239 fs.clearMinimumFontSize({}, chrome.test.callbackPass()); | 239 fs.clearMinimumFontSize({}, chrome.test.callbackPass()); |
240 } | 240 } |
241 ]); | 241 ]); |
OLD | NEW |