Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: grit/format/policy_templates/writers/adm_writer_unittest.py

Issue 7994004: Initial source commit to grit-i18n project. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 '''Unit tests for grit.format.policy_templates.writers.adm_writer'''
7
8
9 import os
10 import sys
11 if __name__ == '__main__':
12 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../..'))
13
14 import tempfile
15 import unittest
16 import StringIO
17
18 from grit.format.policy_templates.writers import writer_unittest_common
19 from grit import grd_reader
20 from grit import util
21 from grit.tool import build
22
23
24 class AdmWriterUnittest(writer_unittest_common.WriterUnittestCommon):
25 '''Unit tests for AdmWriter.'''
26
27 def ConstructOutput(self, classes, body, strings):
28 result = []
29 for clazz in classes:
30 result.append('CLASS ' + clazz)
31 result.append(body)
32 result.append(strings)
33 return ''.join(result)
34
35 def CompareOutputs(self, output, expected_output):
36 '''Compares the output of the adm_writer with its expected output.
37
38 Args:
39 output: The output of the adm writer as returned by grit.
40 expected_output: The expected output.
41
42 Raises:
43 AssertionError: if the two strings are not equivalent.
44 '''
45 self.assertEquals(
46 output.strip(),
47 expected_output.strip().replace('\n', '\r\n'))
48
49 def testEmpty(self):
50 # Test PListWriter in case of empty polices.
51 grd = self.PrepareTest('''
52 {
53 'policy_definitions': [],
54 'placeholders': [],
55 'messages': {
56 'win_supported_winxpsp2': {
57 'text': 'At least "Windows 3.11', 'desc': 'blah'
58 }
59 }
60 }''')
61 output = self.GetOutput(grd, 'fr', {'_chromium': '1',}, 'adm', 'en')
62 expected_output = self.ConstructOutput(
63 ['MACHINE', 'USER'], '''
64 CATEGORY !!chromium
65 KEYNAME "Software\\Policies\\Chromium"
66
67 END CATEGORY
68
69 ''', '''[Strings]
70 SUPPORTED_WINXPSP2="At least "Windows 3.11"
71 chromium="Chromium"''')
72 self.CompareOutputs(output, expected_output)
73
74 def testMainPolicy(self):
75 # Tests a policy group with a single policy of type 'main'.
76 grd = self.PrepareTest('''
77 {
78 'policy_definitions': [
79 {
80 'name': 'MainPolicy',
81 'type': 'main',
82 'supported_on': ['chrome.win:8-'],
83 'caption': 'Caption of main.',
84 'desc': 'Description of main.',
85 },
86 ],
87 'placeholders': [],
88 'messages': {
89 'win_supported_winxpsp2': {
90 'text': 'At least Windows 3.12', 'desc': 'blah'
91 }
92 }
93 }''')
94 output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'adm', 'en')
95 expected_output = self.ConstructOutput(
96 ['MACHINE', 'USER'], '''
97 CATEGORY !!google
98 CATEGORY !!googlechrome
99 KEYNAME "Software\\Policies\\Google\\Chrome"
100
101 POLICY !!MainPolicy_Policy
102 #if version >= 4
103 SUPPORTED !!SUPPORTED_WINXPSP2
104 #endif
105 EXPLAIN !!MainPolicy_Explain
106 VALUENAME "MainPolicy"
107 VALUEON NUMERIC 1
108 VALUEOFF NUMERIC 0
109 END POLICY
110
111 END CATEGORY
112 END CATEGORY
113
114 ''', '''[Strings]
115 SUPPORTED_WINXPSP2="At least Windows 3.12"
116 google="Google"
117 googlechrome="Google Chrome"
118 MainPolicy_Policy="Caption of main."
119 MainPolicy_Explain="Description of main."''')
120 self.CompareOutputs(output, expected_output)
121
122 def testStringPolicy(self):
123 # Tests a policy group with a single policy of type 'string'.
124 grd = self.PrepareTest('''
125 {
126 'policy_definitions': [
127 {
128 'name': 'StringPolicy',
129 'type': 'string',
130 'supported_on': ['chrome.win:8-'],
131 'desc': """Description of group.
132 With a newline.""",
133 'caption': 'Caption of policy.',
134 },
135 ],
136 'placeholders': [],
137 'messages': {
138 'win_supported_winxpsp2': {
139 'text': 'At least Windows 3.13', 'desc': 'blah'
140 }
141 }
142 }''')
143 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
144 expected_output = self.ConstructOutput(
145 ['MACHINE', 'USER'], '''
146 CATEGORY !!chromium
147 KEYNAME "Software\\Policies\\Chromium"
148
149 POLICY !!StringPolicy_Policy
150 #if version >= 4
151 SUPPORTED !!SUPPORTED_WINXPSP2
152 #endif
153 EXPLAIN !!StringPolicy_Explain
154
155 PART !!StringPolicy_Part EDITTEXT
156 VALUENAME "StringPolicy"
157 END PART
158 END POLICY
159
160 END CATEGORY
161
162 ''', '''[Strings]
163 SUPPORTED_WINXPSP2="At least Windows 3.13"
164 chromium="Chromium"
165 StringPolicy_Policy="Caption of policy."
166 StringPolicy_Explain="Description of group.\\nWith a newline."
167 StringPolicy_Part="Caption of policy."
168 ''')
169 self.CompareOutputs(output, expected_output)
170
171 def testIntPolicy(self):
172 # Tests a policy group with a single policy of type 'string'.
173 grd = self.PrepareTest('''
174 {
175 'policy_definitions': [
176 {
177 'name': 'IntPolicy',
178 'type': 'int',
179 'caption': 'Caption of policy.',
180 'desc': 'Description of policy.',
181 'supported_on': ['chrome.win:8-']
182 },
183 ],
184 'placeholders': [],
185 'messages': {
186 'win_supported_winxpsp2': {
187 'text': 'At least Windows 3.13', 'desc': 'blah'
188 }
189 }
190 }''')
191 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
192 expected_output = self.ConstructOutput(
193 ['MACHINE', 'USER'], '''
194 CATEGORY !!chromium
195 KEYNAME "Software\\Policies\\Chromium"
196
197 POLICY !!IntPolicy_Policy
198 #if version >= 4
199 SUPPORTED !!SUPPORTED_WINXPSP2
200 #endif
201 EXPLAIN !!IntPolicy_Explain
202
203 PART !!IntPolicy_Part NUMERIC
204 VALUENAME "IntPolicy"
205 END PART
206 END POLICY
207
208 END CATEGORY
209
210 ''', '''[Strings]
211 SUPPORTED_WINXPSP2="At least Windows 3.13"
212 chromium="Chromium"
213 IntPolicy_Policy="Caption of policy."
214 IntPolicy_Explain="Description of policy."
215 IntPolicy_Part="Caption of policy."
216 ''')
217 self.CompareOutputs(output, expected_output)
218
219 def testIntEnumPolicy(self):
220 # Tests a policy group with a single policy of type 'int-enum'.
221 grd = self.PrepareTest('''
222 {
223 'policy_definitions': [
224 {
225 'name': 'EnumPolicy',
226 'type': 'int-enum',
227 'items': [
228 {
229 'name': 'ProxyServerDisabled',
230 'value': 0,
231 'caption': 'Option1',
232 },
233 {
234 'name': 'ProxyServerAutoDetect',
235 'value': 1,
236 'caption': 'Option2',
237 },
238 ],
239 'desc': 'Description of policy.',
240 'caption': 'Caption of policy.',
241 'supported_on': ['chrome.win:8-']
242 },
243 ],
244 'placeholders': [],
245 'messages': {
246 'win_supported_winxpsp2': {
247 'text': 'At least Windows 3.14', 'desc': 'blah'
248 }
249 }
250 }''')
251 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en')
252 expected_output = self.ConstructOutput(
253 ['MACHINE', 'USER'], '''
254 CATEGORY !!google
255 CATEGORY !!googlechrome
256 KEYNAME "Software\\Policies\\Google\\Chrome"
257
258 POLICY !!EnumPolicy_Policy
259 #if version >= 4
260 SUPPORTED !!SUPPORTED_WINXPSP2
261 #endif
262 EXPLAIN !!EnumPolicy_Explain
263
264 PART !!EnumPolicy_Part DROPDOWNLIST
265 VALUENAME "EnumPolicy"
266 ITEMLIST
267 NAME !!ProxyServerDisabled_DropDown VALUE NUMERIC 0
268 NAME !!ProxyServerAutoDetect_DropDown VALUE NUMERIC 1
269 END ITEMLIST
270 END PART
271 END POLICY
272
273 END CATEGORY
274 END CATEGORY
275
276 ''', '''[Strings]
277 SUPPORTED_WINXPSP2="At least Windows 3.14"
278 google="Google"
279 googlechrome="Google Chrome"
280 EnumPolicy_Policy="Caption of policy."
281 EnumPolicy_Explain="Description of policy."
282 EnumPolicy_Part="Caption of policy."
283 ProxyServerDisabled_DropDown="Option1"
284 ProxyServerAutoDetect_DropDown="Option2"
285 ''')
286 self.CompareOutputs(output, expected_output)
287
288 def testStringEnumPolicy(self):
289 # Tests a policy group with a single policy of type 'int-enum'.
290 grd = self.PrepareTest('''
291 {
292 'policy_definitions': [
293 {
294 'name': 'EnumPolicy',
295 'type': 'string-enum',
296 'caption': 'Caption of policy.',
297 'desc': 'Description of policy.',
298 'items': [
299 {'name': 'ProxyServerDisabled', 'value': 'one',
300 'caption': 'Option1'},
301 {'name': 'ProxyServerAutoDetect', 'value': 'two',
302 'caption': 'Option2'},
303 ],
304 'supported_on': ['chrome.win:8-']
305 },
306 ],
307 'placeholders': [],
308 'messages': {
309 'win_supported_winxpsp2': {
310 'text': 'At least Windows 3.14', 'desc': 'blah'
311 }
312 }
313 }''')
314 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en')
315 expected_output = self.ConstructOutput(
316 ['MACHINE', 'USER'], '''
317 CATEGORY !!google
318 CATEGORY !!googlechrome
319 KEYNAME "Software\\Policies\\Google\\Chrome"
320
321 POLICY !!EnumPolicy_Policy
322 #if version >= 4
323 SUPPORTED !!SUPPORTED_WINXPSP2
324 #endif
325 EXPLAIN !!EnumPolicy_Explain
326
327 PART !!EnumPolicy_Part DROPDOWNLIST
328 VALUENAME "EnumPolicy"
329 ITEMLIST
330 NAME !!ProxyServerDisabled_DropDown VALUE "one"
331 NAME !!ProxyServerAutoDetect_DropDown VALUE "two"
332 END ITEMLIST
333 END PART
334 END POLICY
335
336 END CATEGORY
337 END CATEGORY
338
339 ''', '''[Strings]
340 SUPPORTED_WINXPSP2="At least Windows 3.14"
341 google="Google"
342 googlechrome="Google Chrome"
343 EnumPolicy_Policy="Caption of policy."
344 EnumPolicy_Explain="Description of policy."
345 EnumPolicy_Part="Caption of policy."
346 ProxyServerDisabled_DropDown="Option1"
347 ProxyServerAutoDetect_DropDown="Option2"
348 ''')
349 self.CompareOutputs(output, expected_output)
350
351 def testListPolicy(self):
352 # Tests a policy group with a single policy of type 'list'.
353 grd = self.PrepareTest('''
354 {
355 'policy_definitions': [
356 {
357 'name': 'ListPolicy',
358 'type': 'list',
359 'supported_on': ['chrome.win:8-'],
360 'desc': """Description of list policy.
361 With a newline.""",
362 'caption': 'Caption of list policy.',
363 'label': 'Label of list policy.'
364 },
365 ],
366 'placeholders': [],
367 'messages': {
368 'win_supported_winxpsp2': {
369 'text': 'At least Windows 3.15', 'desc': 'blah'
370 }
371 },
372 }''')
373 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
374 expected_output = self.ConstructOutput(
375 ['MACHINE', 'USER'], '''
376 CATEGORY !!chromium
377 KEYNAME "Software\\Policies\\Chromium"
378
379 POLICY !!ListPolicy_Policy
380 #if version >= 4
381 SUPPORTED !!SUPPORTED_WINXPSP2
382 #endif
383 EXPLAIN !!ListPolicy_Explain
384
385 PART !!ListPolicy_Part LISTBOX
386 KEYNAME "Software\\Policies\\Chromium\\ListPolicy"
387 VALUEPREFIX ""
388 END PART
389 END POLICY
390
391 END CATEGORY
392
393 ''', '''[Strings]
394 SUPPORTED_WINXPSP2="At least Windows 3.15"
395 chromium="Chromium"
396 ListPolicy_Policy="Caption of list policy."
397 ListPolicy_Explain="Description of list policy.\\nWith a newline."
398 ListPolicy_Part="Label of list policy."
399 ''')
400 self.CompareOutputs(output, expected_output)
401
402 def testNonSupportedPolicy(self):
403 # Tests a policy that is not supported on Windows, so it shouldn't
404 # be included in the ADM file.
405 grd = self.PrepareTest('''
406 {
407 'policy_definitions': [
408 {
409 'name': 'NonWinGroup',
410 'type': 'group',
411 'policies': [{
412 'name': 'NonWinPolicy',
413 'type': 'list',
414 'supported_on': ['chrome.linux:8-', 'chrome.mac:8-'],
415 'caption': 'Caption of list policy.',
416 'desc': 'Desc of list policy.',
417 }],
418 'caption': 'Group caption.',
419 'desc': 'Group description.',
420 },
421 ],
422 'placeholders': [],
423 'messages': {
424 'win_supported_winxpsp2': {
425 'text': 'At least Windows 3.16', 'desc': 'blah'
426 }
427 }
428 }''')
429 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
430 expected_output = self.ConstructOutput(
431 ['MACHINE', 'USER'], '''
432 CATEGORY !!chromium
433 KEYNAME "Software\\Policies\\Chromium"
434
435 END CATEGORY
436
437 ''', '''[Strings]
438 SUPPORTED_WINXPSP2="At least Windows 3.16"
439 chromium="Chromium"
440 ''')
441 self.CompareOutputs(output, expected_output)
442
443 def testPolicyGroup(self):
444 # Tests a policy group that has more than one policies.
445 grd = self.PrepareTest('''
446 {
447 'policy_definitions': [
448 {
449 'name': 'Group1',
450 'type': 'group',
451 'desc': 'Description of group.',
452 'caption': 'Caption of group.',
453 'policies': [{
454 'name': 'Policy1',
455 'type': 'list',
456 'supported_on': ['chrome.win:8-'],
457 'caption': 'Caption of policy1.',
458 'desc': """Description of policy1.
459 With a newline."""
460 },{
461 'name': 'Policy2',
462 'type': 'string',
463 'supported_on': ['chrome.win:8-'],
464 'caption': 'Caption of policy2.',
465 'desc': """Description of policy2.
466 With a newline."""
467 }],
468 },
469 ],
470 'placeholders': [],
471 'messages': {
472 'win_supported_winxpsp2': {
473 'text': 'At least Windows 3.16', 'desc': 'blah'
474 }
475 }
476 }''')
477 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
478 expected_output = self.ConstructOutput(
479 ['MACHINE', 'USER'], '''
480 CATEGORY !!chromium
481 KEYNAME "Software\\Policies\\Chromium"
482
483 CATEGORY !!Group1_Category
484 POLICY !!Policy1_Policy
485 #if version >= 4
486 SUPPORTED !!SUPPORTED_WINXPSP2
487 #endif
488 EXPLAIN !!Policy1_Explain
489
490 PART !!Policy1_Part LISTBOX
491 KEYNAME "Software\\Policies\\Chromium\\Policy1"
492 VALUEPREFIX ""
493 END PART
494 END POLICY
495
496 POLICY !!Policy2_Policy
497 #if version >= 4
498 SUPPORTED !!SUPPORTED_WINXPSP2
499 #endif
500 EXPLAIN !!Policy2_Explain
501
502 PART !!Policy2_Part EDITTEXT
503 VALUENAME "Policy2"
504 END PART
505 END POLICY
506
507 END CATEGORY
508
509 END CATEGORY
510
511 ''', '''[Strings]
512 SUPPORTED_WINXPSP2="At least Windows 3.16"
513 chromium="Chromium"
514 Group1_Category="Caption of group."
515 Policy1_Policy="Caption of policy1."
516 Policy1_Explain="Description of policy1.\\nWith a newline."
517 Policy1_Part="Caption of policy1."
518 Policy2_Policy="Caption of policy2."
519 Policy2_Explain="Description of policy2.\\nWith a newline."
520 Policy2_Part="Caption of policy2."
521 ''')
522 self.CompareOutputs(output, expected_output)
523
524 if __name__ == '__main__':
525 unittest.main()
OLDNEW
« no previous file with comments | « grit/format/policy_templates/writers/adm_writer.py ('k') | grit/format/policy_templates/writers/adml_writer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698