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.
6 '''Unit tests for grit.format.policy_templates.writers.plist_strings_writer'''
11 if __name__ == '__main__':
12 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..'))
16 from grit.format.policy_templates.writers import writer_unittest_common
19 class PListStringsWriterUnittest(writer_unittest_common.WriterUnittestCommon):
20 '''Unit tests for PListStringsWriter.'''
23 # Test PListStringsWriter in case of empty polices.
24 grd = self.PrepareTest('''
26 'policy_definitions': [],
29 'mac_chrome_preferences': {
30 'text': '$1 preferen"ces',
35 output = self.GetOutput(
38 {'_chromium': '1', 'mac_bundle_id': 'com.example.Test'},
42 'Chromium.pfm_title = "Chromium";\n'
43 'Chromium.pfm_description = "Chromium preferen\\"ces";')
44 self.assertEquals(output.strip(), expected_output.strip())
46 def testMainPolicy(self):
47 # Tests a policy group with a single policy of type 'main'.
48 grd = self.PrepareTest('''
50 'policy_definitions': [
54 'caption': 'Caption of main.',
55 'desc': 'Description of main.',
59 'supported_on': ['chrome.mac:8-'],
60 'caption': 'Caption of main policy.',
61 'desc': 'Description of main policy.',
67 'mac_chrome_preferences': {
68 'text': 'Preferences of $1',
73 output = self.GetOutput(
76 {'_google_chrome' : '1', 'mac_bundle_id': 'com.example.Test'},
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())
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('''
91 'policy_definitions': [
93 'name': 'StringGroup',
95 'caption': 'Caption of group.',
96 'desc': """Description of group.
99 'name': 'StringPolicy',
101 'caption': 'Caption of policy.',
102 'desc': """Description of policy.
104 'supported_on': ['chrome.mac:8-'],
110 'mac_chrome_preferences': {
111 'text': 'Preferences of $1',
116 output = self.GetOutput(
119 {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'},
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())
130 def testStringListPolicy(self):
131 # Tests a policy group with a single policy of type 'list'.
132 grd = self.PrepareTest('''
134 'policy_definitions': [
141 'name': 'ListPolicy',
143 'caption': 'Caption of policy.',
144 'desc': """Description of policy.
148 'items': { 'type': 'string' },
150 'supported_on': ['chrome.mac:8-'],
156 'mac_chrome_preferences': {
157 'text': 'Preferences of $1',
162 output = self.GetOutput(
165 {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'},
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())
176 def testStringEnumListPolicy(self):
177 # Tests a policy group with a single policy of type 'string-enum-list'.
178 grd = self.PrepareTest('''
180 'policy_definitions': [
187 'name': 'EnumPolicy',
188 'type': 'string-enum-list',
189 'caption': 'Caption of policy.',
190 'desc': """Description of policy.
194 'items': { 'type': 'string' },
198 'name': 'ProxyServerDisabled',
203 'name': 'ProxyServerAutoDetect',
208 'supported_on': ['chrome.mac:8-'],
214 'mac_chrome_preferences': {
215 'text': 'Preferences of $1',
220 output = self.GetOutput(
223 {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'},
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())
235 def testIntEnumPolicy(self):
236 # Tests a policy group with a single policy of type 'int-enum'.
237 grd = self.PrepareTest('''
239 'policy_definitions': [
246 'name': 'EnumPolicy',
248 'desc': 'Description of policy.',
249 'caption': 'Caption of policy.',
252 'name': 'ProxyServerDisabled',
257 'name': 'ProxyServerAutoDetect',
262 'supported_on': ['chrome.mac:8-'],
268 'mac_chrome_preferences': {
269 'text': '$1 preferences',
274 output = self.GetOutput(
277 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'},
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')
287 self.assertEquals(output.strip(), expected_output.strip())
289 def testStringEnumPolicy(self):
290 # Tests a policy group with a single policy of type 'string-enum'.
291 grd = self.PrepareTest('''
293 'policy_definitions': [
300 'name': 'EnumPolicy',
301 'type': 'string-enum',
302 'desc': 'Description of policy.',
303 'caption': 'Caption of policy.',
306 'name': 'ProxyServerDisabled',
311 'name': 'ProxyServerAutoDetect',
316 'supported_on': ['chrome.mac:8-'],
322 'mac_chrome_preferences': {
323 'text': '$1 preferences',
328 output = self.GetOutput(
331 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'},
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')
341 self.assertEquals(output.strip(), expected_output.strip())
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('''
348 'policy_definitions': [
350 'name': 'NonMacGroup',
355 'name': 'NonMacPolicy',
359 'supported_on': ['chrome_os:8-'],
365 'mac_chrome_preferences': {
366 'text': '$1 preferences',
371 output = self.GetOutput(
374 {'_google_chrome': '1', 'mac_bundle_id': 'com.example.Test2'},
378 'Google_Chrome.pfm_title = "Google Chrome";\n'
379 'Google_Chrome.pfm_description = "Google Chrome preferences";')
380 self.assertEquals(output.strip(), expected_output.strip())
383 if __name__ == '__main__':