| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 | 6 |
| 7 """Unittests for grit.format.policy_templates.writers.adml_writer.""" | 7 """Unittests for grit.format.policy_templates.writers.adml_writer.""" |
| 8 | 8 |
| 9 | 9 |
| 10 import os | 10 import os |
| 11 import sys | 11 import sys |
| 12 import unittest | 12 import unittest |
| 13 if __name__ == '__main__': | 13 if __name__ == '__main__': |
| 14 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) | 14 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) |
| 15 | 15 |
| 16 | 16 |
| 17 from grit.format.policy_templates.writers import adml_writer | 17 from grit.format.policy_templates.writers import adml_writer |
| 18 from grit.format.policy_templates.writers import xml_writer_base_unittest | 18 from grit.format.policy_templates.writers import xml_writer_base_unittest |
| 19 | 19 |
| 20 | 20 |
| 21 class AdmlWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest): | 21 class AdmlWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest): |
| 22 | 22 |
| 23 def setUp(self): | 23 def setUp(self): |
| 24 config = { | 24 config = { |
| 25 'app_name': 'test', | 25 'app_name': 'test', |
| 26 'build': 'test', | 26 'build': 'test', |
| 27 'win_supported_os': 'SUPPORTED_TESTOS', | 27 'win_supported_os': 'SUPPORTED_TESTOS', |
| 28 'win_mandatory_category_path': ['test_category'], |
| 29 'win_recommended_category_path': ['test_recommended_category'], |
| 30 'win_category_path_strings': { |
| 31 'test_category': 'TestCategory', |
| 32 'test_recommended_category': 'TestCategory - recommended' |
| 33 }, |
| 28 } | 34 } |
| 29 self.writer = adml_writer.GetWriter(config) | 35 self.writer = adml_writer.GetWriter(config) |
| 30 self.writer.messages = { | 36 self.writer.messages = { |
| 31 'win_supported_winxpsp2': { | 37 'win_supported_winxpsp2': { |
| 32 'text': 'Supported on Test OS or higher', | 38 'text': 'Supported on Test OS or higher', |
| 33 'desc': 'blah' | 39 'desc': 'blah' |
| 34 }, | 40 }, |
| 35 'doc_recommended': { | 41 'doc_recommended': { |
| 36 'text': 'Recommended', | 42 'text': 'Recommended', |
| 37 'desc': 'bleh' | 43 'desc': 'bleh' |
| (...skipping 28 matching lines...) Expand all Loading... |
| 66 self.writer._string_table_elem.removeChild(elem) | 72 self.writer._string_table_elem.removeChild(elem) |
| 67 | 73 |
| 68 def testEmpty(self): | 74 def testEmpty(self): |
| 69 self.writer.BeginTemplate() | 75 self.writer.BeginTemplate() |
| 70 self.writer.EndTemplate() | 76 self.writer.EndTemplate() |
| 71 output = self.writer.GetTemplateText() | 77 output = self.writer.GetTemplateText() |
| 72 expected_output = ( | 78 expected_output = ( |
| 73 '<?xml version="1.0" ?><policyDefinitionResources' | 79 '<?xml version="1.0" ?><policyDefinitionResources' |
| 74 ' revision="1.0" schemaVersion="1.0"><displayName/><description/>' | 80 ' revision="1.0" schemaVersion="1.0"><displayName/><description/>' |
| 75 '<resources><stringTable><string id="SUPPORTED_TESTOS">Supported on' | 81 '<resources><stringTable><string id="SUPPORTED_TESTOS">Supported on' |
| 76 ' Test OS or higher</string></stringTable><presentationTable/>' | 82 ' Test OS or higher</string><string id="test_category">TestCategory' |
| 83 '</string><string id="test_recommended_category">' |
| 84 'TestCategory - recommended</string></stringTable><presentationTable/>' |
| 77 '</resources></policyDefinitionResources>') | 85 '</resources></policyDefinitionResources>') |
| 78 self.AssertXMLEquals(output, expected_output) | 86 self.AssertXMLEquals(output, expected_output) |
| 79 | 87 |
| 80 def testVersionAnnotation(self): | 88 def testVersionAnnotation(self): |
| 81 self.writer.config['version'] = '39.0.0.0' | 89 self.writer.config['version'] = '39.0.0.0' |
| 82 self.writer.BeginTemplate() | 90 self.writer.BeginTemplate() |
| 83 self.writer.EndTemplate() | 91 self.writer.EndTemplate() |
| 84 output = self.writer.GetTemplateText() | 92 output = self.writer.GetTemplateText() |
| 85 expected_output = ( | 93 expected_output = ( |
| 86 '<?xml version="1.0" ?><policyDefinitionResources' | 94 '<?xml version="1.0" ?><policyDefinitionResources' |
| 87 ' revision="1.0" schemaVersion="1.0"><!--test version: 39.0.0.0-->' | 95 ' revision="1.0" schemaVersion="1.0"><!--test version: 39.0.0.0-->' |
| 88 '<displayName/><description/><resources><stringTable>' | 96 '<displayName/><description/><resources><stringTable>' |
| 89 '<string id="SUPPORTED_TESTOS">Supported on' | 97 '<string id="SUPPORTED_TESTOS">Supported on' |
| 90 ' Test OS or higher</string></stringTable><presentationTable/>' | 98 ' Test OS or higher</string><string id="test_category">TestCategory' |
| 99 '</string><string id="test_recommended_category">' |
| 100 'TestCategory - recommended</string></stringTable><presentationTable/>' |
| 91 '</resources></policyDefinitionResources>') | 101 '</resources></policyDefinitionResources>') |
| 92 self.AssertXMLEquals(output, expected_output) | 102 self.AssertXMLEquals(output, expected_output) |
| 93 | 103 |
| 94 def testPolicyGroup(self): | 104 def testPolicyGroup(self): |
| 95 empty_policy_group = { | 105 empty_policy_group = { |
| 96 'name': 'PolicyGroup', | 106 'name': 'PolicyGroup', |
| 97 'caption': 'Test Group Caption', | 107 'caption': 'Test Group Caption', |
| 98 'desc': 'This is the test description of the test policy group.', | 108 'desc': 'This is the test description of the test policy group.', |
| 99 'policies': [ | 109 'policies': [ |
| 100 {'name': 'PolicyStub2', | 110 {'name': 'PolicyStub2', |
| 101 'type': 'main'}, | 111 'type': 'main'}, |
| 102 {'name': 'PolicyStub1', | 112 {'name': 'PolicyStub1', |
| 103 'type': 'main'}, | 113 'type': 'main'}, |
| 104 ], | 114 ], |
| 105 } | 115 } |
| 106 self._InitWriterForAddingPolicyGroups(self.writer) | 116 self._InitWriterForAddingPolicyGroups(self.writer) |
| 107 self.writer.BeginPolicyGroup(empty_policy_group) | 117 self.writer.BeginPolicyGroup(empty_policy_group) |
| 108 self.writer.EndPolicyGroup | 118 self.writer.EndPolicyGroup |
| 109 # Assert generated string elements. | 119 # Assert generated string elements. |
| 110 output = self.GetXMLOfChildren(self.writer._string_table_elem) | 120 output = self.GetXMLOfChildren(self.writer._string_table_elem) |
| 111 expected_output = ( | 121 expected_output = ( |
| 112 '<string id="SUPPORTED_TESTOS">' | 122 '<string id="SUPPORTED_TESTOS">' |
| 113 'Supported on Test OS or higher</string>\n' | 123 'Supported on Test OS or higher</string>\n' |
| 124 '<string id="test_category">TestCategory</string>\n' |
| 125 '<string id="test_recommended_category">' |
| 126 'TestCategory - recommended</string>\n' |
| 114 '<string id="PolicyGroup_group">Test Group Caption</string>') | 127 '<string id="PolicyGroup_group">Test Group Caption</string>') |
| 115 self.AssertXMLEquals(output, expected_output) | 128 self.AssertXMLEquals(output, expected_output) |
| 116 # Assert generated presentation elements. | 129 # Assert generated presentation elements. |
| 117 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) | 130 output = self.GetXMLOfChildren(self.writer._presentation_table_elem) |
| 118 expected_output = '' | 131 expected_output = '' |
| 119 self.AssertXMLEquals(output, expected_output) | 132 self.AssertXMLEquals(output, expected_output) |
| 120 | 133 |
| 121 def testMainPolicy(self): | 134 def testMainPolicy(self): |
| 122 main_policy = { | 135 main_policy = { |
| 123 'name': 'DummyMainPolicy', | 136 'name': 'DummyMainPolicy', |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 '</presentation>\n' | 441 '</presentation>\n' |
| 429 '<presentation id="EnumPolicy.B">\n' | 442 '<presentation id="EnumPolicy.B">\n' |
| 430 ' <dropdownList refId="EnumPolicy.B">' | 443 ' <dropdownList refId="EnumPolicy.B">' |
| 431 'Enum policy B label</dropdownList>\n' | 444 'Enum policy B label</dropdownList>\n' |
| 432 '</presentation>') | 445 '</presentation>') |
| 433 self.AssertXMLEquals(output, expected_output) | 446 self.AssertXMLEquals(output, expected_output) |
| 434 | 447 |
| 435 | 448 |
| 436 if __name__ == '__main__': | 449 if __name__ == '__main__': |
| 437 unittest.main() | 450 unittest.main() |
| OLD | NEW |