Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / grit / grit / format / policy_templates / writers / plist_strings_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.plist_strings_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 PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon):
20   '''Unit tests for PListStringsWriter.'''
21
22   def testEmpty(self):
23     # Test PListStringsWriter in case of empty polices.
24     grd = self.PrepareTest('''
25       {
26         'policy_definitions': [],
27         'placeholders': [],
28         'messages': {
29           'mac_chrome_preferences': {
30             'text': '$1 preferen"ces',
31             'desc': 'blah'
32           }
33         }
34       }''')
35     output = self.GetOutput(
36         grd,
37         'fr',
38         {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'},
39         'plist_strings',
40         'en')
41     expected_output = (
42         'Chromium.pfm_title = "Chromium";\n'
43         'Chromium.pfm_description = "Chromium preferen\\"ces";')
44     self.assertEquals(output.strip(), expected_output.strip())
45
46   def testMainPolicy(self):
47     # Tests a policy group with a single policy of type 'main'.
48     grd = self.PrepareTest('''
49       {
50         'policy_definitions': [
51           {
52             'name': 'MainGroup',
53             'type': 'group',
54             'caption': 'Caption of main.',
55             'desc': 'Description of main.',
56             'policies': [{
57               'name': 'MainPolicy',
58               'type': 'main',
59               'supported_on': ['chrome.mac:8-'],
60               'caption': 'Caption of main policy.',
61               'desc': 'Description of main policy.',
62             }],
63           },
64         ],
65         'placeholders': [],
66         'messages': {
67           'mac_chrome_preferences': {
68             'text': 'Preferences of $1',
69             'desc': 'blah'
70           }
71         }
72       }''')
73     output = self.GetOutput(
74         grd,
75         'fr',
76         {'_google_chrome' : '1', 'mac_bundle_id': 'com.example.Test'},
77         'plist_strings',
78         'en')
79     expected_output = (
80         'Google_Chrome.pfm_title = "Google Chrome";\n'
81         'Google_Chrome.pfm_description = "Preferences of Google Chrome";\n'
82         'MainPolicy.pfm_title = "Caption of main policy.";\n'
83         'MainPolicy.pfm_description = "Description of main policy.";')
84     self.assertEquals(output.strip(), expected_output.strip())
85
86   def testStringPolicy(self):
87     # Tests a policy group with a single policy of type 'string'. Also test
88     # inheriting group description to policy description.
89     grd = self.PrepareTest('''
90       {
91         'policy_definitions': [
92           {
93             'name': 'StringGroup',
94             'type': 'group',
95             'caption': 'Caption of group.',
96             'desc': """Description of group.
97 With a newline.""",
98             'policies': [{
99               'name': 'StringPolicy',
100               'type': 'string',
101               'caption': 'Caption of policy.',
102               'desc': """Description of policy.
103 With a newline.""",
104               'supported_on': ['chrome.mac:8-'],
105             }],
106           },
107         ],
108         'placeholders': [],
109         'messages': {
110           'mac_chrome_preferences': {
111             'text': 'Preferences of $1',
112             'desc': 'blah'
113           }
114         }
115       }''')
116     output = self.GetOutput(
117         grd,
118         'fr',
119         {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'},
120         'plist_strings',
121         'en')
122     expected_output = (
123         'Chromium.pfm_title = "Chromium";\n'
124         'Chromium.pfm_description = "Preferences of Chromium";\n'
125         'StringPolicy.pfm_title = "Caption of policy.";\n'
126         'StringPolicy.pfm_description = '
127             '"Description of policy.\\nWith a newline.";')
128     self.assertEquals(output.strip(), expected_output.strip())
129
130   def testStringListPolicy(self):
131     # Tests a policy group with a single policy of type 'list'.
132     grd = self.PrepareTest('''
133       {
134         'policy_definitions': [
135           {
136             'name': 'ListGroup',
137             'type': 'group',
138             'caption': '',
139             'desc': '',
140             'policies': [{
141               'name': 'ListPolicy',
142               'type': 'list',
143               'caption': 'Caption of policy.',
144               'desc': """Description of policy.
145 With a newline.""",
146               'schema': {
147                   'type': 'array',
148                   'items': { 'type': 'string' },
149               },
150               'supported_on': ['chrome.mac:8-'],
151             }],
152           },
153         ],
154         'placeholders': [],
155         'messages': {
156           'mac_chrome_preferences': {
157             'text': 'Preferences of $1',
158             'desc': 'blah'
159           }
160         }
161       }''')
162     output = self.GetOutput(
163         grd,
164         'fr',
165         {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'},
166         'plist_strings',
167         'en')
168     expected_output = (
169         'Chromium.pfm_title = "Chromium";\n'
170         'Chromium.pfm_description = "Preferences of Chromium";\n'
171         'ListPolicy.pfm_title = "Caption of policy.";\n'
172         'ListPolicy.pfm_description = '
173             '"Description of policy.\\nWith a newline.";')
174     self.assertEquals(output.strip(), expected_output.strip())
175
176   def testStringEnumListPolicy(self):
177     # Tests a policy group with a single policy of type 'string-enum-list'.
178     grd = self.PrepareTest('''
179       {
180         'policy_definitions': [
181           {
182             'name': 'EnumGroup',
183             'type': 'group',
184             'caption': '',
185             'desc': '',
186             'policies': [{
187               'name': 'EnumPolicy',
188               'type': 'string-enum-list',
189               'caption': 'Caption of policy.',
190               'desc': """Description of policy.
191 With a newline.""",
192               'schema': {
193                   'type': 'array',
194                   'items': { 'type': 'string' },
195               },
196               'items': [
197                 {
198                   'name': 'ProxyServerDisabled',
199                   'value': 'one',
200                   'caption': 'Option1'
201                 },
202                 {
203                   'name': 'ProxyServerAutoDetect',
204                   'value': 'two',
205                   'caption': 'Option2'
206                 },
207               ],
208               'supported_on': ['chrome.mac:8-'],
209             }],
210           },
211         ],
212         'placeholders': [],
213         'messages': {
214           'mac_chrome_preferences': {
215             'text': 'Preferences of $1',
216             'desc': 'blah'
217           }
218         }
219       }''')
220     output = self.GetOutput(
221         grd,
222         'fr',
223         {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'},
224         'plist_strings',
225         'en')
226     expected_output = (
227         'Chromium.pfm_title = "Chromium";\n'
228         'Chromium.pfm_description = "Preferences of Chromium";\n'
229         'EnumPolicy.pfm_title = "Caption of policy.";\n'
230         'EnumPolicy.pfm_description = '
231             '"one - Option1\\ntwo - Option2\\n'
232             'Description of policy.\\nWith a newline.";')
233     self.assertEquals(output.strip(), expected_output.strip())
234
235   def testIntEnumPolicy(self):
236     # Tests a policy group with a single policy of type 'int-enum'.
237     grd = self.PrepareTest('''
238       {
239         'policy_definitions': [
240           {
241             'name': 'EnumGroup',
242             'type': 'group',
243             'desc': '',
244             'caption': '',
245             'policies': [{
246               'name': 'EnumPolicy',
247               'type': 'int-enum',
248               'desc': 'Description of policy.',
249               'caption': 'Caption of policy.',
250               'items': [
251                 {
252                   'name': 'ProxyServerDisabled',
253                   'value': 0,
254                   'caption': 'Option1'
255                 },
256                 {
257                   'name': 'ProxyServerAutoDetect',
258                   'value': 1,
259                   'caption': 'Option2'
260                 },
261               ],
262               'supported_on': ['chrome.mac:8-'],
263             }],
264           },
265         ],
266         'placeholders': [],
267         'messages': {
268           'mac_chrome_preferences': {
269             'text': '$1 preferences',
270             'desc': 'blah'
271           }
272         }
273       }''')
274     output = self.GetOutput(
275         grd,
276         'fr',
277         {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'},
278         'plist_strings',
279         'en')
280     expected_output = (
281         'Google_Chrome.pfm_title = "Google Chrome";\n'
282         'Google_Chrome.pfm_description = "Google Chrome preferences";\n'
283         'EnumPolicy.pfm_title = "Caption of policy.";\n'
284         'EnumPolicy.pfm_description = '
285             '"0 - Option1\\n1 - Option2\\nDescription of policy.";\n')
286
287     self.assertEquals(output.strip(), expected_output.strip())
288
289   def testStringEnumPolicy(self):
290     # Tests a policy group with a single policy of type 'string-enum'.
291     grd = self.PrepareTest('''
292       {
293         'policy_definitions': [
294           {
295             'name': 'EnumGroup',
296             'type': 'group',
297             'desc': '',
298             'caption': '',
299             'policies': [{
300               'name': 'EnumPolicy',
301               'type': 'string-enum',
302               'desc': 'Description of policy.',
303               'caption': 'Caption of policy.',
304               'items': [
305                 {
306                   'name': 'ProxyServerDisabled',
307                   'value': 'one',
308                   'caption': 'Option1'
309                 },
310                 {
311                   'name': 'ProxyServerAutoDetect',
312                   'value': 'two',
313                   'caption': 'Option2'
314                 },
315               ],
316               'supported_on': ['chrome.mac:8-'],
317             }],
318           },
319         ],
320         'placeholders': [],
321         'messages': {
322           'mac_chrome_preferences': {
323             'text': '$1 preferences',
324             'desc': 'blah'
325           }
326         }
327       }''')
328     output = self.GetOutput(
329         grd,
330         'fr',
331         {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'},
332         'plist_strings',
333         'en')
334     expected_output = (
335         'Google_Chrome.pfm_title = "Google Chrome";\n'
336         'Google_Chrome.pfm_description = "Google Chrome preferences";\n'
337         'EnumPolicy.pfm_title = "Caption of policy.";\n'
338         'EnumPolicy.pfm_description = '
339             '"one - Option1\\ntwo - Option2\\nDescription of policy.";\n')
340
341     self.assertEquals(output.strip(), expected_output.strip())
342
343   def testNonSupportedPolicy(self):
344     # Tests a policy that is not supported on Mac, so its strings shouldn't
345     # be included in the plist string table.
346     grd = self.PrepareTest('''
347       {
348         'policy_definitions': [
349           {
350             'name': 'NonMacGroup',
351             'type': 'group',
352             'caption': '',
353             'desc': '',
354             'policies': [{
355               'name': 'NonMacPolicy',
356               'type': 'string',
357               'caption': '',
358               'desc': '',
359               'supported_on': ['chrome_os:8-'],
360             }],
361           },
362         ],
363         'placeholders': [],
364         'messages': {
365           'mac_chrome_preferences': {
366             'text': '$1 preferences',
367             'desc': 'blah'
368           }
369         }
370       }''')
371     output = self.GetOutput(
372         grd,
373         'fr',
374         {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'},
375         'plist_strings',
376         'en')
377     expected_output = (
378         'Google_Chrome.pfm_title = "Google Chrome";\n'
379         'Google_Chrome.pfm_description = "Google Chrome preferences";')
380     self.assertEquals(output.strip(), expected_output.strip())
381
382
383 if __name__ == '__main__':
384   unittest.main()