Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / grit / grit / format / policy_templates / writers / adm_writer_unittest.py
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 testMainPolicy(self):
80     # Tests a policy group with a single policy of type 'main'.
81     grd = self.PrepareTest('''
82       {
83         'policy_definitions': [
84           {
85             'name': 'MainPolicy',
86             'type': 'main',
87             'supported_on': ['chrome.win:8-'],
88             'features': { 'can_be_recommended': True },
89             'caption': 'Caption of main.',
90             'desc': 'Description of main.',
91           },
92         ],
93         'placeholders': [],
94         'messages': {
95           'win_supported_winxpsp2': {
96             'text': 'At least Windows 3.12', 'desc': 'blah'
97           },
98           'doc_recommended': {
99             'text': 'Recommended', 'desc': 'bleh'
100           }
101         }
102       }''')
103     output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'adm', 'en')
104     expected_output = self.ConstructOutput(
105         ['MACHINE', 'USER'], '''
106   CATEGORY !!google
107     CATEGORY !!googlechrome
108       KEYNAME "Software\\Policies\\Google\\Chrome"
109
110       POLICY !!MainPolicy_Policy
111         #if version >= 4
112           SUPPORTED !!SUPPORTED_WINXPSP2
113         #endif
114         EXPLAIN !!MainPolicy_Explain
115         VALUENAME "MainPolicy"
116         VALUEON NUMERIC 1
117         VALUEOFF NUMERIC 0
118       END POLICY
119
120     END CATEGORY
121   END CATEGORY
122
123   CATEGORY !!google
124     CATEGORY !!googlechrome_recommended
125       KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
126
127       POLICY !!MainPolicy_Policy
128         #if version >= 4
129           SUPPORTED !!SUPPORTED_WINXPSP2
130         #endif
131         EXPLAIN !!MainPolicy_Explain
132         VALUENAME "MainPolicy"
133         VALUEON NUMERIC 1
134         VALUEOFF NUMERIC 0
135       END POLICY
136
137     END CATEGORY
138   END CATEGORY
139
140
141 ''', '''[Strings]
142 SUPPORTED_WINXPSP2="At least Windows 3.12"
143 google="Google"
144 googlechrome="Google Chrome"
145 googlechrome_recommended="Google Chrome - Recommended"
146 MainPolicy_Policy="Caption of main."
147 MainPolicy_Explain="Description of main."''')
148     self.CompareOutputs(output, expected_output)
149
150   def testMainPolicyRecommendedOnly(self):
151     # Tests a policy group with a single policy of type 'main'.
152     grd = self.PrepareTest('''
153       {
154         'policy_definitions': [
155           {
156             'name': 'MainPolicy',
157             'type': 'main',
158             'supported_on': ['chrome.win:8-'],
159             'features': {
160               'can_be_recommended': True,
161               'can_be_mandatory': False
162             },
163             'caption': 'Caption of main.',
164             'desc': 'Description of main.',
165           },
166         ],
167         'placeholders': [],
168         'messages': {
169           'win_supported_winxpsp2': {
170             'text': 'At least Windows 3.12', 'desc': 'blah'
171           },
172           'doc_recommended': {
173             'text': 'Recommended', 'desc': 'bleh'
174           }
175         }
176       }''')
177     output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'adm', 'en')
178     expected_output = self.ConstructOutput(
179         ['MACHINE', 'USER'], '''
180   CATEGORY !!google
181     CATEGORY !!googlechrome
182       KEYNAME "Software\\Policies\\Google\\Chrome"
183
184     END CATEGORY
185   END CATEGORY
186
187   CATEGORY !!google
188     CATEGORY !!googlechrome_recommended
189       KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
190
191       POLICY !!MainPolicy_Policy
192         #if version >= 4
193           SUPPORTED !!SUPPORTED_WINXPSP2
194         #endif
195         EXPLAIN !!MainPolicy_Explain
196         VALUENAME "MainPolicy"
197         VALUEON NUMERIC 1
198         VALUEOFF NUMERIC 0
199       END POLICY
200
201     END CATEGORY
202   END CATEGORY
203
204
205 ''', '''[Strings]
206 SUPPORTED_WINXPSP2="At least Windows 3.12"
207 google="Google"
208 googlechrome="Google Chrome"
209 googlechrome_recommended="Google Chrome - Recommended"
210 MainPolicy_Policy="Caption of main."
211 MainPolicy_Explain="Description of main."''')
212     self.CompareOutputs(output, expected_output)
213
214   def testStringPolicy(self):
215     # Tests a policy group with a single policy of type 'string'.
216     grd = self.PrepareTest('''
217       {
218         'policy_definitions': [
219           {
220             'name': 'StringPolicy',
221             'type': 'string',
222             'supported_on': ['chrome.win:8-'],
223             'features': { 'can_be_recommended': True },
224             'desc': """Description of group.
225 With a newline.""",
226             'caption': 'Caption of policy.',
227           },
228         ],
229         'placeholders': [],
230         'messages': {
231           'win_supported_winxpsp2': {
232             'text': 'At least Windows 3.13', 'desc': 'blah'
233           },
234           'doc_recommended': {
235             'text': 'Recommended', 'desc': 'bleh'
236           }
237         }
238       }''')
239     output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
240     expected_output = self.ConstructOutput(
241         ['MACHINE', 'USER'], '''
242   CATEGORY !!chromium
243     KEYNAME "Software\\Policies\\Chromium"
244
245     POLICY !!StringPolicy_Policy
246       #if version >= 4
247         SUPPORTED !!SUPPORTED_WINXPSP2
248       #endif
249       EXPLAIN !!StringPolicy_Explain
250
251       PART !!StringPolicy_Part  EDITTEXT
252         VALUENAME "StringPolicy"
253       END PART
254     END POLICY
255
256   END CATEGORY
257
258   CATEGORY !!chromium_recommended
259     KEYNAME "Software\\Policies\\Chromium\\Recommended"
260
261     POLICY !!StringPolicy_Policy
262       #if version >= 4
263         SUPPORTED !!SUPPORTED_WINXPSP2
264       #endif
265       EXPLAIN !!StringPolicy_Explain
266
267       PART !!StringPolicy_Part  EDITTEXT
268         VALUENAME "StringPolicy"
269       END PART
270     END POLICY
271
272   END CATEGORY
273
274
275 ''', '''[Strings]
276 SUPPORTED_WINXPSP2="At least Windows 3.13"
277 chromium="Chromium"
278 chromium_recommended="Chromium - Recommended"
279 StringPolicy_Policy="Caption of policy."
280 StringPolicy_Explain="Description of group.\\nWith a newline."
281 StringPolicy_Part="Caption of policy."
282 ''')
283     self.CompareOutputs(output, expected_output)
284
285   def testIntPolicy(self):
286     # Tests a policy group with a single policy of type 'string'.
287     grd = self.PrepareTest('''
288       {
289         'policy_definitions': [
290           {
291             'name': 'IntPolicy',
292             'type': 'int',
293             'caption': 'Caption of policy.',
294             'features': { 'can_be_recommended': True },
295             'desc': 'Description of policy.',
296             'supported_on': ['chrome.win:8-']
297           },
298         ],
299         'placeholders': [],
300         'messages': {
301           'win_supported_winxpsp2': {
302             'text': 'At least Windows 3.13', 'desc': 'blah'
303           },
304           'doc_recommended': {
305             'text': 'Recommended', 'desc': 'bleh'
306           }
307         }
308       }''')
309     output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
310     expected_output = self.ConstructOutput(
311         ['MACHINE', 'USER'], '''
312   CATEGORY !!chromium
313     KEYNAME "Software\\Policies\\Chromium"
314
315     POLICY !!IntPolicy_Policy
316       #if version >= 4
317         SUPPORTED !!SUPPORTED_WINXPSP2
318       #endif
319       EXPLAIN !!IntPolicy_Explain
320
321       PART !!IntPolicy_Part  NUMERIC
322         VALUENAME "IntPolicy"
323         MIN 0 MAX 2000000000
324       END PART
325     END POLICY
326
327   END CATEGORY
328
329   CATEGORY !!chromium_recommended
330     KEYNAME "Software\\Policies\\Chromium\\Recommended"
331
332     POLICY !!IntPolicy_Policy
333       #if version >= 4
334         SUPPORTED !!SUPPORTED_WINXPSP2
335       #endif
336       EXPLAIN !!IntPolicy_Explain
337
338       PART !!IntPolicy_Part  NUMERIC
339         VALUENAME "IntPolicy"
340         MIN 0 MAX 2000000000
341       END PART
342     END POLICY
343
344   END CATEGORY
345
346
347 ''', '''[Strings]
348 SUPPORTED_WINXPSP2="At least Windows 3.13"
349 chromium="Chromium"
350 chromium_recommended="Chromium - Recommended"
351 IntPolicy_Policy="Caption of policy."
352 IntPolicy_Explain="Description of policy."
353 IntPolicy_Part="Caption of policy."
354 ''')
355     self.CompareOutputs(output, expected_output)
356
357   def testIntEnumPolicy(self):
358     # Tests a policy group with a single policy of type 'int-enum'.
359     grd = self.PrepareTest('''
360       {
361         'policy_definitions': [
362           {
363             'name': 'EnumPolicy',
364             'type': 'int-enum',
365             'items': [
366               {
367                 'name': 'ProxyServerDisabled',
368                 'value': 0,
369                 'caption': 'Option1',
370               },
371               {
372                 'name': 'ProxyServerAutoDetect',
373                 'value': 1,
374                 'caption': 'Option2',
375               },
376             ],
377             'desc': 'Description of policy.',
378             'caption': 'Caption of policy.',
379             'supported_on': ['chrome.win:8-'],
380             'features': { 'can_be_recommended': True },
381           },
382         ],
383         'placeholders': [],
384         'messages': {
385           'win_supported_winxpsp2': {
386             'text': 'At least Windows 3.14', 'desc': 'blah'
387           },
388           'doc_recommended': {
389             'text': 'Recommended', 'desc': 'bleh'
390           }
391         }
392       }''')
393     output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en')
394     expected_output = self.ConstructOutput(
395         ['MACHINE', 'USER'], '''
396   CATEGORY !!google
397     CATEGORY !!googlechrome
398       KEYNAME "Software\\Policies\\Google\\Chrome"
399
400       POLICY !!EnumPolicy_Policy
401         #if version >= 4
402           SUPPORTED !!SUPPORTED_WINXPSP2
403         #endif
404         EXPLAIN !!EnumPolicy_Explain
405
406         PART !!EnumPolicy_Part  DROPDOWNLIST
407           VALUENAME "EnumPolicy"
408           ITEMLIST
409             NAME !!ProxyServerDisabled_DropDown VALUE NUMERIC 0
410             NAME !!ProxyServerAutoDetect_DropDown VALUE NUMERIC 1
411           END ITEMLIST
412         END PART
413       END POLICY
414
415     END CATEGORY
416   END CATEGORY
417
418   CATEGORY !!google
419     CATEGORY !!googlechrome_recommended
420       KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
421
422       POLICY !!EnumPolicy_Policy
423         #if version >= 4
424           SUPPORTED !!SUPPORTED_WINXPSP2
425         #endif
426         EXPLAIN !!EnumPolicy_Explain
427
428         PART !!EnumPolicy_Part  DROPDOWNLIST
429           VALUENAME "EnumPolicy"
430           ITEMLIST
431             NAME !!ProxyServerDisabled_DropDown VALUE NUMERIC 0
432             NAME !!ProxyServerAutoDetect_DropDown VALUE NUMERIC 1
433           END ITEMLIST
434         END PART
435       END POLICY
436
437     END CATEGORY
438   END CATEGORY
439
440
441 ''', '''[Strings]
442 SUPPORTED_WINXPSP2="At least Windows 3.14"
443 google="Google"
444 googlechrome="Google Chrome"
445 googlechrome_recommended="Google Chrome - Recommended"
446 EnumPolicy_Policy="Caption of policy."
447 EnumPolicy_Explain="Description of policy."
448 EnumPolicy_Part="Caption of policy."
449 ProxyServerDisabled_DropDown="Option1"
450 ProxyServerAutoDetect_DropDown="Option2"
451 ''')
452     self.CompareOutputs(output, expected_output)
453
454   def testStringEnumPolicy(self):
455     # Tests a policy group with a single policy of type 'int-enum'.
456     grd = self.PrepareTest('''
457       {
458         'policy_definitions': [
459           {
460             'name': 'EnumPolicy',
461             'type': 'string-enum',
462             'caption': 'Caption of policy.',
463             'desc': 'Description of policy.',
464             'items': [
465               {'name': 'ProxyServerDisabled', 'value': 'one',
466                'caption': 'Option1'},
467               {'name': 'ProxyServerAutoDetect', 'value': 'two',
468                'caption': 'Option2'},
469             ],
470             'supported_on': ['chrome.win:8-'],
471             'features': { 'can_be_recommended': True },
472           },
473         ],
474         'placeholders': [],
475         'messages': {
476           'win_supported_winxpsp2': {
477             'text': 'At least Windows 3.14', 'desc': 'blah'
478           },
479           'doc_recommended': {
480             'text': 'Recommended', 'desc': 'bleh'
481           }
482         }
483       }''')
484     output = self.GetOutput(grd, 'fr', {'_google_chrome': '1'}, 'adm', 'en')
485     expected_output = self.ConstructOutput(
486         ['MACHINE', 'USER'], '''
487   CATEGORY !!google
488     CATEGORY !!googlechrome
489       KEYNAME "Software\\Policies\\Google\\Chrome"
490
491       POLICY !!EnumPolicy_Policy
492         #if version >= 4
493           SUPPORTED !!SUPPORTED_WINXPSP2
494         #endif
495         EXPLAIN !!EnumPolicy_Explain
496
497         PART !!EnumPolicy_Part  DROPDOWNLIST
498           VALUENAME "EnumPolicy"
499           ITEMLIST
500             NAME !!ProxyServerDisabled_DropDown VALUE "one"
501             NAME !!ProxyServerAutoDetect_DropDown VALUE "two"
502           END ITEMLIST
503         END PART
504       END POLICY
505
506     END CATEGORY
507   END CATEGORY
508
509   CATEGORY !!google
510     CATEGORY !!googlechrome_recommended
511       KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
512
513       POLICY !!EnumPolicy_Policy
514         #if version >= 4
515           SUPPORTED !!SUPPORTED_WINXPSP2
516         #endif
517         EXPLAIN !!EnumPolicy_Explain
518
519         PART !!EnumPolicy_Part  DROPDOWNLIST
520           VALUENAME "EnumPolicy"
521           ITEMLIST
522             NAME !!ProxyServerDisabled_DropDown VALUE "one"
523             NAME !!ProxyServerAutoDetect_DropDown VALUE "two"
524           END ITEMLIST
525         END PART
526       END POLICY
527
528     END CATEGORY
529   END CATEGORY
530
531
532 ''', '''[Strings]
533 SUPPORTED_WINXPSP2="At least Windows 3.14"
534 google="Google"
535 googlechrome="Google Chrome"
536 googlechrome_recommended="Google Chrome - Recommended"
537 EnumPolicy_Policy="Caption of policy."
538 EnumPolicy_Explain="Description of policy."
539 EnumPolicy_Part="Caption of policy."
540 ProxyServerDisabled_DropDown="Option1"
541 ProxyServerAutoDetect_DropDown="Option2"
542 ''')
543     self.CompareOutputs(output, expected_output)
544
545   def testListPolicy(self):
546     # Tests a policy group with a single policy of type 'list'.
547     grd = self.PrepareTest('''
548       {
549         'policy_definitions': [
550           {
551             'name': 'ListPolicy',
552             'type': 'list',
553             'supported_on': ['chrome.win:8-'],
554             'features': { 'can_be_recommended': True },
555             'desc': """Description of list policy.
556 With a newline.""",
557             'caption': 'Caption of list policy.',
558             'label': 'Label of list policy.'
559           },
560         ],
561         'placeholders': [],
562         'messages': {
563           'win_supported_winxpsp2': {
564             'text': 'At least Windows 3.15', 'desc': 'blah'
565           },
566           'doc_recommended': {
567             'text': 'Recommended', 'desc': 'bleh'
568           }
569         },
570       }''')
571     output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
572     expected_output = self.ConstructOutput(
573         ['MACHINE', 'USER'], '''
574   CATEGORY !!chromium
575     KEYNAME "Software\\Policies\\Chromium"
576
577     POLICY !!ListPolicy_Policy
578       #if version >= 4
579         SUPPORTED !!SUPPORTED_WINXPSP2
580       #endif
581       EXPLAIN !!ListPolicy_Explain
582
583       PART !!ListPolicy_Part  LISTBOX
584         KEYNAME "Software\\Policies\\Chromium\\ListPolicy"
585         VALUEPREFIX ""
586       END PART
587     END POLICY
588
589   END CATEGORY
590
591   CATEGORY !!chromium_recommended
592     KEYNAME "Software\\Policies\\Chromium\\Recommended"
593
594     POLICY !!ListPolicy_Policy
595       #if version >= 4
596         SUPPORTED !!SUPPORTED_WINXPSP2
597       #endif
598       EXPLAIN !!ListPolicy_Explain
599
600       PART !!ListPolicy_Part  LISTBOX
601         KEYNAME "Software\\Policies\\Chromium\\Recommended\\ListPolicy"
602         VALUEPREFIX ""
603       END PART
604     END POLICY
605
606   END CATEGORY
607
608
609 ''', '''[Strings]
610 SUPPORTED_WINXPSP2="At least Windows 3.15"
611 chromium="Chromium"
612 chromium_recommended="Chromium - Recommended"
613 ListPolicy_Policy="Caption of list policy."
614 ListPolicy_Explain="Description of list policy.\\nWith a newline."
615 ListPolicy_Part="Label of list policy."
616 ''')
617     self.CompareOutputs(output, expected_output)
618
619   def testStringEnumListPolicy(self):
620     # Tests a policy group with a single policy of type 'string-enum-list'.
621     grd = self.PrepareTest('''
622       {
623         'policy_definitions': [
624           {
625             'name': 'ListPolicy',
626             'type': 'string-enum-list',
627             'supported_on': ['chrome.win:8-'],
628             'features': { 'can_be_recommended': True },
629             'desc': """Description of list policy.
630 With a newline.""",
631             'items': [
632               {'name': 'ProxyServerDisabled', 'value': 'one',
633                'caption': 'Option1'},
634               {'name': 'ProxyServerAutoDetect', 'value': 'two',
635                'caption': 'Option2'},
636             ],
637             'caption': 'Caption of list policy.',
638             'label': 'Label of list policy.'
639           },
640         ],
641         'placeholders': [],
642         'messages': {
643           'win_supported_winxpsp2': {
644             'text': 'At least Windows 3.15', 'desc': 'blah'
645           },
646           'doc_recommended': {
647             'text': 'Recommended', 'desc': 'bleh'
648           }
649         },
650       }''')
651     output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
652     expected_output = self.ConstructOutput(
653         ['MACHINE', 'USER'], '''
654   CATEGORY !!chromium
655     KEYNAME "Software\\Policies\\Chromium"
656
657     POLICY !!ListPolicy_Policy
658       #if version >= 4
659         SUPPORTED !!SUPPORTED_WINXPSP2
660       #endif
661       EXPLAIN !!ListPolicy_Explain
662
663       PART !!ListPolicy_Part  LISTBOX
664         KEYNAME "Software\\Policies\\Chromium\\ListPolicy"
665         VALUEPREFIX ""
666       END PART
667     END POLICY
668
669   END CATEGORY
670
671   CATEGORY !!chromium_recommended
672     KEYNAME "Software\\Policies\\Chromium\\Recommended"
673
674     POLICY !!ListPolicy_Policy
675       #if version >= 4
676         SUPPORTED !!SUPPORTED_WINXPSP2
677       #endif
678       EXPLAIN !!ListPolicy_Explain
679
680       PART !!ListPolicy_Part  LISTBOX
681         KEYNAME "Software\\Policies\\Chromium\\Recommended\\ListPolicy"
682         VALUEPREFIX ""
683       END PART
684     END POLICY
685
686   END CATEGORY
687
688
689 ''', '''[Strings]
690 SUPPORTED_WINXPSP2="At least Windows 3.15"
691 chromium="Chromium"
692 chromium_recommended="Chromium - Recommended"
693 ListPolicy_Policy="Caption of list policy."
694 ListPolicy_Explain="Description of list policy.\\nWith a newline."
695 ListPolicy_Part="Label of list policy."
696 ''')
697     self.CompareOutputs(output, expected_output)
698
699   def testDictionaryPolicy(self):
700     # Tests a policy group with a single policy of type 'dict'.
701     grd = self.PrepareTest('''
702       {
703         'policy_definitions': [
704           {
705             'name': 'DictionaryPolicy',
706             'type': 'dict',
707             'supported_on': ['chrome.win:8-'],
708             'features': { 'can_be_recommended': True },
709             'desc': 'Description of group.',
710             'caption': 'Caption of policy.',
711           },
712         ],
713         'placeholders': [],
714         'messages': {
715           'win_supported_winxpsp2': {
716             'text': 'At least Windows 3.13', 'desc': 'blah'
717           },
718           'doc_recommended': {
719             'text': 'Recommended', 'desc': 'bleh'
720           }
721         }
722       }''')
723     output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
724     expected_output = self.ConstructOutput(
725         ['MACHINE', 'USER'], '''
726   CATEGORY !!chromium
727     KEYNAME "Software\\Policies\\Chromium"
728
729     POLICY !!DictionaryPolicy_Policy
730       #if version >= 4
731         SUPPORTED !!SUPPORTED_WINXPSP2
732       #endif
733       EXPLAIN !!DictionaryPolicy_Explain
734
735       PART !!DictionaryPolicy_Part  EDITTEXT
736         VALUENAME "DictionaryPolicy"
737       END PART
738     END POLICY
739
740   END CATEGORY
741
742   CATEGORY !!chromium_recommended
743     KEYNAME "Software\\Policies\\Chromium\\Recommended"
744
745     POLICY !!DictionaryPolicy_Policy
746       #if version >= 4
747         SUPPORTED !!SUPPORTED_WINXPSP2
748       #endif
749       EXPLAIN !!DictionaryPolicy_Explain
750
751       PART !!DictionaryPolicy_Part  EDITTEXT
752         VALUENAME "DictionaryPolicy"
753       END PART
754     END POLICY
755
756   END CATEGORY
757
758
759 ''', '''[Strings]
760 SUPPORTED_WINXPSP2="At least Windows 3.13"
761 chromium="Chromium"
762 chromium_recommended="Chromium - Recommended"
763 DictionaryPolicy_Policy="Caption of policy."
764 DictionaryPolicy_Explain="Description of group."
765 DictionaryPolicy_Part="Caption of policy."
766 ''')
767     self.CompareOutputs(output, expected_output)
768
769   def testNonSupportedPolicy(self):
770     # Tests a policy that is not supported on Windows, so it shouldn't
771     # be included in the ADM file.
772     grd = self.PrepareTest('''
773       {
774         'policy_definitions': [
775           {
776             'name': 'NonWinGroup',
777             'type': 'group',
778             'policies': [{
779               'name': 'NonWinPolicy',
780               'type': 'list',
781               'supported_on': ['chrome.linux:8-', 'chrome.mac:8-'],
782               'caption': 'Caption of list policy.',
783               'desc': 'Desc of list policy.',
784             }],
785             'caption': 'Group caption.',
786             'desc': 'Group description.',
787           },
788         ],
789         'placeholders': [],
790         'messages': {
791           'win_supported_winxpsp2': {
792             'text': 'At least Windows 3.16', 'desc': 'blah'
793           },
794           'doc_recommended': {
795             'text': 'Recommended', 'desc': 'bleh'
796           }
797         }
798       }''')
799     output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
800     expected_output = self.ConstructOutput(
801         ['MACHINE', 'USER'], '''
802   CATEGORY !!chromium
803     KEYNAME "Software\\Policies\\Chromium"
804
805   END CATEGORY
806
807   CATEGORY !!chromium_recommended
808     KEYNAME "Software\\Policies\\Chromium\\Recommended"
809
810   END CATEGORY
811
812
813 ''', '''[Strings]
814 SUPPORTED_WINXPSP2="At least Windows 3.16"
815 chromium="Chromium"
816 chromium_recommended="Chromium - Recommended"
817 ''')
818     self.CompareOutputs(output, expected_output)
819
820   def testNonRecommendedPolicy(self):
821     # Tests a policy that is not recommended, so it should be included.
822     grd = self.PrepareTest('''
823       {
824         'policy_definitions': [
825           {
826             'name': 'MainPolicy',
827             'type': 'main',
828             'supported_on': ['chrome.win:8-'],
829             'caption': 'Caption of main.',
830             'desc': 'Description of main.',
831           },
832         ],
833         'placeholders': [],
834         'messages': {
835           'win_supported_winxpsp2': {
836             'text': 'At least Windows 3.12', 'desc': 'blah'
837           },
838           'doc_recommended': {
839             'text': 'Recommended', 'desc': 'bleh'
840           }
841         }
842       }''')
843     output = self.GetOutput(grd, 'fr', {'_google_chrome' : '1'}, 'adm', 'en')
844     expected_output = self.ConstructOutput(
845         ['MACHINE', 'USER'], '''
846   CATEGORY !!google
847     CATEGORY !!googlechrome
848       KEYNAME "Software\\Policies\\Google\\Chrome"
849
850       POLICY !!MainPolicy_Policy
851         #if version >= 4
852           SUPPORTED !!SUPPORTED_WINXPSP2
853         #endif
854         EXPLAIN !!MainPolicy_Explain
855         VALUENAME "MainPolicy"
856         VALUEON NUMERIC 1
857         VALUEOFF NUMERIC 0
858       END POLICY
859
860     END CATEGORY
861   END CATEGORY
862
863   CATEGORY !!google
864     CATEGORY !!googlechrome_recommended
865       KEYNAME "Software\\Policies\\Google\\Chrome\\Recommended"
866
867     END CATEGORY
868   END CATEGORY
869
870
871 ''', '''[Strings]
872 SUPPORTED_WINXPSP2="At least Windows 3.12"
873 google="Google"
874 googlechrome="Google Chrome"
875 googlechrome_recommended="Google Chrome - Recommended"
876 MainPolicy_Policy="Caption of main."
877 MainPolicy_Explain="Description of main."''')
878     self.CompareOutputs(output, expected_output)
879
880   def testPolicyGroup(self):
881     # Tests a policy group that has more than one policies.
882     grd = self.PrepareTest('''
883       {
884         'policy_definitions': [
885           {
886             'name': 'Group1',
887             'type': 'group',
888             'desc': 'Description of group.',
889             'caption': 'Caption of group.',
890             'policies': [{
891               'name': 'Policy1',
892               'type': 'list',
893               'supported_on': ['chrome.win:8-'],
894               'features': { 'can_be_recommended': True },
895               'caption': 'Caption of policy1.',
896               'desc': """Description of policy1.
897 With a newline."""
898             },{
899               'name': 'Policy2',
900               'type': 'string',
901               'supported_on': ['chrome.win:8-'],
902               'caption': 'Caption of policy2.',
903               'desc': """Description of policy2.
904 With a newline."""
905             }],
906           },
907         ],
908         'placeholders': [],
909         'messages': {
910           'win_supported_winxpsp2': {
911             'text': 'At least Windows 3.16', 'desc': 'blah'
912           },
913           'doc_recommended': {
914             'text': 'Recommended', 'desc': 'bleh'
915           }
916         }
917       }''')
918     output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en')
919     expected_output = self.ConstructOutput(
920         ['MACHINE', 'USER'], '''
921   CATEGORY !!chromium
922     KEYNAME "Software\\Policies\\Chromium"
923
924     CATEGORY !!Group1_Category
925       POLICY !!Policy1_Policy
926         #if version >= 4
927           SUPPORTED !!SUPPORTED_WINXPSP2
928         #endif
929         EXPLAIN !!Policy1_Explain
930
931         PART !!Policy1_Part  LISTBOX
932           KEYNAME "Software\\Policies\\Chromium\\Policy1"
933           VALUEPREFIX ""
934         END PART
935       END POLICY
936
937       POLICY !!Policy2_Policy
938         #if version >= 4
939           SUPPORTED !!SUPPORTED_WINXPSP2
940         #endif
941         EXPLAIN !!Policy2_Explain
942
943         PART !!Policy2_Part  EDITTEXT
944           VALUENAME "Policy2"
945         END PART
946       END POLICY
947
948     END CATEGORY
949
950   END CATEGORY
951
952   CATEGORY !!chromium_recommended
953     KEYNAME "Software\\Policies\\Chromium\\Recommended"
954
955     CATEGORY !!Group1_Category
956       POLICY !!Policy1_Policy
957         #if version >= 4
958           SUPPORTED !!SUPPORTED_WINXPSP2
959         #endif
960         EXPLAIN !!Policy1_Explain
961
962         PART !!Policy1_Part  LISTBOX
963           KEYNAME "Software\\Policies\\Chromium\\Recommended\\Policy1"
964           VALUEPREFIX ""
965         END PART
966       END POLICY
967
968     END CATEGORY
969
970   END CATEGORY
971
972
973 ''', '''[Strings]
974 SUPPORTED_WINXPSP2="At least Windows 3.16"
975 chromium="Chromium"
976 chromium_recommended="Chromium - Recommended"
977 Group1_Category="Caption of group."
978 Policy1_Policy="Caption of policy1."
979 Policy1_Explain="Description of policy1.\\nWith a newline."
980 Policy1_Part="Caption of policy1."
981 Policy2_Policy="Caption of policy2."
982 Policy2_Explain="Description of policy2.\\nWith a newline."
983 Policy2_Part="Caption of policy2."
984 ''')
985     self.CompareOutputs(output, expected_output)
986
987 if __name__ == '__main__':
988   unittest.main()