diff options
author | Android Chromium Automerger <chromium-automerger@android> | 2014-06-26 23:23:13 +0000 |
---|---|---|
committer | Android Chromium Automerger <chromium-automerger@android> | 2014-06-26 23:23:13 +0000 |
commit | 8d835902938db62442bf9e699decb799650010e5 (patch) | |
tree | 3178a05fc7275893e20049e919215c8c8c2b8110 | |
parent | c949180284c29ee118778013f5cacb19a0e2575f (diff) | |
parent | 786be15cb6c0f7d78f3eab9fda9d4266619ddbf0 (diff) | |
download | grit-8d835902938db62442bf9e699decb799650010e5.tar.gz |
Merge tools/grit from https://chromium.googlesource.com/external/grit-i18n.git at 786be15cb6c0f7d78f3eab9fda9d4266619ddbf0
This commit was generated by merge_from_chromium.py.
Change-Id: I933017920aa438bf934eb712125b45455981d8c0
18 files changed, 521 insertions, 11 deletions
diff --git a/grit/format/policy_templates/policy_template_generator.py b/grit/format/policy_templates/policy_template_generator.py index 11d097e..a1eb123 100644 --- a/grit/format/policy_templates/policy_template_generator.py +++ b/grit/format/policy_templates/policy_template_generator.py @@ -118,7 +118,7 @@ class PolicyTemplateGenerator: if policy['type'] == 'group': self._ProcessPolicyList(policy['policies']) - elif policy['type'] in ('string-enum', 'int-enum'): + elif policy['type'] in ('string-enum', 'int-enum', 'string-enum-list'): # Iterate through all the items of an enum-type policy, and add captions. for item in policy['items']: item['caption'] = self._ImportMessage(item['caption']) diff --git a/grit/format/policy_templates/policy_template_generator_unittest.py b/grit/format/policy_templates/policy_template_generator_unittest.py index f06cc2d..adc4a22 100644 --- a/grit/format/policy_templates/policy_template_generator_unittest.py +++ b/grit/format/policy_templates/policy_template_generator_unittest.py @@ -262,6 +262,29 @@ class PolicyTemplateGeneratorUnittest(unittest.TestCase): self.tester.assertEquals(policy['items'][2]['caption'], 'string3') self.do_test(policy_data_mock, LocalMockWriter()) + def testStringEnumTexts(self): + # Test that GUI messages are assigned correctly to string-enums + # (aka dropdown menus). + policy_data_mock = { + 'policy_definitions': [{ + 'name': 'Policy1', + 'type': 'string-enum-list', + 'caption': '', 'desc': '', + 'supported_on': [], + 'items': [ + {'name': 'item1', 'value': 'one', 'caption': 'string1', 'desc': ''}, + {'name': 'item2', 'value': 'two', 'caption': 'string2', 'desc': ''}, + {'name': 'item3', 'value': 'three', 'caption': 'string3', 'desc': ''}, + ] + }] + } + class LocalMockWriter(mock_writer.MockWriter): + def WritePolicy(self, policy): + self.tester.assertEquals(policy['items'][0]['caption'], 'string1') + self.tester.assertEquals(policy['items'][1]['caption'], 'string2') + self.tester.assertEquals(policy['items'][2]['caption'], 'string3') + self.do_test(policy_data_mock, LocalMockWriter()) + def testPolicyFiltering(self): # Test that policies are filtered correctly based on their annotations. policy_data_mock = { diff --git a/grit/format/policy_templates/writers/adm_writer.py b/grit/format/policy_templates/writers/adm_writer.py index 3103c3e..6a2f8b2 100644 --- a/grit/format/policy_templates/writers/adm_writer.py +++ b/grit/format/policy_templates/writers/adm_writer.py @@ -71,6 +71,7 @@ class AdmWriter(template_writer.TemplateWriter): 'string-enum': 'DROPDOWNLIST', 'int-enum': 'DROPDOWNLIST', 'list': 'LISTBOX', + 'string-enum-list': 'LISTBOX', 'dict': 'EDITTEXT' } @@ -106,7 +107,7 @@ class AdmWriter(template_writer.TemplateWriter): builder.AddLine() adm_type = self.TYPE_TO_INPUT[policy['type']] builder.AddLine('PART !!%s %s' % (policy_part_name, adm_type), 1) - if policy['type'] == 'list': + if policy['type'] in ('list', 'string-enum-list'): # Note that the following line causes FullArmor ADMX Migrator to create # corrupt ADMX files. Please use admx_writer to get ADMX files. builder.AddLine('KEYNAME "%s\\%s"' % (key_name, policy['name'])) diff --git a/grit/format/policy_templates/writers/adm_writer_unittest.py b/grit/format/policy_templates/writers/adm_writer_unittest.py index 49c31d8..52e4aee 100644 --- a/grit/format/policy_templates/writers/adm_writer_unittest.py +++ b/grit/format/policy_templates/writers/adm_writer_unittest.py @@ -552,6 +552,86 @@ ListPolicy_Part="Label of list policy." ''') self.CompareOutputs(output, expected_output) + def testStringEnumListPolicy(self): + # Tests a policy group with a single policy of type 'string-enum-list'. + grd = self.PrepareTest(''' + { + 'policy_definitions': [ + { + 'name': 'ListPolicy', + 'type': 'string-enum-list', + 'supported_on': ['chrome.win:8-'], + 'features': { 'can_be_recommended': True }, + 'desc': """Description of list policy. +With a newline.""", + 'items': [ + {'name': 'ProxyServerDisabled', 'value': 'one', + 'caption': 'Option1'}, + {'name': 'ProxyServerAutoDetect', 'value': 'two', + 'caption': 'Option2'}, + ], + 'caption': 'Caption of list policy.', + 'label': 'Label of list policy.' + }, + ], + 'placeholders': [], + 'messages': { + 'win_supported_winxpsp2': { + 'text': 'At least Windows 3.15', 'desc': 'blah' + }, + 'doc_recommended': { + 'text': 'Recommended', 'desc': 'bleh' + } + }, + }''') + output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'adm', 'en') + expected_output = self.ConstructOutput( + ['MACHINE', 'USER'], ''' + CATEGORY !!chromium + KEYNAME "Software\\Policies\\Chromium" + + POLICY !!ListPolicy_Policy + #if version >= 4 + SUPPORTED !!SUPPORTED_WINXPSP2 + #endif + EXPLAIN !!ListPolicy_Explain + + PART !!ListPolicy_Part LISTBOX + KEYNAME "Software\\Policies\\Chromium\\ListPolicy" + VALUEPREFIX "" + END PART + END POLICY + + END CATEGORY + + CATEGORY !!chromium_recommended + KEYNAME "Software\\Policies\\Chromium\\Recommended" + + POLICY !!ListPolicy_Policy + #if version >= 4 + SUPPORTED !!SUPPORTED_WINXPSP2 + #endif + EXPLAIN !!ListPolicy_Explain + + PART !!ListPolicy_Part LISTBOX + KEYNAME "Software\\Policies\\Chromium\\Recommended\\ListPolicy" + VALUEPREFIX "" + END PART + END POLICY + + END CATEGORY + + +''', '''[Strings] +SUPPORTED_WINXPSP2="At least Windows 3.15" +chromium="Chromium" +chromium_recommended="Chromium - Recommended" +ListPolicy_Policy="Caption of list policy." +ListPolicy_Explain="Description of list policy.\\nWith a newline." +ListPolicy_Part="Label of list policy." +''') + self.CompareOutputs(output, expected_output) + def testDictionaryPolicy(self): # Tests a policy group with a single policy of type 'dict'. grd = self.PrepareTest(''' diff --git a/grit/format/policy_templates/writers/adml_writer.py b/grit/format/policy_templates/writers/adml_writer.py index 20b7c0d..c525602 100644 --- a/grit/format/policy_templates/writers/adml_writer.py +++ b/grit/format/policy_templates/writers/adml_writer.py @@ -99,7 +99,7 @@ class ADMLWriter(xml_formatted_writer.XMLFormattedWriter): dropdownlist_elem = self.AddElement(presentation_elem, 'dropdownList', {'refId': policy_name}) dropdownlist_elem.appendChild(self._doc.createTextNode(policy_label)) - elif policy_type == 'list': + elif policy_type in ('list', 'string-enum-list'): self._AddString(self._string_table_elem, policy_name + 'Desc', policy_caption) diff --git a/grit/format/policy_templates/writers/adml_writer_unittest.py b/grit/format/policy_templates/writers/adml_writer_unittest.py index 3600005..8a8f4f7 100644 --- a/grit/format/policy_templates/writers/adml_writer_unittest.py +++ b/grit/format/policy_templates/writers/adml_writer_unittest.py @@ -284,6 +284,44 @@ class AdmlWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest): '</presentation>') self.AssertXMLEquals(output, expected_output) + def testStringEnumListPolicy(self): + list_policy = { + 'name': 'ListPolicyStub', + 'type': 'string-enum-list', + 'caption': 'List policy caption', + 'label': 'List policy label', + 'desc': 'This is a test description.', + 'items': [ + { + 'name': 'item 1', + 'value': 'value 1', + 'caption': 'Caption Item 1', + }, + { + 'name': 'item 2', + 'value': 'value 2', + 'caption': 'Caption Item 2', + }, + ], + } + self. _InitWriterForAddingPolicies(self.writer, list_policy) + self.writer.WritePolicy(list_policy) + # Assert generated string elements. + output = self.GetXMLOfChildren(self.writer._string_table_elem) + expected_output = ( + '<string id="ListPolicyStub">List policy caption</string>\n' + '<string id="ListPolicyStub_Explain">' + 'This is a test description.</string>\n' + '<string id="ListPolicyStubDesc">List policy caption</string>') + self.AssertXMLEquals(output, expected_output) + # Assert generated presentation elements. + output = self.GetXMLOfChildren(self.writer._presentation_table_elem) + expected_output = ( + '<presentation id="ListPolicyStub">\n' + ' <listBox refId="ListPolicyStubDesc">List policy label</listBox>\n' + '</presentation>') + self.AssertXMLEquals(output, expected_output) + def testDictionaryPolicy(self): dict_policy = { 'name': 'DictionaryPolicyStub', diff --git a/grit/format/policy_templates/writers/admx_writer.py b/grit/format/policy_templates/writers/admx_writer.py index 69c797d..bc33c19 100644 --- a/grit/format/policy_templates/writers/admx_writer.py +++ b/grit/format/policy_templates/writers/admx_writer.py @@ -286,7 +286,7 @@ class ADMXWriter(xml_formatted_writer.XMLFormattedWriter): elif policy_type in ('int-enum', 'string-enum'): parent = self._GetElements(policy_elem) self._AddEnumPolicy(parent, policy) - elif policy_type == 'list': + elif policy_type in ('list', 'string-enum-list'): parent = self._GetElements(policy_elem) self._AddListPolicy(parent, key, policy_name) elif policy_type == 'group': diff --git a/grit/format/policy_templates/writers/admx_writer_unittest.py b/grit/format/policy_templates/writers/admx_writer_unittest.py index c99131f..a573f26 100644 --- a/grit/format/policy_templates/writers/admx_writer_unittest.py +++ b/grit/format/policy_templates/writers/admx_writer_unittest.py @@ -369,6 +369,33 @@ class AdmxWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest): self.AssertXMLEquals(output, expected_output) + def testStringEnumListPolicy(self): + list_policy = { + 'name': 'SampleListPolicy', + 'type': 'string-enum-list', + 'items': [ + {'name': 'item_1', 'value': 'one'}, + {'name': 'item_2', 'value': 'two'}, + ] + } + self._initWriterForPolicy(self.writer, list_policy) + self.writer.WritePolicy(list_policy) + output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) + expected_output = ( + '<policy class="TestClass" displayName="$(string.SampleListPolicy)"' + ' explainText="$(string.SampleListPolicy_Explain)"' + ' key="Software\\Policies\\Test" name="SampleListPolicy"' + ' presentation="$(presentation.SampleListPolicy)">\n' + ' <parentCategory ref="PolicyGroup"/>\n' + ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' + ' <elements>\n' + ' <list id="SampleListPolicyDesc"' + ' key="Software\Policies\Test\SampleListPolicy" valuePrefix=""/>\n' + ' </elements>\n' + '</policy>') + + self.AssertXMLEquals(output, expected_output) + def testDictionaryPolicy(self): dict_policy = { 'name': 'SampleDictionaryPolicy', diff --git a/grit/format/policy_templates/writers/doc_writer.py b/grit/format/policy_templates/writers/doc_writer.py index 7cca976..e8543c2 100644 --- a/grit/format/policy_templates/writers/doc_writer.py +++ b/grit/format/policy_templates/writers/doc_writer.py @@ -116,7 +116,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): # Replace URLs with links in the description. self._AddTextWithLinks(parent, policy['desc']) # Add list of enum items. - if policy['type'] in ('string-enum', 'int-enum'): + if policy['type'] in ('string-enum', 'int-enum', 'string-enum-list'): ul = self.AddElement(parent, 'ul') for item in policy['items']: if policy['type'] == 'int-enum': @@ -379,7 +379,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): self.AddText(parent, ', '.join(pieces)) elif policy_type == 'string-enum': self.AddText(parent, '"%s"' % (example_value)) - elif policy_type == 'list': + elif policy_type in ('list', 'string-enum-list'): self._AddListExample(parent, policy) elif policy_type == 'dict': self._AddDictionaryExample(parent, policy) @@ -640,6 +640,7 @@ class DocWriter(xml_formatted_writer.XMLFormattedWriter): 'int-enum': 'Integer', 'string-enum': 'String', 'list': 'List of strings', + 'string-enum-list': 'List of strings', 'dict': 'Dictionary', 'external': 'External data reference', } diff --git a/grit/format/policy_templates/writers/doc_writer_unittest.py b/grit/format/policy_templates/writers/doc_writer_unittest.py index 6c087d5..05ea240 100644 --- a/grit/format/policy_templates/writers/doc_writer_unittest.py +++ b/grit/format/policy_templates/writers/doc_writer_unittest.py @@ -282,7 +282,7 @@ See <a href="http://policy-explanation.example.com">http://policy-explanation.ex '<root>0x00000010 (Windows), 16 (Linux), 16 (Mac)</root>') def testStringEnumExample(self): - # Test representation of 'int-enum' example values. + # Test representation of 'string-enum' example values. policy = { 'name': 'PolicyName', 'type': 'string-enum', @@ -293,6 +293,40 @@ See <a href="http://policy-explanation.example.com">http://policy-explanation.ex self.doc_root.toxml(), '<root>"wacky"</root>') + def testListExample(self): + # Test representation of 'list' example values. + policy = { + 'name': 'PolicyName', + 'type': 'list', + 'example_value': ['one', 'two'], + 'supported_on': [ { 'platforms': ['linux'] } ] + } + self.writer._AddExample(self.doc_root, policy) + self.assertEquals( + self.doc_root.toxml(), + '<root><dl style="style_dd dl;">' + '<dt>Linux:</dt>' + '<dd style="style_.monospace;">' + '["one", "two"]' + '</dd></dl></root>') + + def testStringEnumListExample(self): + # Test representation of 'string-enum-list' example values. + policy = { + 'name': 'PolicyName', + 'type': 'string-enum-list', + 'example_value': ['one', 'two'], + 'supported_on': [ { 'platforms': ['linux'] } ] + } + self.writer._AddExample(self.doc_root, policy) + self.assertEquals( + self.doc_root.toxml(), + '<root><dl style="style_dd dl;">' + '<dt>Linux:</dt>' + '<dd style="style_.monospace;">' + '["one", "two"]' + '</dd></dl></root>') + def testStringExample(self): # Test representation of 'string' example values. policy = { diff --git a/grit/format/policy_templates/writers/ios_plist_writer_unittest.py b/grit/format/policy_templates/writers/ios_plist_writer_unittest.py index 14a0cab..4743e4e 100644 --- a/grit/format/policy_templates/writers/ios_plist_writer_unittest.py +++ b/grit/format/policy_templates/writers/ios_plist_writer_unittest.py @@ -180,6 +180,21 @@ class IOSPListWriterUnittest(writer_unittest_common.WriterUnittestCommon): } self._VerifyGeneratedOutput(templates, expected) + def testStringEnumList(self): + templates = self._MakeTemplate('StringEnumListPolicy', + 'string-enum-list', '["a", "b"]', + ''' + 'items': [ + { 'name': 'Foo', 'value': 'a', 'caption': '' }, + { 'name': 'Bar', 'value': 'b', 'caption': '' }, + ], + ''') + + expected = { + 'StringEnumListPolicy': [ "a", "b" ], + } + self._VerifyGeneratedOutput(templates, expected) + def testListOfDictionary(self): templates = self._MakeTemplate( 'ManagedBookmarks', 'dict', diff --git a/grit/format/policy_templates/writers/json_writer_unittest.py b/grit/format/policy_templates/writers/json_writer_unittest.py index 00acde3..05ae255 100644 --- a/grit/format/policy_templates/writers/json_writer_unittest.py +++ b/grit/format/policy_templates/writers/json_writer_unittest.py @@ -231,6 +231,39 @@ class JsonWriterUnittest(writer_unittest_common.WriterUnittestCommon): '}') self.CompareOutputs(output, expected_output) + def testStringEnumListPolicy(self): + # Tests a policy group with a single policy of type 'string-enum-list'. + grd = self.PrepareTest( + '{' + ' "policy_definitions": [' + ' {' + ' "name": "ListPolicy",' + ' "type": "string-enum-list",' + ' "caption": "Example List",' + ' "desc": "Example List",' + ' "items": [' + ' {"name": "ProxyServerDisabled", "value": "one",' + ' "caption": ""},' + ' {"name": "ProxyServerAutoDetect", "value": "two",' + ' "caption": ""},' + ' ],' + ' "supported_on": ["chrome.linux:8-"],' + ' "example_value": ["one", "two"]' + ' },' + ' ],' + ' "placeholders": [],' + ' "messages": {},' + '}') + output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'json', 'en') + expected_output = ( + TEMPLATE_HEADER + + ' // Example List\n' + + HEADER_DELIMETER + + ' // Example List\n\n' + ' //"ListPolicy": ["one", "two"]\n\n' + '}') + self.CompareOutputs(output, expected_output) + def testDictionaryPolicy(self): # Tests a policy group with a single policy of type 'dict'. example = { diff --git a/grit/format/policy_templates/writers/plist_strings_writer.py b/grit/format/policy_templates/writers/plist_strings_writer.py index 08fcddd..966aaf2 100644 --- a/grit/format/policy_templates/writers/plist_strings_writer.py +++ b/grit/format/policy_templates/writers/plist_strings_writer.py @@ -52,7 +52,7 @@ class PListStringsWriter(template_writer.TemplateWriter): if policy['type'] == 'external': # This type can only be set through cloud policy. return - elif policy['type'] in ('int-enum','string-enum'): + elif policy['type'] in ('int-enum','string-enum', 'string-enum-list'): # Append the captions of enum items to the description string. item_descs = [] for item in policy['items']: diff --git a/grit/format/policy_templates/writers/plist_strings_writer_unittest.py b/grit/format/policy_templates/writers/plist_strings_writer_unittest.py index 613a3cd..17fc85c 100644 --- a/grit/format/policy_templates/writers/plist_strings_writer_unittest.py +++ b/grit/format/policy_templates/writers/plist_strings_writer_unittest.py @@ -127,6 +127,111 @@ With a newline.""", '"Description of policy.\\nWith a newline.";') self.assertEquals(output.strip(), expected_output.strip()) + def testStringListPolicy(self): + # Tests a policy group with a single policy of type 'list'. + grd = self.PrepareTest(''' + { + 'policy_definitions': [ + { + 'name': 'ListGroup', + 'type': 'group', + 'caption': '', + 'desc': '', + 'policies': [{ + 'name': 'ListPolicy', + 'type': 'list', + 'caption': 'Caption of policy.', + 'desc': """Description of policy. +With a newline.""", + 'schema': { + 'type': 'array', + 'items': { 'type': 'string' }, + }, + 'supported_on': ['chrome.mac:8-'], + }], + }, + ], + 'placeholders': [], + 'messages': { + 'mac_chrome_preferences': { + 'text': 'Preferences of $1', + 'desc': 'blah' + } + } + }''') + output = self.GetOutput( + grd, + 'fr', + {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, + 'plist_strings', + 'en') + expected_output = ( + 'Chromium.pfm_title = "Chromium";\n' + 'Chromium.pfm_description = "Preferences of Chromium";\n' + 'ListPolicy.pfm_title = "Caption of policy.";\n' + 'ListPolicy.pfm_description = ' + '"Description of policy.\\nWith a newline.";') + self.assertEquals(output.strip(), expected_output.strip()) + + def testStringEnumListPolicy(self): + # Tests a policy group with a single policy of type 'string-enum-list'. + grd = self.PrepareTest(''' + { + 'policy_definitions': [ + { + 'name': 'EnumGroup', + 'type': 'group', + 'caption': '', + 'desc': '', + 'policies': [{ + 'name': 'EnumPolicy', + 'type': 'string-enum-list', + 'caption': 'Caption of policy.', + 'desc': """Description of policy. +With a newline.""", + 'schema': { + 'type': 'array', + 'items': { 'type': 'string' }, + }, + 'items': [ + { + 'name': 'ProxyServerDisabled', + 'value': 'one', + 'caption': 'Option1' + }, + { + 'name': 'ProxyServerAutoDetect', + 'value': 'two', + 'caption': 'Option2' + }, + ], + 'supported_on': ['chrome.mac:8-'], + }], + }, + ], + 'placeholders': [], + 'messages': { + 'mac_chrome_preferences': { + 'text': 'Preferences of $1', + 'desc': 'blah' + } + } + }''') + output = self.GetOutput( + grd, + 'fr', + {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, + 'plist_strings', + 'en') + expected_output = ( + 'Chromium.pfm_title = "Chromium";\n' + 'Chromium.pfm_description = "Preferences of Chromium";\n' + 'EnumPolicy.pfm_title = "Caption of policy.";\n' + 'EnumPolicy.pfm_description = ' + '"one - Option1\\ntwo - Option2\\n' + 'Description of policy.\\nWith a newline.";') + self.assertEquals(output.strip(), expected_output.strip()) + def testIntEnumPolicy(self): # Tests a policy group with a single policy of type 'int-enum'. grd = self.PrepareTest(''' diff --git a/grit/format/policy_templates/writers/plist_writer.py b/grit/format/policy_templates/writers/plist_writer.py index 2297858..6ca905b 100644 --- a/grit/format/policy_templates/writers/plist_writer.py +++ b/grit/format/policy_templates/writers/plist_writer.py @@ -32,6 +32,7 @@ class PListWriter(xml_formatted_writer.XMLFormattedWriter): 'int': 'integer', 'int-enum': 'integer', 'string-enum': 'string', + 'string-enum-list': 'array', 'main': 'boolean', 'list': 'array', 'dict': 'dictionary', @@ -107,7 +108,7 @@ class PListWriter(xml_formatted_writer.XMLFormattedWriter): else: element_type = 'string' self.AddElement(range_list, element_type, {}, str(item['value'])) - elif policy_type == 'list': + elif policy_type in ('list', 'string-enum-list'): subkeys = self._AddKeyValuePair(dict, 'pfm_subkeys', 'array') subkeys_dict = self.AddElement(subkeys, 'dict') subkeys_type = self._AddKeyValuePair(subkeys_dict, 'pfm_type', 'string') diff --git a/grit/format/policy_templates/writers/plist_writer_unittest.py b/grit/format/policy_templates/writers/plist_writer_unittest.py index a9d146d..f76db73 100644 --- a/grit/format/policy_templates/writers/plist_writer_unittest.py +++ b/grit/format/policy_templates/writers/plist_writer_unittest.py @@ -165,6 +165,127 @@ class PListWriterUnittest(writer_unittest_common.WriterUnittestCommon): </array>''') self.assertEquals(output.strip(), expected_output.strip()) + def testListPolicy(self): + # Tests a policy group with a single policy of type 'list'. + grd = self.PrepareTest(''' + { + 'policy_definitions': [ + { + 'name': 'ListGroup', + 'type': 'group', + 'desc': '', + 'caption': '', + 'policies': [{ + 'name': 'ListPolicy', + 'type': 'list', + 'schema': { + 'type': 'array', + 'items': { 'type': 'string' }, + }, + 'supported_on': ['chrome.mac:8-'], + 'desc': '', + 'caption': '', + }], + }, + ], + 'placeholders': [], + 'messages': {}, + }''') + output = self.GetOutput( + grd, + 'fr', + {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, + 'plist', + 'en') + expected_output = self._GetExpectedOutputs( + 'Chromium', 'com.example.Test', '''<array> + <dict> + <key>pfm_name</key> + <string>ListPolicy</string> + <key>pfm_description</key> + <string/> + <key>pfm_title</key> + <string/> + <key>pfm_targets</key> + <array> + <string>user-managed</string> + </array> + <key>pfm_type</key> + <string>array</string> + <key>pfm_subkeys</key> + <array> + <dict> + <key>pfm_type</key> + <string>string</string> + </dict> + </array> + </dict> + </array>''') + self.assertEquals(output.strip(), expected_output.strip()) + + def testStringEnumListPolicy(self): + # Tests a policy group with a single policy of type 'string-enum-list'. + grd = self.PrepareTest(''' + { + 'policy_definitions': [ + { + 'name': 'ListGroup', + 'type': 'group', + 'desc': '', + 'caption': '', + 'policies': [{ + 'name': 'ListPolicy', + 'type': 'string-enum-list', + 'schema': { + 'type': 'array', + 'items': { 'type': 'string' }, + }, + 'items': [ + {'name': 'ProxyServerDisabled', 'value': 'one', 'caption': ''}, + {'name': 'ProxyServerAutoDetect', 'value': 'two', 'caption': ''}, + ], + 'supported_on': ['chrome.mac:8-'], + 'supported_on': ['chrome.mac:8-'], + 'desc': '', + 'caption': '', + }], + }, + ], + 'placeholders': [], + 'messages': {}, + }''') + output = self.GetOutput( + grd, + 'fr', + {'_chromium' : '1', 'mac_bundle_id': 'com.example.Test'}, + 'plist', + 'en') + expected_output = self._GetExpectedOutputs( + 'Chromium', 'com.example.Test', '''<array> + <dict> + <key>pfm_name</key> + <string>ListPolicy</string> + <key>pfm_description</key> + <string/> + <key>pfm_title</key> + <string/> + <key>pfm_targets</key> + <array> + <string>user-managed</string> + </array> + <key>pfm_type</key> + <string>array</string> + <key>pfm_subkeys</key> + <array> + <dict> + <key>pfm_type</key> + <string>string</string> + </dict> + </array> + </dict> + </array>''') + self.assertEquals(output.strip(), expected_output.strip()) + def testIntPolicy(self): # Tests a policy group with a single policy of type 'int'. grd = self.PrepareTest(''' diff --git a/grit/format/policy_templates/writers/reg_writer.py b/grit/format/policy_templates/writers/reg_writer.py index beb1590..dcb70f4 100644 --- a/grit/format/policy_templates/writers/reg_writer.py +++ b/grit/format/policy_templates/writers/reg_writer.py @@ -47,7 +47,7 @@ class RegWriter(template_writer.TemplateWriter): list.sort() methods to sort policies. See TemplateWriter.SortPoliciesGroupsFirst for usage. ''' - is_list = policy['type'] == 'list' + is_list = policy['type'] in ('list', 'string-enum-list') # Lists come after regular policies. return (is_list, policy['name']) @@ -57,7 +57,7 @@ class RegWriter(template_writer.TemplateWriter): if policy['type'] == 'external': # This type can only be set through cloud policy. return - elif policy['type'] == 'list': + elif policy['type'] in ('list', 'string-enum-list'): self._StartBlock(key, policy['name'], list) i = 1 for item in example_value: diff --git a/grit/format/policy_templates/writers/reg_writer_unittest.py b/grit/format/policy_templates/writers/reg_writer_unittest.py index d559c9f..f698cb4 100644 --- a/grit/format/policy_templates/writers/reg_writer_unittest.py +++ b/grit/format/policy_templates/writers/reg_writer_unittest.py @@ -212,6 +212,37 @@ class RegWriterUnittest(writer_unittest_common.WriterUnittestCommon): '"1"="foo"', '"2"="bar"']) + def testStringEnumListPolicy(self): + # Tests a policy group with a single policy of type 'string-enum-list'. + grd = self.PrepareTest( + '{' + ' "policy_definitions": [' + ' {' + ' "name": "ListPolicy",' + ' "type": "string-enum-list",' + ' "caption": "",' + ' "desc": "",' + ' "items": [' + ' {"name": "ProxyServerDisabled", "value": "foo",' + ' "caption": ""},' + ' {"name": "ProxyServerAutoDetect", "value": "bar",' + ' "caption": ""},' + ' ],' + ' "supported_on": ["chrome.linux:8-"],' + ' "example_value": ["foo", "bar"]' + ' },' + ' ],' + ' "placeholders": [],' + ' "messages": {},' + '}') + output = self.GetOutput(grd, 'fr', {'_chromium' : '1'}, 'reg', 'en') + expected_output = self.NEWLINE.join([ + 'Windows Registry Editor Version 5.00', + '', + '[HKEY_LOCAL_MACHINE\\Software\\Policies\\Chromium\\ListPolicy]', + '"1"="foo"', + '"2"="bar"']) + def testDictionaryPolicy(self): # Tests a policy group with a single policy of type 'dict'. example = { |