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

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

Issue 1442863002: Remove contents of grit's SVN repository. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 5 years, 1 month 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2012 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(__file__), '../../../..'))
13
14 import unittest
15
16 from grit.format.policy_templates.writers import writer_unittest_common
17
18
19 class AdmWriterUnittest(writer_unittest_common.WriterUnittestCommon):
20 '''Unit tests for AdmWriter.'''
21
22 def ConstructOutput(self, classes, body, strings):
23 result = []
24 for clazz in classes:
25 result.append('CLASS ' + clazz)
26 result.append(body)
27 result.append(strings)
28 return ''.join(result)
29
30 def CompareOutputs(self, output, expected_output):
31 '''Compares the output of the adm_writer with its expected output.
32
33 Args:
34 output: The output of the adm writer as returned by grit.
35 expected_output: The expected output.
36
37 Raises:
38 AssertionError: if the two strings are not equivalent.
39 '''
40 self.assertEquals(
41 output.strip(),
42 expected_output.strip().replace('\n', '\r\n'))
43
44 def testEmpty(self):
45 # Test PListWriter in case of empty polices.
46 grd = self.PrepareTest('''
47 {
48 'policy_definitions': [],
49 'placeholders': [],
50 'messages': {
51 'win_supported_winxpsp2': {
52 'text': 'At least "Windows 3.11', 'desc': 'blah'
53 },
54 'doc_recommended': {
55 'text': 'Recommended', 'desc': 'bleh'
56 }
57 }
58 }''')
59 output = self.GetOutput(grd, 'fr', {'_chromium': '1',}, 'adm', 'en')
60 expected_output = self.ConstructOutput(
61 ['MACHINE', 'USER'], '''
62 CATEGORY !!chromium
63 KEYNAME "Software\\Policies\\Chromium"
64
65 END CATEGORY
66
67 CATEGORY !!chromium_recommended
68 KEYNAME "Software\\Policies\\Chromium\\Recommended"
69
70 END CATEGORY
71
72
73 ''', '''[Strings]
74 SUPPORTED_WINXPSP2="At least "Windows 3.11"
75 chromium="Chromium"
76 chromium_recommended="Chromium - Recommended"''')
77 self.CompareOutputs(output, expected_output)
78
79 def testVersionAnnotation(self):
80 # Test PListWriter in case of empty polices.
81 grd = self.PrepareTest('''
82 {
83 'policy_definitions': [],
84 'placeholders': [],
85 'messages': {
86 'win_supported_winxpsp2': {
87 'text': 'At least "Windows 3.11', 'desc': 'blah'
88 },
89 'doc_recommended': {
90 'text': 'Recommended', 'desc': 'bleh'
91 }
92 }
93 }''')
94 output = self.GetOutput(
95 grd, 'fr', {'_chromium': '1', 'version':'39.0.0.0'}, 'adm', 'en')
96 expected_output = '; chromium version: 39.0.0.0\n' + \
97 self.ConstructOutput(['MACHINE', 'USER'], '''
98 CATEGORY !!chromium
99 KEYNAME "Software\\Policies\\Chromium"
100
101 END CATEGORY
102
103 CATEGORY !!chromium_recommended
104 KEYNAME "Software\\Policies\\Chromium\\Recommended"
105
106 END CATEGORY
107
108
109 ''', '''[Strings]
110 SUPPORTED_WINXPSP2="At least "Windows 3.11"
111 chromium="Chromium"
112 chromium_recommended="Chromium - Recommended"''')
113 self.CompareOutputs(output, expected_output)
114
115 def testMainPolicy(self):
116 # Tests a policy group with a single policy of type 'main'.
117 grd = self.PrepareTest('''
118 {
119 'policy_definitions': [
120 {
121 'name': 'MainPolicy',
122 'type': 'main',
123 'supported_on': ['chrome.win:8-'],
124 'features': { 'can_be_recommended': True },
125 'caption': 'Caption of main.',
126 'desc': 'Description of main.',
127 },
128 ],
129 'placeholders': [],
130 'messages': {
131 'win_supported_winxpsp2': {
132 'text': 'At least Windows 3.12', 'desc': 'blah'
133 },
134 'doc_recommended': {
135 'text': 'Recommended', 'desc': 'bleh'
136 }
137 }
138 }''')
139 output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'adm', 'en')
140 expected_output = self.ConstructOutput(
141 ['MACHINE', 'USER'], '''
142 CATEGORY !!google
143 CATEGORY !!googlechrome
144 KEYNAME "Software\\Policies\\Google\\Chrome"
145
146 POLICY !!MainPolicy_Policy
147 #if version >= 4
148 SUPPORTED !!SUPPORTED_WINXPSP2
149 #endif
150 EXPLAIN !!MainPolicy_Explain
151 VALUENAME "MainPolicy"
152 VALUEON NUMERIC 1
153 VALUEOFF NUMERIC 0
154 END POLICY
155
156 END CATEGORY
157 END CATEGORY
158
159 CATEGORY !!google
160 CATEGORY !!googlechrome_recommended
161 KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
162
163 POLICY !!MainPolicy_Policy
164 #if version >= 4
165 SUPPORTED !!SUPPORTED_WINXPSP2
166 #endif
167 EXPLAIN !!MainPolicy_Explain
168 VALUENAME "MainPolicy"
169 VALUEON NUMERIC 1
170 VALUEOFF NUMERIC 0
171 END POLICY
172
173 END CATEGORY
174 END CATEGORY
175
176
177 ''', '''[Strings]
178 SUPPORTED_WINXPSP2="At least Windows 3.12"
179 google="Google"
180 googlechrome="Google Chrome"
181 googlechrome_recommended="Google Chrome - Recommended"
182 MainPolicy_Policy="Caption of main."
183 MainPolicy_Explain="Description of main."''')
184 self.CompareOutputs(output, expected_output)
185
186 def testMainPolicyRecommendedOnly(self):
187 # Tests a policy group with a single policy of type 'main'.
188 grd = self.PrepareTest('''
189 {
190 'policy_definitions': [
191 {
192 'name': 'MainPolicy',
193 'type': 'main',
194 'supported_on': ['chrome.win:8-'],
195 'features': {
196 'can_be_recommended': True,
197 'can_be_mandatory': False
198 },
199 'caption': 'Caption of main.',
200 'desc': 'Description of main.',
201 },
202 ],
203 'placeholders': [],
204 'messages': {
205 'win_supported_winxpsp2': {
206 'text': 'At least Windows 3.12', 'desc': 'blah'
207 },
208 'doc_recommended': {
209 'text': 'Recommended', 'desc': 'bleh'
210 }
211 }
212 }''')
213 output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'adm', 'en')
214 expected_output = self.ConstructOutput(
215 ['MACHINE', 'USER'], '''
216 CATEGORY !!google
217 CATEGORY !!googlechrome
218 KEYNAME "Software\\Policies\\Google\\Chrome"
219
220 END CATEGORY
221 END CATEGORY
222
223 CATEGORY !!google
224 CATEGORY !!googlechrome_recommended
225 KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
226
227 POLICY !!MainPolicy_Policy
228 #if version >= 4
229 SUPPORTED !!SUPPORTED_WINXPSP2
230 #endif
231 EXPLAIN !!MainPolicy_Explain
232 VALUENAME "MainPolicy"
233 VALUEON NUMERIC 1
234 VALUEOFF NUMERIC 0
235 END POLICY
236
237 END CATEGORY
238 END CATEGORY
239
240
241 ''', '''[Strings]
242 SUPPORTED_WINXPSP2="At least Windows 3.12"
243 google="Google"
244 googlechrome="Google Chrome"
245 googlechrome_recommended="Google Chrome - Recommended"
246 MainPolicy_Policy="Caption of main."
247 MainPolicy_Explain="Description of main."''')
248 self.CompareOutputs(output, expected_output)
249
250 def testStringPolicy(self):
251 # Tests a policy group with a single policy of type 'string'.
252 grd = self.PrepareTest('''
253 {
254 'policy_definitions': [
255 {
256 'name': 'StringPolicy',
257 'type': 'string',
258 'supported_on': ['chrome.win:8-'],
259 'features': { 'can_be_recommended': True },
260 'desc': """Description of group.
261 With a newline.""",
262 'caption': 'Caption of policy.',
263 },
264 ],
265 'placeholders': [],
266 'messages': {
267 'win_supported_winxpsp2': {
268 'text': 'At least Windows 3.13', 'desc': 'blah'
269 },
270 'doc_recommended': {
271 'text': 'Recommended', 'desc': 'bleh'
272 }
273 }
274 }''')
275 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
276 expected_output = self.ConstructOutput(
277 ['MACHINE', 'USER'], '''
278 CATEGORY !!chromium
279 KEYNAME "Software\\Policies\\Chromium"
280
281 POLICY !!StringPolicy_Policy
282 #if version >= 4
283 SUPPORTED !!SUPPORTED_WINXPSP2
284 #endif
285 EXPLAIN !!StringPolicy_Explain
286
287 PART !!StringPolicy_Part EDITTEXT
288 VALUENAME "StringPolicy"
289 MAXLEN 1000000
290 END PART
291 END POLICY
292
293 END CATEGORY
294
295 CATEGORY !!chromium_recommended
296 KEYNAME "Software\\Policies\\Chromium\\Recommended"
297
298 POLICY !!StringPolicy_Policy
299 #if version >= 4
300 SUPPORTED !!SUPPORTED_WINXPSP2
301 #endif
302 EXPLAIN !!StringPolicy_Explain
303
304 PART !!StringPolicy_Part EDITTEXT
305 VALUENAME "StringPolicy"
306 MAXLEN 1000000
307 END PART
308 END POLICY
309
310 END CATEGORY
311
312
313 ''', '''[Strings]
314 SUPPORTED_WINXPSP2="At least Windows 3.13"
315 chromium="Chromium"
316 chromium_recommended="Chromium - Recommended"
317 StringPolicy_Policy="Caption of policy."
318 StringPolicy_Explain="Description of group.\\nWith a newline."
319 StringPolicy_Part="Caption of policy."
320 ''')
321 self.CompareOutputs(output, expected_output)
322
323 def testIntPolicy(self):
324 # Tests a policy group with a single policy of type 'string'.
325 grd = self.PrepareTest('''
326 {
327 'policy_definitions': [
328 {
329 'name': 'IntPolicy',
330 'type': 'int',
331 'caption': 'Caption of policy.',
332 'features': { 'can_be_recommended': True },
333 'desc': 'Description of policy.',
334 'supported_on': ['chrome.win:8-']
335 },
336 ],
337 'placeholders': [],
338 'messages': {
339 'win_supported_winxpsp2': {
340 'text': 'At least Windows 3.13', 'desc': 'blah'
341 },
342 'doc_recommended': {
343 'text': 'Recommended', 'desc': 'bleh'
344 }
345 }
346 }''')
347 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
348 expected_output = self.ConstructOutput(
349 ['MACHINE', 'USER'], '''
350 CATEGORY !!chromium
351 KEYNAME "Software\\Policies\\Chromium"
352
353 POLICY !!IntPolicy_Policy
354 #if version >= 4
355 SUPPORTED !!SUPPORTED_WINXPSP2
356 #endif
357 EXPLAIN !!IntPolicy_Explain
358
359 PART !!IntPolicy_Part NUMERIC
360 VALUENAME "IntPolicy"
361 MIN 0 MAX 2000000000
362 END PART
363 END POLICY
364
365 END CATEGORY
366
367 CATEGORY !!chromium_recommended
368 KEYNAME "Software\\Policies\\Chromium\\Recommended"
369
370 POLICY !!IntPolicy_Policy
371 #if version >= 4
372 SUPPORTED !!SUPPORTED_WINXPSP2
373 #endif
374 EXPLAIN !!IntPolicy_Explain
375
376 PART !!IntPolicy_Part NUMERIC
377 VALUENAME "IntPolicy"
378 MIN 0 MAX 2000000000
379 END PART
380 END POLICY
381
382 END CATEGORY
383
384
385 ''', '''[Strings]
386 SUPPORTED_WINXPSP2="At least Windows 3.13"
387 chromium="Chromium"
388 chromium_recommended="Chromium - Recommended"
389 IntPolicy_Policy="Caption of policy."
390 IntPolicy_Explain="Description of policy."
391 IntPolicy_Part="Caption of policy."
392 ''')
393 self.CompareOutputs(output, expected_output)
394
395 def testIntEnumPolicy(self):
396 # Tests a policy group with a single policy of type 'int-enum'.
397 grd = self.PrepareTest('''
398 {
399 'policy_definitions': [
400 {
401 'name': 'EnumPolicy',
402 'type': 'int-enum',
403 'items': [
404 {
405 'name': 'ProxyServerDisabled',
406 'value': 0,
407 'caption': 'Option1',
408 },
409 {
410 'name': 'ProxyServerAutoDetect',
411 'value': 1,
412 'caption': 'Option2',
413 },
414 ],
415 'desc': 'Description of policy.',
416 'caption': 'Caption of policy.',
417 'supported_on': ['chrome.win:8-'],
418 'features': { 'can_be_recommended': True },
419 },
420 ],
421 'placeholders': [],
422 'messages': {
423 'win_supported_winxpsp2': {
424 'text': 'At least Windows 3.14', 'desc': 'blah'
425 },
426 'doc_recommended': {
427 'text': 'Recommended', 'desc': 'bleh'
428 }
429 }
430 }''')
431 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en')
432 expected_output = self.ConstructOutput(
433 ['MACHINE', 'USER'], '''
434 CATEGORY !!google
435 CATEGORY !!googlechrome
436 KEYNAME "Software\\Policies\\Google\\Chrome"
437
438 POLICY !!EnumPolicy_Policy
439 #if version >= 4
440 SUPPORTED !!SUPPORTED_WINXPSP2
441 #endif
442 EXPLAIN !!EnumPolicy_Explain
443
444 PART !!EnumPolicy_Part DROPDOWNLIST
445 VALUENAME "EnumPolicy"
446 ITEMLIST
447 NAME !!ProxyServerDisabled_DropDown VALUE NUMERIC 0
448 NAME !!ProxyServerAutoDetect_DropDown VALUE NUMERIC 1
449 END ITEMLIST
450 END PART
451 END POLICY
452
453 END CATEGORY
454 END CATEGORY
455
456 CATEGORY !!google
457 CATEGORY !!googlechrome_recommended
458 KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
459
460 POLICY !!EnumPolicy_Policy
461 #if version >= 4
462 SUPPORTED !!SUPPORTED_WINXPSP2
463 #endif
464 EXPLAIN !!EnumPolicy_Explain
465
466 PART !!EnumPolicy_Part DROPDOWNLIST
467 VALUENAME "EnumPolicy"
468 ITEMLIST
469 NAME !!ProxyServerDisabled_DropDown VALUE NUMERIC 0
470 NAME !!ProxyServerAutoDetect_DropDown VALUE NUMERIC 1
471 END ITEMLIST
472 END PART
473 END POLICY
474
475 END CATEGORY
476 END CATEGORY
477
478
479 ''', '''[Strings]
480 SUPPORTED_WINXPSP2="At least Windows 3.14"
481 google="Google"
482 googlechrome="Google Chrome"
483 googlechrome_recommended="Google Chrome - Recommended"
484 EnumPolicy_Policy="Caption of policy."
485 EnumPolicy_Explain="Description of policy."
486 EnumPolicy_Part="Caption of policy."
487 ProxyServerDisabled_DropDown="Option1"
488 ProxyServerAutoDetect_DropDown="Option2"
489 ''')
490 self.CompareOutputs(output, expected_output)
491
492 def testStringEnumPolicy(self):
493 # Tests a policy group with a single policy of type 'int-enum'.
494 grd = self.PrepareTest('''
495 {
496 'policy_definitions': [
497 {
498 'name': 'EnumPolicy',
499 'type': 'string-enum',
500 'caption': 'Caption of policy.',
501 'desc': 'Description of policy.',
502 'items': [
503 {'name': 'ProxyServerDisabled', 'value': 'one',
504 'caption': 'Option1'},
505 {'name': 'ProxyServerAutoDetect', 'value': 'two',
506 'caption': 'Option2'},
507 ],
508 'supported_on': ['chrome.win:8-'],
509 'features': { 'can_be_recommended': True },
510 },
511 ],
512 'placeholders': [],
513 'messages': {
514 'win_supported_winxpsp2': {
515 'text': 'At least Windows 3.14', 'desc': 'blah'
516 },
517 'doc_recommended': {
518 'text': 'Recommended', 'desc': 'bleh'
519 }
520 }
521 }''')
522 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en')
523 expected_output = self.ConstructOutput(
524 ['MACHINE', 'USER'], '''
525 CATEGORY !!google
526 CATEGORY !!googlechrome
527 KEYNAME "Software\\Policies\\Google\\Chrome"
528
529 POLICY !!EnumPolicy_Policy
530 #if version >= 4
531 SUPPORTED !!SUPPORTED_WINXPSP2
532 #endif
533 EXPLAIN !!EnumPolicy_Explain
534
535 PART !!EnumPolicy_Part DROPDOWNLIST
536 VALUENAME "EnumPolicy"
537 ITEMLIST
538 NAME !!ProxyServerDisabled_DropDown VALUE "one"
539 NAME !!ProxyServerAutoDetect_DropDown VALUE "two"
540 END ITEMLIST
541 END PART
542 END POLICY
543
544 END CATEGORY
545 END CATEGORY
546
547 CATEGORY !!google
548 CATEGORY !!googlechrome_recommended
549 KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
550
551 POLICY !!EnumPolicy_Policy
552 #if version >= 4
553 SUPPORTED !!SUPPORTED_WINXPSP2
554 #endif
555 EXPLAIN !!EnumPolicy_Explain
556
557 PART !!EnumPolicy_Part DROPDOWNLIST
558 VALUENAME "EnumPolicy"
559 ITEMLIST
560 NAME !!ProxyServerDisabled_DropDown VALUE "one"
561 NAME !!ProxyServerAutoDetect_DropDown VALUE "two"
562 END ITEMLIST
563 END PART
564 END POLICY
565
566 END CATEGORY
567 END CATEGORY
568
569
570 ''', '''[Strings]
571 SUPPORTED_WINXPSP2="At least Windows 3.14"
572 google="Google"
573 googlechrome="Google Chrome"
574 googlechrome_recommended="Google Chrome - Recommended"
575 EnumPolicy_Policy="Caption of policy."
576 EnumPolicy_Explain="Description of policy."
577 EnumPolicy_Part="Caption of policy."
578 ProxyServerDisabled_DropDown="Option1"
579 ProxyServerAutoDetect_DropDown="Option2"
580 ''')
581 self.CompareOutputs(output, expected_output)
582
583 def testListPolicy(self):
584 # Tests a policy group with a single policy of type 'list'.
585 grd = self.PrepareTest('''
586 {
587 'policy_definitions': [
588 {
589 'name': 'ListPolicy',
590 'type': 'list',
591 'supported_on': ['chrome.win:8-'],
592 'features': { 'can_be_recommended': True },
593 'desc': """Description of list policy.
594 With a newline.""",
595 'caption': 'Caption of list policy.',
596 'label': 'Label of list policy.'
597 },
598 ],
599 'placeholders': [],
600 'messages': {
601 'win_supported_winxpsp2': {
602 'text': 'At least Windows 3.15', 'desc': 'blah'
603 },
604 'doc_recommended': {
605 'text': 'Recommended', 'desc': 'bleh'
606 }
607 },
608 }''')
609 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
610 expected_output = self.ConstructOutput(
611 ['MACHINE', 'USER'], '''
612 CATEGORY !!chromium
613 KEYNAME "Software\\Policies\\Chromium"
614
615 POLICY !!ListPolicy_Policy
616 #if version >= 4
617 SUPPORTED !!SUPPORTED_WINXPSP2
618 #endif
619 EXPLAIN !!ListPolicy_Explain
620
621 PART !!ListPolicy_Part LISTBOX
622 KEYNAME "Software\\Policies\\Chromium\\ListPolicy"
623 VALUEPREFIX ""
624 END PART
625 END POLICY
626
627 END CATEGORY
628
629 CATEGORY !!chromium_recommended
630 KEYNAME "Software\\Policies\\Chromium\\Recommended"
631
632 POLICY !!ListPolicy_Policy
633 #if version >= 4
634 SUPPORTED !!SUPPORTED_WINXPSP2
635 #endif
636 EXPLAIN !!ListPolicy_Explain
637
638 PART !!ListPolicy_Part LISTBOX
639 KEYNAME "Software\\Policies\\Chromium\\Recommended\\ListPolicy"
640 VALUEPREFIX ""
641 END PART
642 END POLICY
643
644 END CATEGORY
645
646
647 ''', '''[Strings]
648 SUPPORTED_WINXPSP2="At least Windows 3.15"
649 chromium="Chromium"
650 chromium_recommended="Chromium - Recommended"
651 ListPolicy_Policy="Caption of list policy."
652 ListPolicy_Explain="Description of list policy.\\nWith a newline."
653 ListPolicy_Part="Label of list policy."
654 ''')
655 self.CompareOutputs(output, expected_output)
656
657 def testStringEnumListPolicy(self):
658 # Tests a policy group with a single policy of type 'string-enum-list'.
659 grd = self.PrepareTest('''
660 {
661 'policy_definitions': [
662 {
663 'name': 'ListPolicy',
664 'type': 'string-enum-list',
665 'supported_on': ['chrome.win:8-'],
666 'features': { 'can_be_recommended': True },
667 'desc': """Description of list policy.
668 With a newline.""",
669 'items': [
670 {'name': 'ProxyServerDisabled', 'value': 'one',
671 'caption': 'Option1'},
672 {'name': 'ProxyServerAutoDetect', 'value': 'two',
673 'caption': 'Option2'},
674 ],
675 'caption': 'Caption of list policy.',
676 'label': 'Label of list policy.'
677 },
678 ],
679 'placeholders': [],
680 'messages': {
681 'win_supported_winxpsp2': {
682 'text': 'At least Windows 3.15', 'desc': 'blah'
683 },
684 'doc_recommended': {
685 'text': 'Recommended', 'desc': 'bleh'
686 }
687 },
688 }''')
689 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
690 expected_output = self.ConstructOutput(
691 ['MACHINE', 'USER'], '''
692 CATEGORY !!chromium
693 KEYNAME "Software\\Policies\\Chromium"
694
695 POLICY !!ListPolicy_Policy
696 #if version >= 4
697 SUPPORTED !!SUPPORTED_WINXPSP2
698 #endif
699 EXPLAIN !!ListPolicy_Explain
700
701 PART !!ListPolicy_Part LISTBOX
702 KEYNAME "Software\\Policies\\Chromium\\ListPolicy"
703 VALUEPREFIX ""
704 END PART
705 END POLICY
706
707 END CATEGORY
708
709 CATEGORY !!chromium_recommended
710 KEYNAME "Software\\Policies\\Chromium\\Recommended"
711
712 POLICY !!ListPolicy_Policy
713 #if version >= 4
714 SUPPORTED !!SUPPORTED_WINXPSP2
715 #endif
716 EXPLAIN !!ListPolicy_Explain
717
718 PART !!ListPolicy_Part LISTBOX
719 KEYNAME "Software\\Policies\\Chromium\\Recommended\\ListPolicy"
720 VALUEPREFIX ""
721 END PART
722 END POLICY
723
724 END CATEGORY
725
726
727 ''', '''[Strings]
728 SUPPORTED_WINXPSP2="At least Windows 3.15"
729 chromium="Chromium"
730 chromium_recommended="Chromium - Recommended"
731 ListPolicy_Policy="Caption of list policy."
732 ListPolicy_Explain="Description of list policy.\\nWith a newline."
733 ListPolicy_Part="Label of list policy."
734 ''')
735 self.CompareOutputs(output, expected_output)
736
737 def testDictionaryPolicy(self):
738 # Tests a policy group with a single policy of type 'dict'.
739 grd = self.PrepareTest('''
740 {
741 'policy_definitions': [
742 {
743 'name': 'DictionaryPolicy',
744 'type': 'dict',
745 'supported_on': ['chrome.win:8-'],
746 'features': { 'can_be_recommended': True },
747 'desc': 'Description of group.',
748 'caption': 'Caption of policy.',
749 },
750 ],
751 'placeholders': [],
752 'messages': {
753 'win_supported_winxpsp2': {
754 'text': 'At least Windows 3.13', 'desc': 'blah'
755 },
756 'doc_recommended': {
757 'text': 'Recommended', 'desc': 'bleh'
758 }
759 }
760 }''')
761 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
762 expected_output = self.ConstructOutput(
763 ['MACHINE', 'USER'], '''
764 CATEGORY !!chromium
765 KEYNAME "Software\\Policies\\Chromium"
766
767 POLICY !!DictionaryPolicy_Policy
768 #if version >= 4
769 SUPPORTED !!SUPPORTED_WINXPSP2
770 #endif
771 EXPLAIN !!DictionaryPolicy_Explain
772
773 PART !!DictionaryPolicy_Part EDITTEXT
774 VALUENAME "DictionaryPolicy"
775 MAXLEN 1000000
776 END PART
777 END POLICY
778
779 END CATEGORY
780
781 CATEGORY !!chromium_recommended
782 KEYNAME "Software\\Policies\\Chromium\\Recommended"
783
784 POLICY !!DictionaryPolicy_Policy
785 #if version >= 4
786 SUPPORTED !!SUPPORTED_WINXPSP2
787 #endif
788 EXPLAIN !!DictionaryPolicy_Explain
789
790 PART !!DictionaryPolicy_Part EDITTEXT
791 VALUENAME "DictionaryPolicy"
792 MAXLEN 1000000
793 END PART
794 END POLICY
795
796 END CATEGORY
797
798
799 ''', '''[Strings]
800 SUPPORTED_WINXPSP2="At least Windows 3.13"
801 chromium="Chromium"
802 chromium_recommended="Chromium - Recommended"
803 DictionaryPolicy_Policy="Caption of policy."
804 DictionaryPolicy_Explain="Description of group."
805 DictionaryPolicy_Part="Caption of policy."
806 ''')
807 self.CompareOutputs(output, expected_output)
808
809 def testNonSupportedPolicy(self):
810 # Tests a policy that is not supported on Windows, so it shouldn't
811 # be included in the ADM file.
812 grd = self.PrepareTest('''
813 {
814 'policy_definitions': [
815 {
816 'name': 'NonWinGroup',
817 'type': 'group',
818 'policies': [{
819 'name': 'NonWinPolicy',
820 'type': 'list',
821 'supported_on': ['chrome.linux:8-', 'chrome.mac:8-'],
822 'caption': 'Caption of list policy.',
823 'desc': 'Desc of list policy.',
824 }],
825 'caption': 'Group caption.',
826 'desc': 'Group description.',
827 },
828 ],
829 'placeholders': [],
830 'messages': {
831 'win_supported_winxpsp2': {
832 'text': 'At least Windows 3.16', 'desc': 'blah'
833 },
834 'doc_recommended': {
835 'text': 'Recommended', 'desc': 'bleh'
836 }
837 }
838 }''')
839 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
840 expected_output = self.ConstructOutput(
841 ['MACHINE', 'USER'], '''
842 CATEGORY !!chromium
843 KEYNAME "Software\\Policies\\Chromium"
844
845 END CATEGORY
846
847 CATEGORY !!chromium_recommended
848 KEYNAME "Software\\Policies\\Chromium\\Recommended"
849
850 END CATEGORY
851
852
853 ''', '''[Strings]
854 SUPPORTED_WINXPSP2="At least Windows 3.16"
855 chromium="Chromium"
856 chromium_recommended="Chromium - Recommended"
857 ''')
858 self.CompareOutputs(output, expected_output)
859
860 def testNonRecommendedPolicy(self):
861 # Tests a policy that is not recommended, so it should be included.
862 grd = self.PrepareTest('''
863 {
864 'policy_definitions': [
865 {
866 'name': 'MainPolicy',
867 'type': 'main',
868 'supported_on': ['chrome.win:8-'],
869 'caption': 'Caption of main.',
870 'desc': 'Description of main.',
871 },
872 ],
873 'placeholders': [],
874 'messages': {
875 'win_supported_winxpsp2': {
876 'text': 'At least Windows 3.12', 'desc': 'blah'
877 },
878 'doc_recommended': {
879 'text': 'Recommended', 'desc': 'bleh'
880 }
881 }
882 }''')
883 output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'adm', 'en')
884 expected_output = self.ConstructOutput(
885 ['MACHINE', 'USER'], '''
886 CATEGORY !!google
887 CATEGORY !!googlechrome
888 KEYNAME "Software\\Policies\\Google\\Chrome"
889
890 POLICY !!MainPolicy_Policy
891 #if version >= 4
892 SUPPORTED !!SUPPORTED_WINXPSP2
893 #endif
894 EXPLAIN !!MainPolicy_Explain
895 VALUENAME "MainPolicy"
896 VALUEON NUMERIC 1
897 VALUEOFF NUMERIC 0
898 END POLICY
899
900 END CATEGORY
901 END CATEGORY
902
903 CATEGORY !!google
904 CATEGORY !!googlechrome_recommended
905 KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
906
907 END CATEGORY
908 END CATEGORY
909
910
911 ''', '''[Strings]
912 SUPPORTED_WINXPSP2="At least Windows 3.12"
913 google="Google"
914 googlechrome="Google Chrome"
915 googlechrome_recommended="Google Chrome - Recommended"
916 MainPolicy_Policy="Caption of main."
917 MainPolicy_Explain="Description of main."''')
918 self.CompareOutputs(output, expected_output)
919
920 def testPolicyGroup(self):
921 # Tests a policy group that has more than one policies.
922 grd = self.PrepareTest('''
923 {
924 'policy_definitions': [
925 {
926 'name': 'Group1',
927 'type': 'group',
928 'desc': 'Description of group.',
929 'caption': 'Caption of group.',
930 'policies': [{
931 'name': 'Policy1',
932 'type': 'list',
933 'supported_on': ['chrome.win:8-'],
934 'features': { 'can_be_recommended': True },
935 'caption': 'Caption of policy1.',
936 'desc': """Description of policy1.
937 With a newline."""
938 },{
939 'name': 'Policy2',
940 'type': 'string',
941 'supported_on': ['chrome.win:8-'],
942 'caption': 'Caption of policy2.',
943 'desc': """Description of policy2.
944 With a newline."""
945 }],
946 },
947 ],
948 'placeholders': [],
949 'messages': {
950 'win_supported_winxpsp2': {
951 'text': 'At least Windows 3.16', 'desc': 'blah'
952 },
953 'doc_recommended': {
954 'text': 'Recommended', 'desc': 'bleh'
955 }
956 }
957 }''')
958 output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
959 expected_output = self.ConstructOutput(
960 ['MACHINE', 'USER'], '''
961 CATEGORY !!chromium
962 KEYNAME "Software\\Policies\\Chromium"
963
964 CATEGORY !!Group1_Category
965 POLICY !!Policy1_Policy
966 #if version >= 4
967 SUPPORTED !!SUPPORTED_WINXPSP2
968 #endif
969 EXPLAIN !!Policy1_Explain
970
971 PART !!Policy1_Part LISTBOX
972 KEYNAME "Software\\Policies\\Chromium\\Policy1"
973 VALUEPREFIX ""
974 END PART
975 END POLICY
976
977 POLICY !!Policy2_Policy
978 #if version >= 4
979 SUPPORTED !!SUPPORTED_WINXPSP2
980 #endif
981 EXPLAIN !!Policy2_Explain
982
983 PART !!Policy2_Part EDITTEXT
984 VALUENAME "Policy2"
985 MAXLEN 1000000
986 END PART
987 END POLICY
988
989 END CATEGORY
990
991 END CATEGORY
992
993 CATEGORY !!chromium_recommended
994 KEYNAME "Software\\Policies\\Chromium\\Recommended"
995
996 CATEGORY !!Group1_Category
997 POLICY !!Policy1_Policy
998 #if version >= 4
999 SUPPORTED !!SUPPORTED_WINXPSP2
1000 #endif
1001 EXPLAIN !!Policy1_Explain
1002
1003 PART !!Policy1_Part LISTBOX
1004 KEYNAME "Software\\Policies\\Chromium\\Recommended\\Policy1"
1005 VALUEPREFIX ""
1006 END PART
1007 END POLICY
1008
1009 END CATEGORY
1010
1011 END CATEGORY
1012
1013
1014 ''', '''[Strings]
1015 SUPPORTED_WINXPSP2="At least Windows 3.16"
1016 chromium="Chromium"
1017 chromium_recommended="Chromium - Recommended"
1018 Group1_Category="Caption of group."
1019 Policy1_Policy="Caption of policy1."
1020 Policy1_Explain="Description of policy1.\\nWith a newline."
1021 Policy1_Part="Caption of policy1."
1022 Policy2_Policy="Caption of policy2."
1023 Policy2_Explain="Description of policy2.\\nWith a newline."
1024 Policy2_Part="Caption of policy2."
1025 ''')
1026 self.CompareOutputs(output, expected_output)
1027
1028 def testDuplicatedStringEnumPolicy(self):
1029 # Verifies that duplicated enum constants get merged, and that
1030 # string constants get escaped.
1031 grd = self.PrepareTest('''
1032 {
1033 'policy_definitions': [
1034 {
1035 'name': 'EnumPolicy.A',
1036 'type': 'string-enum',
1037 'caption': 'Caption of policy A.',
1038 'desc': 'Description of policy A.',
1039 'items': [
1040 {'name': 'tls1.2', 'value': 'tls1.2', 'caption': 'tls1.2' },
1041 ],
1042 'supported_on': ['chrome.win:39-'],
1043 },
1044 {
1045 'name': 'EnumPolicy.B',
1046 'type': 'string-enum',
1047 'caption': 'Caption of policy B.',
1048 'desc': 'Description of policy B.',
1049 'items': [
1050 {'name': 'tls1.2', 'value': 'tls1.2', 'caption': 'tls1.2' },
1051 ],
1052 'supported_on': ['chrome.win:39-'],
1053 },
1054 ],
1055 'placeholders': [],
1056 'messages': {
1057 'win_supported_winxpsp2': {
1058 'text': 'At least Windows 3.14', 'desc': 'blah'
1059 },
1060 'doc_recommended': {
1061 'text': 'Recommended', 'desc': 'bleh'
1062 }
1063 }
1064 }''')
1065 output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en')
1066 expected_output = self.ConstructOutput(
1067 ['MACHINE', 'USER'], '''
1068 CATEGORY !!google
1069 CATEGORY !!googlechrome
1070 KEYNAME "Software\\Policies\\Google\\Chrome"
1071
1072 POLICY !!EnumPolicy_A_Policy
1073 #if version >= 4
1074 SUPPORTED !!SUPPORTED_WINXPSP2
1075 #endif
1076 EXPLAIN !!EnumPolicy_A_Explain
1077
1078 PART !!EnumPolicy_A_Part DROPDOWNLIST
1079 VALUENAME "EnumPolicy.A"
1080 ITEMLIST
1081 NAME !!tls1_2_DropDown VALUE "tls1.2"
1082 END ITEMLIST
1083 END PART
1084 END POLICY
1085
1086 POLICY !!EnumPolicy_B_Policy
1087 #if version >= 4
1088 SUPPORTED !!SUPPORTED_WINXPSP2
1089 #endif
1090 EXPLAIN !!EnumPolicy_B_Explain
1091
1092 PART !!EnumPolicy_B_Part DROPDOWNLIST
1093 VALUENAME "EnumPolicy.B"
1094 ITEMLIST
1095 NAME !!tls1_2_DropDown VALUE "tls1.2"
1096 END ITEMLIST
1097 END PART
1098 END POLICY
1099
1100 END CATEGORY
1101 END CATEGORY
1102
1103 CATEGORY !!google
1104 CATEGORY !!googlechrome_recommended
1105 KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
1106
1107 END CATEGORY
1108 END CATEGORY
1109
1110
1111 ''', '''[Strings]
1112 SUPPORTED_WINXPSP2="At least Windows 3.14"
1113 google="Google"
1114 googlechrome="Google Chrome"
1115 googlechrome_recommended="Google Chrome - Recommended"
1116 EnumPolicy_A_Policy="Caption of policy A."
1117 EnumPolicy_A_Explain="Description of policy A."
1118 EnumPolicy_A_Part="Caption of policy A."
1119 tls1_2_DropDown="tls1.2"
1120 EnumPolicy_B_Policy="Caption of policy B."
1121 EnumPolicy_B_Explain="Description of policy B."
1122 EnumPolicy_B_Part="Caption of policy B."
1123 ''')
1124 self.CompareOutputs(output, expected_output)
1125
1126 if __name__ == '__main__':
1127 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